UNPKG

@visulima/fs

Version:

Human friendly file system utilities for Node.js

23 lines (20 loc) 642 B
import { toPath } from '@visulima/path/utils'; import parseJson from './parseJson-C8xb-3LR.js'; import readFileSync from './readFileSync-BDgEnnqT.js'; function readJsonSync(path, reviver, options) { if (typeof reviver === "object") { options = reviver; reviver = void 0; } const content = readFileSync(path, { buffer: true, encoding: void 0 }); let data = new TextDecoder().decode(content); const { beforeParse, color } = options ?? {}; if (typeof beforeParse === "function") { data = beforeParse(data); } return parseJson(data, reviver, toPath(path), { color }); } export { readJsonSync as default };