vfile utility to find one or more files by searching the file system downwards
npm install vfile-find-down[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[vfile][] utility to find files by searching the file system downwards.
* What is this?
* When should I use this?
* Install
* Use
* API
* [findDown(test[, paths][, callback])](#finddowntest-paths-callback)
* [findDownAll(test[, paths][, callback])](#finddownalltest-paths-callback)
* Assert
* Callback
* CallbackAll
* Result
* Test
* Types
* Compatibility
* Contribute
* License
This utility lets you find one or many files downwards.
You can use this utility if you want to find files in, say, a folder.
One example is all markdown files.
If you instead want to find files upwards, such as config files, you can use
[vfile-find-up][vfile-find-up].
This package is [ESM only][esm].
In Node.js (version 16), install with [npm][]:
``sh`
npm install vfile-find-down
`js
import {findDown} from 'vfile-find-down'
console.log(await findDown('.md'))
`
Yields:
`js`
VFile {
cwd: '/Users/tilde/Projects/oss/vfile-find-down',
data: {},
history: [ '/Users/tilde/Projects/oss/vfile-find-down/readme.md' ],
messages: []
}
This package exports the identifiers
[findDown][api-find-down] andfindDownAll
[][api-find-down-all].
There is no default export.
Find the first file or folder downwards.
> 👉 Note: files are not read (their value is not populated).to-vfile
> use [][to-vfile] for that.
###### Signatures
* (test[, paths], callback) => undefined(test[, paths]) => Promise
*
###### Parameters
* test ([Test][api-test])paths
— things to search for
* (Array, default: process.cwd())callback
— places to search from
* ([Callback][api-callback], optional)
— callback called when done
###### Returns
Nothing when callback is given (undefined), otherwise a promise thatVFile
resolves to a file ([][vfile] or undefined).
Find files or folders downwards.
> 👉 Note: files are not read (their value is not populated).to-vfile
> use [][to-vfile] for that.
###### Signatures
* (test[, paths], callback) => undefined(test[, paths]) => Promise
*
###### Parameters
* test ([Test][api-test])paths
— things to search for
* (Array, default: process.cwd())callback
— places to search from
* ([CallbackAll][api-callback-all], optional)
— callback called when done
###### Returns
Nothing when callback is given (undefined), otherwise a promise thatArray
resolves to files ([][vfile]).
Handle a file (TypeScript type).
###### Parameters
* file ([VFile][vfile])stats
— file to handle
* ([Stats][stats])fs.stat
— stats from
###### Returns
How to handle this file ([Result][api-result], optional).
Callback called when done finding one file (TypeScript type).
###### Parameters
* error (Error or undefined)file
— error; errors are currently never passed
* ([VFile][vfile] or undefined)
— file
###### Returns
Nothing (undefined).
Callback called when done (TypeScript type).
###### Parameters
* error (Error or undefined)files
— error; errors are currently never passed
* ([Array][vfile])
— files
###### Returns
Nothing (undefined).
What to do when collecting a file or folder (TypeScript type).
###### Fields
* break (boolean, default: false)include
— stop searching after this file or folder
* (boolean, default: false)skip
— include this file or folder
* (boolean, default: false)
— do not search inside this folder
Things to search for (TypeScript type).
For strings, the basename or extname of files must match them andnode_modules
hidden folders and will not be searched.
For arrays, any test in them must match.
###### Type
`ts`
type Test = Array
This package is fully typed with [TypeScript][].
It exports the additional types
[Assert][api-assert],Callback
[][api-callback],CallbackAll
[][api-callback-all],Result
[][api-result], andTest
[][api-test].
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, vfile-find-down@^7,
compatible with Node.js 16.
See [contributing.md][contributing] in [vfile/.github][health] for ways tosupport.md`][support] for ways to get help.
get started.
See [
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/vfile/vfile-find-down/workflows/main/badge.svg
[build]: https://github.com/vfile/vfile-find-down/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-find-down.svg
[coverage]: https://codecov.io/github/vfile/vfile-find-down
[downloads-badge]: https://img.shields.io/npm/dm/vfile-find-down.svg
[downloads]: https://www.npmjs.com/package/vfile-find-down
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/vfile/vfile/discussions
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[typescript]: https://www.typescriptlang.org
[contributing]: https://github.com/vfile/.github/blob/main/contributing.md
[support]: https://github.com/vfile/.github/blob/main/support.md
[health]: https://github.com/vfile/.github
[coc]: https://github.com/vfile/.github/blob/main/code-of-conduct.md
[license]: license
[author]: https://wooorm.com
[vfile]: https://github.com/vfile/vfile
[to-vfile]: https://github.com/vfile/to-vfile
[vfile-find-up]: https://github.com/vfile/vfile-find-up
[stats]: https://nodejs.org/api/fs.html#fs_class_fs_stats
[api-find-down-all]: #finddownalltest-paths-callback
[api-find-down]: #finddowntest-paths-callback
[api-assert]: #assert
[api-callback]: #callback
[api-callback-all]: #callbackall
[api-result]: #result
[api-test]: #test