Module: @sapphire/node-utilities
Functions
findFilesRecursively
▸ findFilesRecursively(path
, predicate?
): AsyncIterableIterator
<string
>
Example
// With CommonJS: To find all files ending with `.ts` in the src directory:
const path = require('node:path');
for await (const file of findFilesRecursively(path.join(__dirname, 'src'), (filePath) => filePath.endsWith('.ts'))) {
console.log(file);
}
Example
// With ESM: To find all files ending with `.ts` in the src directory:
for await (const file of findFilesRecursively(new URL('src', import.meta.url), (filePath) => filePath.endsWith('.ts'))) {
console.log(file);
}
Parameters
Name | Type | Description |
---|---|---|
path | PathLike | The path in which to find files. |
predicate | (filePath : string ) => boolean | A predicate function receives the path as a parameter. Truthy values will have the path included, falsey values will have the file excluded. |
Returns
AsyncIterableIterator
<string
>
An AsyncIterableIterator of all the files. To loop over these use for await (const file of findFilesRecursively(path, predicate)) {}
Defined in
lib/findFilesRecursively.ts:30
findFilesRecursivelyRegex
▸ findFilesRecursivelyRegex(path
, regex
): AsyncIterableIterator
<string
>
Parameters
Name | Type | Description |
---|---|---|
path | PathLike | The path in which to find files. This can be a string, buffer, or URL. |
regex | RegExp | The regex pattern that the file name must match. |
Returns
AsyncIterableIterator
<string
>
An AsyncIterableIterator of all the files. To loop over these use for await (const file of findFilesRecursivelyRegex(path, fileNameEndsWith)) {}
Defined in
lib/findFilesRecursively.ts:87
findFilesRecursivelyStringEndsWith
▸ findFilesRecursivelyStringEndsWith(path
, fileEndsWith
): AsyncIterableIterator
<string
>
Parameters
Name | Type | Description |
---|---|---|
path | PathLike | The path in which to find files. This can be a string, buffer, or URL. |
fileEndsWith | string | The string pattern with which the file name must end. Ideally this is a file extension, however you can also provide more parts of the end of the file. Note that we do not support a full globby pattern using asterisk for wildcards. It has to be an exact match with String.endsWith |
Returns
AsyncIterableIterator
<string
>
An AsyncIterableIterator of all the files. To loop over these use for await (const file of findFilesRecursivelyStringEndsWith(path, fileNameEndsWith)) {}
Defined in
lib/findFilesRecursively.ts:65
findFilesRecursivelyStringIncludes
▸ findFilesRecursivelyStringIncludes(path
, include
): AsyncIterableIterator
<string
>
Parameters
Name | Type | Description |
---|---|---|
path | PathLike | The path in which to find files. This can be a string, buffer, or URL. |
include | string | The string pattern which must be present in the file name. Note that we do not support a full globby pattern using asterisk for wildcards. It has to be an exact match with String.includes |
Returns
AsyncIterableIterator
<string
>
An AsyncIterableIterator of all the files. To loop over these use for await (const file of findFilesRecursivelyStringIncludes(path, fileNameEndsWith)) {}
Defined in
lib/findFilesRecursively.ts:77
findFilesRecursivelyStringStartsWith
▸ findFilesRecursivelyStringStartsWith(path
, fileStartsWith
): AsyncIterableIterator
<string
>
Parameters
Name | Type | Description |
---|---|---|
path | PathLike | The path in which to find files. This can be a string, buffer, or URL. |
fileStartsWith | string | The string pattern with which the file name must start. Note that we do not support a full globby pattern using asterisk for wildcards. It has to be an exact match with String.startsWith |
Returns
AsyncIterableIterator
<string
>
An AsyncIterableIterator of all the files. To loop over these use for await (const file of findFilesRecursivelyStringStartsWith(path, fileNameEndsWith)) {}