@thi.ng/file-io
Version:
Assorted file I/O utils (w/ logging support) for NodeJS/Bun
22 lines (21 loc) • 649 B
JavaScript
import { readText, readTextAsync, writeText, writeTextAsync } from "./text.js";
const readJSON = (path, logger) => JSON.parse(readText(path, logger));
const readJSONAsync = async (path, logger) => JSON.parse(await readTextAsync(path, logger));
const writeJSON = (path, obj, replacer, space, logger, dryRun = false) => writeText(
path,
JSON.stringify(obj, replacer, space) + "\n",
logger,
dryRun
);
const writeJSONAsync = (path, obj, replacer, space, logger, dryRun = false) => writeTextAsync(
path,
JSON.stringify(obj, replacer, space) + "\n",
logger,
dryRun
);
export {
readJSON,
readJSONAsync,
writeJSON,
writeJSONAsync
};