vfile-find-up

vfile utility to find one or more files by searching the file system upwards

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
vfile-find-up
606.0.02 years ago7 years agoMinified + gzip package size for vfile-find-up in KB

Readme

vfile-find-up
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
Find vfiles by searching the file system upwards.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.
npm install vfile-find-up
## Use

```js
import {findUp} from 'vfile-find-up'

findUp('package.json', console.log)

Yields:
null [ VFile {
  data: {},
  messages: [],
  history: [ '/Users/tilde/projects/oss/vfile-find-up/package.json' ],
  cwd: '/Users/tilde/projects/oss/vfile-find-up' } ]

API

This package exports the following identifiers: findUp, findUpOne, INCLUDE, BREAK. There is no default export.

findUp(tests[, path][, callback])

Search for tests upwards. Calls callback with either an error or an array of files passing tests. Note: Virtual Files are not read (their contents is not populated).
Sigantures
  • (tests: Test, path?: string, callback: Callback): void
  • (tests: Test, path?: string): Promise.<Array.<VFile>>
Parameters
tests
Things to search for (string, Function, or Array.<tests>).
If a string is passed in, the basename or extname of files must match it for them to be included.
If an array is passed in, any test must match a given file for it to be included.
Otherwise, they must be functiontest.
path
Place to searching from (string, default: process.cwd()).
callback
Function called with all matching files (function cb(err[, files])).

findUpOne(tests[, path][, callback])

Like findUp, but either calls callback with the first found file, or null or without callback resolves to a file or null.

function test(file)

Check whether a virtual file should be included. Called with a vfile.
Returns
  • true or INCLUDE — Include the file in the results
  • BREAK — Stop searching for files
  • anything else is ignored: the file is not included

The different flags can be combined by using the pipe operator: INCLUDE | BREAK.

Contribute

See contributing.mdcontributing in vfile/.githubhealth for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITlicense © Titus Wormerauthor