Skip to content

Latest commit

 

History

History
112 lines (75 loc) · 1.71 KB

.verb.md

File metadata and controls

112 lines (75 loc) · 1.71 KB

Usage

const pkg = require('{%= name %}');
const Base = require('base');
const app = new Base();

app.use(pkg());

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

API

Visit [pkg-store][] for additional API details and documentation.

.pkg.set

app.pkg.set(key, value);

Set property key with the given value.

Example

// 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.

app.pkg.save();

.pkg.get

app.pkg.get(key);

Get property key from package.json.

Example

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

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

.pkg.has

app.pkg.has(key);

Returns true if package.json has property key.

Example

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

.pkg.union

app.pkg.union(key, val);

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

Example

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

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

.pkg.expand

Creates a shallow clone of package.json with values expanded by [expand-pkg][].

Example

console.log(app.pkg.get('author'));
//=> 'Jon Schlinkert (https://github.com/jonschlinkert)'

const expanded = app.pkg.expand();
console.log(expanded.author);
//=> {name: 'Jon Schlinkert', url: 'https://github.com/jonschlinkert'}