{"name":"klaw-sync","version":"2.0.0","description":"Recursive, synchronous, and fast file system walker","main":"klaw-sync.js","repository":{"type":"git","url":"git+https://github.com/manidlou/node-klaw-sync.git"},"keywords":["fs","walk","walker","walk-sync","klaw","readdir-sync"],"author":{"name":"Mani Maghsoudlou"},"license":"MIT","bugs":{"url":"https://github.com/manidlou/node-klaw-sync/issues"},"homepage":"https://github.com/manidlou/node-klaw-sync#readme","devDependencies":{"benchmark":"^2.1.4","fs-extra":"^1.0.0","glob":"^7.1.1","minimist":"^1.2.0","mocha":"^3.2.0","standard":"^8.6.0","walk-sync":"^0.3.1"},"optionalDependencies":{"graceful-fs":"^4.1.11"},"standard":{"env":["mocha"]},"scripts":{"lint":"standard","unit":"mocha","test":"npm run lint && npm run unit","benchmark":"node ./benchmark/bm.js"},"gitHead":"2059501cbf02743e9cf5c45065b747604da593a7","dependencies":{"graceful-fs":"^4.1.11"},"_id":"klaw-sync@2.0.0","_shasum":"dbe0f153d03f8f33ff936c06d4393ccec502c883","_from":".","_npmVersion":"4.5.0","_nodeVersion":"7.9.0","_npmUser":{"name":"manidlou","email":"manidlou@gmail.com"},"dist":{"shasum":"dbe0f153d03f8f33ff936c06d4393ccec502c883","tarball":"http://registry-npm.ywwl.com/klaw-sync/download/klaw-sync-2.0.0.tgz","integrity":"sha512-oVlOdGavyyts4sCQ0gpTOvqVfWb8jwPxxhWbRWlh9Ztv1cNH+BE5vrV0QkQamONC9dKgbgl42Ve/vPNCtsb6FA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHs1t7Qhw6CsoaRKrUqygSHIcZ3va7NG69exYgFVkcfxAiEA3PpasL3Tg3bh/n7eulQIofynmbxDdSa5/3yI9ATzm1M="}],"size":3932,"noattachment":false,"key":"/klaw-sync/-/klaw-sync-2.0.0.tgz"},"maintainers":[{"name":"manidlou","email":"manidlou@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/klaw-sync-2.0.0.tgz_1492992715695_0.8919805774930865"},"directories":{},"readme":"node-klaw-sync\n==============\n\n[![npm Package](https://img.shields.io/npm/v/klaw-sync.svg?style=flat-square)](https://www.npmjs.com/package/klaw-sync)\n[![Build Status](https://travis-ci.org/manidlou/node-klaw-sync.svg?branch=master)](https://travis-ci.org/manidlou/node-klaw-sync)\n[![windows Build status](https://ci.appveyor.com/api/projects/status/braios34k6qw4h5p/branch/master?svg=true)](https://ci.appveyor.com/project/manidlou/node-klaw-sync/branch/master)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](https://standardjs.com)\n[![Known Vulnerabilities](https://snyk.io/test/npm/klaw-sync/badge.svg?style=flat-square)](https://snyk.io/test/npm/klaw-sync)\n\n`klaw-sync` is a Node.js recursive and fast 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).\n\nInstall\n-------\n\n    npm i klaw-sync\n\nUsage\n-----\n\n### klawSync(directory[, options])\n\n- `directory` `<String>`\n- `options` `<Object>` (optional) _all options are `false` by default_\n  - `nodir` `<Boolean>`\n    - return only files (ignore directories).\n  - `nofile` `<Boolean>`\n    - return only directories (ignore files).\n  - `depthLimit`: `<Number>`\n    - the number of times to recurse before stopping. `-1` for unlimited.\n  - `fs`: `<Object>`\n    - custom `fs`, useful when mocking `fs` object.\n  - `filter` `<Function>`\n    - function that gets one argument `fn({path: '', stats: {}})` and returns true to include or false to exclude the item.\n  - `traverseAll` `<Boolean>`\n    - traverse all subdirectories, regardless of `filter` option. (When set to `true`, `traverseAll` produces similar behavior to the default behavior prior to v4.0.0. The current default of  `traverseAll: false` is equivalent to the old `noRecurseOnFailedFilter: true`).\n- **Return:** `<Array<Object>>` `[{path: '', stats: {}}]`\n\nExamples\n--------\n\n```js\nconst klawSync = require('klaw-sync')\n\nconst paths = klawSync('/some/dir')\n// paths = [{path: '/some/dir/dir1', stats: {}}, {path: '/some/dir/file1', stats: {}}]\n```\n\n_**catch error**_\n\n```js\nconst klawSync = require('klaw-sync')\n\nlet paths\ntry {\n  paths = klawSync('/some/dir')\n} catch (er) {\n  console.error(er)\n}\nconsole.dir(paths)\n```\n\n_**files only**_\n\n```js\nconst klawSync = require('klaw-sync')\n\nconst files = klawSync('/some/dir', {nodir: true})\n// files = [{path: '/some/dir/file1', stats: {}}, {path: '/some/dir/file2', stats: {}}]\n```\n\n_**directories only**_\n\n```js\nconst klawSync = require('klaw-sync')\n\nconst dirs = klawSync('/some/dir', {nofile: true})\n// dirs = [{path: '/some/dir/dir1', stats: {}}, {path: '/some/dir/dir2', stats: {}}]\n```\n\n_**ignore hidden directories**_\n\n\n```js\nconst path = require('path')\nconst klawSync = require('klaw-sync')\n\nconst filterFn = item => {\n  const basename = path.basename(item.path)\n  return basename === '.' || basename[0] !== '.'\n}\n\nconst paths = klawSync('/some/dir', { filter: filterFn})\n```\n\n_**filter based on stats**_\n\nHere `traverseAll` option is required since we still want to read all directories even if they don't pass the `filter` function, to see if their contents do pass the `filter` function.\n\n```js\nconst klawSync = require('klaw-sync')\n\nconst refTime = new Date(2017, 3, 24).getTime()\nconst filterFn = item => item.stats.mtime.getTime() > refTime\n\nconst paths = klawSync('/some/dir', { filter: filterFn })\n```\n\nRun tests\n---------\n\nlint: `npm run lint`\n\nunit test: `npm run unit`\n\nlint & unit: `npm test`\n\nbenchmark: `npm run benchmark`\n\nPerformance compare to other similar modules\n-----------------------------------------------\n\nRunning some [benchmark](https://github.com/bestiejs/benchmark.js) tests on these modules:\n\n- `klaw-sync`\n- [walk-sync](https://github.com/joliss/node-walk-sync)\n\n(as of Jan 25, 2017) `klaw-sync` is the fastest module!\n\n##### results (tested on Ubuntu 18.04, Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz, 8 CPUs, 8g RAM, node v10.9.0)\n\n```bash\nRunning benchmark tests..\n\nroot dir length: 1110\nwalk-sync x 139 ops/sec ±2.48% (76 runs sampled)\nklaw-sync x 163 ops/sec ±1.20% (80 runs sampled)\nFastest is klaw-sync\n\nroot dir length: 11110\nwalk-sync x 13.23 ops/sec ±1.10% (37 runs sampled)\nklaw-sync x 15.10 ops/sec ±1.06% (41 runs sampled)\nFastest is klaw-sync\n\nroot dir length: 111110\nwalk-sync x 1.17 ops/sec ±2.06% (7 runs sampled)\nklaw-sync x 1.25 ops/sec ±2.10% (8 runs sampled)\nFastest is klaw-sync\n```\n\nCredit\n------\n\nSpecial thanks to:\n\n- [agnivade](https://github.com/agnivade)\n- [jprichardson](https://github.com/jprichardson)\n- [RyanZim](https://github.com/RyanZim)\n\nfor their contribution and support.\n\nLicense\n-------\n\nLicensed under MIT\n","publish_time":1492992715917,"_cnpm_publish_time":1492992715917,"dist-tags":{"latest":"8.0.0"}}