Installations
npm install klaw-sync
Developer
manidlou
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
10.9.0
NPM Version
6.4.1
Statistics
158 Stars
89 Commits
10 Forks
3 Watching
1 Branches
4 Contributors
Updated on 22 Oct 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
366,198,080
Last day
-8.2%
501,110
Compared to previous day
Last week
1.4%
2,816,135
Compared to previous week
Last month
10%
11,936,031
Compared to previous month
Last year
20.1%
122,731,324
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
node-klaw-sync
klaw-sync
is a Node.js recursive and fast 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)nodir
<Boolean>
default:undefined
- return only files (ignore directories).
nofile
<Boolean>
default:undefined
- return only directories (ignore files).
depthLimit
:<Number>
default:-1
- the number of times to recurse before stopping.
-1
for unlimited.
- the number of times to recurse before stopping.
fs
:<Object>
default:graceful-fs
- custom
fs
, useful when mockingfs
object.
- custom
filter
<Function>
default:undefined
- function that gets one argument
fn({path: '', stats: {}})
and returns true to include or false to exclude the item.
- function that gets one argument
traverseAll
<Boolean>
default:undefined
- traverse all subdirectories, regardless of
filter
option. This can be useful when you have a filter function and still want to traverse all subdirectories even if your filter function doesn't pass for some directories.
- traverse all subdirectories, regardless of
- Return:
<Array<Object>>
[{path: '', stats: {}}]
Examples
1const klawSync = require('klaw-sync') 2 3const paths = klawSync('/some/dir') 4// paths = [{path: '/some/dir/dir1', stats: {}}, {path: '/some/dir/file1', stats: {}}]
catch error
1const klawSync = require('klaw-sync') 2 3let paths 4try { 5 paths = klawSync('/some/dir') 6} catch (er) { 7 console.error(er) 8} 9console.dir(paths)
files only
1const klawSync = require('klaw-sync') 2 3const files = klawSync('/some/dir', {nodir: true}) 4// files = [{path: '/some/dir/file1', stats: {}}, {path: '/some/dir/file2', stats: {}}]
directories only
1const klawSync = require('klaw-sync') 2 3const dirs = klawSync('/some/dir', {nofile: true}) 4// dirs = [{path: '/some/dir/dir1', stats: {}}, {path: '/some/dir/dir2', stats: {}}]
ignore hidden directories
1const path = require('path') 2const klawSync = require('klaw-sync') 3 4const filterFn = item => { 5 const basename = path.basename(item.path) 6 return basename === '.' || basename[0] !== '.' 7} 8 9const paths = klawSync('/some/dir', { filter: filterFn})
filter based on stats
Here traverseAll
option is required since we still want to read all subdirectories even if they don't pass the filter
function, to see if their contents do pass the filter
function.
1const klawSync = require('klaw-sync')
2
3const refTime = new Date(2017, 3, 24).getTime()
4const filterFn = item => item.stats.mtime.getTime() > refTime
5
6const paths = klawSync('/some/dir', { traverseAll: true, filter: filterFn })
Run tests
lint: npm run lint
unit test: npm run unit
lint & unit: npm test
benchmark: npm run benchmark
Performance compare to other similar modules
Running some benchmark tests on these modules:
klaw-sync
- walk-sync
(as of Jan 25, 2017) klaw-sync
is the fastest module!
results (tested on Ubuntu 18.04, Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz, 8 CPUs, 8g RAM, node v10.9.0)
1Running benchmark tests.. 2 3root dir length: 1110 4walk-sync x 80.71 ops/sec ±1.42% (72 runs sampled) 5klaw-sync x 160 ops/sec ±1.17% (79 runs sampled) 6Fastest is klaw-sync 7 8root dir length: 11110 9walk-sync x 7.55 ops/sec ±3.39% (23 runs sampled) 10klaw-sync x 14.95 ops/sec ±0.27% (40 runs sampled) 11Fastest is klaw-sync 12 13root dir length: 111110 14walk-sync x 0.63 ops/sec ±6.92% (6 runs sampled) 15klaw-sync x 1.22 ops/sec ±0.96% (7 runs sampled) 16Fastest is klaw-sync
License
Licensed under MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 2/26 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Score
3
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More