nv-file-dir
v1.0.0
Published
nv-file-dir ============== - simple async wrap OF serveral-dir-method OF fs/promises OF nodejs - remove,mk,make from 4 formats: paths,pls,dict,tac
Downloads
1
Readme
nv-file-dir
- simple async wrap OF serveral-dir-method OF fs/promises OF nodejs
- remove,mk,make from 4 formats: paths,pls,dict,tac
install
- npm install nv-file-dir
usage
const {
remove,
mk_one_dir,
mk_from_tac,
mk_from_dict,
mk_from_pls,
mk_from_paths,
} = require("nv-file-dir");
example
basic
> await x.remove("TT")
Uncaught [Error: ENOTEMPTY: directory not empty, rmdir 'TT'] {
errno: -39,
code: 'ENOTEMPTY',
syscall: 'rmdir',
path: 'TT'
}
> await x.remove("TT",true) // remove(dirname_or_filename,force=false)
[
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/TT/xx',
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/TT'
]
>
mk
from PATHS
var paths = [
"a/b/c",
"a/c",
"a/b/e/" , //dir ends with "/"
"a/f/../g" // a/g
]
await mk_from_paths(paths)
> await mk_from_paths(paths)
{
existed: [
'/',
'/opt/',
'/opt/JS/',
'/opt/JS/NV6-/',
'/opt/JS/NV6-/nvfile/',
'/opt/JS/NV6-/nvfile/pkgs/',
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/'
],
created: [
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a/',
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a/b/',
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a/b/c',
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a/b/e/',
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a/c',
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a/g'
]
}
nv-file-dir# tree a
a
├── b
│ ├── c
│ └── e
├── c
└── g
2 directories, 3 files
from PLS
var pls = [
["a","b","c"],
["a","c"],
["a","b","e",""], , //dir ends with ""
["a","g"]
]
await mk_from_pls(pls)
from DICT
var d = {
a: {
b:{
c:null, //null means file
e:{} //this means empty dir
},
c:null, //null means file
g:null, //null means file
}
}
await mk_from_dict(d);
from TAC
attribs
> mk_from_tac
[AsyncFunction: mk_from_tac] {
ATTR: {
dir: { type: 'dir' },
file: { type: 'file', data: 'some content str or buf' },
slink: { type: 'slink', data: 'softlink/to/path' }
}
}
>
var tac = [
'a',[
'b',[
'c',
'e',{type:'dir'} //this is a empty dir
],
'c',{type:'file',data:'some content'}, //this is a file with content
'g',{type:'slink',data:'a/b/c'} //this is a softlink to a/b/c
]
]
> await mk_from_tac(tac)
{
existed: [],
created: [
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a',
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a/b',
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a/b/c',
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a/b/e',
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a/c',
'/opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a/g'
]
}
>
/*
nv-file-dir# tree a
a
├── b
│ ├── c
│ └── e
├── c
└── g -> /opt/JS/NV6-/nvfile/pkgs/nv-file-dir/a/b/c
2 directories, 3 files
nv-file-dir# cat a/c
some content
*/
APIS
{
mk_one_dir: [AsyncFunction: mk_one_dir],
mk_from_paths: [AsyncFunction: mk_from_paths],
mk_from_pls: [AsyncFunction: mk_from_pls],
mk_from_dict: [AsyncFunction: mk_from_dict],
mk_from_tac: [AsyncFunction: mk_from_tac] {
ATTR: { dir: [Object], file: [Object], slink: [Object] }
},
remove: [AsyncFunction: remove],
is_dir_path: [Function: is_dir_path],
fmt_paths: [Function: fmt_paths],
is_dir_pl: [Function: is_dir_pl],
is_abs_pl: [Function: is_abs_pl],
fmt_pls: [Function: fmt_pls]
}
LICENSE
- ISC