Distopico Vegan 9e639edc8d | 6 years ago | |
---|---|---|
.. | ||
index.js | 6 years ago | |
license | 6 years ago | |
package.json | 6 years ago | |
readme.md | 6 years ago |
Get namespaced config from the closest package.json
Having tool specific config in package.json reduces the amount of metafiles in your repo (there are usually a lot!) and makes the config obvious compared to hidden dotfiles like .eslintrc
, which can end up causing confusion. XO, for example, uses the xo
namespace in package.json, and ESLint uses eslintConfig
. Many more tools supports this, like AVA, Babel, nyc, etc.
$ npm install pkg-conf
{
"name": "some-package",
"version": "1.0.0",
"unicorn": {
"rainbow": true
}
}
const pkgConf = require('pkg-conf');
(async () => {
const config = await pkgConf('unicorn');
console.log(config.rainbow);
//=> true
})();
It walks up parent directories until a package.json
can be found, reads it, and returns the user specified namespace or an empty object if not found.
Returns a Promise
for the config.
Returns the config.
Type: string
The package.json namespace you want.
Type: string
Default: process.cwd()
Directory to start looking up for a package.json file.
Type: Object
Default config.
Type: boolean
Default: false
Skip package.json
files that have the namespaced config explicitly set to false
.
Continues searching upwards until the next package.json
file is reached. This can be useful when you need to support the ability for users to have nested package.json
files, but only read from the root one, like in the case of electron-builder
where you have one package.json
file for the app and one top-level for development.
Example usage for the user:
{
"name": "some-package",
"version": "1.0.0",
"unicorn": false
}
Pass in the config
returned from any of the above methods.
Returns the filepath to the package.json file or null
when not found.
MIT © Sindre Sorhus