blob: b5ff48e5e087d5239640257b45f81f30059fc47b [file] [log] [blame]
Brandon Walderman110d5922022-04-19 10:35:07 -07001function 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
8function 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
14module.exports = { stringify, stripBom }