UNPKG

@thi.ng/file-io

Version:

Assorted file I/O utils (with logging support) for NodeJS/Bun

19 lines (18 loc) 458 B
import { isArray } from "@thi.ng/checks/is-array"; import { readFileSync } from "node:fs"; import { writeFile } from "./write.js"; const readText = (path, logger, encoding = "utf-8") => { logger?.debug("reading file:", path); return readFileSync(path, encoding); }; const writeText = (path, body, logger, dryRun = false) => writeFile( path, isArray(body) ? body.join("\n") : body, "utf-8", logger, dryRun ); export { readText, writeText };