{"_id":"jsonfile-updater","_rev":"2835006","name":"jsonfile-updater","description":"Node module for programatically updating package.json and other JSON files","dist-tags":{"latest":"3.1.0"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"time":{"modified":"2022-09-06T15:32:17.000Z","created":"2017-02-22T19:13:16.880Z","3.1.0":"2017-09-28T06:22:46.385Z","3.0.0":"2017-09-28T02:59:53.658Z","2.1.0":"2017-03-05T20:06:12.586Z","2.0.0":"2017-03-05T19:48:54.115Z","1.1.1":"2017-03-01T13:42:38.137Z","1.1.0":"2017-02-27T20:27:03.746Z","1.0.0":"2017-02-22T19:13:16.880Z"},"users":{},"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"repository":{"type":"git","url":"git+https://github.com/hacksparrow/jsonfile-updater.git"},"versions":{"3.1.0":{"name":"jsonfile-updater","version":"3.1.0","description":"Node module for programatically updating package.json and other JSON files","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"git+https://github.com/hacksparrow/jsonfile-updater.git"},"keywords":["package.json","json file","json","file","update","updater"],"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/jsonfile-updater/issues"},"homepage":"https://github.com/hacksparrow/jsonfile-updater#readme","devDependencies":{"mocha":"^3.5.3"},"engines":{"node":">=6"},"gitHead":"c79c9feb3f7fb44123c4e0a4c97b045548d24645","_id":"jsonfile-updater@3.1.0","_npmVersion":"5.3.0","_nodeVersion":"8.2.1","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"dist":{"shasum":"fd29c28d85bb2a96200b53832643a17865db1e85","size":9690,"noattachment":false,"key":"/jsonfile-updater/-/jsonfile-updater-3.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/jsonfile-updater/download/jsonfile-updater-3.1.0.tgz"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jsonfile-updater-3.1.0.tgz_1506579766201_0.7403503053355962"},"directories":{},"publish_time":1506579766385,"_hasShrinkwrap":false,"_cnpm_publish_time":1506579766385,"_cnpmcore_publish_time":"2021-12-16T13:58:05.060Z"},"3.0.0":{"name":"jsonfile-updater","version":"3.0.0","description":"Node module for programatically updating package.json and other JSON files","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"git+https://github.com/hacksparrow/jsonfile-updater.git"},"keywords":["package.json","json file","json","file","update","updater"],"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/jsonfile-updater/issues"},"homepage":"https://github.com/hacksparrow/jsonfile-updater#readme","devDependencies":{"mocha":"^3.5.3"},"gitHead":"47440e3501a9095535e430f2ae557890d7659204","_id":"jsonfile-updater@3.0.0","_npmVersion":"5.3.0","_nodeVersion":"8.2.1","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"dist":{"shasum":"0422c0ff72991ecf5f3c4d493ce90b87cfcbc66f","size":9251,"noattachment":false,"key":"/jsonfile-updater/-/jsonfile-updater-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/jsonfile-updater/download/jsonfile-updater-3.0.0.tgz"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jsonfile-updater-3.0.0.tgz_1506567593590_0.31579341064207256"},"directories":{},"publish_time":1506567593658,"_hasShrinkwrap":false,"_cnpm_publish_time":1506567593658,"_cnpmcore_publish_time":"2021-12-16T13:58:05.289Z"},"2.1.0":{"name":"jsonfile-updater","version":"2.1.0","description":"Node module for programatically updating package.json and other JSON files","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"git+https://github.com/hacksparrow/jsonfile-updater.git"},"keywords":["package.json","json file","json","file","update","updater"],"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/jsonfile-updater/issues"},"homepage":"https://github.com/hacksparrow/jsonfile-updater#readme","dependencies":{"sort-keys":"^1.1.2"},"gitHead":"9c252735221c47353e92799dacc2d27816294d1b","_id":"jsonfile-updater@2.1.0","_shasum":"c4073c87a4b3ca6459d9640188c13a84ce0adaed","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"dist":{"shasum":"c4073c87a4b3ca6459d9640188c13a84ce0adaed","size":6682,"noattachment":false,"key":"/jsonfile-updater/-/jsonfile-updater-2.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/jsonfile-updater/download/jsonfile-updater-2.1.0.tgz"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/jsonfile-updater-2.1.0.tgz_1488744372330_0.20746985636651516"},"directories":{},"publish_time":1488744372586,"_hasShrinkwrap":false,"_cnpm_publish_time":1488744372586,"_cnpmcore_publish_time":"2021-12-16T13:58:05.501Z"},"2.0.0":{"name":"jsonfile-updater","version":"2.0.0","description":"Node module for programatically updating package.json and other JSON files","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"git+https://github.com/hacksparrow/jsonfile-updater.git"},"keywords":["package.json","json file","json","file","update","updater"],"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/jsonfile-updater/issues"},"homepage":"https://github.com/hacksparrow/jsonfile-updater#readme","gitHead":"ef65f2b5df1aef7bf8caa150e7d5e14126ac385f","_id":"jsonfile-updater@2.0.0","_shasum":"c50f51542f6a1b854928c2b353c6864f5d7dd5fc","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"dist":{"shasum":"c50f51542f6a1b854928c2b353c6864f5d7dd5fc","size":6616,"noattachment":false,"key":"/jsonfile-updater/-/jsonfile-updater-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/jsonfile-updater/download/jsonfile-updater-2.0.0.tgz"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/jsonfile-updater-2.0.0.tgz_1488743333893_0.9596188245341182"},"directories":{},"publish_time":1488743334115,"_hasShrinkwrap":false,"_cnpm_publish_time":1488743334115,"_cnpmcore_publish_time":"2021-12-16T13:58:05.698Z"},"1.1.1":{"name":"jsonfile-updater","version":"1.1.1","description":"Node module for programatically updating package.json and other JSON files","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"git+https://github.com/hacksparrow/jsonfile-updater.git"},"keywords":["package.json","json file","json","file","update","updater"],"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/jsonfile-updater/issues"},"homepage":"https://github.com/hacksparrow/jsonfile-updater#readme","gitHead":"9a408dd8a806f11522b4ee5cc448f9a260e023b2","_id":"jsonfile-updater@1.1.1","_shasum":"100b39da0f8491f6497c593ca208e74ac277abbf","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"dist":{"shasum":"100b39da0f8491f6497c593ca208e74ac277abbf","size":4908,"noattachment":false,"key":"/jsonfile-updater/-/jsonfile-updater-1.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/jsonfile-updater/download/jsonfile-updater-1.1.1.tgz"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/jsonfile-updater-1.1.1.tgz_1488375756305_0.258602490182966"},"directories":{},"publish_time":1488375758137,"_hasShrinkwrap":false,"_cnpm_publish_time":1488375758137,"_cnpmcore_publish_time":"2021-12-16T13:58:06.289Z"},"1.1.0":{"name":"jsonfile-updater","version":"1.1.0","description":"Node module for programatically updating package.json and other JSON files","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"git+https://github.com/hacksparrow/jsonfile-updater.git"},"keywords":["package.json","json file","json","file","update","updater"],"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/jsonfile-updater/issues"},"homepage":"https://github.com/hacksparrow/jsonfile-updater#readme","gitHead":"826232bc05ff0fd9dc5fdc423c1891e2941c4b17","_id":"jsonfile-updater@1.1.0","_shasum":"2d01a8ad3f1cc83037a9c629d344c02bc83ee8b6","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"dist":{"shasum":"2d01a8ad3f1cc83037a9c629d344c02bc83ee8b6","size":4078,"noattachment":false,"key":"/jsonfile-updater/-/jsonfile-updater-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/jsonfile-updater/download/jsonfile-updater-1.1.0.tgz"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/jsonfile-updater-1.1.0.tgz_1488227223464_0.3072773478925228"},"directories":{},"publish_time":1488227223746,"_hasShrinkwrap":false,"_cnpm_publish_time":1488227223746,"_cnpmcore_publish_time":"2021-12-16T13:58:06.489Z"},"1.0.0":{"name":"jsonfile-updater","version":"1.0.0","description":"Node module for programatically updating package.json and other JSON files","main":"index.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"git+https://github.com/hacksparrow/jsonfile-updater.git"},"tags":["package.json","json file","json","file","update","updater"],"author":{"name":"Hage Yaapa","email":"captain@hacksparrow.com"},"license":"MIT","bugs":{"url":"https://github.com/hacksparrow/jsonfile-updater/issues"},"homepage":"https://github.com/hacksparrow/jsonfile-updater#readme","gitHead":"009710a23d0d1ef0779b62aa2bf5b6d31c7c2dde","_id":"jsonfile-updater@1.0.0","_shasum":"bacf271623656603d2e352b385081e4b1fa6a13b","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"hacksparrow","email":"captain@hacksparrow.com"},"dist":{"shasum":"bacf271623656603d2e352b385081e4b1fa6a13b","size":3679,"noattachment":false,"key":"/jsonfile-updater/-/jsonfile-updater-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/jsonfile-updater/download/jsonfile-updater-1.0.0.tgz"},"maintainers":[{"name":"hacksparrow","email":"captain@hacksparrow.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/jsonfile-updater-1.0.0.tgz_1487790796642_0.6131789917126298"},"directories":{},"publish_time":1487790796880,"_hasShrinkwrap":false,"_cnpm_publish_time":1487790796880,"_cnpmcore_publish_time":"2021-12-16T13:58:06.719Z"}},"readme":"# jsonfile-updater\n\nNode module for programmatically updating `package.json` and other `.json` files.\n\n**NOTE**: This package does not create JSON files, it can only edit existing valid JSON files. A file with just `{}`\nis all you need to get started.\n\n`jsonfile-updater` enforces strict typing. Meaning, once a property of a certain type is added in the JSON file, it can be\noverwritten or set a new value with the same type only.\n\nSupported types are: boolean, string, number, array, and object. Functions are not supported.\n\n## Usage\n\n### Instantiation\n\n```js\nvar updater = require('jsonfile-updater')\n```\n\nFurther examples will be referring to the `updater` object created in the code above.\n\nIf you want to try out the examples, include the following code in your file.\n\n```js\nvar fs = require('fs')\nfunction getParsedPackage() {\n  return JSON.parse(fs.readFileSync('./settings.json'))\n}\n```\n\nThe `jsonfile-updater` methods support both callback and promise. If you omit the callback parameter,\nthey return a promise, which can greatly simplify the code when used with [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)-[await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await).\n\n### Adding properties\n\n**`add(property, value[, callback])`**\n\nUsing the `add()` instance method, you can add new properties. If you try to add a property that aleady exists, the module\nwill return an error. If you want to overwrite an existing property use `set()` or `append()`.\n\nAdding a string-type property:\n\n_Callback_\n\n```js\nupdater('./settings.json').add('time', 'now', function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg.time === 'now') // true\n})\n```\n\n_Promise_\n\n```js\nupdater('./settings.json').add('time', 'now')\n.then(() => {\n  var pkg = getParsedPackage()\n  console.log(pkg.time === 'now') // true\n}, reason => console.log(reason))\n```\n\nAdding an array-type property:\n\n```js\nupdater('./settings.json').add('tags', ['nodejs', 'javascript'], function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg.tags)\n})\n```\n\nAdding an object-type property:\n\n```js\nupdater('./settings.json').add('dependencies', { a: '1.2.1', b: '2.0.0'}, function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg.dependencies)\n})\n```\n\nYou can add a sub-property using the dot notation:\n\n```js\nupdater('./settings.json').add('author.age', 100, function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg.author.age) // 100\n})\n```\n\n### Updating properties\n\nThere are two methods for updating existing properties: `set()` for overwriting an existing value, `append()` for\nadding additional data to an existing value.\n\n**`set(property, value[, callback])`**\n\nUsing the `set()` method, you can overwrite existing properties. If you try to update a property does not exist,\nthe module will return an error. The new value should be the same as the old value's data type.\n\n_Callback_\n\n```js\nupdater('./settings.json').set('license', 'FREE', function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg.license)\n})\n```\n\n_Promise_\n\n```js\nupdater('./settings.json').set('license', 'FREE')\n.then(() => {\n  var pkg = getParsedPackage()\n  console.log(pkg.license)\n}, reason => console.log(reason))\n```\n\n```js\nupdater('./settings.json').set('tags', 'cool', function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg.tags.includes('cool')) // true\n})\n```\n\n```js\nupdater('./settings.json').update('author', { 'username': 'hacksparrow' }, function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg.author)\n})\n```\n\nYou can target a sub-property using the dot notation:\n\n```js\nupdater('./settings.json').update('author.age', 200, function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg.author.age) // 200\n})\n```\n\n**`append(property, value[, preserve][, callback])`**\n\nUsing the `append()` method, you can append items to an existing value. If you try to update a property does not exist,\nthe module will return an error. `append()` does not work for all data types and work differently on different data types.\n\n1. Booleans cannot be appended to anything\n2. A string can be appended only to string or array (pushed)\n3. A number can be appended only to an array (pushed)\n4. An array can be appended only to another array (concatenated by default)\n5. An object can be appended only to an array (pushed) or another object (merged)\n\nWhen an array is append to an array, the \"appendee\" will be concatened to the \"appender\". To preserve the array of the\n\"appendee\", and push it to the \"appender\", specify the `preserve` option when calling `append`.\n\nAppending a string to an array:\n\n_Callback_\n```js\nupdater('./settings.json').append('tags', 'cool', function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg.tags)\n})\n```\n\n_Promise_\n```js\nupdater('./settings.json').append('tags', 'cool')\n.then(() => {\n  var pkg = getParsedPackage()\n  console.log(pkg.tags)\n}, reason => console.log(reason))\n```\n\nAppending a preserved array to an array:\n\n```js\nupdater('./settings.json').append('tags', ['cool', 'new'], true, function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg.tags)\n})\n```\n\nFor more examples, refer [/test/test.js](/test/test.js).\n\n### Deleting properties\n\n**`delete(property|[properties ...][, callback])`**\n\nUsing the `delete()` method, you can delete existing properties. If you try to delete a property that does not exist,\nthe module will return an error.\n\nFYI: `delete()` is also aliased as `remove()`.\n\nDeleting a single property:\n\n_Callback_\n```js\nupdater('./settings.json').delete('name', function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg)\n})\n```\n\n_Promise_\n```js\nupdater('./settings.json').delete('name')\n.then(() => {\n  var pkg = getParsedPackage()\n  console.log(pkg)\n}, reason => console.log(reason))\n```\n\nDeleting multiple properties:\n\n```js\nupdater('./settings.json').delete(['name', 'version'], function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg)\n})\n```\n\nYou can target a sub-property using the dot notation:\n\n```js\nupdater('./settings.json').delete('author.age', function(err) {\n  if (err) return console.log(err)\n  var pkg = getParsedPackage()\n  console.log(pkg.author.age) // undefined\n})\n```\n\n## LICENSE\n\n[MIT](LICENSE)\n","_attachments":{},"homepage":"https://github.com/hacksparrow/jsonfile-updater#readme","bugs":{"url":"https://github.com/hacksparrow/jsonfile-updater/issues"},"license":"MIT"}