Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pkg-store

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pkg-store

Use package.json as a config store.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23K
decreased by-2.34%
Maintainers
1
Weekly downloads
 
Created
Source

pkg-store NPM version NPM downloads Build Status

Use package.json as a config store.

Install

Install with npm:

$ npm install pkg-store --save

Inherits cache-base, please see the cache-base documentation for more details.

Usage

Pass the cwd and options to use, or an options object with cwd or path. If nothing is passed, the current working directory will be used.

var pkg = require('pkg-store')(cwd, options);
// or
var pkg = require('pkg-store')(options);
// or
var pkg = require('pkg-store')();

Example

var pkg = require('pkg-store')(process.cwd());

API

Inherits cache-base, please see the cache-base documentation for more details.

.set

pkg.set(key, value);

Set property key with the given value.

Example

// given {"name": "my-project"}
pkg.set('bin.foo', 'bar');

console.log(pkg.data);
//=> {"name": "my-project", "bin": {"foo": "bar"}}

.save

Persist package.json to the file system at pkg.path.

pkg.save();

.get

pkg.get(key);

Get property key from package.json.

Example

// given {"name": "my-project"}
pkg.set('bin.foo', 'bar');

console.log(pkg.get('bin'));
//=> {"foo": "bar"}

.has

pkg.has(key);

Returns true if package.json has property key.

Example

// given: {"name": "my-project"}
console.log(pkg.has('name'));
//=> true
console.log(pkg.has('zzzzzzz'));
//=> false

.union

pkg.union(key, val);

Create array key, or concatenate values to array key. Also uniquifies the array.

Example

pkg.union('keywords', 'foo');
pkg.union('keywords', ['bar', 'baz']);

console.log(pkg.get('keywords'));
//=> ['foo', 'bar', 'baz']

You might also be interested in these projects:

  • data-store: Easily get, set and persist config data. | homepage
  • expand-pkg: Parse string values in package.json into objects. | 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 using the map-schema library. | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with verb:

$ npm install verb && npm run docs

Or, if verb is installed globally:

$ verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb, v, on March 30, 2016.

Keywords

FAQs

Package last updated on 31 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc