package-config
Get namespaced config from the closest package.json
Last updated a year ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install package-config 
SYNC missed versions from official npm registry.

package-config

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.

Install

npm install package-config

Usage

{
	"name": "some-package",
	"version": "1.0.0",
	"unicorn": {
		"rainbow": true
	}
}
import {packageConfig} from 'package-config';

const config = await packageConfig('unicorn');

console.log(config.rainbow);
//=> true

API

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.

packageConfig(namespace, options?)

Returns a Promise for the config.

packageConfigSync(namespace, options?)

Returns the config.

namespace

Type: string

The package.json namespace you want.

options

Type: object

cwd

Type: string
Default: process.cwd()

The directory to start looking up for a package.json file.

defaults

Type: object

The default config.

skipOnFalse

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
}

packageJsonPath(config)

Pass in the config returned from any of the above methods.

Returns the file path to the package.json file or undefined if not found.

Related

Current Tags

  • 5.0.0                                ...           latest (a year ago)

2 Versions

  • 5.0.0                                ...           a year ago
  • 0.1.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (3)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE