fs-funcs
A very limited subset of fs functions I use every day
Install
npm i fs-funcs
Package on npm
API
- exec-file
- exec
- exist
- first-bytes
- get-filesize
- is-directory
- is-file
- is-symlink
- mkdir
- read-json
- rm
- stat
- write-json
exec-file(file, [args], [options])
Execute the file
Argument | Action |
---|---|
file | the executed file |
args | the list of string arguments |
options | optional options , default to { maxBuffer: 20971520 } |
args
can be an Array
or a String
The default maxBuffer
is 20 Mo instead of 200 ko
result
is an object with two properties { stdout, stderr }
The EOF chars \n
or \r\n
are removed from the returned strings stdout
and stderr
const execfile =
exec(command, [options])
Execute the command
Argument | Action |
---|---|
command | the executed command |
options | optional options , default to { maxBuffer: 20971520 } |
The default maxBuffer
is 20 Mo instead of 200 ko
result
is an object with two properties { stdout, stderr }
The EOF chars \n
or \r\n
are removed from the returned strings stdout
and stderr
const exec =
exist(path, [nofollow])
Check if path
exists
Argument | Action |
---|---|
path | the tested path |
nofollow | optional nofollow , default to false . If true , test the symlink and not is target |
const exist =
first-bytes(path, [length])
Get a Buffer with the first bytes of a file
Argument | Action |
---|---|
path | the file path |
length | optional length , default to 15 |
const firstbytes =
get-filesize(path)
Get the size of a file
Argument | Action |
---|---|
path | the file path |
const getfilesize =
is-directory(path, [nothrow])
Check if path
is a directory
Argument | Action |
---|---|
path | the tested path |
nothrow | optional nothrow , default to false . If true , resolve to false instead of throw an error |
const isdirectory =
is-file(path, [nothrow])
Check if path
is a file
Argument | Action |
---|---|
path | the tested path |
nothrow | optional nothrow , default to false . If true , resolve to false instead of throw an error |
const isfile =
is-symlink(path, [nothrow])
Check if path
is a symlink
Argument | Action |
---|---|
path | the tested path |
nothrow | optional nothrow , default to false . If true , resolve to false instead of throw an error |
const issymlink =
mkdir(path, [pop])
Recursively mkdir
Argument | Action |
---|---|
path | the created path |
pop | optional pop , default to false . If true , remove the last part of the path |
const mkdir =
read-json(path)
Read and serialize a JSON file
Argument | Action |
---|---|
path | the file path |
const readjson =
rm(path)
Remove a path
Argument | Action |
---|---|
path | the removed path |
const rm =
stat(path, [nofollow])
Get some data about path
Argument | Action |
---|---|
path | the tested path |
nofollow | optional nofollow , default to false . If true , test the symlink and not is target |
The booleans readable
, writable
and executable
are related to the user privileges
const stat =
write-json(path, data, [minify])
Write a prettified JSON file. The directory tree is created if needed
Argument | Action |
---|---|
path | the created path |
data | the stringified data |
minify | optional minify , default to false . If true , the JSON will not be beautified |
const writejson =
License
MIT