{"name":"object-path","version":"0.11.7","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.11.7","maintainers":[{"name":"mariocasciaro","email":"m@mario.fyi"}],"homepage":"https://github.com/mariocasciaro/object-path","bugs":{"url":"https://github.com/mariocasciaro/object-path/issues"},"dist":{"shasum":"5f211161f34bb395e4b13a5f565b79d933b6f65d","tarball":"http://registry-npm.ywwl.com/object-path/download/object-path-0.11.7.tgz","fileCount":9,"integrity":"sha512-T4evaK9VfGGQskXBDILcn6F90ZD+WO3OwRFFQ2rmZdUH4vQeDBpiolTpVlPY2yj5xSepyILTjDyM6UvbbdHMZw==","signatures":[{"sig":"MEUCIDTcJGvs8nkvC5+XW6dNBO0xkTMuYwEdzb9YPYxzAESpAiEA9lN65O+rUaPUw8TR/roakoa8NBpsa8GyeCF8lSTe3bo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":49224,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhKPtaCRA9TVsSAnZWagAAOrwP/R0ZT5RFrvmI/qO8B3Wb\n++UDkdeqYyLNtIOx7G1ta2QDbtmsRVSv6RaqpaIv+F6HW4oQKaUIsKGilk2Q\n2BnmXDYtHsO9epTbS+3Xdd6e3JuGiRNa0g2bJHGLZKzpxseoIsXy6ZJvsUt6\nlgkkmRFXWNyLAYPLGAZEgjZlFKkzvaDnkPBvLeB5QNmCScHGn1teO4DzrF15\nelBobcZ0YWpOG/5wBYF6vfCzd52zBxbgo8Vu5ZveTg0dBNE28hROAu9j6CNs\n6K3/FI7fY6i2LbCcKjC9tePHlaUEhHRUOdtXODVLI3pXuw6sUhJQtwuzsaGG\nglqFX2nd6Hz4kF5skBRGSxW+ysCWxls/UjKDYPwNXGbIJmMAgUXQ8FMam3U3\nNArQgg+WiVzHVfiWCzwwKqqDyAUBseoX2HvYQi55BrNPkbvl8jTK4iJjYBH9\n27t5rgQjzAMcmHxmG/VUGTYuwfvid2YsQS89UcjZ/Gz3ixNte694Wb5ldccO\nv47F2QvmWDfRZeCwTmpMEvqgH9dd0C25CSnHixJ1HYWqnqURnB6wu2fhdGZP\nMwdkVkwWCg6IneVro9CYKSz6ItlkWdyM8C2omZMT9vK0v3rsinsncLaflX/2\nsKAoA8VkJ5qjgEhr/bbQqgnSLOmCZdjGNiTY0nkdWUJgE0ef2N4jEzWB2ksz\n4Pna\r\n=Ml5g\r\n-----END PGP SIGNATURE-----\r\n","size":9900,"noattachment":false,"key":"/object-path/-/object-path-0.11.7.tgz"},"engines":{"node":">= 10.12.0"},"gitHead":"43a926f5bcba44e522456b0e2b4b341de32c4a19","scripts":{"test":"mocha test.js","coverage":"nyc npm test","benchmark":"node benchmark.js","coveralls":"nyc npm test && nyc report --reporter=text-lcov | coveralls"},"_npmUser":{"name":"mariocasciaro","email":"m@mario.fyi"},"repository":{"url":"git://github.com/mariocasciaro/object-path.git","type":"git"},"_npmVersion":"7.5.2","description":"Access deep object properties using a path","directories":{},"_nodeVersion":"14.9.0","_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.1.0","chai":"^4.3.4","mocha":"^9.1.0","coveralls":"^3.1.1","mocha-lcov-reporter":"^1.3.0","@mariocasciaro/benchpress":"^0.1.3"},"_npmOperationalInternal":{"tmp":"tmp/object-path_0.11.7_1630075738573_0.9510719576738014","host":"s3://npm-registry-packages"},"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":1630075738722,"_cnpm_publish_time":1630075738722,"dist-tags":{"latest":"0.11.8"}}