Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TomerAberbach/get-all-files
⚡ A blazing fast recursive directory crawler with lazy sync and async iterator support.
https://github.com/TomerAberbach/get-all-files
async-iterator-support benchmark directory file-tree files fs iterates javascript micromatch node-js node-module nodejs npm npm-module npm-package path paths readdir recursive
Last synced: 2 days ago
JSON representation
⚡ A blazing fast recursive directory crawler with lazy sync and async iterator support.
- Host: GitHub
- URL: https://github.com/TomerAberbach/get-all-files
- Owner: TomerAberbach
- License: mit
- Created: 2018-06-12T20:53:39.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-10-15T03:32:54.000Z (20 days ago)
- Last Synced: 2024-10-27T11:13:21.647Z (7 days ago)
- Topics: async-iterator-support, benchmark, directory, file-tree, files, fs, iterates, javascript, micromatch, node-js, node-module, nodejs, npm, npm-module, npm-package, path, paths, readdir, recursive
- Language: TypeScript
- Homepage: https://npm.im/get-all-files
- Size: 685 KB
- Stars: 16
- Watchers: 5
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-blazingly-fast - get-all-files - ⚡ A blazing fast recursive directory crawler with lazy sync and async iterator support. (JavaScript)
README
get-all-files
A blazing fast recursive directory crawler with lazy sync and async iterator support.## Install
```sh
$ npm i get-all-files
```## Usage
```js
import { getAllFiles, getAllFilesSync } from 'get-all-files'// Lazily iterate over filenames asynchronously
for await (const filename of getAllFiles(`path/to/dir/or/file`)) {
// Could break early on some condition and get-all-files
// won't have unnecessarily accumulated the filenames in an array
console.log(filename)
}// Get array of filenames asynchronously
console.log(await getAllFiles(`path/to/dir/or/file`).toArray())// Lazily iterate over filenames synchronously
for (const filename of getAllFilesSync(`path/to/dir/or/file`)) {
// Could break early on some condition and get-all-files
// won't have unnecessarily accumulated the filenames in an array
console.log(filename)
}// Get array of filenames synchronously
console.log(getAllFilesSync(`path/to/dir/or/file`).toArray())
```## API
### Methods
#### `getAllFiles(path[, options])`
Returns a lazy
[async iterable/iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
that asynchronously iterates over the file paths recursively found at `path` in
no particular order.Calling `toArray` on the returned value returns a promise that resolves to an
array of the file paths.#### `getAllFilesSync(path[, options])`
Returns a lazy
[iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol)/[iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol)
that iterates over the file paths recursively found at `path` in no particular
order.Calling `toArray` on the returned value returns an array of the file paths.
### Parameters
#### `path`
Type: `string`
A path to a file or directory to recursively find files in.
#### `options`
Type: `object`
##### Properties
###### `resolve`
Type: `boolean`\
Default: `false`Whether to resolve paths to absolute paths (relative to `process.cwd()`).
###### `isExcludedDir`
Type: `(dirname: string) => boolean`\
Default: `() => false`A predicate that determines whether the directory with the given `dirname`
should be crawled. There is no `isExcludedFile` option because you can exclude
files by checking conditions while lazily iterating using`getAllFiles.sync` or
`getAllFiles.async`.## Contributing
Stars are always welcome!
For bugs and feature requests,
[please create an issue](https://github.com/TomerAberbach/get-all-files/issues/new).## License
[MIT](https://github.com/TomerAberbach/get-all-files/blob/main/license) ©
[Tomer Aberbach](https://github.com/TomerAberbach)