@thi.ng/file-io
Version:
Assorted file I/O utils (w/ logging support) for NodeJS/Bun
11 lines (10 loc) • 393 B
JavaScript
import { existsSync, mkdirSync, statSync } from "node:fs";
import { dirname } from "node:path";
const ensureDir = (dir) => dir.length > 0 && !existsSync(dir) ? (mkdirSync(dir, { recursive: true }), true) : false;
const ensureDirForFile = (path) => ensureDir(dirname(path));
const isDirectory = (path) => statSync(path).isDirectory();
export {
ensureDir,
ensureDirForFile,
isDirectory
};