README
About
node:fs
module wrapper.
Install
npm install @xan105/fs
API
⚠️ This module is only available as an ECMAScript module (ESM) starting with version 2.0.0.
Previous version(s) are CommonJS (CJS) with an ESM wrapper.
Named export
- path
- win32
readFile(filePath: string, options?: obj): Promise<string | Buffer>
bomWarning
(default: true): warn on utf bom removal.
Auto remove utf bom (only in string data).
Otherwise same as fs.readFile().
readJSON(filePath: string): Promise<string>
writeFile(filePath: string, data: any, options?: obj): Promise<string>
bom
(default: false): add utf bom (only in string data).
Create target parent dir if not exist.
Otherwise same as fs.writeFile().
writeJSON(filePath: string, data: any, pretty: boolean): Promise<string>
pretty
(default: true): insert white space into the output JSON string for readability purposes.
copyFile(src: string, dest: string, flags: any): Promise<void>
Create target parent dir if not exist.
unlink(filePath: string): Promise<void>
alias: deleteFile(filePath: string): Promise<void>
alias: rm(filePath: string): Promise<void>
Silently fails on error.
mv(oldPath: string, newPath: string): Promise<string>
Create target parent dir if not exist. Move on same drive otherwise copy to target and delete origin.
exists(path: string): Promise<boolean>
existsAndIsOlderOrYoungerThan(path: string, option?: obj): Promise<boolean>
timeUnit
: s|m|h|d|w|M|Y (default day)
time
: amount of time unit (default 1)
younger
: compare mode younger than (true) or older than (false/default)
existsAndIsOlderThan(path: string, option?: obj): Promise<boolean>
timeUnit
: s|m|h|d|w|M|Y (default day)
time
: amount of time unit (default 1)
existsAndIsYoungerThan(path: string, option?: obj): Promise<boolean>
timeUnit
: s|m|h|d|w|M|Y (default day)
time
: amount of time unit (default 1)
stat(path: string): Promise<any>
alias stats(path: string): Promise<any>
On error returns an empty obj.
mkdir(dirPath: string): Promise<void>
Recursive.
rmdir(dirPath: string): Promise<void>
Recursive. Delete files if any.
isDirEmpty(dirPath: string): Promise<boolean>
hashFile(filePath: string, algo?: string): Promise<string>
algo
defaults to "sha1". Uses stream.
path
resolve(path: string): string
Handles a very rare bug (user reported).
dirname(path: string): string
Handles path and fileURL.
normalize(path: string, win32?: boolean): string
replace every \\
with /
When win32
is set to true (default is false)
replace every /
with \\