UNPKG

@stryke/fs

Version:

A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.

2 lines (1 loc) 774 B
import{correctPath as i}from"@stryke/path/correct-path";import{existsSync as n}from"@stryke/path/exists";import{findFilePath as c}from"@stryke/path/file-path-fns";import{writeFileSync as s}from"node:fs";import{writeFile as d}from"node:fs/promises";import{createDirectory as p,createDirectorySync as a}from"./helpers";export const writeFileSync=(e,t="",o={})=>{if(!e)throw new Error("No file path provided to write data");const r=c(i(e));if(!n(r))if(o.createDirectory!==!1)a(r);else throw new Error(`Directory ${r} does not exist`);s(e,t||"",o)},writeFile=async(e,t="",o={})=>{if(!e)throw new Error("No file path provided to read data");const r=c(i(e));if(!n(r))if(o.createDirectory!==!1)await p(r);else throw new Error(`Directory ${r} does not exist`);return d(e,t||"",o)};