{"name":"object-path","version":"0.10.0","keywords":["deep","path","access","bean","get","property","dot","prop","object","obj","notation","segment","value","nested","key"],"author":{"name":"Mario Casciaro"},"license":"MIT","_id":"object-path@0.10.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":"2d1d3de2d5937705c9078bb15f8fdd69ea936e86","tarball":"http://registry-npm.ywwl.com/object-path/download/object-path-0.10.0.tgz","integrity":"sha512-IsfGJnTd6aetX9FdAr1E/BMvkqLpg7PetWisyscAZZmCtKjQYMRtC7oiXGEg+t+Cc2U7t6+E1UYAnJoDdmDlBQ==","signatures":[{"sig":"MEUCICKrAGAgfABCpawYkv1tr/w/plTDK1iEeIVN5dhIuliSAiEA+Jp5FVlT8eHUVUIHUy93EzQI2lKxKlHEwtxc+/lRPXA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":8196,"noattachment":false,"key":"/object-path/-/object-path-0.10.0.tgz"},"_from":".","_shasum":"2d1d3de2d5937705c9078bb15f8fdd69ea936e86","engines":{"node":">=0.10.0"},"gitHead":"4bd4bbf06844a18cbc306f201f9ce4ad617b470f","scripts":{"test":"istanbul cover ./node_modules/mocha/bin/_mocha test.js --report html -- -R spec"},"_npmUser":{"name":"mariocasciaro","email":"contact@mariocasciaro.me"},"repository":{"url":"git://github.com/mariocasciaro/object-path.git","type":"git"},"_npmVersion":"2.14.12","description":"Access deep object properties using a path","directories":{},"_nodeVersion":"4.2.6","devDependencies":{"chai":"^3.5.0","mocha":"^2.2.4","istanbul":"^0.4.4","coveralls":"^2.11.2","mocha-lcov-reporter":"^1.2.0","@mariocasciaro/benchpress":"^0.1.3"},"_npmOperationalInternal":{"tmp":"tmp/object-path-0.10.0.tgz_1467123480970_0.04168023983947933","host":"packages-12-west.internal.npmjs.com"},"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":1467123483279,"_cnpm_publish_time":1467123483279,"dist-tags":{"latest":"0.11.8"}}