{"name":"object-path","version":"0.11.5","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.5","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":"d4e3cf19601a5140a55a16ad712019a9c50b577a","tarball":"http://registry-npm.ywwl.com/object-path/download/object-path-0.11.5.tgz","fileCount":9,"integrity":"sha512-jgSbThcoR/s+XumvGMTMf81QVBmah+/Q7K7YduKeKVWL7N111unR2d6pZZarSk6kY/caeNxUDyxOvMWyzoU2eg==","signatures":[{"sig":"MEYCIQCeYC2ndrrfMZkb6QRaj19M/+PkK/x56ho2V+IzWFUZygIhAP6cZ02/amPmJlK77160V25XbzN6nngv7JCuj9+O+3e2","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":48185,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfgeXyCRA9TVsSAnZWagAAGz8P/01JG3PIqx8KEtaRjced\n+03PgyTLi6ga1MXSXnPmR41VjGmgoDDcoWEskeIv6G0AWrZqF9V7F23R04r9\n+LJpTfxmZ8h7hfb1ai9WoLx//Xj2w3gNm+QlkVZn7u3gHt8PuriEDdNHtNxJ\nQRmOlJbW6L4pi68Y+SGQT09c+obFcG/BDyY3AwLWWr4JHDNeAQ2XIJgBrBie\nTTUhCN8q1JfZSVDMlho0iW2YXNPZeJAEx5st/CjZGY+BG2/559573/BN3KVG\ntLfQ9orRaVZwtqsKjWVR8p91iZ0C2NaAxtlCRsLtpCDBIs2D9Y/kwFhbdZiM\nr4nVCqjcU+PEAbIpEOCo6OJPdaVhNTIovR7IAkR4mv8HpwcpBIiSxLRHyyUt\nP6TUnqQqcNx1NOYvvX+iGTF2dpK1fROqBbyhj6HtHu57jEczNu/wpK7hCDdm\nDGWVVpXot5nLif3CnYzXSF38DEfDuj52pFEZVWKYfCkOTF+MT8dRlOhR4M9i\nqgJs1DrmYgq59bxOgdCabaFJy3CQVGPfIMan8+KatUMfJQ+jHDFKt4NKvtHS\noOpf39mTV7mPuzCtL6ZTq7fbS9fjZTy4o6fwlLN+EWTBfy/xpym+a7jVppi1\nBi2lnPYTU752Up6kBaUJp9mD80MNZcs9CkECRkcKejPRIpS3c+pXcxda4sYs\nlumN\r\n=Jeyb\r\n-----END PGP SIGNATURE-----\r\n","size":9731,"noattachment":false,"key":"/object-path/-/object-path-0.11.5.tgz"},"engines":{"node":">= 10.12.0"},"gitHead":"63324602658f0860a25bde311b0087625dfee439","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":"6.14.8","description":"Access deep object properties using a path","directories":{},"_nodeVersion":"14.9.0","_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.1.0","chai":"^4.2.0","mocha":"^8.1.3","coveralls":"^3.1.0","mocha-lcov-reporter":"^1.3.0","@mariocasciaro/benchpress":"^0.1.3"},"_npmOperationalInternal":{"tmp":"tmp/object-path_0.11.5_1602348530432_0.24872902351771176","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":1602348530597,"_cnpm_publish_time":1602348530597,"dist-tags":{"latest":"0.11.8"}}