root edcb89e9dc init il y a 4 ans
..
CHANGELOG.md edcb89e9dc init il y a 4 ans
LICENSE edcb89e9dc init il y a 4 ans
README.md edcb89e9dc init il y a 4 ans
klaw-sync.js edcb89e9dc init il y a 4 ans
package.json edcb89e9dc init il y a 4 ans

README.md

klaw-sync

npm Package Build Status windows Build status

Standard JavaScript

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.

Install

npm i klaw-sync

Usage

klawSync(directory[, options])

  • 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: {}}]

Examples

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']})

Run tests

lint: npm run lint

unit test: npm run unit

lint & unit: npm test

Performance compare to other similar modules

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"

Credit

Special thanks to:

for their contribution and support.

License

Licensed under MIT