# pkg-store

> Use package.json as a config store.

Latest version **1.0.1** (published 2017-12-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install pkg-store
pnpm add pkg-store
yarn add pkg-store
bun add pkg-store
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-12-21 |
| First published | 2015-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Jon Schlinkert |
| Maintainers | jonschlinkert |
| Keywords | config, data, get, json, package, package-json, package.json, pkg, set, store, update |

## Links

- npm: https://www.npmjs.com/package/pkg-store
- Repository: https://github.com/jonschlinkert/pkg-store
- Issues: https://github.com/jonschlinkert/pkg-store/issues
- npm.io page: https://npm.io/package/pkg-store

## Dependencies (2)

- [cache-base](https://npm.io/package/cache-base.md) ^2.0.2
- [write-json](https://npm.io/package/write-json.md) ^2.0.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-12-21
- 1.0.0 — 2017-12-21
- 0.2.2 — 2016-04-13
- 0.2.1 — 2016-03-31
- 0.2.0 — 2016-03-31
- 0.1.2 — 2016-02-04
- 0.1.1 — 2016-01-23
- 0.1.0 — 2015-12-23

## README

# pkg-store [![NPM version](https://img.shields.io/npm/v/pkg-store.svg?style=flat)](https://www.npmjs.com/package/pkg-store) [![NPM monthly downloads](https://img.shields.io/npm/dm/pkg-store.svg?style=flat)](https://npmjs.org/package/pkg-store) [![NPM total downloads](https://img.shields.io/npm/dt/pkg-store.svg?style=flat)](https://npmjs.org/package/pkg-store) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/pkg-store.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/pkg-store)

> Use package.json as a config store.

Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save pkg-store
```

## Usage

```js
const Pkg = require('pkg-store');
```

## API

Extends [cache-base](https://github.com/jonschlinkert/cache-base), please see the `cache-base` documentation for more details.

### [Pkg](index.js#L37)

Initialize a new `Pkg` store at the given `cwd` with the specified `options`.

**Params**

* `cwd` **{String}**: Directory of the package.json to read.
* `options` **{Object}**

**Example**

```js
const pkg = require('pkg-store')(process.cwd());
const pkg = new Pkg(cwd, options);
// or
const pkg = new Pkg(options);

console.log(pkg.path);
//=> '~/your-project/package.json'

console.log(pkg.data);
//=> { name: 'your-project', ... }
```

### [.save](index.js#L63)

Write the `pkg.data` object to the file system at `pkg.path`.

**Params**

* `callback` **{Function}**: (optional)

**Example**

```js
pkg.save();
```

### [.read](index.js#L83)

Reads `pkg.path` from the file system and returns an object.

* `returns` **{undefined}**

**Example**

```js
const data = pkg.read();
```

### .set

```js
pkg.set(key, value);
```

Set property `key` with the given `value`.

**Example**

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

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

### .get

```js
pkg.get(key);
```

Get property `key` from package.json.

**Example**

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

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

### .has

```js
pkg.has(key);
```

Returns `true` if `package.json` has property `key`.

**Example**

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

### .union

```js
pkg.union(key, val);
```

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

**Example**

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

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

## About

<details>
<summary><strong>Contributing</strong></summary>

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

</details>

<details>
<summary><strong>Running Tests</strong></summary>

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

</details>
<details>
<summary><strong>Building docs</strong></summary>

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

</details>

### Related projects

You might also be interested in these projects:

* [data-store](https://www.npmjs.com/package/data-store): Easily get, set and persist config data. | [homepage](https://github.com/jonschlinkert/data-store "Easily get, set and persist config data.")
* [expand-pkg](https://www.npmjs.com/package/expand-pkg): Parse string values in package.json into objects. | [homepage](https://github.com/jonschlinkert/expand-pkg "Parse string values in package.json into objects.")
* [find-pkg](https://www.npmjs.com/package/find-pkg): Find the first directory with a package.json, recursing up, starting with the given directory. Similar… [more](https://github.com/jonschlinkert/find-pkg) | [homepage](https://github.com/jonschlinkert/find-pkg "Find the first directory with a package.json, recursing up, starting with the given directory. Similar to look-up but does not support globs and only searches for package.json. Async and sync.")
* [normalize-pkg](https://www.npmjs.com/package/normalize-pkg): Normalize values in package.json using the map-schema library. | [homepage](https://github.com/jonschlinkert/normalize-pkg "Normalize values in package.json using the map-schema library.")

### Author

**Jon Schlinkert**

* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert)
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)

### License

Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on December 21, 2017._

---
_Source: https://npm.io/package/pkg-store · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
