{"name":"object-path-immutable","version":"0.5.2","description":"Modify deep object properties without modifying the original object (immutability). Works great with React and Redux.","author":{"name":"Mario Casciaro","email":"mariocasciaro@gmail.com"},"homepage":"https://github.com/mariocasciaro/object-path-immutable","repository":{"type":"git","url":"git://github.com/mariocasciaro/object-path-immutable.git"},"engines":{"node":">=0.10.0"},"scripts":{"pretest":"standard","test":"istanbul cover _mocha test.js --report html -- -R spec","prepublish":"npm run test"},"dependencies":{},"devDependencies":{"chai":"^3.5.0","coveralls":"^2.11.14","istanbul":"^0.4.5","mocha":"^3.1.1","mocha-lcov-reporter":"^1.2.0","standard":"^8.3.0"},"keywords":["deep","path","access","get","property","dot","prop","object","obj","notation","segment","value","nested","key","immutable","immutability","react","redux","state"],"gitHead":"3ca34a1e3a3c69838965c19b798a6a0de7d71131","bugs":{"url":"https://github.com/mariocasciaro/object-path-immutable/issues"},"_id":"object-path-immutable@0.5.2","_npmVersion":"5.3.0","_nodeVersion":"8.5.0","_npmUser":{"name":"mariocasciaro","email":"contact@mariocasciaro.me"},"dist":{"integrity":"sha512-6fnJfXjj/SCdqctFRN8wJAxvbnHsFZ9ISnvgEImZ3ophWDx38r6Wu8PZJ9LXrjhihOOhGiLKicN682VtL/9cfg==","shasum":"fb7041de26598db99aacccbc1a9c03fd1187269e","tarball":"http://registry-npm.ywwl.com/object-path-immutable/download/object-path-immutable-0.5.2.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEMCHwh0h7kS53dVLZPO+oFiLctMy3fCH3ZuDK+SdbpxUlcCIATmwjSd/Smu4hr2yGLbNcU7Vf6ECwUsHYfrYnNnkYdm"}],"size":5599,"noattachment":false,"key":"/object-path-immutable/-/object-path-immutable-0.5.2.tgz"},"maintainers":[{"name":"mariocasciaro","email":"contact@mariocasciaro.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/object-path-immutable-0.5.2.tgz_1505759900449_0.29255498270504177"},"directories":{},"readme":"[![build](https://img.shields.io/travis/mariocasciaro/object-path-immutable.svg?style=flat-square)](https://travis-ci.org/mariocasciaro/object-path-immutable)\n[![coverage](https://img.shields.io/coveralls/mariocasciaro/object-path-immutable.svg?style=flat-square)](https://coveralls.io/r/mariocasciaro/object-path-immutable)\n[![downloads](https://img.shields.io/npm/dm/object-path-immutable.svg?style=flat-square)](https://www.npmjs.com/package/object-path-immutable)\n[![version](https://img.shields.io/npm/v/object-path-immutable.svg?style=flat-square)](https://www.npmjs.com/package/object-path-immutable)\n[![deps](https://img.shields.io/david/mariocasciaro/object-path-immutable.svg?style=flat-square)](https://david-dm.org/mariocasciaro/object-path-immutable)\n[![devdeps](https://img.shields.io/david/dev/mariocasciaro/object-path-immutable.svg?style=flat-square)](https://david-dm.org/mariocasciaro/object-path-immutable#info=devDependencies)\n\nobject-path-immutable\n===========\n\nTiny JS library to modify deep object properties without modifying the original object (immutability).\nWorks great with React (especially when using `setState()`) and Redux (inside a reducer).\n\nThis can be seen as a simpler and more intuitive alternative to the *React Immutability Helpers* and *Immutable.js*.\n\n## Changelog\n\n[View Changelog](CHANGELOG.md)\n\n## Install\n\n    npm install object-path-immutable --save\n\n## Quick usage\n\nThe following, sets a property without modifying the original object.\nIt will minimize the number of clones down the line. The resulting object is just a plain JS object literal,\nso be warned that it will not be protected against property mutations (like `Immutable.js`)\n\n```javascript\nconst obj = {\n  a: {\n    b: 'c',\n    c: ['d', 'f']\n  }\n}\n\nconst newObj = immutable.set(obj, 'a.b', 'f')\n// {\n//   a: {\n//     b: 'f',\n//     c: ['d', 'f']\n//   }\n// }\n\n// obj !== newObj\n// obj.a !== newObj.a\n// obj.a.b !== newObj.a.b\n\n// However:\n// obj.a.c === newObj.a.c\n```\n\n### Wrap mode\n\nYou can also chain the api's and call `value()` at the end to retrieve the resulting object.\n\n```javascript\nconst newObj = immutable.wrap(obj).set('a.b', 'f').del('a.c.0').value()\n```\n\n## API\n\n```javascript\n// Premises\n\nconst obj = {\n  a: {\n    b: 'c',\n    c: ['d', 'f']\n  }\n}\n\nimport * as immutable from 'object-path-immutable'\n```\n\n#### set (initialObject, path, value)\n\nChanges an object property.\n\n- Path can be either a string or an array.\n\n```javascript\nconst newObj1 = immutable.set(obj, 'a.b', 'f')\nconst newObj2 = immutable.set(obj, ['a', 'b'], 'f')\n\n// {\n//   a: {\n//     b: 'f',\n//     c: ['d', 'f']\n//   }\n// }\n\n// Note that if the path is specified as a string, numbers are automatically interpreted as array indexes.\n\nconst newObj = immutable.set(obj, 'a.c.1', 'fooo')\n// {\n//   a: {\n//     b: 'f',\n//     c: ['d', 'fooo']\n//   }\n// }\n```\n\n#### update (initialObject, path, updater)\n\nUpdates an object property.\n\n```javascript\nconst obj = {\n  a: {\n    b: 1\n  }\n}\n\nconst newObj = immutable.update(obj, ['a', 'b'], v => v + 1)\n\n// {\n//   a: {\n//     b: 2,\n//   }\n// }\n```\n\n#### push (initialObject, path, value)\n\nPush into a deep array (it will create intermediate objects/arrays if necessary).\n\n```javascript\nconst newObj = immutable.push(obj, 'a.d', 'f')\n// {\n//   a: {\n//     b: 'f',\n//     c: ['d', 'f'],\n//     d: ['f']\n//   }\n// }\n```\n\n#### del (initialObject, path)\n\nDeletes a property.\n\n```javascript\nconst newObj = immutable.del(obj, 'a.c')\n// {\n//   a: {\n//     b: 'f'\n//   }\n// }\n```\n\nCan also delete a deep array item using splice\n\n```javascript\nconst newObj = immutable.del(obj, 'a.c.0')\n// {\n//   a: {\n//     b: 'f',\n//     c: ['f']\n//   }\n// }\n```\n\n#### assign (initialObject, path, payload)\n\nShallow copy properties.\n\n```javascript\nconst newObj = immutable.assign(obj, 'a', { b: 'f', g: 'h' })\n// {\n//   a: {\n//     b: 'f',\n//     c: ['d, 'f'],\n//     g: 'h'\n//   }\n// }\n```\n\n#### insert (initialObject, path, payload, position)\n\nInsert property at the specific array index.\n\n```javascript\nconst newObj = immutable.insert(obj, 'a.c', 'k', 1)\n// var obj = {\n//   a: {\n//     b: 'c',\n//     c: ['d, 'k' 'f'],\n//   }\n// }\n```\n\n\n#### merge (initialObject, path, value)\n\nDeep merge properties.\n\n```javascript\nconst newObj = immutable.merge(obj, 'a.c', {b: 'd'})\n```\n\n### Getters (not available in wrap mode)\n\n#### get (object, path, defaultValue)\n\nRetrieve a deep object property. Imported from [object-path](https://github.com/mariocasciaro/object-path) for convenience.\n\n## Equivalent library with side effects\n\n[object-path](https://github.com/mariocasciaro/object-path)\n\n","publish_time":1505759901473,"_cnpm_publish_time":1505759901473,"dist-tags":{"latest":"4.1.2"}}