pkg-store
Use package.json as a config store.
Install
Install with npm:
$ npm i pkg-store --save
Usage
var pkg = require('pkg-store')(process.cwd());
API
All methods allow the optional use of dot-notation for property keys. See the data-store documentation for all available methods.
.set/.get
The .set
method automatically persists values to package.json
:
pkg.set('bin.foo', 'bar');
console.log(pkg.get('bin'));
console.log(pkg.get('bin.foo'));
.has
Returns true
if package.json
has the given property:
console.log(pkg.has('name'));
console.log(pkg.has('zzzzzzz'));
.union
Add and append array values (automatically persists values to package.json
):
pkg.union('keywords', 'foo');
pkg.union('keywords', 'bar');
pkg.union('keywords', 'baz');
console.log(pkg.get('keywords'));
Events
Most methods also emit an event. See data-store for more details.
pkg.on('union', function(key, value) {
console.log(arguments);
});
pkg.union('keywords', 'foo');
pkg.union('keywords', 'bar');
pkg.union('keywords', 'baz');
Related projects
- data-store: Easily get, set and persist config data. | homepage
- find-pkg: Find the first directory with a package.json, recursing up, starting with the given directory. Similar… more | homepage
- normalize-pkg: Normalize values in package.json to improve compatibility, programmatic readability and usefulness with third party libs. | homepage
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Jon Schlinkert
License
Copyright © 2016 Jon Schlinkert
Released under the MIT license.
This file was generated by verb on January 23, 2016.