const pkg = require('{%= name %}');
const Base = require('base');
const app = new Base();
app.use(pkg());
console.log(app.pkg.data);
//=> {"name": "my-project", ...}
Visit [pkg-store][] for additional API details and documentation.
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"}}
Persist package.json to the file system at app.pkg.path
.
app.pkg.save();
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"}
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
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']
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'}