{"name":"klaw-sync","version":"7.0.0","keywords":["fs","walk","walker","walk-sync","klaw","readdir-sync"],"author":{"name":"Mani Maghsoudlou"},"license":"MIT","_id":"klaw-sync@7.0.0","maintainers":[{"name":"manidlou","email":"manidlou@gmail.com"}],"homepage":"https://github.com/manidlou/node-klaw-sync#readme","bugs":{"url":"https://github.com/manidlou/node-klaw-sync/issues"},"dist":{"shasum":"edb757fa7860e6ea3f2cec8a4e410a2d54dc259b","tarball":"http://registry-npm.ywwl.com/klaw-sync/download/klaw-sync-7.0.0.tgz","fileCount":5,"integrity":"sha512-UQVrq/XIu/nqf/t89IAhc0sLy0x7VlE+Gv2XCouN4rp0RKrv/S4rx80O61V6LCHqoidBr3Sz28gWvobiPAH9UQ==","signatures":[{"sig":"MEQCIGldIDbndiKLFnXwP2kMLX9Kp1zkckw33bQ5mcc1uO/5AiAQJbX9G+rmlqVaafMQ5esjwbITYb1Ci+3kNC5NO04Ftw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":11134,"size":4538,"noattachment":false,"key":"/klaw-sync/-/klaw-sync-7.0.0.tgz"},"main":"klaw-sync.js","gitHead":"56215e299b58ea394975f2b713130131ca0def15","scripts":{"lint":"standard","test":"npm run lint && npm run unit","unit":"mocha","lint:fix":"standard --fix","benchmark":"node ./benchmark/bm.js"},"_npmUser":{"name":"manidlou","email":"manidlou@gmail.com"},"standard":{"env":["mocha"]},"repository":{"url":"git+https://github.com/manidlou/node-klaw-sync.git","type":"git"},"_npmVersion":"10.5.0","description":"Recursive, synchronous, and fast file system walker","directories":{},"_nodeVersion":"20.12.1","dependencies":{"memfs":"^4.17.0","graceful-fs":"^4.1.11"},"_hasShrinkwrap":false,"devDependencies":{"mkp":"^1.0.1","mocha":"^5.1.1","fs-extra":"^5.0.0","standard":"^11.0.1","benchmark":"^2.1.4","walk-sync":"^2.0.2"},"_npmOperationalInternal":{"tmp":"tmp/klaw-sync_7.0.0_1742410613845_0.6650120560221591","host":"s3://npm-registry-packages-npm-production"},"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)\n  - `nodir` `<Boolean>` default: `undefined`\n    - return only files (ignore directories).\n  - `nofile` `<Boolean>` default: `undefined`\n    - return only directories (ignore files).\n  - `depthLimit`: `<Number>` default: `-1`\n    - the number of times to recurse before stopping. `-1` for unlimited.\n  - `fs`: `<Object>` default: `graceful-fs`\n    - custom `fs`, useful when mocking `fs` object.\n  - `filter` `<Function>` default: `undefined`\n    - function that gets one argument `fn({path: '', stats: {}})` and returns true to include or false to exclude the item.\n  - `traverseAll` `<Boolean>` default: `undefined`\n    - 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.\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 subdirectories 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', { traverseAll: true, 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 80.71 ops/sec ±1.42% (72 runs sampled)\nklaw-sync x 160 ops/sec ±1.17% (79 runs sampled)\nFastest is klaw-sync\n\nroot dir length: 11110\nwalk-sync x 7.55 ops/sec ±3.39% (23 runs sampled)\nklaw-sync x 14.95 ops/sec ±0.27% (40 runs sampled)\nFastest is klaw-sync\n\nroot dir length: 111110\nwalk-sync x 0.63 ops/sec ±6.92% (6 runs sampled)\nklaw-sync x 1.22 ops/sec ±0.96% (7 runs sampled)\nFastest is klaw-sync\n```\n\nContributing\n-----------\n\n1. Fork the repository\n2. Clone your forked version\n   ```bash\n   git clone https://github.com/YOUR_USERNAME/node-klaw-sync.git\n   ```\n3. Create a new branch for your changes\n   ```bash\n   git checkout -b feature/your-feature-name\n   ```\n4. Make your changes and commit them\n5. Push to your fork\n   ```bash\n   git push origin feature/your-feature-name\n   ```\n6. Create a Pull Request from your fork to the original repository\n\nBefore submitting a PR:\n- Ensure tests pass: `npm test`\n- Add tests for new features\n- Follow the existing code style\n\nLicense\n-------\n\nLicensed under MIT\n","publish_time":1742410614158,"_cnpm_publish_time":1742410614158,"dist-tags":{"latest":"8.0.0"}}