{"id":13447508,"url":"https://github.com/manidlou/node-klaw-sync","last_synced_at":"2025-05-16T15:09:20.318Z","repository":{"id":57742048,"uuid":"78049672","full_name":"manidlou/node-klaw-sync","owner":"manidlou","description":"Node.js recursive synchronous fast file system walker","archived":false,"fork":false,"pushed_at":"2025-03-19T18:59:42.000Z","size":179,"stargazers_count":160,"open_issues_count":3,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-12T14:55:14.746Z","etag":null,"topics":["fs","nodejs","sync","walker"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/manidlou.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-01-04T20:18:37.000Z","updated_at":"2025-03-18T01:55:35.000Z","dependencies_parsed_at":"2025-04-12T14:18:01.993Z","dependency_job_id":"d0b7916c-8845-47ea-856d-42039a719fb3","html_url":"https://github.com/manidlou/node-klaw-sync","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manidlou%2Fnode-klaw-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manidlou%2Fnode-klaw-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manidlou%2Fnode-klaw-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manidlou%2Fnode-klaw-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manidlou","download_url":"https://codeload.github.com/manidlou/node-klaw-sync/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254553958,"owners_count":22090417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fs","nodejs","sync","walker"],"created_at":"2024-07-31T05:01:19.643Z","updated_at":"2025-05-16T15:09:15.305Z","avatar_url":"https://github.com/manidlou.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"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` `\u003cString\u003e`\n- `options` `\u003cObject\u003e` (optional)\n  - `nodir` `\u003cBoolean\u003e` default: `undefined`\n    - return only files (ignore directories).\n  - `nofile` `\u003cBoolean\u003e` default: `undefined`\n    - return only directories (ignore files).\n  - `depthLimit`: `\u003cNumber\u003e` default: `-1`\n    - the number of times to recurse before stopping. `-1` for unlimited.\n  - `fs`: `\u003cObject\u003e` default: `graceful-fs`\n    - custom `fs`, useful when mocking `fs` object.\n  - `filter` `\u003cFunction\u003e` default: `undefined`\n    - function that gets one argument `fn({path: '', stats: {}})` and returns true to include or false to exclude the item.\n  - `traverseAll` `\u003cBoolean\u003e` 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:** `\u003cArray\u003cObject\u003e\u003e` `[{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 =\u003e {\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 =\u003e item.stats.mtime.getTime() \u003e 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 \u0026 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanidlou%2Fnode-klaw-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanidlou%2Fnode-klaw-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanidlou%2Fnode-klaw-sync/lists"}