@visulima/fs
Version:
Human friendly file system utilities for Node.js
25 lines (22 loc) • 933 B
JavaScript
import { stringify } from 'yaml';
import writeFile from './writeFile-NT1fLEEe.js';
async function writeYaml(path, data, replacer, options) {
let stringifyOptions;
let effectiveReplacer;
let space;
if (typeof replacer === "object" && replacer !== null && !Array.isArray(replacer) && typeof replacer !== "function") {
stringifyOptions = replacer;
effectiveReplacer = stringifyOptions.replacer;
space = stringifyOptions.space;
} else if (typeof options === "object" && options !== null) {
stringifyOptions = options;
effectiveReplacer = replacer;
space = stringifyOptions.space ?? (typeof options === "number" || typeof options === "string" ? options : void 0);
} else {
effectiveReplacer = replacer;
space = options;
}
const content = stringify(data, effectiveReplacer, space ?? stringifyOptions);
await writeFile(path, content, stringifyOptions);
}
export { writeYaml as default };