GithubHelp home page GithubHelp logo

cwonrails / pkg-conf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sindresorhus/pkg-conf

0.0 2.0 0.0 15 KB

Get namespaced config from the closest package.json

License: MIT License

JavaScript 100.00%

pkg-conf's Introduction

pkg-conf Build Status

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 --save pkg-conf

Usage

{
	"name": "some-package",
	"version": "1.0.0",
	"unicorn": {
		"rainbow": true
	}
}
const pkgConf = require('pkg-conf');

pkgConf('unicorn').then(config => {
	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.

pkgConf(namespace, [options])

Returns a Promise for the config.

pkgConf.sync(namespace, [options])

Returns the config.

namespace

Type: string

The package.json namespace you want.

options

cwd

Type: string
Default: process.cwd()

Directory to start looking up for a package.json file.

defaults

Type: Object

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
}

pkgConf.filepath(config)

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

Returns the filepath to the package.json file or null when not found.

Related

  • read-pkg-up - Read the closest package.json file
  • read-pkg - Read a package.json file
  • find-up - Find a file by walking up parent directories

License

MIT © Sindre Sorhus

pkg-conf's People

Contributors

ekmartin avatar jamestalmage avatar sindresorhus avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.