MCPcopy Create free account
hub / github.com/6pac/SlickGrid / readJSONSync

Function readJSONSync

scripts/fs-utils.mjs:18–37  ·  view source on GitHub ↗
(file, options = {})

Source from the content-addressed store, hash-verified

16}
17
18export 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
39export function stringify(obj, { EOL = '\n', finalEOL = true, replacer = null, spaces } = {}) {
40 const EOF = finalEOL ? EOL : '';

Callers 1

release.mjsFile · 0.90

Calls 1

stripBomFunction · 0.85

Tested by

no test coverage detected