Closed
Description
Would be nice if this had 0 dependencies:
import {readFileSync} from 'node:fs';
import {readFile} from 'node:fs/promises';
const parse = (uint8, options = {}) => {
// unlike buf.toString('utf8') or or readFile(path, 'utf8'), TextDecoder will remove BOM
let data = new TextDecoder().decode(uint8);
if (typeof options.beforeParse === 'function') {
data = options.beforeParse(data);
}
return JSON.parse(data, options.reviver);
};
export const loadJsonFile = (filePath, options) =>
readFile(filePath).then(data => parse(data, options));
export const loadJsonFileSync = (filePath, options) =>
parse(readFileSync(filePath), options);
Metadata
Metadata
Assignees
Labels
No labels