readFiles
Reads all files in a directory and its subdirectories synchronously. Optionally, it can filter files by their extensions.
Parameters
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
dirName | string | false | The directory to read files from. | |
options | Object | true | An object with optional parameters. | |
options.extensions | Array<string> | true | [ ] | An array of file extensions to filter the files by. If not provided, all files are read. |
options.noPromise | boolean | true | false | A boolean indicating whether to return the result directly or wrapped in a Promise. If true, the result is returned directly. If false or not provided, the result is wrapped in a Promise. |
Returns
Example
readFiles(`${process.cwd()}/src`, { noPromise: true }); // [ "./src/functions/duration.js", "./src/functions/fetchWithTimeout.js", "./src/typings/duration.d.ts", "./src/typings/fetchWithTimeout.d.ts" ]
readFiles(`${process.cwd()}/src`, { extensions: [".js"], noPromise: true }); // [ "./src/functions/duration.js", "./src/functions/fetchWithTimeout.js" ]
./
├───src
| ├───functions
| | ├───duration.js
| | └───fetchWithTimeout.js
| └───typings
| ├───duration.d.ts
| └───fetchWithTimeout.d.ts