{"name":"property-expr","version":"2.0.5","description":"tiny util for getting and setting deep object props safely","main":"index.js","types":"index.d.ts","scripts":{"test":"node ./test.js","debug":"node --inspect-brk ./test.js"},"repository":{"type":"git","url":"git+https://github.com/jquense/expr.git"},"keywords":["expr","expression","setter","getter","deep","property","Justin-Beiber","accessor"],"author":{"name":"@monasticpanic Jason Quense"},"license":"MIT","prettier":{"singleQuote":true,"semi":false},"gitHead":"f7d10bb64c9d52484ff3ddbcb4a8eedc08e54856","bugs":{"url":"https://github.com/jquense/expr/issues"},"homepage":"https://github.com/jquense/expr#readme","_id":"property-expr@2.0.5","_nodeVersion":"14.18.0","_npmVersion":"6.14.15","dist":{"integrity":"sha512-IJUkICM5dP5znhCckHSv30Q4b5/JA5enCtkRHYaOVOAocnH/1BQEYTC5NMfT3AVl/iXKdr3aqQbQn9DxyWknwA==","shasum":"278bdb15308ae16af3e3b9640024524f4dc02cb4","tarball":"http://registry-npm.ywwl.com/property-expr/download/property-expr-2.0.5.tgz","fileCount":7,"unpackedSize":10610,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh4fAQCRA9TVsSAnZWagAAKgsQAJBL5Wl8GqMfTXCl7YPn\ngWvGtFX2QMLtSl1CJrOgJKR693moaNc3Xwki5nCtiM3DJ4AFWJAePddwe4zD\n5zXXIpvFTYZ3eFeJCJ/LjblUe6mkPO1R7DkRdo8gBXiweD2dgUyrf5ywkZzL\nTlBXyQg5DDP29H6QGi5eNPhhPzEhwlBzDwHvQv5YQDTE8bFOnvTr/Kit6GCe\nt7/d+mlG+TQPgFWNEqXz8VYuHan9cM/ez0mb7JMxlpnS/MFfOhyKEl6z+tAr\nmHN0dVjH2NTMsLfhw3ZtzSFwYN5q0ESkTUpseEkLoutCMpeB8v4iBmdamR7h\nUziAjQHMbzOr+scXtsx/bkkY7j0ZV4uhbuzUhNqsIIJGpcEIHASKqJkNV/6g\npxpue2shgC7CzHdmQNCxPezcO3iBg21/EwsV17oj8m/8bBNv9PI6+n7cb/Ux\nxQK1jqdLq9QcFu33vxVVz7i2aNavPNIxFBYi70uAOHcsy/D1GWPIRwLw7ZZU\nB3rt6AXU1TLm8tbc3/tVrATmJb/caXVEISkDkZXjFJD6mTlAY07QuAtncSaQ\nji0VumQ/ppcxwhWrt6dacYWmWJvoPy2vmRYsAUnf6Np30TKZkKcrN3rCbOEP\n+MNV6LQOPmOu6kdL13RWeNWaqBFf7HYTuCnxs9TtSqaY6634aR/YBCZxwgCV\nzokh\r\n=y92R\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDC9PcZgbeFmGcDmJz34zTM2i/UspchAHkcSjeHHAJVoQIhAOSpHyg3DLMyS8JbPUo7ggPs1jk6vF1ARojGiTPipO5q"}],"size":4476,"noattachment":false,"key":"/property-expr/-/property-expr-2.0.5.tgz"},"_npmUser":{"name":"monastic.panic","email":"monastic.panic@gmail.com"},"directories":{},"maintainers":[{"name":"monastic.panic","email":"monastic.panic@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/property-expr_2.0.5_1642197008639_0.8962106229596063"},"_hasShrinkwrap":false,"readme":"# expr\n\nTiny property path utilities, including path parsing and metadata and deep property setters and getters\n\n    npm install property-expr\n\n## Use\n\nSetters and getters:\n\n```js\nlet expr = require('property-expr')\nlet obj = {\n  foo: {\n    bar: ['hi', { buz: { baz: 'found me!' } }]\n  }\n}\n\nlet getBaz = expr.getter('foo.bar[1][\"buz\"].baz')\nlet setBaz = expr.setter('foo.bar[1][\"buz\"].baz')\n\nconsole.log(getBaz(obj)) // => 'found me!'\nsetBaz(obj, 'set me!')\nconsole.log(obj.foo.bar[1].buz.baz) // => 'set me!'\n```\n\n### `getter(expression, [ safeAccess ])`\n\nReturns a function that accepts an obj and returns the value at the supplied expression. You can create a \"safe\" getter, which won't error out when accessing properties that don't exist, reducing existance checks befroe property access:\n\n```js\nexpr.getter('foo.bar.baz', true)({ foo: {} }) // => undefined\n//instead of val = foo.bar && foo.bar.baz\n```\n\n### `setter(expression)`\n\nReturns a function that accepts an obj and a value and sets the property pointed to by the expression to the supplied value.\n\n### `expr(expression, [ safeAccess], [ paramName = 'data'])`\n\nReturns a normalized expression string pointing to a property on root object\n`paramName`.\n\n    expr.expr(\"foo['bar'][0].baz\", true, 'obj') // => \"(((obj.foo || {})['bar'] || {})[0])\"\n\n### `split(path) -> Array`\n\nReturns an array of each path segment.\n\n```js\nexpr.split(\"foo['bar'][0].baz\") // [ \"foo\", \"'bar'\", \"0\", \"baz\"]\n```\n\n### `forEach(path, iterator[, thisArg])`\n\nIterate through a path but segment, with some additional helpful metadata about the segment. The iterator function is called with: `pathSegment`, `isBracket`, `isArray`, `idx`, `segments`\n\n```js\nexpr.forEach('foo[\"bar\"][1]', function(\n  pathSegment,\n  isBracket,\n  isArray,\n  idx,\n  segments\n) {\n  // 'foo'   -> isBracket = false, isArray = false, idx = 0\n  // '\"bar\"' -> isBracket = true,  isArray = false, idx = 1\n  // '0'     -> isBracket = false, isArray = true,  idx = 2\n})\n```\n\n### `normalizePath(path)`\n\nReturns an array of path segments without quotes and spaces.\n\n```js\nexpr.normalizePath('foo[\"bar\"][ \"1\" ][2][ \" sss \" ]')\n// ['foo', 'bar', '1', '2', ' sss ']\n```\n\n### `new Cache(maxSize)`\n\nJust an utility class, returns an instance of cache. When the max size is exceeded, cache clears its storage.\n\n```js\nvar cache = new Cache(2)\ncache.set('a', 123) // returns 123\ncache.get('a') // returns 123\ncache.clear()\n\ncache.set('a', 1)\ncache.set('b', 2) // cache contains 2 values\ncache.set('c', 3) // cache was cleaned automatically and contains 1 value\n```\n\n### CSP\n\nThis pacakge used to rely on `new Function` to compile setters and getters into fast\nreusable functions. Since `new Function` is forbidden by folks using Content Security Policy `unsafe-eval`\nwe've moved away from that approach. I believe that for most cases the perf hit is not noticable\nbut if it is in your case please reach out.\n\nIf you really want to use the old version require `property-expr/compiler` instead\n","publish_time":1642197008810,"_cnpm_publish_time":1642197008810,"dist-tags":{"latest":"2.0.6"}}