Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabiospampinato/tiny-readdir-glob
A simple promisified recursive readdir function, with support for globs.
https://github.com/fabiospampinato/tiny-readdir-glob
glob promise readdir recursive simple tiny
Last synced: about 2 months ago
JSON representation
A simple promisified recursive readdir function, with support for globs.
- Host: GitHub
- URL: https://github.com/fabiospampinato/tiny-readdir-glob
- Owner: fabiospampinato
- License: mit
- Created: 2023-11-23T23:40:51.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-03-29T14:19:11.000Z (10 months ago)
- Last Synced: 2024-11-12T18:29:32.050Z (2 months ago)
- Topics: glob, promise, readdir, recursive, simple, tiny
- Language: TypeScript
- Homepage:
- Size: 33.2 KB
- Stars: 26
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Tiny Readdir Glob
A simple promisified recursive readdir function, with support for globs.
## Install
```sh
npm install --save tiny-readdir-glob
```## Usage
```ts
import readdir from 'tiny-readdir-glob';const aborter = new AbortController ();
const result = await readdir ( ['src/**/*.js'], {
depth: 20, // Maximum depth to look at
limit: 1_000_000, // Maximum number of files explored, useful as a stop gap in some edge cases
followSymlinks: true, // Whether to follow symlinks or not
ignore: ['**/.git', '**/node_modules'], // Globs, or raw function, that if returns true will ignore this particular file or a directory and its descendants
signal: aborter.signal, // Optional abort signal, useful for aborting potentially expensive operations
onDirents: dirents => console.log ( dirents ) // Optional callback that will be called as soon as new dirents are available, useful for example for discovering ".gitignore" files while searching
});console.log ( result.directories ); // => Array of absolute paths pointing to directories, filtered by the provided glob
console.log ( result.files ); // => Array of absolute paths pointing to files, filtered by the provided glob
console.log ( result.symlinks ); // => Array of absolute paths pointing to symlinks, filtered by the provided globconsole.log ( result.directoriesFound ); // => Array of absolute paths pointing to directories, not fully filtered by the provided glob yet
console.log ( result.filesFound ); // => Array of absolute paths pointing to files, not fully filtered by the provided glob yet
console.log ( result.symlinksFound ); // => Array of absolute paths pointing to symlinks, not fully filtered by the provided glob yetconsole.log ( result.directoriesFoundNames ); // => Set of directories names found
console.log ( result.filesFoundNames ); // => Set of files name found
console.log ( result.symlinksFoundNames ); // => Set of symlinks names foundconsole.log ( result.directoriesFoundNamesToPaths ); // => Record of directories names found to their paths
console.log ( result.filesFoundNamesToPaths ); // => Record of files name found to their paths
console.log ( result.symlinksFoundNamesToPaths ); // => Record of symlinks names found to their pathssetTimeout ( () => aborter.abort (), 10000 ); // Aborting if it's going to take longer than 10s
```## License
MIT © Fabio Spampinato