File system manipulation without headache.
๐ฆ Scoped @xan105
packages are for my own personal use but feel free to use them.
npm install @xan105/fs
Compatibility
- Node โ๏ธ
Previous version(s) are CommonJS (CJS) with an ESM wrapper.
Auto remove utf bom (string only).
Parse JSON and remove utf bom if any.
Create target parent dir if doesn't exist.
โ๏ธ Options:
-
bom
(default: false)add utf bom (string only).
Write JSON to file and return filePath for convenience.
โ๏ธ Options:
-
pretty
(default: true)insert white space into the output JSON string for readability purposes.
-
bigint2str
(default: true)convert bigint to string.
Create target parent dir if doesn't exist.
Create target parent dir if doesn't exist.
Move on same drive otherwise copy to target and delete origin.
โ๏ธ Options:
time
: amount of time unit (default 1)timeUnit
: s|m|h|d|w|M|Y (default day)younger
: compare mode younger than (true) or older than (false/default)
โ๏ธ Options:
time
: amount of time unit (default 1)timeUnit
: s|m|h|d|w|M|Y (default day)
โ๏ธ Options:
time
: amount of time unit (default 1)timeUnit
: s|m|h|d|w|M|Y (default day))
alias stats(path: string): Promise<object>
On error returns an empty object.
Recursive.
alias unlink(path: string): Promise<void>
alias deleteFile(path: string): Promise<void>
alias rmdir(path: string): Promise<void>
Nuke the target ๐๐ฅ.
Hash specified file (use stream). algo
defaults to "sha256".
Create, change and modify timestamps of a file.
List directory contents.
โ๏ธ Options:
-
verbose
: boolean (false) -
recursive
: boolean (false) -
absolute
: boolean false)Return absolute or relative path
-
follow
: boolean (false)Whether or not to follow symlink
-
normalize
: boolean (false)Whether or not to normalize path seperator to "/"
-
ignore
:dir
: boolean (false)file
: boolean (false)symlink
: boolean (false)socket
: boolean (false)dot
: boolean (true)
-
filter
: string[] (empty) -
whitelist
: boolean (false)Turn the filter list into a whitelist
-
ext
: string[] (empty)Allowed file extension
-
pattern
: RegExp (none)
Return value:
If verbose
is true
returns a detailed list as
[
{
name: string, //file name
path: string, //path of file
link?: string | undefined //symlink target
},
...
]
Otherwise string[] (path of file)
Compare files to determine if they are identical.
Comparison is by default done with "sha1" algo
(cf: hashFile()
) unless files size don't match.
Resolve fileURL and path if necessary.
Handles path and fileURL.
replace every \\
with /
When win32
is set to true (default is false)
replace every /
with \\