@visulima/fs
Version:
Human friendly file system utilities for Node.js
26 lines (23 loc) • 817 B
JavaScript
import { toPath } from '@visulima/path/utils';
import parseJson from './parseJson-n9THWOFI.mjs';
import readFileSync from './readFileSync-Cck96_o0.mjs';
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
function readJsonSync(path, reviver, options) {
if (typeof reviver === "object") {
options = reviver;
reviver = undefined;
}
const content = readFileSync(path, {
buffer: true,
encoding: undefined
});
let data = new TextDecoder().decode(content);
const { beforeParse, color } = options ?? {};
if (typeof beforeParse === "function") {
data = beforeParse(data);
}
return parseJson(data, reviver, toPath(path), { color });
}
__name(readJsonSync, "readJsonSync");
export { readJsonSync as default };