@visulima/fs
Version:
Human friendly file system utilities for Node.js
28 lines (24 loc) • 827 B
JavaScript
;
const utils = require('@visulima/path/utils');
const parseJson = require('./parseJson-DcUo4Rpt.cjs');
const readFile = require('./readFile-iFUhZHnh.cjs');
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
async function readJson(path, reviver, options) {
if (typeof reviver === "object") {
options = reviver;
reviver = undefined;
}
const content = await readFile(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, utils.toPath(path), { color });
}
__name(readJson, "readJson");
module.exports = readJson;