utils.js
1 function stringify (obj, { EOL = '\n', finalEOL = true, replacer = null, spaces } = {}) { 2 const EOF = finalEOL ? EOL : '' 3 const str = JSON.stringify(obj, replacer, spaces) 4 5 return str.replace(/\n/g, EOL) + EOF 6 } 7 8 function stripBom (content) { 9 // we do this because JSON.parse would convert it to a utf8 string if encoding wasn't specified 10 if (Buffer.isBuffer(content)) content = content.toString('utf8') 11 return content.replace(/^\uFEFF/, '') 12 } 13 14 module.exports = { stringify, stripBom }