Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hughsk/closest-package
Find the closest package.json file meeting specific criteria
https://github.com/hughsk/closest-package
Last synced: 12 days ago
JSON representation
Find the closest package.json file meeting specific criteria
- Host: GitHub
- URL: https://github.com/hughsk/closest-package
- Owner: hughsk
- License: other
- Created: 2014-08-07T22:06:39.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-13T19:21:18.000Z (about 9 years ago)
- Last Synced: 2024-10-17T16:39:38.061Z (22 days ago)
- Language: JavaScript
- Size: 155 KB
- Stars: 15
- Watchers: 5
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# closest-package [![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)
Find the closest package.json file meeting specific criteria by searching
upwards from a given directory until hitting root.## Usage
[![NPM](https://nodei.co/npm/closest-package.png)](https://nodei.co/npm/closest-package/)
### `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:``` javascript
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 parsed `package.json` file.
* `filename`: the `package.json`'s absolute filename.### `file = closest.sync(dir, [filter])`
Same as the `closest` function, however executed synchronously:
``` javascript
var result = closest.sync(__dirname, function(json, filename) {
return json.name === 'async'
})console.log(result)
```## License
MIT. See [LICENSE.md](http://github.com/hughsk/closest-package/blob/master/LICENSE.md) for details.