add-new-key-value
add a new key/value to an JS Object
API
var addKeyValue = require('add-new-key-value')
addKeyValue({JS Object}, {key:string}, {value})
the JS Object should valid as well the key or will return undefined
addKeyValue.strict({JS Object}, {key:string}, {value})
the same as the above method but if the value is undefined will ignore the creation on the new property for the given object
note: will overwrite existing keys
Usage
var addKeyValue = var pkg = // case 1console// should return '1.0.0' console// property should exist and return undefined // case 2var newPkg = console// should return '1.0.0' // case 3 - with strictvar newPkg = addKeyValueconsole// should return null var newPkg = addKeyValueconsole// should return '1.0.0' // case 4 - with strictvar newPkg = addKeyValueconsole// property should not exist and return undefined
Development
this projet has been set up with a precommit that forces you to follow a code style, no jshint issues and 100% of code coverage before commit
to run test
npm test
to run jshint
npm run jshint
to run code style
npm run code-style
to run check code coverage
npm run check-coverage
to open the code coverage report
npm run open-coverage