|
4 tahun lalu | |
---|---|---|
.. | ||
CHANGELOG.md | 4 tahun lalu | |
LICENSE | 4 tahun lalu | |
README.md | 4 tahun lalu | |
klaw-sync.js | 4 tahun lalu | |
package.json | 4 tahun lalu |
klaw-sync
is a Node.js recursive file system walker, which is the synchronous counterpart of klaw. It lists all files and directories inside a directory recursively and returns an array of objects that each object has two properties: path
and stats
. path
is the full path of the file or directory and stats
is an instance of fs.Stats.
npm i klaw-sync
directory
{String}
options
{Object}
optional (all options are false
by default)
ignore
{String | Array<String>}
any paths or micromatch patterns to ignore (can be string or an array of strings)nodir
{Boolean}
return only files (ignore directories)nofile
{Boolean}
return only directories (ignore files)return: {Array<Object>}
[{path: '', stats: {}}]
var klawSync = require('klaw-sync')
var paths = klawSync('/some/dir')
// paths = [{path: '/some/dir/dir1', stats: {}}, {path: '/some/dir/file1', stats: {}}]
catch error
var klawSync = require('klaw-sync')
var paths
try {
paths = klawSync('/some/dir')
} catch (er) {
console.error(er)
}
console.dir(paths)
files only
var klawSync = require('klaw-sync')
var files = klawSync('/some/dir', {nodir: true})
// files = [{path: '/some/dir/file1', stats: {}}, {path: '/some/dir/file2', stats: {}}]
directories only
var klawSync = require('klaw-sync')
var dirs = klawSync('/some/dir', {nofile: true})
// dirs = [{path: '/some/dir/dir1', stats: {}}, {path: '/some/dir/dir2', stats: {}}]
ignore node_modules
var klawSync = require('klaw-sync')
var paths = klawSync('/some/dir', {ignore: 'node_modules'})
ignore node_modules
and .git
using micromatch patterns
var klawSync = require('klaw-sync')
var paths = klawSync('/some/dir', {ignore: '{node_modules,.git}'})
ignore node_modules
, .git
and all *.js
files using micromatch patterns
var klawSync = require('klaw-sync')
var paths = klawSync('/some/dir', {ignore: ['{node_modules,.git}', '*.js']})
lint: npm run lint
unit test: npm run unit
lint & unit: npm test
The bm.js
runs some basic benchmark tests for two cases, without --ignore
(basic usage) and with --ignore
, on these modules:
Just for fun, it turned out (as of January 25, 2017) for the most cases klaw-sync
is faster than other modules!
#####run benchmark
To run benchmark, just specify the root --dir=
. To ignore paths or patterns, use -i
flag.
npm run benchmark -- --dir=/some/dir
npm run benchmark -- --dir=/some/dir -i "node_modules"
npm run benchmark -- --dir=/some/dir -i "node_modules" -i "*.js"
Special thanks to:
for their contribution and support.
Licensed under MIT