///
/**
* Find the first file or folder downwards.
*
* > π **Note**: files are not read (their `value` is not populated).
* > use `to-vfile` for that.
*
* @overload
* @param {Test} test
* @param {Array | URL | string | null | undefined} paths
* @param {Callback} callback
* @returns {undefined}
*
* @overload
* @param {Test} test
* @param {Callback} callback
* @returns {undefined}
*
* @overload
* @param {Test} test
* @param {Array | URL | string | null | undefined} [paths]
* @returns {Promise}
*
* @param {Test} test
* Things to search for.
* @param {Array | Callback | URL | string | null | undefined} [paths]
* Places to search from.
* @param {Callback | null | undefined} [callback]
* Callback called when done.
* @returns {Promise | undefined}
* Nothing when `callback` is given, otherwise a promise that resolves to
* a file or `undefined`.
*/
export function findDown(test: Test, paths: Array | URL | string | null | undefined, callback: Callback): undefined;
/**
* Find the first file or folder downwards.
*
* > π **Note**: files are not read (their `value` is not populated).
* > use `to-vfile` for that.
*
* @overload
* @param {Test} test
* @param {Array | URL | string | null | undefined} paths
* @param {Callback} callback
* @returns {undefined}
*
* @overload
* @param {Test} test
* @param {Callback} callback
* @returns {undefined}
*
* @overload
* @param {Test} test
* @param {Array | URL | string | null | undefined} [paths]
* @returns {Promise}
*
* @param {Test} test
* Things to search for.
* @param {Array | Callback | URL | string | null | undefined} [paths]
* Places to search from.
* @param {Callback | null | undefined} [callback]
* Callback called when done.
* @returns {Promise | undefined}
* Nothing when `callback` is given, otherwise a promise that resolves to
* a file or `undefined`.
*/
export function findDown(test: Test, callback: Callback): undefined;
/**
* Find the first file or folder downwards.
*
* > π **Note**: files are not read (their `value` is not populated).
* > use `to-vfile` for that.
*
* @overload
* @param {Test} test
* @param {Array | URL | string | null | undefined} paths
* @param {Callback} callback
* @returns {undefined}
*
* @overload
* @param {Test} test
* @param {Callback} callback
* @returns {undefined}
*
* @overload
* @param {Test} test
* @param {Array | URL | string | null | undefined} [paths]
* @returns {Promise}
*
* @param {Test} test
* Things to search for.
* @param {Array | Callback | URL | string | null | undefined} [paths]
* Places to search from.
* @param {Callback | null | undefined} [callback]
* Callback called when done.
* @returns {Promise | undefined}
* Nothing when `callback` is given, otherwise a promise that resolves to
* a file or `undefined`.
*/
export function findDown(test: Test, paths?: Array | URL | string | null | undefined): Promise;
/**
* Find files or folders downwards.
*
* > π **Note**: files are not read (their `value` is not populated).
* > use `to-vfile` for that.
*
* @overload
* @param {Test} test
* @param {Array | URL | string | null | undefined} paths
* @param {CallbackAll} callback
* @returns {undefined}
*
* @overload
* @param {Test} test
* @param {CallbackAll} callback
* @returns {undefined}
*
* @overload
* @param {Test} test
* @param {Array | URL | string | null | undefined} [paths]
* @returns {Promise>}
*
* @param {Test} test
* Things to search for.
* @param {Array | CallbackAll | URL | string | null | undefined} [paths]
* Places to search from.
* @param {CallbackAll | null | undefined} [callback]
* Callback called when done.
* @returns {Promise> | undefined}
* Nothing when `callback` is given, otherwise a promise that resolves to
* files.
*/
export function findDownAll(test: Test, paths: Array | URL | string | null | undefined, callback: CallbackAll): undefined;
/**
* Find files or folders downwards.
*
* > π **Note**: files are not read (their `value` is not populated).
* > use `to-vfile` for that.
*
* @overload
* @param {Test} test
* @param {Array | URL | string | null | undefined} paths
* @param {CallbackAll} callback
* @returns {undefined}
*
* @overload
* @param {Test} test
* @param {CallbackAll} callback
* @returns {undefined}
*
* @overload
* @param {Test} test
* @param {Array | URL | string | null | undefined} [paths]
* @returns {Promise>}
*
* @param {Test} test
* Things to search for.
* @param {Array | CallbackAll | URL | string | null | undefined} [paths]
* Places to search from.
* @param {CallbackAll | null | undefined} [callback]
* Callback called when done.
* @returns {Promise> | undefined}
* Nothing when `callback` is given, otherwise a promise that resolves to
* files.
*/
export function findDownAll(test: Test, callback: CallbackAll): undefined;
/**
* Find files or folders downwards.
*
* > π **Note**: files are not read (their `value` is not populated).
* > use `to-vfile` for that.
*
* @overload
* @param {Test} test
* @param {Array | URL | string | null | undefined} paths
* @param {CallbackAll} callback
* @returns {undefined}
*
* @overload
* @param {Test} test
* @param {CallbackAll} callback
* @returns {undefined}
*
* @overload
* @param {Test} test
* @param {Array | URL | string | null | undefined} [paths]
* @returns {Promise>}
*
* @param {Test} test
* Things to search for.
* @param {Array | CallbackAll | URL | string | null | undefined} [paths]
* Places to search from.
* @param {CallbackAll | null | undefined} [callback]
* Callback called when done.
* @returns {Promise> | undefined}
* Nothing when `callback` is given, otherwise a promise that resolves to
* files.
*/
export function findDownAll(test: Test, paths?: Array | URL | string | null | undefined): Promise>;
/**
* Handle a file.
*/
export type Assert = (file: VFile, stats: fs.Stats) => Result | undefined;
/**
* Callback called when done.
*/
export type CallbackAll = (error: Error | undefined, files?: Array | undefined) => undefined;
/**
* Callback called when done finding one file.
*/
export type Callback = (error: Error | undefined, file?: VFile | undefined) => undefined;
/**
* Things to search for.
*
* For strings, the `basename` or `extname` of files must match them and
* hidden folders and `node_modules` will not be searched.
* For arrays, any test in them must match.
*/
export type Test = Array | Assert | string;
/**
* What to do when collecting a file or folder.
*/
export type Result = {
/**
* Stop searching after this file or folder.
*/
break?: boolean | null | undefined;
/**
* Include this file or folder.
*/
include?: boolean | null | undefined;
/**
* Do not search inside this folder.
*/
skip?: boolean | null | undefined;
};
/**
* State.
*/
export type State = {
/**
* Whether we stopped searching.
*/
broken: boolean;
/**
* Files that have been checked already.
*/
checked: Set;
/**
* Whether weβre looking for one file.
*/
one: boolean;
/**
* File test.
*/
test: Assert;
};
import { VFile } from 'vfile';
import fs from 'node:fs';