1.1.11 • Published 3 years ago
efdir v1.1.11
efdir
file and dir
Install
npm install efdir
Cli
npm install efdir -g
0. jefdir_mkdirp_and_touch
//last c NOT-end-with '/'
jefdir_mkdirp_and_touch a/b/c
EFDIR# tree a
a
└── b
└── c //file
1 directory, 1 file
EFDIR#
//last f/ end with '/'
jefdir_mkdirp_and_touch d/e/f/
>
EFDIR# tree d
d
└── e
└── f //dir
2 directories, 0 files
1. jefdir_dir_to_json
jefdir_dir_to_json.js -src ../node_modules/semver/
//NOT include content in json
{
'CHANGELOG.md': '',
'LICENSE': '',
'README.md': '',
'bin':
{
'semver': ''
},
'package.json': '',
'range.bnf': '',
'semver.js': ''
}
bin#
bin# ls -l
total 12
-rw-r--r-- 1 root root 501 Oct 7 11:31 dir_to_json.js
-rw-r--r-- 1 root root 95 Oct 7 05:12 mkdirp_and_touch.js
-rw-r--r-- 1 root root 173 Oct 7 11:33 opt-JS-EFDIR-node_modules-semver.json //NOT include content in json
jefdir_dir_to_json.js -src ../node_modules/semver/ --copy_content
//INCLUDE content in json
bin# ls -l
total 92
-rw-r--r-- 1 root root 501 Oct 7 11:31 dir_to_json.js
-rw-r--r-- 1 root root 95 Oct 7 05:12 mkdirp_and_touch.js
-rw-r--r-- 1 root root 84020 Oct 7 11:31 opt-JS-EFDIR-node_modules-semver.json //-----INCLUDE content in json
2. jefdir_json_to_dir
bin#
{
'CHANGELOG.md': '',
'LICENSE': '',
'README.md': '',
'bin':
{
'semver': ''
},
'package.json': '',
'range.bnf': '',
'semver.js': ''
}
bin#
jefdir_json_to_dir -src opt-JS-EFDIR-node_modules-semver.json -dst tst
bin# tree tst/
tst/
├── bin
│ └── semver
├── CHANGELOG.md
├── LICENSE
├── package.json
├── range.bnf
├── README.md
└── semver.js
1 directory, 7 files
Usage
0. walkdir
EFDIR# node
> efdir = require("./efdir.js")
>
> var arr = efdir.walkdir("../EFDIR")
undefined
> arr
[ '/opt/JS/EFDIR/LICENSE',
'/opt/JS/EFDIR/README.md',
'/opt/JS/EFDIR/efdir.js',
'/opt/JS/EFDIR/node_modules/abbrev/LICENSE'
....
]
1. with filter
> var efdir = require("./efdir.js")
undefined
> var arr = efdir.walkdir("../EFDIR","only-dir")
undefined
> arr
[ '/opt/JS/EFDIR',
'/opt/JS/EFDIR/node_modules',
'/opt/JS/EFDIR/node_modules/.bin',
'/opt/JS/EFDIR/node_modules/abbrev',
'/opt/JS/EFDIR/node_modules/balanced-match',
......
]
> var arr = efdir.walkdir("../EFDIR",function(r){
... return(r.includes("realpath"))
... })
undefined
> arr
[ '/opt/JS/EFDIR/node_modules/fs.realpath',
'/opt/JS/EFDIR/node_modules/fs.realpath/LICENSE',
'/opt/JS/EFDIR/node_modules/fs.realpath/README.md',
'/opt/JS/EFDIR/node_modules/fs.realpath/index.js',
'/opt/JS/EFDIR/node_modules/fs.realpath/old.js',
'/opt/JS/EFDIR/node_modules/fs.realpath/package.json' ]
>
> efdir.WALK_FILTERS
{ 'no-dot-files': [Function: no-dot-files],
none: [Function: none],
'only-dot-files': [Function: only-dot-files],
'only-dir': [Function: only-dir],
'only-file': [Function: only-file] }
>
2. with depth range
> var efdir = require("./efdir.js")
undefined
> var arr = efdir.walkDirInRange("../EFDIR",{start:0,end:2})
undefined
> arr
[ '/opt/JS/EFDIR/LICENSE',
'/opt/JS/EFDIR/README.md',
'/opt/JS/EFDIR/efdir.js',
'/opt/JS/EFDIR/package.json' ]
>
3. transcodec
var src_str = "你们好"
var dst_str = efdir.transcodec(src_str,'utf8','latin1')
> efdir.transcodec(dst_str,'latin1','utf8')
'你们好'
>
4. rfile and wfile
> str_latin1 = efdir.rfile('txt','latin1')
'å�¤æ�æ�¯ä¸�æ�¯æ��件夹\n'
efdir.wfile('txt.latin1',str_latin1,'latin1')
> efdir.rfile('txt.latin1','utf8')
'判断是不是文件夹\n'
efdir.rfile('txt','utf8')
5. mkdirp_and_touch
> efidr.mkdirp_and_touch('a/b/c')
[ 'a', 'a/b', 'a/b/c' ]
>
EFDIR# tree a
a
└── b
└── c //file
1 directory, 1 file
EFDIR#
> efdir.mkdirp_and_touch('d/e/f/') //last end with '/'
[ 'd', 'd/e', 'd/e/f', 'd/e/f.dir/' ]
>
EFDIR# tree d
d
└── e
└── f //dir
2 directories, 0 files
6. dict_to_pl$entries
var efdir = require('efdir')
var j = {
'CHANGELOG.md': '',
'LICENSE': '',
'README.md': '',
'bin':
{
'semver': ''
},
'package.json': '',
'range.bnf': '',
'semver.js': ''
}
efdir.dict_to_pl$entries(j,'./')
> efdir.dict_to_pl$entries(j,'./')
[
[ '/opt/JS/EFDIR', {} ],
[ '/opt/JS/EFDIR/CHANGELOG.md', '' ],
[ '/opt/JS/EFDIR/LICENSE', '' ],
[ '/opt/JS/EFDIR/README.md', '' ],
[ '/opt/JS/EFDIR/bin', {} ],
[ '/opt/JS/EFDIR/bin/semver', '' ],
[ '/opt/JS/EFDIR/package.json', '' ],
[ '/opt/JS/EFDIR/range.bnf', '' ],
[ '/opt/JS/EFDIR/semver.js', '' ]
]
>
APIS
is_file(path_str)
is_dir(path_str)
transcodec(s,src_codec,dst_codec)
rjson(fn)
wjson(fn,js)
rfile(fn)
wfile(fn,s)
lsdir(dn)
WALK_FILTERS
walkdir(root, filter)
walkDirInRange(root,d={start:0},filter)
dir_to_json(fn,{copy_content:false})
dict_to_pl$entries(j,dstfn="./")
json_to_dir(j,dstfn="./")
cfg_to_dir(srcfn,dstfn="./")
rplc_ext(fn,new_ext)
rplc_name(fn,new_name)
unparse(d)
PACKAGE DEPENDANY
(optional)
1.1.11
3 years ago
1.1.8
4 years ago
1.1.10
4 years ago
1.1.7
4 years ago
1.1.6
5 years ago
1.1.5
5 years ago
1.1.4
5 years ago
1.1.3
5 years ago
1.1.2
5 years ago
1.1.0
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago