Norway Porridge Makers

    pkg-add

    1.1.0 • Public • Published

    pkg-add

    Adds a key and value to the closest package.json

    Build Status npm version Dependency Status js-standard-style

    Install

    Install with npm

    $ npm i -g pkg-add

    Example

    pkg-add is primarily a command line utility for one aspect of managing package.json files

    echo '{"foo": "bar"}' | pkg-add > package.json

    Usage

    pkg-add simply adds field into the closest package.json and will fail if the key already exists.

    To use simply stream in a JSON object to merge with the package json.

    -f --force

    Use -f to force overwriting existing keys in the package json.

    Programmatic Usage

    $ npm i -S pkg-add

    The main pkg-add function needs an object which acts as a master, usually this is from the package.json, but, it needn’t be, any object will do. The object is treated as immutable, fresh objects will always be returned.

    The only current option is whether to force merging over the master object, this defaults to false and will throw an error if keys exist on the master.

    The main function returns another function which can be used to add properties. This add function simply merges the objects and returns a new one.

    const package = require('package.json')
    const add = require('pkg-add')(pkg, {
      force: false  
    })
     
    console.log(add('foo', 'bar'))
    // or
    console.log(add({
      foo: 'bar'
    }))

    Running tests

    $ npm install
    $ npm test

    Contributing

    Pull requests are always welcome, please follow the standard style and ensure all tests are passing.

    For bugs and feature requests, please create an issue.

    License

    MIT

    Install

    npm i pkg-add

    DownloadsWeekly Downloads

    7

    Version

    1.1.0

    License

    MIT

    Last publish

    Collaborators

    • mattstyles