Find vfiles by searching the file system upwards.
npm:
npm install vfile-find-up
var findUp = require('vfile-find-up');
// Search for files named `package.json` from the current
// working directory upwards:
findUp.all('package.json', console.log);
// null [ VFile {
// data: {},
// messages: [],
// history: [ '/Users/tilde/projects/oss/vfile-find-up/package.json' ],
// cwd: '/Users/tilde/projects/oss/vfile-find-up' } ]
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).
tests
(string|Function|Array.<tests>
) — A test is a function invoked with avfile
. If an array is passed in, any test must match a given file for it to be included. If astring
is passed in, thebasename
orextname
of files must match it for them to be included.path
(string
, default:process.cwd()
) — Place to searching from;callback
(function cb(err[, files])
); — Function invoked with all matching files.
Like vfileFindUp.all
, but invokes callback
with the first found
file, or null
.
Check whether a virtual file should be included. Invoked with a vfile.
true
orvfileFindUp.INCLUDE
— Include the file in the results;vfileFindUp.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:
vfileFindUp.INCLUDE | vfileFindUp.BREAK
.