Comparing version 1.0.2 to 1.1.0
'use strict' | ||
var path = require('path') | ||
var mm = require('multimatch') | ||
var mm = require('micromatch') | ||
var fs | ||
@@ -11,11 +11,11 @@ try { | ||
function _procPath (dir, file, opts, list) { | ||
function _procPath (dir, pathItem, opts, list) { | ||
var nestedPath | ||
var stat | ||
// use string concatenation which is faster than | ||
// path.join() and path.resolve() | ||
// here since dir already resolved, we use string concatenation | ||
// which showed faster performance than path.join() and path.resolve() | ||
if (path.sep === '/') { | ||
nestedPath = dir + '/' + file | ||
nestedPath = dir + '/' + pathItem | ||
} else { | ||
nestedPath = dir + '\\' + file | ||
nestedPath = dir + '\\' + pathItem | ||
} | ||
@@ -40,2 +40,3 @@ stat = fs.lstatSync(nestedPath) | ||
list = list || [] | ||
dir = path.resolve(dir) | ||
try { | ||
@@ -50,8 +51,8 @@ files = fs.readdirSync(dir) | ||
files.forEach(function (file) { | ||
if (ignore.length <= 0) { | ||
_procPath(dir, file, opts, list) | ||
} else { | ||
if (ignore.indexOf(file) < 0) { | ||
if (ignore.length > 0) { | ||
if (ignore.indexOf(file) === -1) { | ||
_procPath(dir, file, opts, list) | ||
} | ||
} else { | ||
_procPath(dir, file, opts, list) | ||
} | ||
@@ -58,0 +59,0 @@ }) |
{ | ||
"name": "klaw-sync", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Recursive and synchronous file system walker", | ||
@@ -25,3 +25,3 @@ "main": "klaw-sync.js", | ||
"dependencies": { | ||
"multimatch": "^2.1.0" | ||
"micromatch": "^2.3.11" | ||
}, | ||
@@ -49,4 +49,4 @@ "devDependencies": { | ||
"test": "npm run lint && npm run unit", | ||
"benchmark": "node bm.js" | ||
"benchmark": "node ./benchmark/bm.js" | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
Node.js: klaw-sync | ||
================= | ||
klaw-sync | ||
========= | ||
@@ -10,3 +10,3 @@ [![npm Package](https://img.shields.io/npm/v/klaw-sync.svg?style=flat-square)](https://www.npmjs.com/package/klaw-sync) | ||
`klaw-sync` is a recursive file system walker, which is the synchronous counterpart of [klaw](https://github.com/jprichardson/node-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](https://nodejs.org/api/fs.html#fs_class_fs_stats). | ||
`klaw-sync` is a Node.js recursive file system walker, which is the synchronous counterpart of [klaw](https://github.com/jprichardson/node-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](https://nodejs.org/api/fs.html#fs_class_fs_stats). | ||
@@ -16,3 +16,3 @@ Install | ||
npm install klaw-sync | ||
npm i klaw-sync | ||
@@ -26,3 +26,3 @@ Usage | ||
- `options` `{Object}` *optional* (all options are `false` by default) | ||
- `ignore` `{String | Array<String>}` any paths or [minimatch](https://github.com/isaacs/minimatch) patterns to ignore (can be string or an array of strings) | ||
- `ignore` `{String | Array<String>}` any paths or [micromatch](https://github.com/jonschlinkert/micromatch#features) patterns to ignore (can be string or an array of strings) | ||
- `nodir` `{Boolean}` return only files (ignore directories) | ||
@@ -42,3 +42,3 @@ - `nofile` `{Boolean}` return only directories (ignore files) | ||
**catch error** | ||
_**catch error**_ | ||
@@ -54,6 +54,6 @@ ```js | ||
} | ||
console.log(paths) | ||
console.dir(paths) | ||
``` | ||
**files only** | ||
_**files only**_ | ||
@@ -66,3 +66,3 @@ ```js | ||
**directories only** | ||
_**directories only**_ | ||
@@ -75,3 +75,3 @@ ```js | ||
**ignore `node_modules`** | ||
_**ignore `node_modules`**_ | ||
@@ -83,3 +83,3 @@ ```js | ||
**ignore `node_modules` and `.git` using [minimatch](https://github.com/isaacs/minimatch) patterns** | ||
_**ignore `node_modules` and `.git` using [micromatch](https://github.com/jonschlinkert/micromatch#features) patterns**_ | ||
@@ -91,3 +91,3 @@ ```js | ||
**ignore `node_modules`, `.git` and all `*.js` files using [minimatch](https://github.com/isaacs/minimatch) patterns** | ||
_**ignore `node_modules`, `.git` and all `*.js` files using [micromatch](https://github.com/jonschlinkert/micromatch#features) patterns**_ | ||
@@ -109,6 +109,6 @@ ```js | ||
Performance comparison to other similar modules | ||
Performance compare to other similar modules | ||
----------------------------------------------- | ||
Sometimes it's fun to run speed tests on similar functions or modules. The `bm.js` runs some basic [benchmark](https://github.com/bestiejs/benchmark.js) tests for two cases, `without --ignore` (basic usage) and `with --ignore`, on these modules: | ||
The `bm.js` runs some basic [benchmark](https://github.com/bestiejs/benchmark.js) tests for two cases, `without --ignore` (basic usage) and `with --ignore`, on these modules: | ||
@@ -119,30 +119,15 @@ - `klaw-sync` | ||
All of these modules are great. I appreciate the works. I've personally learned a lot from them. | ||
Just for fun, it turned out (as of January 25, 2017) for the most cases `klaw-sync` is faster than other modules! | ||
Just for fun, it turned out 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. | ||
#####run benchmark (performance) | ||
`npm run benchmark -- --dir=/some/dir` | ||
_basic usage without anything to ignore_ | ||
`npm run benchmark -- --dir=/some/dir -i "node_modules"` | ||
`npm run benchmark -- --dir=/some/dir -p` | ||
`npm run benchmark -- --dir=/some/dir -i "node_modules" -i "*.js"` | ||
_one item to ignore_ | ||
`npm run benchmark -- --dir=/some/dir -p -i "node_modules"` | ||
_multiple items to ignore_ | ||
`npm run benchmark -- --dir=/some/dir -p -i "node_modules" -i "*.js"` | ||
#####run benchmark (exec time) | ||
`npm run benchmark -- --dir=/some/dir -t` | ||
`npm run benchmark -- --dir=/some/dir -t -i ".git"` | ||
`npm run benchmark -- --dir=/some/dir -t -i ".git" -i "*.js"` | ||
Credit | ||
@@ -149,0 +134,0 @@ ------ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
7967
5
57
0
137
+ Addedmicromatch@^2.3.11
+ Addedarr-diff@2.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarray-unique@0.2.1(transitive)
+ Addedbraces@1.8.5(transitive)
+ Addedexpand-brackets@0.1.5(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedextglob@0.3.2(transitive)
+ Addedfilename-regex@2.0.1(transitive)
+ Addedfill-range@2.2.4(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedglob-base@0.3.0(transitive)
+ Addedglob-parent@2.0.0(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-dotfile@1.0.3(transitive)
+ Addedis-equal-shallow@0.1.3(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-glob@2.0.1(transitive)
+ Addedis-number@2.1.04.0.0(transitive)
+ Addedis-posix-bracket@0.1.1(transitive)
+ Addedis-primitive@2.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.0(transitive)
+ Addedkind-of@3.2.26.0.3(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmicromatch@2.3.11(transitive)
+ Addednormalize-path@2.1.1(transitive)
+ Addedobject.omit@2.0.1(transitive)
+ Addedparse-glob@3.0.4(transitive)
+ Addedpreserve@0.2.0(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedregex-cache@0.4.4(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
- Removedmultimatch@^2.1.0
- Removedarray-differ@1.0.0(transitive)
- Removedarray-union@1.0.2(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedarrify@1.0.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedmultimatch@2.1.0(transitive)