@thi.ng/file-io
Version:
Assorted file I/O utils (with logging support) for NodeJS/Bun
13 lines (12 loc) • 420 B
JavaScript
import { isString } from "@thi.ng/checks/is-string";
import { writeFileSync } from "node:fs";
import { ensureDirForFile } from "./dir.js";
const writeFile = (path, body, opts, logger, dryRun = false) => {
logger?.info(`${dryRun ? "[dryrun] " : ""}writing file: ${path}`);
if (dryRun) return;
ensureDirForFile(path);
writeFileSync(path, body, !opts && isString(body) ? "utf-8" : opts);
};
export {
writeFile
};