@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) • 619 B
JavaScript
import{existsSync as e,readFileSync as t}from"node:fs";import{readFile as i}from"node:fs/promises";export const readFileSync=r=>{try{if(!r)throw new Error("No file path provided to read data");return t(r,{encoding:"utf8"})}catch{throw new Error("An error occurred writing data to file")}},readFile=async r=>{try{if(!r)throw new Error("No file path provided to read data");return await i(r,{encoding:"utf8"})}catch{throw new Error("An error occurred writing data to file")}};export function readFileIfExistingSync(r){return e(r)?readFileSync(r):""}export async function readFileIfExisting(r){return e(r)?readFile(r):""}