unified

Project: vfile/vfile-find-up

Package: vfile-find-up@5.0.1

  1. Dependencies: 1·Dependents: 9
  2. vfile utility to find one or more files by searching the file system upwards
  1. util 105
  2. utility 103
  3. file 29
  4. virtual 21
  5. vfile 18
  6. vfile-util 16
  7. find 9
  8. walk 7

vfile-find-up

Build Coverage Downloads Sponsors Backers Chat

Find vfiles by searching the file system upwards.

Install

npm:

npm install vfile-find-up

Use

var findUp = require('vfile-find-up')

findUp.all('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

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

Search for tests upwards. Invokes callback with either an error or an array of files passing tests. Note: Virtual Files are not read (their contents is not populated).

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 function.

path

Place to searching from (string, default: process.cwd()).

callback

Function invoked with all matching files (function cb(err[, files])).

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

Like findUp.all, but invokes callback with the first found file, or null.

function test(file)

Check whether a virtual file should be included. Invoked with a vfile.

Returns

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

Contribute

See contributing.md in vfile/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer