| 16 | } |
| 17 | |
| 18 | export function readJSONSync(file, options = {}) { |
| 19 | if (typeof options === 'string') { |
| 20 | options = { encoding: options }; |
| 21 | } |
| 22 | |
| 23 | const shouldThrow = 'throws' in options ? options.throws : true; |
| 24 | |
| 25 | try { |
| 26 | let content = readFileSync(file, options); |
| 27 | content = stripBom(content); |
| 28 | return JSON.parse(content, options.reviver); |
| 29 | } catch (err) { |
| 30 | if (shouldThrow) { |
| 31 | err.message = `${file}: ${err.message}`; |
| 32 | throw err; |
| 33 | } else { |
| 34 | return null; |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | export function stringify(obj, { EOL = '\n', finalEOL = true, replacer = null, spaces } = {}) { |
| 40 | const EOF = finalEOL ? EOL : ''; |