{"id":18777286,"url":"https://github.com/iyowei/scan-dir","last_synced_at":"2026-04-28T23:34:36.608Z","repository":{"id":57119761,"uuid":"438942395","full_name":"iyowei/scan-dir","owner":"iyowei","description":"并行扫描文件夹，可在扫描的同时更新或过滤数据，一定程度复用遍历。","archived":false,"fork":false,"pushed_at":"2021-12-18T07:47:36.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-24T05:56:08.506Z","etag":null,"topics":["fs","iyowei","nodejs","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/iyowei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-16T10:04:41.000Z","updated_at":"2021-12-31T07:54:52.000Z","dependencies_parsed_at":"2022-08-23T15:40:55.673Z","dependency_job_id":null,"html_url":"https://github.com/iyowei/scan-dir","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyowei%2Fscan-dir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyowei%2Fscan-dir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyowei%2Fscan-dir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyowei%2Fscan-dir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iyowei","download_url":"https://codeload.github.com/iyowei/scan-dir/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239687444,"owners_count":19680733,"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","iyowei","nodejs","walker"],"created_at":"2024-11-07T20:09:35.903Z","updated_at":"2025-12-16T19:30:17.359Z","avatar_url":"https://github.com/iyowei.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[node version badge]: https://img.shields.io/badge/node.js-%3E%3D12.20.0-brightgreen?style=flat\u0026logo=Node.js\n[download node.js]: https://nodejs.org/en/download/\n[prs welcome badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat\n[lsdirsync]: https://github.com/iyowei/ls-dir-sync\n[lsdir]: https://github.com/iyowei/ls-dir\n[scandireachsync]: https://github.com/iyowei/scan-dir-sync\n[scandireach]: https://github.com/iyowei/scan-dir-each\n[scandirsync]: https://github.com/iyowei/scan-dir-sync\n[scandir]: https://github.com/iyowei/scan-dir\n\n# scanDir(path, [worker, raw = false])\n\n\u003e 并行扫描文件夹，可在扫描的同时更新或过滤数据，一定程度复用遍历。\n\n## 使用\n\n\u003e 项目中同时使用 [`lsDir()`][lsdir]、[`scanDirEach()`][scandireach] 模块的话，推荐使用当前模块。\n\n- `path` 待扫描的路径，**必需提供**，{String}\n- `worker` 处理器，如果扫描的同时需要更新、过滤操作可提供，一定程度复用穷举，**可选**，{ Function }\n  - 返回 { Object | Boolean | Promise }\n    - `false` 过滤掉当前扫描结果\n    - `true` 保留当前扫描结果\n    - 对象字面量，保留 / 更新当前扫描结果\n    - 如果需要在处理器中需要安放些异步操作，如远程数据请求，可在处理器中返回一个 Promise，该 Promise 可返回，\n      - `false` 过滤掉当前扫描结果\n      - `true` 保留当前扫描结果\n      - 对象字面量，保留 / 更新当前扫描结果\n      - 其它类型则默认为没有任何处理\n    - 其它类型则默认为没有任何处理\n- `raw` 是否专门返回未加工的扫描结果，使用 `worker` 后才会生效，默认 `false`，**可选**，{ Boolean }\n- 返回，扫描结果 { Array }\n  - 如果设置了 `raw` 为 `true`，则返回 **二维数组**，第一项为加工后的扫描结果，第二项为未加工的扫描结果\n  - 默认返回 **一维数组**，即：加工后的扫描结果\n\n```js\nimport { log } from \"console\";\nimport scanDir from \"@iyowei/scan-dir\";\n\n(async () =\u003e {\n  const got = await scanDir(\n    process.cwd(),\n    (cur, index) =\u003e\n      new Promise((resolve) =\u003e {\n        // 可以做些异步操作，如远程数据请求\n        resolve(index % 2 === 0 ? cur : false);\n      }),\n    false\n  );\n\n  log(got);\n\n  /**\n   * [\n   *   {\n   *     path: '',\n   *     dirent: [Dirent]\n   *   },\n   *   ...\n   * ]\n   */\n})();\n```\n\n## 安装\n\n[![Node Version Badge][node version badge]][download node.js]\n\n```shell\n# Pnpm\npnpm add @iyowei/scan-dir\n\n# yarn\nyarn add @iyowei/scan-dir\n\n# npm\nnpm add @iyowei/scan-dir\n```\n\n## 相关\n\n- [**`lsDirSync()`**][lsdirsync]，串行扫描文件夹；\n- [**`lsDir()`**][lsdir]，并行扫描文件夹；\n- [**`scanDirEachSync()`**][scandireachsync]，可在扫描的同时更新或过滤数据，**串行** 实现；\n- [**`scanDirEach()`**][scandireach]，可在扫描的同时更新或过滤数据，**并行** 实现；\n- [**`scanDirSync()`**][scandirsync]，`worker` 选填，有 `worker`，行为同 `scanDirEachSync()` 一致，否则与 `lsDirSync()` 一致，如果项目中同时使用了 `scanDirEachSync()`、`lsDirSync()`，则推荐使用 `scanDirSync()`；\n\n## 参与贡献\n\n![PRs Welcome][prs welcome badge]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiyowei%2Fscan-dir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiyowei%2Fscan-dir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiyowei%2Fscan-dir/lists"}