Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

klaw-sync

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

klaw-sync - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

CHANGELOG.md

21

klaw-sync.js
'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 @@ ------

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc