|
| 1 | +/** |
| 2 | + * Options object |
| 3 | + */ |
| 4 | +export type Opts = { |
| 5 | + /** |
| 6 | + * - A pathFilter cb. |
| 7 | + */ |
| 8 | + pathFilter?: pathFilter | undefined; |
| 9 | + /** |
| 10 | + * - A statFilter cb. |
| 11 | + */ |
| 12 | + statFilter?: statFilter | undefined; |
| 13 | + /** |
| 14 | + * - The maximum number of folders to walk down into. |
| 15 | + */ |
| 16 | + maxDepth?: number | undefined; |
| 17 | + /** |
| 18 | + * - A shaper cb. |
| 19 | + */ |
| 20 | + shaper?: shaper | undefined; |
| 21 | +}; |
| 22 | +/** |
| 23 | + * pathFilter lets you filter files based on a resolved `filepath`. |
| 24 | + */ |
| 25 | +export type pathFilter = (filepath: string) => boolean; |
| 26 | +/** |
| 27 | + * statFilter lets you filter files based on a lstat object. |
| 28 | + */ |
| 29 | +export type statFilter = (st: Object) => boolean; |
| 30 | +/** |
| 31 | + * FWStats is the object that the okdistribute/folder-walker module returns by default. |
| 32 | + */ |
| 33 | +export type FWStats = { |
| 34 | + /** |
| 35 | + * - The filepath of the directory where the walk started. |
| 36 | + */ |
| 37 | + root: string; |
| 38 | + /** |
| 39 | + * - The resolved filepath. |
| 40 | + */ |
| 41 | + filepath: string; |
| 42 | + /** |
| 43 | + * - A fs.Stats instance. |
| 44 | + */ |
| 45 | + stat: Object; |
| 46 | + /** |
| 47 | + * - The relative path to `root`. |
| 48 | + */ |
| 49 | + relname: string; |
| 50 | + /** |
| 51 | + * - The resolved filepath of the files containing directory. |
| 52 | + */ |
| 53 | + basename: string; |
| 54 | +}; |
| 55 | +/** |
| 56 | + * shaper lets you change the shape of the returned file data from walk-time stats. |
| 57 | + */ |
| 58 | +export type shaper = (fwStats: FWStats) => any; |
| 59 | +/** |
| 60 | + * Options object |
| 61 | + * |
| 62 | + * @typedef Opts |
| 63 | + * @property {pathFilter} [pathFilter] - A pathFilter cb. |
| 64 | + * @property {statFilter} [statFilter] - A statFilter cb. |
| 65 | + * @property {Number} [maxDepth=Infinity] - The maximum number of folders to walk down into. |
| 66 | + * @property {shaper} [shaper] - A shaper cb. |
| 67 | + */ |
| 68 | +/** |
| 69 | + * Create an async generator that iterates over all folders and directories inside of `dirs`. |
| 70 | + * |
| 71 | + * @async |
| 72 | + * @generator |
| 73 | + * @function |
| 74 | + * @public |
| 75 | + * @param {String|String[]} dirs - The path of the directory to walk, or an array of directory paths. |
| 76 | + * @param {?(Opts)} opts - Options used for the directory walk. |
| 77 | + * |
| 78 | + * @yields {Promise<String|any>} - An async iterator that returns anything. |
| 79 | + */ |
| 80 | +export function asyncFolderWalker(dirs: string | string[], opts: (Opts) | null): AsyncGenerator<any, void, unknown>; |
| 81 | +/** |
| 82 | + * allFiles gives you all files from the directory walk as an array. |
| 83 | + * |
| 84 | + * @async |
| 85 | + * @function |
| 86 | + * @public |
| 87 | + * @param {String|String[]} dirs - The path of the directory to walk, or an array of directory paths. |
| 88 | + * @param {?(Opts)} opts - Options used for the directory walk. |
| 89 | + * |
| 90 | + * @returns {Promise<String[]|any>} - An async iterator that returns anything. |
| 91 | + */ |
| 92 | +export function allFiles(dirs: string | string[], opts: (Opts) | null): Promise<string[] | any>; |
| 93 | +/** |
| 94 | + * Async iterable collector |
| 95 | + * |
| 96 | + * @async |
| 97 | + * @function |
| 98 | + * @private |
| 99 | + * @param {AsyncIterator} iterator - The iterator to collect into an array |
| 100 | + */ |
| 101 | +export function all(iterator: AsyncIterator<any, any, undefined>): Promise<any[]>; |
0 commit comments