Update package.json
Install
$ npm install --save update-pkg
Usage
const Pkg = const pkg = pkgdata //=> package.json object pkgpkg// or Promisepkg
API
new Pkg(cwd, [options])
Return a new Pkg instance and would resolve package.json
located at cwd
folder. Default cwd
is ./
.
options
create
Type: boolean
Default: false
Create package.json
when it does not exist, otherwise it will throw an error.
.data
Type: object
Default: {}
The parsed content of package.json
.
.set(keyPath, value)
Set value by the given keyPath
like author.name
and value
like EGOIST
.
.update(keyPath, updater)
updater
is the function to produce the updated value.
.append(keyPath, value)
Append a value
to specific keyPath.
.preppend(keyPath, value)
Prepend a value
to specific keyPath.
.get(keyPath)
Get value by the given keyPath.
.save()
Type: function
Return: Promise
Save data to package.json
.
.saveSync()
Type: function
Return: this
Save data to package.json
but synchronously.
License
MIT © EGOIST