closest-package
v1.0.0
Published
Find the closest package.json file meeting specific criteria
Downloads
6,373
Maintainers
Readme
closest-package
Find the closest package.json file meeting specific criteria by searching upwards from a given directory until hitting root.
Usage
closest(dir, [filter], found(err, file))
Given a starting directory dir
, look up through every directory to see if
it contains a package.json
file matching the filter
function, for example:
closest(__dirname, function(json, filename) {
return json.name === 'async'
}, function(err, file) {
console.log(file)
})
Note that filter
is optional and takes the following arguments:
json
: the parsedpackage.json
file.filename
: thepackage.json
's absolute filename.
file = closest.sync(dir, [filter])
Same as the closest
function, however executed synchronously:
var result = closest.sync(__dirname, function(json, filename) {
return json.name === 'async'
})
console.log(result)
License
MIT. See LICENSE.md for details.