UNPKG

@visulima/fs

Version:

Human friendly file system utilities for Node.js

23 lines (20 loc) 634 B
import { toPath } from '@visulima/path/utils'; import parseJson from './parseJson-C8xb-3LR.js'; import readFile from './readFile-BcK0rkht.js'; async function readJson(path, reviver, options) { if (typeof reviver === "object") { options = reviver; reviver = void 0; } const content = await readFile(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 { readJson as default };