import { Dirent, Stats } from "fs"; /** * type of the 3rd argument for the filter callback */ export type ExtrasData = { /** name of the file being considered */ file: string; /** path to the directory being processed that contains the file */ path: string; /** result from fs.lstat or readdir */ stat: Dirent | Stats; /** full path with cwd + path + file */ fullFile: string; /** path to file without cwd: path + file */ dirFile: string; /** extsion of the file, ie: `.js` */ ext: string; /** file name without the extension */ noExt: string; /** files in the directory */ files: (string | Dirent)[]; }; /** * Info from the filter callback to indicate what to do next */ export type FilterInfo = { /** name of the group to add the file or directory (if grouping is enabled) */ group?: string; /** if `true` then skip the file or directory, else add it */ skip?: boolean; /** stop the scanning and return the result immediately. */ stop?: boolean; /** if not `undefined`, then use this as the value to add to the output */ formatName?: string; }; /** * result from the filter callback * - `false` or `undefined` - skip the file or directory * - `true` - include the file in the default result * - _string_ - name of the group to add the file or directory (if grouping is enabled) * - _FilterInfo_ - see type {@link FilterInfo} for details */ export type FilterResult = boolean | string | FilterInfo; /** * filter callback for file or directory entry * @param file - name of the file/dir being considered * @param path - path to the directory containing the file. Not the full path, * just the relative path from CWD. It's empty string for the files in the * first level directory. * @param extras - extras data */ export type FilterCallback = (file: string, path: string, extras: ExtrasData) => FilterResult; /** * Options for filterScanDir */ export type Options = { /** current working directory to start scanning */ cwd?: string; /** * prefix to add to the paths to scan. It's applied after `cwd`. * - The `prefix` will be in the resulting paths. Useful if you want * to scan a dir further down from `cwd` but you don't want to prepend * CWD to the resulting paths. */ prefix?: string; /** prepend CWD to paths returned */ prependCwd?: boolean; /** sort files from each dir */ sortFiles?: boolean; /** include directories in result */ includeDir?: boolean; /** include symlinks in result (when includeDir is false, symlinks to directories are excluded unless this is true) */ includeSymlink?: boolean; /** zero base max level of directories to recurse into. Default: `Infinity` */ maxLevel?: number; /** * use `fs.lstat` to get stat of each file, instead of `readir`'s `withFileTypes` option. * * - *Default*: `true` - for significant performance improvement, set this to `false` * */ fullStat?: boolean; /** * for async version only - numer of directories to process concurrently. *Default*: `50` * * - Set this to `0` or `1` to disable concurrent mode * * NOTE: setting this to a very large number, or `Infinity`, could potentially * increase performance very significantly, however, there is a dimishing return * and more memory usage, so the default is already fairly good. */ concurrency?: number; /** set to `true` to throw errors instead of ignoring them */ rethrowError?: boolean; /** callback to filter files. */ filter?: FilterCallback; /** callback to filter directories. */ filterDir?: FilterCallback; /** array or string of extensions to ignore. ext must include `.`, ie: `".js"` */ ignoreExt?: string | string[]; /** array or string of extensions to include only, apply after `ignoreExt` */ filterExt?: string | string[]; /** * path separator to use to join entries * * - *Default*: `path.posix.sep` * - If you didn't specify this, then `cwd` is automatically converted to use `/`. */ pathSep?: string; }; /** * options specifically to set grouping flag `true` to enable grouping of files */ export type GroupingOptions = { /** * enable grouping of files * This is default to disabled, so it's only expecting `true` to enable it. */ grouping: true; } & Options; /** * The scanned result if grouping is enabled. * * - The default `files` group will contain all files not assigned a group * - All other files with a group will be assigned to that field */ export type GroupingResult = { files: string[]; } & Record; /** * async version of filter scan dir * @param options * @returns */ export declare function filterScanDir(options?: string): Promise; export declare function filterScanDir(options?: Options): Promise; export declare function filterScanDir(options?: GroupingOptions): Promise; /** sync version of filter scan dir */ export declare function filterScanDirSync(options?: string): string[]; export declare function filterScanDirSync(options?: Options): string[]; export declare function filterScanDirSync(options?: GroupingOptions): GroupingResult;