Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/base/base-pkg
Base plugin for adding a `pkg` object with get/set methods for getting data from package.json or setting data to package.json.
https://github.com/base/base-pkg
config data libary module npm package package-json project store
Last synced: 3 days ago
JSON representation
Base plugin for adding a `pkg` object with get/set methods for getting data from package.json or setting data to package.json.
- Host: GitHub
- URL: https://github.com/base/base-pkg
- Owner: base
- License: mit
- Created: 2016-02-20T13:27:42.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-21T08:51:23.000Z (almost 7 years ago)
- Last Synced: 2024-10-14T06:29:40.166Z (about 1 month ago)
- Topics: config, data, libary, module, npm, package, package-json, project, store
- Language: JavaScript
- Size: 194 KB
- Stars: 13
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# base-pkg [![NPM version](https://img.shields.io/npm/v/base-pkg.svg?style=flat)](https://www.npmjs.com/package/base-pkg) [![NPM monthly downloads](https://img.shields.io/npm/dm/base-pkg.svg?style=flat)](https://npmjs.org/package/base-pkg) [![NPM total downloads](https://img.shields.io/npm/dt/base-pkg.svg?style=flat)](https://npmjs.org/package/base-pkg) [![Linux Build Status](https://img.shields.io/travis/node-base/base-pkg.svg?style=flat&label=Travis)](https://travis-ci.org/node-base/base-pkg)
> Plugin for adding a `pkg` method that exposes pkg-store to your base application.
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 base-pkg
```## Usage
```js
var pkg = require('base-pkg');
var Base = require('base');
var app = new Base();app.use(pkg());
console.log(app.pkg.data);
//=> {"name": "my-project", ...}
```## API
Visit [pkg-store](https://github.com/jonschlinkert/pkg-store) for additional API details and documentation.
### .pkg.set
```js
app.pkg.set(key, value);
```Set property `key` with the given `value`.
**Example**
```js
// given {"name": "my-project"}
app.pkg.set('bin.foo', 'bar');console.log(app.pkg.data);
//=> {"name": "my-project", "bin": {"foo": "bar"}}
```### .pkg.save
Persist package.json to the file system at `app.pkg.path`.
```js
app.pkg.save();
```### .pkg.get
```js
app.pkg.get(key);
```Get property `key` from package.json.
**Example**
```js
// given {"name": "my-project"}
app.pkg.set('bin.foo', 'bar');console.log(app.pkg.get('bin'));
//=> {"foo": "bar"}
```### .pkg.has
```js
app.pkg.has(key);
```Returns `true` if `package.json` has property `key`.
**Example**
```js
// given: {"name": "my-project"}
console.log(app.pkg.has('name'));
//=> true
console.log(app.pkg.has('zzzzzzz'));
//=> false
```### .pkg.union
```js
app.pkg.union(key, val);
```Create array `key`, or concatenate values to array `key`. Also uniquifies the array.
**Example**
```js
app.pkg.union('keywords', 'foo');
app.pkg.union('keywords', ['bar', 'baz']);console.log(app.pkg.get('keywords'));
//=> ['foo', 'bar', 'baz']
```## .pkg.expand
Creates a get/set API using [cache-base](https://github.com/jonschlinkert/cache-base), where the cache is populated with a shallow clone of `package.json` with values expanded by [expand-pkg](https://github.com/jonschlinkert/expand-pkg).
**Example**
```js
console.log(app.pkg.get('author'));
//=> 'Jon Schlinkert (https://github.com/jonschlinkert)'var expanded = app.pkg.expand();
var author = expanded.get('author');
//=> {name: 'Jon Schlinkert', url: 'https://github.com/jonschlinkert'}
```## About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Running Tests
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
```Building docs
_(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
```### Related projects
You might also be interested in these projects:
* [base-options](https://www.npmjs.com/package/base-options): Adds a few options methods to base-methods, like `option`, `enable` and `disable`. See the readme… [more](https://github.com/jonschlinkert/base-options) | [homepage](https://github.com/jonschlinkert/base-options "Adds a few options methods to base-methods, like `option`, `enable` and `disable`. See the readme for the full API.")
* [base](https://www.npmjs.com/package/base): Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks | [homepage](https://github.com/node-base/base "Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks")
* [cache-base](https://www.npmjs.com/package/cache-base): Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects. | [homepage](https://github.com/jonschlinkert/cache-base "Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects.")
* [pkg-store](https://www.npmjs.com/package/pkg-store): Use package.json as a config store. | [homepage](https://github.com/jonschlinkert/pkg-store "Use package.json as a config store.")### 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._