Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iyowei/scan-dir-each
并行扫描文件夹,可在扫描的同时更新或过滤数据,一定程度复用遍历。
https://github.com/iyowei/scan-dir-each
fs iyowei nodejs walker
Last synced: about 7 hours ago
JSON representation
并行扫描文件夹,可在扫描的同时更新或过滤数据,一定程度复用遍历。
- Host: GitHub
- URL: https://github.com/iyowei/scan-dir-each
- Owner: iyowei
- License: mit
- Created: 2021-12-16T09:50:11.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-18T07:32:03.000Z (almost 3 years ago)
- Last Synced: 2024-10-03T06:53:46.247Z (about 1 month ago)
- Topics: fs, iyowei, nodejs, walker
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[node version badge]: https://img.shields.io/badge/node.js-%3E%3D12.20.0-brightgreen?style=flat&logo=Node.js
[download node.js]: https://nodejs.org/en/download/
[prs welcome badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat
[lsdirsync]: https://github.com/iyowei/ls-dir-sync
[lsdir]: https://github.com/iyowei/ls-dir
[scandireachsync]: https://github.com/iyowei/scan-dir-sync
[scandireach]: https://github.com/iyowei/scan-dir-each
[scandirsync]: https://github.com/iyowei/scan-dir-sync
[scandir]: https://github.com/iyowei/scan-dir# scanDirEach(path, [worker = () => true, raw = false])
> 并行扫描文件夹,可在扫描的同时更新或过滤数据,一定程度复用遍历。
## 使用
- `path` 待扫描的路径,**必需提供**,{String}
- `worker` 处理器,如果扫描的同时需要更新、过滤操作可提供,一定程度复用穷举,**可选**,{ Function }
- 返回 { Object | Boolean | Promise }
- `false` 过滤掉当前扫描结果
- `true` 保留当前扫描结果
- 对象字面量,保留 / 更新当前扫描结果
- 如果需要在处理器中需要安放些异步操作,如远程数据请求,可在处理器中返回一个 Promise,该 Promise 可返回,
- `false` 过滤掉当前扫描结果
- `true` 保留当前扫描结果
- 对象字面量,保留 / 更新当前扫描结果
- 其它类型则默认为没有任何处理
- 其它类型则默认为没有任何处理
- `raw` 是否专门返回未加工的扫描结果,使用 `worker` 后才会生效,默认 `false`,**可选**,{ Boolean }
- 返回,扫描结果 { Array }
- 如果设置了 `raw` 为 `true`,则返回 **二维数组**,第一项为加工后的扫描结果,第二项为未加工的扫描结果
- 默认返回 **一维数组**,即:加工后的扫描结果```js
import { log } from "console";
import scanDirEach from "@iyowei/scan-dir-each";(async () => {
const got = await scanDirEach(
process.cwd(),
(cur, index) =>
new Promise((resolve) => {
// 可以做些异步操作,如远程数据请求
resolve(index % 2 === 0 ? cur : false);
}),
false
);log(got);
/**
* [
* {
* path: '',
* dirent: [Dirent]
* },
* ...
* ]
*/
})();
```## 安装
[![Node Version Badge][node version badge]][download node.js]
```shell
# Pnpm
pnpm add @iyowei/scan-dir-each# yarn
yarn add @iyowei/scan-dir-each# npm
npm add @iyowei/scan-dir-each
```## 相关
- [**`lsDirSync()`**][lsdirsync],串行扫描文件夹;
- [**`lsDir()`**][lsdir],并行扫描文件夹;
- [**`scanDirEachSync()`**][scandireachsync],可在扫描的同时更新或过滤数据,**串行** 实现;
- [**`scanDirSync()`**][scandirsync],`worker` 选填,有 `worker`,行为同 `scanDirEachSync()` 一致,否则与 `lsDirSync()` 一致,如果项目中同时使用了 `scanDirEachSync()`、`lsDirSync()`,则推荐使用 `scanDirSync()`;
- [**`scanDir()`**][scandir],`worker` 选填,有 `worker`,行为同 `scanDirEach()` 一致,否则与 `lsDir()` 一致,如果项目中同时使用了 `scanDirEach()`、`lsDir()`,则推荐使用 `scanDir()`;## 参与贡献
![PRs Welcome][prs welcome badge]