@sapphire/node-utilities 1.1.0-next.384ff84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/README.md +111 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +41 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
# @sapphire/node-utilities
|
|
6
|
+
|
|
7
|
+
**Common JavaScript utilities for the Sapphire Community.**
|
|
8
|
+
|
|
9
|
+
[](https://github.com/sapphiredev/utilities/blob/main/LICENSE.md)
|
|
10
|
+
[](https://codecov.io/gh/sapphiredev/utilities)
|
|
11
|
+
[](https://bundlephobia.com/result?p=@sapphire/node-utilities)
|
|
12
|
+
[](https://www.npmjs.com/package/@sapphire/node-utilities)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- Written in TypeScript
|
|
19
|
+
- Offers CommonJS, and ESM bundles
|
|
20
|
+
- Fully tested
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
You can use the following command to install this package, or replace `npm install` with your package manager of choice.
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npm install @sapphire/node-utilities
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Buy us some doughnuts
|
|
33
|
+
|
|
34
|
+
Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
|
|
35
|
+
|
|
36
|
+
We accept donations through Open Collective, Ko-fi, Paypal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.
|
|
37
|
+
|
|
38
|
+
| Donate With | Address |
|
|
39
|
+
| :-------------: | :-------------------------------------------------: |
|
|
40
|
+
| Open Collective | [Click Here](https://sapphirejs.dev/opencollective) |
|
|
41
|
+
| Ko-fi | [Click Here](https://sapphirejs.dev/kofi) |
|
|
42
|
+
| Patreon | [Click Here](https://sapphirejs.dev/patreon) |
|
|
43
|
+
| PayPal | [Click Here](https://sapphirejs.dev/paypal) |
|
|
44
|
+
|
|
45
|
+
## Contributors β¨
|
|
46
|
+
|
|
47
|
+
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
48
|
+
|
|
49
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
50
|
+
<!-- prettier-ignore-start -->
|
|
51
|
+
<!-- markdownlint-disable -->
|
|
52
|
+
<table>
|
|
53
|
+
<tr>
|
|
54
|
+
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Code">π»</a> <a href="#infra-favna" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#projectManagement-favna" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Documentation">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Tests">β οΈ</a></td>
|
|
55
|
+
<td align="center"><a href="https://github.com/kyranet"><img src="https://avatars0.githubusercontent.com/u/24852502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura RomΓ‘n</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Code">π»</a> <a href="#projectManagement-kyranet" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Akyranet" title="Reviewed Pull Requests">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Tests">β οΈ</a></td>
|
|
56
|
+
<td align="center"><a href="https://github.com/PyroTechniac"><img src="https://avatars2.githubusercontent.com/u/39341355?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gryffon Bellish</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3APyroTechniac" title="Reviewed Pull Requests">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Tests">β οΈ</a></td>
|
|
57
|
+
<td align="center"><a href="https://github.com/vladfrangu"><img src="https://avatars3.githubusercontent.com/u/17960496?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vlad Frangu</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3Avladfrangu" title="Bug reports">π</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Avladfrangu" title="Reviewed Pull Requests">π</a> <a href="#userTesting-vladfrangu" title="User Testing">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Tests">β οΈ</a></td>
|
|
58
|
+
<td align="center"><a href="https://github.com/Stitch07"><img src="https://avatars0.githubusercontent.com/u/29275227?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stitch07</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Code">π»</a> <a href="#projectManagement-Stitch07" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Tests">β οΈ</a></td>
|
|
59
|
+
<td align="center"><a href="https://github.com/apps/depfu"><img src="https://avatars3.githubusercontent.com/in/715?v=4?s=100" width="100px;" alt=""/><br /><sub><b>depfu[bot]</b></sub></a><br /><a href="#maintenance-depfu[bot]" title="Maintenance">π§</a></td>
|
|
60
|
+
<td align="center"><a href="https://github.com/apps/allcontributors"><img src="https://avatars0.githubusercontent.com/in/23186?v=4?s=100" width="100px;" alt=""/><br /><sub><b>allcontributors[bot]</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=allcontributors[bot]" title="Documentation">π</a></td>
|
|
61
|
+
</tr>
|
|
62
|
+
<tr>
|
|
63
|
+
<td align="center"><a href="https://github.com/Nytelife26"><img src="https://avatars1.githubusercontent.com/u/22531310?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler J Russell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Nytelife26" title="Documentation">π</a></td>
|
|
64
|
+
<td align="center"><a href="https://github.com/Alcremie"><img src="https://avatars0.githubusercontent.com/u/54785334?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ivan Lieder</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Alcremie" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AAlcremie" title="Bug reports">π</a></td>
|
|
65
|
+
<td align="center"><a href="https://github.com/RealShadowNova"><img src="https://avatars3.githubusercontent.com/u/46537907?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hezekiah Hendry</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=RealShadowNova" title="Code">π»</a> <a href="#tool-RealShadowNova" title="Tools">π§</a></td>
|
|
66
|
+
<td align="center"><a href="https://github.com/Vetlix"><img src="https://avatars.githubusercontent.com/u/31412314?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vetlix</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Vetlix" title="Code">π»</a></td>
|
|
67
|
+
<td align="center"><a href="https://github.com/ethamitc"><img src="https://avatars.githubusercontent.com/u/27776796?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ethan Mitchell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ethamitc" title="Documentation">π</a></td>
|
|
68
|
+
<td align="center"><a href="https://github.com/noftaly"><img src="https://avatars.githubusercontent.com/u/34779161?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Elliot</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=noftaly" title="Code">π»</a></td>
|
|
69
|
+
<td align="center"><a href="https://jurien.dev"><img src="https://avatars.githubusercontent.com/u/5418114?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jurien Hamaker</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=jurienhamaker" title="Code">π»</a></td>
|
|
70
|
+
</tr>
|
|
71
|
+
<tr>
|
|
72
|
+
<td align="center"><a href="https://fanoulis.dev/"><img src="https://avatars.githubusercontent.com/u/38255093?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Charalampos Fanoulis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=cfanoulis" title="Documentation">π</a></td>
|
|
73
|
+
<td align="center"><a href="https://github.com/apps/dependabot"><img src="https://avatars.githubusercontent.com/in/29110?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dependabot[bot]</b></sub></a><br /><a href="#maintenance-dependabot[bot]" title="Maintenance">π§</a></td>
|
|
74
|
+
<td align="center"><a href="https://kaname.netlify.app/"><img src="https://avatars.githubusercontent.com/u/56084970?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kaname</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kaname-png" title="Code">π»</a></td>
|
|
75
|
+
<td align="center"><a href="https://github.com/nandhagk"><img src="https://avatars.githubusercontent.com/u/62976649?v=4?s=100" width="100px;" alt=""/><br /><sub><b>nandhagk</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/issues?q=author%3Anandhagk" title="Bug reports">π</a></td>
|
|
76
|
+
<td align="center"><a href="https://megatank58.me/"><img src="https://avatars.githubusercontent.com/u/51410502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>megatank58</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=megatank58" title="Code">π»</a></td>
|
|
77
|
+
<td align="center"><a href="https://github.com/UndiedGamer"><img src="https://avatars.githubusercontent.com/u/84702365?v=4?s=100" width="100px;" alt=""/><br /><sub><b>UndiedGamer</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=UndiedGamer" title="Code">π»</a></td>
|
|
78
|
+
<td align="center"><a href="https://github.com/Lioness100"><img src="https://avatars.githubusercontent.com/u/65814829?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lioness100</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Documentation">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Code">π»</a></td>
|
|
79
|
+
</tr>
|
|
80
|
+
<tr>
|
|
81
|
+
<td align="center"><a href="https://gitlab.com/DavidPH/"><img src="https://avatars.githubusercontent.com/u/44669930?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=DavidPHH" title="Code">π»</a></td>
|
|
82
|
+
<td align="center"><a href="https://github.com/apps/renovate"><img src="https://avatars.githubusercontent.com/in/2740?v=4?s=100" width="100px;" alt=""/><br /><sub><b>renovate[bot]</b></sub></a><br /><a href="#maintenance-renovate[bot]" title="Maintenance">π§</a></td>
|
|
83
|
+
<td align="center"><a href="https://renovate.whitesourcesoftware.com/"><img src="https://avatars.githubusercontent.com/u/25180681?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WhiteSource Renovate</b></sub></a><br /><a href="#maintenance-renovate-bot" title="Maintenance">π§</a></td>
|
|
84
|
+
<td align="center"><a href="https://fc5570.me/"><img src="https://avatars.githubusercontent.com/u/68158483?v=4?s=100" width="100px;" alt=""/><br /><sub><b>FC</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=FC5570" title="Code">π»</a></td>
|
|
85
|
+
<td align="center"><a href="https://github.com/Tokipudi"><img src="https://avatars.githubusercontent.com/u/29551076?v=4?s=100" width="100px;" alt=""/><br /><sub><b>JΓ©rΓ©my de Saint Denis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Tokipudi" title="Code">π»</a></td>
|
|
86
|
+
<td align="center"><a href="https://github.com/ItsMrCube"><img src="https://avatars.githubusercontent.com/u/25201357?v=4?s=100" width="100px;" alt=""/><br /><sub><b>MrCube</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ItsMrCube" title="Code">π»</a></td>
|
|
87
|
+
<td align="center"><a href="https://github.com/bitomic"><img src="https://avatars.githubusercontent.com/u/35199700?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bitomic</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=bitomic" title="Code">π»</a></td>
|
|
88
|
+
</tr>
|
|
89
|
+
<tr>
|
|
90
|
+
<td align="center"><a href="https://c43721.dev/"><img src="https://avatars.githubusercontent.com/u/55610086?v=4?s=100" width="100px;" alt=""/><br /><sub><b>c43721</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=c43721" title="Code">π»</a></td>
|
|
91
|
+
<td align="center"><a href="https://commandtechno.com/"><img src="https://avatars.githubusercontent.com/u/68407783?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Commandtechno</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Commandtechno" title="Code">π»</a></td>
|
|
92
|
+
<td align="center"><a href="https://github.com/dhruv-kaushikk"><img src="https://avatars.githubusercontent.com/u/73697546?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=dhruv-kaushikk" title="Code">π»</a></td>
|
|
93
|
+
<td align="center"><a href="https://axis.moe/"><img src="https://avatars.githubusercontent.com/u/54381371?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=axisiscool" title="Code">π»</a></td>
|
|
94
|
+
<td align="center"><a href="https://github.com/imranbarbhuiya"><img src="https://avatars.githubusercontent.com/u/74945038?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Parbez</b></sub></a><br /><a href="#maintenance-imranbarbhuiya" title="Maintenance">π§</a></td>
|
|
95
|
+
<td align="center"><a href="https://github.com/NotKaskus"><img src="https://avatars.githubusercontent.com/u/75168528?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Paul Andrew</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=NotKaskus" title="Documentation">π</a></td>
|
|
96
|
+
<td align="center"><a href="https://linktr.ee/mzato0001"><img src="https://avatars.githubusercontent.com/u/62367547?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mzato</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Mzato0001" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AMzato0001" title="Bug reports">π</a></td>
|
|
97
|
+
</tr>
|
|
98
|
+
<tr>
|
|
99
|
+
<td align="center"><a href="https://github.com/MajesticString"><img src="https://avatars.githubusercontent.com/u/66224939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harry Allen</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=MajesticString" title="Documentation">π</a></td>
|
|
100
|
+
<td align="center"><a href="https://github.com/EvolutionX-10"><img src="https://avatars.githubusercontent.com/u/85353424?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Evo</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=EvolutionX-10" title="Code">π»</a></td>
|
|
101
|
+
<td align="center"><a href="https://enes.ovh/"><img src="https://avatars.githubusercontent.com/u/61084101?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Enes GenΓ§</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=enxg" title="Code">π»</a></td>
|
|
102
|
+
<td align="center"><a href="https://github.com/muchnameless"><img src="https://avatars.githubusercontent.com/u/12682826?v=4?s=100" width="100px;" alt=""/><br /><sub><b>muchnameless</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=muchnameless" title="Code">π»</a></td>
|
|
103
|
+
</tr>
|
|
104
|
+
</table>
|
|
105
|
+
|
|
106
|
+
<!-- markdownlint-restore -->
|
|
107
|
+
<!-- prettier-ignore-end -->
|
|
108
|
+
|
|
109
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
110
|
+
|
|
111
|
+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { PathLike } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param path The path in which to find files.
|
|
6
|
+
* @param predicate A predicate function receives the path as a parameter. Truthy values will have the path included, falsey values will have the file excluded.
|
|
7
|
+
*
|
|
8
|
+
* @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursively(path, predicate)) {}`
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // With CommonJS: To find all files ending with `.ts` in the src directory:
|
|
13
|
+
* const path = require('node:path');
|
|
14
|
+
*
|
|
15
|
+
* for await (const file of findFilesRecursively(path.join(__dirname, 'src'), (filePath) => filePath.endsWith('.ts'))) {
|
|
16
|
+
* console.log(file);
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // With ESM: To find all files ending with `.ts` in the src directory:
|
|
23
|
+
* for await (const file of findFilesRecursively(new URL('src', import.meta.url), (filePath) => filePath.endsWith('.ts'))) {
|
|
24
|
+
* console.log(file);
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function findFilesRecursively(path: PathLike, predicate?: (filePath: string) => boolean): AsyncIterableIterator<string>;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param path The path in which to find files. This can be a string, buffer, or {@link URL}.
|
|
32
|
+
* @param fileStartsWith The string pattern with which the file name must start.
|
|
33
|
+
*
|
|
34
|
+
* Note that we do **not** support a full globby pattern using asterisk for wildcards. It has to be an exact match with {@link String.startsWith}
|
|
35
|
+
*
|
|
36
|
+
* @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursivelyStringStartsWith(path, fileNameEndsWith)) {}`
|
|
37
|
+
*/
|
|
38
|
+
declare function findFilesRecursivelyStringStartsWith(path: PathLike, fileStartsWith: string): AsyncIterableIterator<string>;
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param path The path in which to find files. This can be a string, buffer, or {@link URL}.
|
|
42
|
+
* @param fileEndsWith The string pattern with which the file name must end.
|
|
43
|
+
* Ideally this is a file extension, however you can also provide more parts of the end of the file.
|
|
44
|
+
*
|
|
45
|
+
* Note that we do **not** support a full globby pattern using asterisk for wildcards. It has to be an exact match with {@link String.endsWith}
|
|
46
|
+
*
|
|
47
|
+
* @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursivelyStringEndsWith(path, fileNameEndsWith)) {}`
|
|
48
|
+
*/
|
|
49
|
+
declare function findFilesRecursivelyStringEndsWith(path: PathLike, fileEndsWith: string): AsyncIterableIterator<string>;
|
|
50
|
+
/**
|
|
51
|
+
* @param path The path in which to find files. This can be a string, buffer, or {@link URL}.
|
|
52
|
+
* @param include The string pattern which must be present in the file name.
|
|
53
|
+
*
|
|
54
|
+
* Note that we do **not** support a full globby pattern using asterisk for wildcards. It has to be an exact match with {@link String.includes}
|
|
55
|
+
*
|
|
56
|
+
* @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursivelyStringIncludes(path, fileNameEndsWith)) {}`
|
|
57
|
+
*/
|
|
58
|
+
declare function findFilesRecursivelyStringIncludes(path: PathLike, include: string): AsyncIterableIterator<string>;
|
|
59
|
+
/**
|
|
60
|
+
* @param path The path in which to find files. This can be a string, buffer, or {@link URL}.
|
|
61
|
+
* @param regex The regex pattern that the file name must match.
|
|
62
|
+
*
|
|
63
|
+
* @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursivelyRegex(path, fileNameEndsWith)) {}`
|
|
64
|
+
*/
|
|
65
|
+
declare function findFilesRecursivelyRegex(path: PathLike, regex: RegExp): AsyncIterableIterator<string>;
|
|
66
|
+
|
|
67
|
+
export { findFilesRecursively, findFilesRecursivelyRegex, findFilesRecursivelyStringEndsWith, findFilesRecursivelyStringIncludes, findFilesRecursivelyStringStartsWith };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
var src_exports = {};
|
|
24
|
+
__export(src_exports, {
|
|
25
|
+
findFilesRecursively: () => findFilesRecursively,
|
|
26
|
+
findFilesRecursivelyRegex: () => findFilesRecursivelyRegex,
|
|
27
|
+
findFilesRecursivelyStringEndsWith: () => findFilesRecursivelyStringEndsWith,
|
|
28
|
+
findFilesRecursivelyStringIncludes: () => findFilesRecursivelyStringIncludes,
|
|
29
|
+
findFilesRecursivelyStringStartsWith: () => findFilesRecursivelyStringStartsWith
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(src_exports);
|
|
32
|
+
|
|
33
|
+
// src/lib/findFilesRecursively.ts
|
|
34
|
+
var import_promises = require("fs/promises");
|
|
35
|
+
var import_node_path = require("path");
|
|
36
|
+
async function* findFilesRecursively(path, predicate = () => true) {
|
|
37
|
+
const dir = await (0, import_promises.opendir)(path);
|
|
38
|
+
for await (const item of dir) {
|
|
39
|
+
if (item.isFile() && predicate(item.name)) {
|
|
40
|
+
yield (0, import_node_path.join)(dir.path, item.name);
|
|
41
|
+
} else if (item.isDirectory()) {
|
|
42
|
+
yield* findFilesRecursively((0, import_node_path.join)(dir.path, item.name), predicate);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
__name(findFilesRecursively, "findFilesRecursively");
|
|
47
|
+
function findFilesRecursivelyStringStartsWith(path, fileStartsWith) {
|
|
48
|
+
return findFilesRecursively(path, (filePath) => filePath.startsWith(fileStartsWith));
|
|
49
|
+
}
|
|
50
|
+
__name(findFilesRecursivelyStringStartsWith, "findFilesRecursivelyStringStartsWith");
|
|
51
|
+
function findFilesRecursivelyStringEndsWith(path, fileEndsWith) {
|
|
52
|
+
return findFilesRecursively(path, (filePath) => filePath.endsWith(fileEndsWith));
|
|
53
|
+
}
|
|
54
|
+
__name(findFilesRecursivelyStringEndsWith, "findFilesRecursivelyStringEndsWith");
|
|
55
|
+
function findFilesRecursivelyStringIncludes(path, include) {
|
|
56
|
+
return findFilesRecursively(path, (filePath) => filePath.includes(include));
|
|
57
|
+
}
|
|
58
|
+
__name(findFilesRecursivelyStringIncludes, "findFilesRecursivelyStringIncludes");
|
|
59
|
+
function findFilesRecursivelyRegex(path, regex) {
|
|
60
|
+
return findFilesRecursively(path, (filePath) => regex.test(filePath));
|
|
61
|
+
}
|
|
62
|
+
__name(findFilesRecursivelyRegex, "findFilesRecursivelyRegex");
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
findFilesRecursively,
|
|
66
|
+
findFilesRecursivelyRegex,
|
|
67
|
+
findFilesRecursivelyStringEndsWith,
|
|
68
|
+
findFilesRecursivelyStringIncludes,
|
|
69
|
+
findFilesRecursivelyStringStartsWith
|
|
70
|
+
});
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/findFilesRecursively.ts"],"sourcesContent":["export * from './lib/findFilesRecursively';\n","import type { PathLike } from 'node:fs';\nimport { opendir } from 'node:fs/promises';\nimport { join } from 'node:path';\n\n/**\n *\n * @param path The path in which to find files.\n * @param predicate A predicate function receives the path as a parameter. Truthy values will have the path included, falsey values will have the file excluded.\n *\n * @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursively(path, predicate)) {}`\n *\n * @example\n * ```typescript\n * // With CommonJS: To find all files ending with `.ts` in the src directory:\n * const path = require('node:path');\n *\n * for await (const file of findFilesRecursively(path.join(__dirname, 'src'), (filePath) => filePath.endsWith('.ts'))) {\n * console.log(file);\n * }\n * ```\n *\n * @example\n * ```typescript\n * // With ESM: To find all files ending with `.ts` in the src directory:\n * for await (const file of findFilesRecursively(new URL('src', import.meta.url), (filePath) => filePath.endsWith('.ts'))) {\n * console.log(file);\n * }\n * ```\n */\nexport async function* findFilesRecursively(path: PathLike, predicate: (filePath: string) => boolean = () => true): AsyncIterableIterator<string> {\n\tconst dir = await opendir(path);\n\n\tfor await (const item of dir) {\n\t\tif (item.isFile() && predicate(item.name)) {\n\t\t\tyield join(dir.path, item.name);\n\t\t} else if (item.isDirectory()) {\n\t\t\tyield* findFilesRecursively(join(dir.path, item.name), predicate);\n\t\t}\n\t}\n}\n\n/**\n *\n * @param path The path in which to find files. This can be a string, buffer, or {@link URL}.\n * @param fileStartsWith The string pattern with which the file name must start.\n *\n * Note that we do **not** support a full globby pattern using asterisk for wildcards. It has to be an exact match with {@link String.startsWith}\n *\n * @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursivelyStringStartsWith(path, fileNameEndsWith)) {}`\n */\nexport function findFilesRecursivelyStringStartsWith(path: PathLike, fileStartsWith: string) {\n\treturn findFilesRecursively(path, (filePath) => filePath.startsWith(fileStartsWith));\n}\n\n/**\n *\n * @param path The path in which to find files. This can be a string, buffer, or {@link URL}.\n * @param fileEndsWith The string pattern with which the file name must end.\n * Ideally this is a file extension, however you can also provide more parts of the end of the file.\n *\n * Note that we do **not** support a full globby pattern using asterisk for wildcards. It has to be an exact match with {@link String.endsWith}\n *\n * @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursivelyStringEndsWith(path, fileNameEndsWith)) {}`\n */\nexport function findFilesRecursivelyStringEndsWith(path: PathLike, fileEndsWith: string) {\n\treturn findFilesRecursively(path, (filePath) => filePath.endsWith(fileEndsWith));\n}\n\n/**\n * @param path The path in which to find files. This can be a string, buffer, or {@link URL}.\n * @param include The string pattern which must be present in the file name.\n *\n * Note that we do **not** support a full globby pattern using asterisk for wildcards. It has to be an exact match with {@link String.includes}\n *\n * @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursivelyStringIncludes(path, fileNameEndsWith)) {}`\n */\nexport function findFilesRecursivelyStringIncludes(path: PathLike, include: string) {\n\treturn findFilesRecursively(path, (filePath) => filePath.includes(include));\n}\n\n/**\n * @param path The path in which to find files. This can be a string, buffer, or {@link URL}.\n * @param regex The regex pattern that the file name must match.\n *\n * @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursivelyRegex(path, fileNameEndsWith)) {}`\n */\nexport function findFilesRecursivelyRegex(path: PathLike, regex: RegExp) {\n\treturn findFilesRecursively(path, (filePath) => regex.test(filePath));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sBAAwB;AACxB,uBAAqB;AA2BrB,gBAAuB,qBAAqB,MAAgB,YAA2C,MAAM,MAAqC;AACjJ,QAAM,MAAM,UAAM,yBAAQ,IAAI;AAE9B,mBAAiB,QAAQ,KAAK;AAC7B,QAAI,KAAK,OAAO,KAAK,UAAU,KAAK,IAAI,GAAG;AAC1C,gBAAM,uBAAK,IAAI,MAAM,KAAK,IAAI;AAAA,IAC/B,WAAW,KAAK,YAAY,GAAG;AAC9B,aAAO,yBAAqB,uBAAK,IAAI,MAAM,KAAK,IAAI,GAAG,SAAS;AAAA,IACjE;AAAA,EACD;AACD;AAVuB;AAqBhB,SAAS,qCAAqC,MAAgB,gBAAwB;AAC5F,SAAO,qBAAqB,MAAM,CAAC,aAAa,SAAS,WAAW,cAAc,CAAC;AACpF;AAFgB;AAcT,SAAS,mCAAmC,MAAgB,cAAsB;AACxF,SAAO,qBAAqB,MAAM,CAAC,aAAa,SAAS,SAAS,YAAY,CAAC;AAChF;AAFgB;AAYT,SAAS,mCAAmC,MAAgB,SAAiB;AACnF,SAAO,qBAAqB,MAAM,CAAC,aAAa,SAAS,SAAS,OAAO,CAAC;AAC3E;AAFgB;AAUT,SAAS,0BAA0B,MAAgB,OAAe;AACxE,SAAO,qBAAqB,MAAM,CAAC,aAAa,MAAM,KAAK,QAAQ,CAAC;AACrE;AAFgB;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/lib/findFilesRecursively.ts
|
|
5
|
+
import { opendir } from "node:fs/promises";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
async function* findFilesRecursively(path, predicate = () => true) {
|
|
8
|
+
const dir = await opendir(path);
|
|
9
|
+
for await (const item of dir) {
|
|
10
|
+
if (item.isFile() && predicate(item.name)) {
|
|
11
|
+
yield join(dir.path, item.name);
|
|
12
|
+
} else if (item.isDirectory()) {
|
|
13
|
+
yield* findFilesRecursively(join(dir.path, item.name), predicate);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
__name(findFilesRecursively, "findFilesRecursively");
|
|
18
|
+
function findFilesRecursivelyStringStartsWith(path, fileStartsWith) {
|
|
19
|
+
return findFilesRecursively(path, (filePath) => filePath.startsWith(fileStartsWith));
|
|
20
|
+
}
|
|
21
|
+
__name(findFilesRecursivelyStringStartsWith, "findFilesRecursivelyStringStartsWith");
|
|
22
|
+
function findFilesRecursivelyStringEndsWith(path, fileEndsWith) {
|
|
23
|
+
return findFilesRecursively(path, (filePath) => filePath.endsWith(fileEndsWith));
|
|
24
|
+
}
|
|
25
|
+
__name(findFilesRecursivelyStringEndsWith, "findFilesRecursivelyStringEndsWith");
|
|
26
|
+
function findFilesRecursivelyStringIncludes(path, include) {
|
|
27
|
+
return findFilesRecursively(path, (filePath) => filePath.includes(include));
|
|
28
|
+
}
|
|
29
|
+
__name(findFilesRecursivelyStringIncludes, "findFilesRecursivelyStringIncludes");
|
|
30
|
+
function findFilesRecursivelyRegex(path, regex) {
|
|
31
|
+
return findFilesRecursively(path, (filePath) => regex.test(filePath));
|
|
32
|
+
}
|
|
33
|
+
__name(findFilesRecursivelyRegex, "findFilesRecursivelyRegex");
|
|
34
|
+
export {
|
|
35
|
+
findFilesRecursively,
|
|
36
|
+
findFilesRecursivelyRegex,
|
|
37
|
+
findFilesRecursivelyStringEndsWith,
|
|
38
|
+
findFilesRecursivelyStringIncludes,
|
|
39
|
+
findFilesRecursivelyStringStartsWith
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/findFilesRecursively.ts"],"sourcesContent":["import type { PathLike } from 'node:fs';\nimport { opendir } from 'node:fs/promises';\nimport { join } from 'node:path';\n\n/**\n *\n * @param path The path in which to find files.\n * @param predicate A predicate function receives the path as a parameter. Truthy values will have the path included, falsey values will have the file excluded.\n *\n * @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursively(path, predicate)) {}`\n *\n * @example\n * ```typescript\n * // With CommonJS: To find all files ending with `.ts` in the src directory:\n * const path = require('node:path');\n *\n * for await (const file of findFilesRecursively(path.join(__dirname, 'src'), (filePath) => filePath.endsWith('.ts'))) {\n * console.log(file);\n * }\n * ```\n *\n * @example\n * ```typescript\n * // With ESM: To find all files ending with `.ts` in the src directory:\n * for await (const file of findFilesRecursively(new URL('src', import.meta.url), (filePath) => filePath.endsWith('.ts'))) {\n * console.log(file);\n * }\n * ```\n */\nexport async function* findFilesRecursively(path: PathLike, predicate: (filePath: string) => boolean = () => true): AsyncIterableIterator<string> {\n\tconst dir = await opendir(path);\n\n\tfor await (const item of dir) {\n\t\tif (item.isFile() && predicate(item.name)) {\n\t\t\tyield join(dir.path, item.name);\n\t\t} else if (item.isDirectory()) {\n\t\t\tyield* findFilesRecursively(join(dir.path, item.name), predicate);\n\t\t}\n\t}\n}\n\n/**\n *\n * @param path The path in which to find files. This can be a string, buffer, or {@link URL}.\n * @param fileStartsWith The string pattern with which the file name must start.\n *\n * Note that we do **not** support a full globby pattern using asterisk for wildcards. It has to be an exact match with {@link String.startsWith}\n *\n * @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursivelyStringStartsWith(path, fileNameEndsWith)) {}`\n */\nexport function findFilesRecursivelyStringStartsWith(path: PathLike, fileStartsWith: string) {\n\treturn findFilesRecursively(path, (filePath) => filePath.startsWith(fileStartsWith));\n}\n\n/**\n *\n * @param path The path in which to find files. This can be a string, buffer, or {@link URL}.\n * @param fileEndsWith The string pattern with which the file name must end.\n * Ideally this is a file extension, however you can also provide more parts of the end of the file.\n *\n * Note that we do **not** support a full globby pattern using asterisk for wildcards. It has to be an exact match with {@link String.endsWith}\n *\n * @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursivelyStringEndsWith(path, fileNameEndsWith)) {}`\n */\nexport function findFilesRecursivelyStringEndsWith(path: PathLike, fileEndsWith: string) {\n\treturn findFilesRecursively(path, (filePath) => filePath.endsWith(fileEndsWith));\n}\n\n/**\n * @param path The path in which to find files. This can be a string, buffer, or {@link URL}.\n * @param include The string pattern which must be present in the file name.\n *\n * Note that we do **not** support a full globby pattern using asterisk for wildcards. It has to be an exact match with {@link String.includes}\n *\n * @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursivelyStringIncludes(path, fileNameEndsWith)) {}`\n */\nexport function findFilesRecursivelyStringIncludes(path: PathLike, include: string) {\n\treturn findFilesRecursively(path, (filePath) => filePath.includes(include));\n}\n\n/**\n * @param path The path in which to find files. This can be a string, buffer, or {@link URL}.\n * @param regex The regex pattern that the file name must match.\n *\n * @return An {@link AsyncIterableIterator<string>} of all the files. To loop over these use `for await (const file of findFilesRecursivelyRegex(path, fileNameEndsWith)) {}`\n */\nexport function findFilesRecursivelyRegex(path: PathLike, regex: RegExp) {\n\treturn findFilesRecursively(path, (filePath) => regex.test(filePath));\n}\n"],"mappings":";;;;AACA,SAAS,eAAe;AACxB,SAAS,YAAY;AA2BrB,gBAAuB,qBAAqB,MAAgB,YAA2C,MAAM,MAAqC;AACjJ,QAAM,MAAM,MAAM,QAAQ,IAAI;AAE9B,mBAAiB,QAAQ,KAAK;AAC7B,QAAI,KAAK,OAAO,KAAK,UAAU,KAAK,IAAI,GAAG;AAC1C,YAAM,KAAK,IAAI,MAAM,KAAK,IAAI;AAAA,IAC/B,WAAW,KAAK,YAAY,GAAG;AAC9B,aAAO,qBAAqB,KAAK,IAAI,MAAM,KAAK,IAAI,GAAG,SAAS;AAAA,IACjE;AAAA,EACD;AACD;AAVuB;AAqBhB,SAAS,qCAAqC,MAAgB,gBAAwB;AAC5F,SAAO,qBAAqB,MAAM,CAAC,aAAa,SAAS,WAAW,cAAc,CAAC;AACpF;AAFgB;AAcT,SAAS,mCAAmC,MAAgB,cAAsB;AACxF,SAAO,qBAAqB,MAAM,CAAC,aAAa,SAAS,SAAS,YAAY,CAAC;AAChF;AAFgB;AAYT,SAAS,mCAAmC,MAAgB,SAAiB;AACnF,SAAO,qBAAqB,MAAM,CAAC,aAAa,SAAS,SAAS,OAAO,CAAC;AAC3E;AAFgB;AAUT,SAAS,0BAA0B,MAAgB,OAAe;AACxE,SAAO,qBAAqB,MAAM,CAAC,aAAa,MAAM,KAAK,QAAQ,CAAC;AACrE;AAFgB;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sapphire/node-utilities",
|
|
3
|
+
"version": "1.1.0-next.384ff84.0",
|
|
4
|
+
"description": "Node specific JavaScript utilities for the Sapphire Community",
|
|
5
|
+
"author": "@sapphire",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/index.mjs",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/utilities",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "vitest run",
|
|
19
|
+
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"docs": "typedoc-json-parser",
|
|
22
|
+
"prepack": "yarn build",
|
|
23
|
+
"bump": "cliff-jumper",
|
|
24
|
+
"check-update": "cliff-jumper --dry-run"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/sapphiredev/utilities.git",
|
|
29
|
+
"directory": "packages/node-utilities"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist/**/*.js*",
|
|
33
|
+
"dist/**/*.mjs*",
|
|
34
|
+
"dist/**/*.d*"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=v16.0.0",
|
|
38
|
+
"npm": ">=7.0.0"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"@sapphire/utilities",
|
|
42
|
+
"@sapphire/node-utilities",
|
|
43
|
+
"bot",
|
|
44
|
+
"typescript",
|
|
45
|
+
"ts",
|
|
46
|
+
"yarn",
|
|
47
|
+
"discord",
|
|
48
|
+
"sapphire",
|
|
49
|
+
"standalone"
|
|
50
|
+
],
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/sapphiredev/utilities/issues"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@favware/cliff-jumper": "^1.8.7",
|
|
59
|
+
"@vitest/coverage-c8": "^0.23.4",
|
|
60
|
+
"tsup": "^6.2.3",
|
|
61
|
+
"typedoc": "^0.23.15",
|
|
62
|
+
"typedoc-json-parser": "^5.0.0",
|
|
63
|
+
"typescript": "^4.8.3",
|
|
64
|
+
"vitest": "^0.23.4"
|
|
65
|
+
}
|
|
66
|
+
}
|