{"name":"object-path","version":"0.9.0","keywords":["deep","path","access","bean"],"author":{"name":"Mario Casciaro"},"license":"MIT","_id":"object-path@0.9.0","maintainers":[{"name":"mariocasciaro","email":"mariocasciaro@gmail.com"}],"homepage":"https://github.com/mariocasciaro/object-path","bugs":{"url":"https://github.com/mariocasciaro/object-path/issues"},"dist":{"shasum":"6dfdd274305c366c95adf6731e95fbcd783ec07d","tarball":"http://registry-npm.ywwl.com/object-path/download/object-path-0.9.0.tgz","integrity":"sha512-lGFKbJKDXVREezJ6ru6jPqPKO/4GpDzy/SaVcS+2ot8+mZDmuYQAdwzVKBH6Nn+V4ktKMULDKeH8HMMQgYFn+A==","signatures":[{"sig":"MEUCIE6jlIYp9yNnHsxnWmHcHTyecCv6oC43JTNyQoTWEFYNAiEAmLnSLtBLqRetnEptP9Xpj9JR0Mz5IyVWoYiycyHfC20=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":7157,"noattachment":false,"key":"/object-path/-/object-path-0.9.0.tgz"},"_from":".","_shasum":"6dfdd274305c366c95adf6731e95fbcd783ec07d","engines":{"node":">=0.8.0"},"gitHead":"4894644d9b8446aa6c93540c52473bd8982ea7f0","scripts":{"test":"node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha test.js --report html -- -R spec"},"_npmUser":{"name":"mariocasciaro","email":"contact@mariocasciaro.me"},"testling":{"files":"test.js","harness":"mocha","browsers":{"ie":[8,9],"opera":[15],"chrome":[30,22],"iphone":[6],"safari":[5,6],"firefox":[10,24],"android-browser":[4.2]}},"repository":{"url":"git://github.com/mariocasciaro/object-path.git","type":"git"},"_npmVersion":"1.4.28","description":"Access deep properties using a path","directories":{},"devDependencies":{"chai":"~1.9.1","mocha":"~1.20.1","istanbul":"~0.3.0","coveralls":"~2.11.1","mocha-lcov-reporter":"~0.0.1"},"readme":"\n\nobject-path\n===========\n\nAccess deep properties using a path\n\n[![NPM version](https://badge.fury.io/js/object-path.png)](http://badge.fury.io/js/object-path)\n[![Build Status](https://travis-ci.org/mariocasciaro/object-path.png)](https://travis-ci.org/mariocasciaro/object-path)\n[![Coverage Status](https://coveralls.io/repos/mariocasciaro/object-path/badge.png)](https://coveralls.io/r/mariocasciaro/object-path)\n[![devDependency Status](https://david-dm.org/mariocasciaro/object-path/dev-status.svg)](https://david-dm.org/mariocasciaro/object-path#info=devDependencies)\n![Downloads](http://img.shields.io/npm/dm/object-path.svg)\n\n## Changelog\n\n### 0.11.8\n\n* **SECURITY FIX**. Fix a prototype pollution vulnerability in the `del()`, `empty()`, `push()`, `insert()` functions when using the \"inherited props\" mode (e.g. when a new `object-path` instance is created with the `includeInheritedProps` option set to `true` or when using the `withInheritedProps` default instance. To help with preventing this type of vulnerability in the client code, also the `get()` function will now throw an exception if an object's magic properties are accessed. The vulnerability does not exist in the default instance exposed by object path (e.g `objectPath.del()`) if using version >= `0.11.0`.\n\n### 0.11.6\n\n* **SECURITY FIX**. Fix a circumvention of the security fix released in 0.11.5 when non-string/non-numeric values are used in the path (e.g. `op.withInheritedProps.set({}, [['__proto__'], 'polluted'], true)`)\n\n### 0.11.5\n\n* **SECURITY FIX**. Fix a prototype pollution vulnerability in the `set()` function when using the \"inherited props\" mode (e.g. when a new `object-path` instance is created with the `includeInheritedProps` option set to `true` or when using the `withInheritedProps` default instance. The vulnerability does not exist in the default instance exposed by object path (e.g `objectPath.set()`) if using version >= `0.11.0`.\n\n### 0.11.0\n\n* Introduce ability to specify options and create new instances of `object-path`\n* Introduce option to control the way `object-path` deals with inherited properties (`includeInheritedProps`)\n* New default `object-path` instance already configured to handle not-own object properties (`withInheritedProps`)\n\n### 0.10.0\n\n* Improved performance of `get`, `set`, and `push` by 2x-3x\n* Introduced a benchmarking test suite\n* **BREAKING CHANGE**: `del`, `empty`, `set` will not affect not-own object's properties (made them consistent with the other methods)\n\n## Install\n\n### Node.js\n\n```\nnpm install object-path --save\n```\n\n### Bower\n\n```\nbower install object-path --save\n```\n\n### Typescript typings\n\n```\ntypings install --save dt~object-path\n```\n\n## Usage\n\n```javascript\n\nvar obj = {\n  a: {\n    b: \"d\",\n    c: [\"e\", \"f\"],\n    '\\u1200': 'unicode key',\n    'dot.dot': 'key'\n  }\n};\n\nvar objectPath = require(\"object-path\");\n\n//get deep property\nobjectPath.get(obj, \"a.b\");  //returns \"d\"\nobjectPath.get(obj, [\"a\", \"dot.dot\"]);  //returns \"key\"\nobjectPath.get(obj, 'a.\\u1200');  //returns \"unicode key\"\n\n//get the first non-undefined value\nobjectPath.coalesce(obj, ['a.z', 'a.d', ['a','b']], 'default');\n\n//empty a given path (but do not delete it) depending on their type,so it retains reference to objects and arrays.\n//functions that are not inherited from prototype are set to null.\n//object instances are considered objects and just own property names are deleted\nobjectPath.empty(obj, 'a.b'); // obj.a.b is now ''\nobjectPath.empty(obj, 'a.c'); // obj.a.c is now []\nobjectPath.empty(obj, 'a'); // obj.a is now {}\n\n//works also with arrays\nobjectPath.get(obj, \"a.c.1\");  //returns \"f\"\nobjectPath.get(obj, [\"a\",\"c\",\"1\"]);  //returns \"f\"\n\n//can return a default value with get\nobjectPath.get(obj, [\"a.c.b\"], \"DEFAULT\");  //returns \"DEFAULT\", since a.c.b path doesn't exists, if omitted, returns undefined\n\n//set\nobjectPath.set(obj, \"a.h\", \"m\"); // or objectPath.set(obj, [\"a\",\"h\"], \"m\");\nobjectPath.get(obj, \"a.h\");  //returns \"m\"\n\n//set will create intermediate object/arrays\nobjectPath.set(obj, \"a.j.0.f\", \"m\");\n\n//will insert values in array\nobjectPath.insert(obj, \"a.c\", \"m\", 1); // obj.a.c = [\"e\", \"m\", \"f\"]\n\n//push into arrays (and create intermediate objects/arrays)\nobjectPath.push(obj, \"a.k\", \"o\");\n\n//ensure a path exists (if it doesn't, set the default value you provide)\nobjectPath.ensureExists(obj, \"a.k.1\", \"DEFAULT\");\nvar oldVal = objectPath.ensureExists(obj, \"a.b\", \"DEFAULT\"); // oldval === \"d\"\n\n//deletes a path\nobjectPath.del(obj, \"a.b\"); // obj.a.b is now undefined\nobjectPath.del(obj, [\"a\",\"c\",0]); // obj.a.c is now ['f']\n\n//tests path existence\nobjectPath.has(obj, \"a.b\"); // true\nobjectPath.has(obj, [\"a\",\"d\"]); // false\n\n//bind object\nvar model = objectPath({\n  a: {\n    b: \"d\",\n    c: [\"e\", \"f\"]\n  }\n});\n\n//now any method from above is supported directly w/o passing an object\nmodel.get(\"a.b\");  //returns \"d\"\nmodel.get([\"a.c.b\"], \"DEFAULT\");  //returns \"DEFAULT\"\nmodel.del(\"a.b\"); // obj.a.b is now undefined\nmodel.has(\"a.b\"); // false\n\n```\n### How `object-path` deals with inherited properties\n\nBy default `object-path` will only access an object's own properties. Look at the following example:\n\n```javascript\nvar proto = {\n  notOwn: {prop: 'a'}\n}\nvar obj = Object.create(proto);\n\n//This will return undefined (or the default value you specified), because notOwn is\n//an inherited property\nobjectPath.get(obj, 'notOwn.prop');\n\n//This will set the property on the obj instance and not the prototype.\n//In other words proto.notOwn.prop === 'a' and obj.notOwn.prop === 'b'\nobjectPath.set(obj, 'notOwn.prop', 'b');\n```\nTo configure `object-path` to also deal with inherited properties, you need to create a new instance and specify\nthe `includeInheritedProps = true` in the options object:\n\n```javascript\nvar objectPath = require(\"object-path\");\nvar objectPathWithInheritedProps = objectPath.create({includeInheritedProps: true})\n```\n\nAlternatively, `object-path` exposes an instance already configured to handle inherited properties (`objectPath.withInheritedProps`):\n```javascript\nvar objectPath = require(\"object-path\");\nvar objectPathWithInheritedProps = objectPath.withInheritedProps\n```\n\nOnce you have the new instance, you can access inherited properties as you access other properties:\n```javascript\nvar proto = {\n  notOwn: {prop: 'a'}\n}\nvar obj = Object.create(proto);\n\n//This will return 'a'\nobjectPath.withInheritedProps.get(obj, 'notOwn.prop');\n\n//This will set proto.notOwn.prop to 'b'\nobjectPath.set(obj, 'notOwn.prop', 'b');\n```\n\n**NOTE**: For security reasons `object-path` will throw an exception when trying to access an object's magic properties (e.g. `__proto__`, `constructor`) when in \"inherited props\" mode.\n\n### Immutability\n\nIf you are looking for an *immutable* alternative of this library, you can take a look at: [object-path-immutable](https://github.com/mariocasciaro/object-path-immutable)\n\n\n### Credits\n\n* [Mario Casciaro](https://github.com/mariocasciaro) - Author\n* [Paulo Cesar](https://github.com/pocesar) - Major contributor\n","publish_time":1422526291029,"_cnpm_publish_time":1422526291029,"dist-tags":{"latest":"0.11.8"}}