{"name":"dset","version":"2.0.1","repository":{"type":"git","url":"git+https://github.com/lukeed/dset.git"},"description":"A tiny (161B) utility for safely writing deep Object values~!","unpkg":"dist/dset.min.js","umd:main":"dist/dset.min.js","module":"dist/dset.es.js","main":"dist/dset.js","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"lukeed.com"},"engines":{"node":">=4"},"scripts":{"build":"node builder","pretest":"npm run build","test":"tape test/*.js | tap-spec"},"keywords":["deepset","values","object","write","deep","safe","set"],"devDependencies":{"gzip-size":"^3.0.0","mk-dirs":"^1.0.0","pretty-bytes":"^4.0.2","rewrite-imports":"^1.0.0","tap-spec":"^4.1.1","tape":"^4.8.0","uglify-js":"^3.2.0"},"gitHead":"215b634f0e5ead89ae8f3579e1bff819bbed92ec","bugs":{"url":"https://github.com/lukeed/dset/issues"},"homepage":"https://github.com/lukeed/dset#readme","_id":"dset@2.0.1","_shasum":"a15fff3d1e4d60ac0c95634625cbd5441a76deb1","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.11.1","_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"dist":{"shasum":"a15fff3d1e4d60ac0c95634625cbd5441a76deb1","tarball":"http://registry-npm.ywwl.com/dset/download/dset-2.0.1.tgz","integrity":"sha512-nI29OZMRYq36hOcifB6HTjajNAAiBKSXsyWZrq+VniusseuP2OpNlTiYgsaNRSGvpyq5Wjbc2gQLyBdTyWqhnQ==","fileCount":6,"unpackedSize":4724,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJblDAcCRA9TVsSAnZWagAAJrsQAJMZX0B96f0kpuO5iPRK\nxl+pau3e1zAC8Uz6IWQ26RNzIF0vybXGSdaVbGB10RMqWnN0dN/1dYkKN52X\ner2StEDULwthqSgIQosDAxMDvV0hIrkCQkEKJbqNDNBiwCZWMoOy45yFkvku\n3cFjbhoDsZNc4Ob09BuMRP2E9patNVNhdWymQ8Q2PyJkTogXGsIAovp5ZLfX\noZ5N6PbWZTw6dDVbzC4R5TdNrnTKsBraQPv8748Lkya1yo2ixodNh4t6nwRy\ncKQbTb4J6SPSYgh6rtvhF7s//PZI/3PzsZV23aANPDMDXYU6dJT7tHUICUWL\nYaNbRROz6QwSNpXv98Lpt232led+iYR0ho7fdcqx/FPBrUSBSTbmfxt9i8oT\nvA9dfYjfwqkDxZhMr93fYFXJ6+nfS50D9XIHVdLBf6V7lo+MoF8/1kLLFVDe\nhaIxAj8JFeSJV7Zs1hJFEp/6xIzD5+THmh7Tcj0E6EPVLd5oooMJUUywnvlN\nzwr72pEx/6E/ImI62VshPrH/fdPAddHUpSFX9yT+C1s4SbbvMXZK+jGIXOBz\niVys1gsw1Qx8Mk4rjMqXKxt+6IVN0WDT8FQNLsnl+hzITFoOMpfaDSBDw00R\nWelSSa7Wx5YpSP1IyWv3WM8t5F1KGYjjolEqmFaPcrIRdXpRYIcwCr4nCSHP\nfbVb\r\n=ZGtx\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC9CbzK72F/MxpTvItgJ7rBSgMx9wUz8xlA+GposfTVtQIgRTKLb4aW62vZ0HavHsDfDtjepyhVGoAAOMWHBh3YO60="}],"size":2555,"noattachment":false,"key":"/dset/-/dset-2.0.1.tgz"},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dset_2.0.1_1536438299239_0.4496956083062793"},"_hasShrinkwrap":false,"deprecated":"Please use dset@2.1.0 or later for an important security patch","readme":"# dset [![CI](https://github.com/lukeed/dset/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/lukeed/dset/actions) [![codecov](https://badgen.net/codecov/c/github/lukeed/dset)](https://codecov.io/gh/lukeed/dset)\n\n> A tiny (194B) utility for safely writing deep Object values~!\n\nFor _accessing_ deep object properties, please see [`dlv`](https://github.com/developit/dlv).\n\n> **Using GraphQL?** You may want `dset/merge` – see [Merging](#merging) for more info.\n\n## Install\n\n```sh\n$ npm install --save dset\n```\n\n## Modes\n\nThere are two \"versions\" of `dset` available:\n\n#### `dset`\n> **Size (gzip):** 194 bytes<br>\n> **Availability:** [CommonJS](https://unpkg.com/dset/dist/index.js), [ES Module](https://unpkg.com/dset/dist/index.mjs), [UMD](https://unpkg.com/dset/dist/index.min.js)\n\n```js\nimport { dset } from 'dset';\n```\n\n#### `dset/merge`\n> **Size (gzip):** 288 bytes<br>\n> **Availability:** [CommonJS](https://unpkg.com/dset/merge/index.js), [ES Module](https://unpkg.com/dset/merge/index.mjs), [UMD](https://unpkg.com/dset/merge/index.min.js)\n\n```js\nimport { dset } from 'dset/merge';\n```\n\n\n## Usage\n\n```js\nimport { dset } from 'dset';\n\nlet foo = { abc: 123 };\ndset(foo, 'foo.bar', 'hello');\n// or: dset(foo, ['foo', 'bar'], 'hello');\nconsole.log(foo);\n//=> {\n//=>   abc: 123,\n//=>   foo: { bar: 'hello' },\n//=> }\n\ndset(foo, 'abc.hello', 'world');\n// or: dset(foo, ['abc', 'hello'], 'world');\nconsole.log(foo);\n//=> {\n//=>   abc: { hello: 'world' },\n//=>   foo: { bar: 'hello' },\n//=> }\n\nlet bar = { a: { x: 7 }, b:[1, 2, 3] };\ndset(bar, 'b.1', 999);\n// or: dset(bar, ['b', 1], 999);\n// or: dset(bar, ['b', '1'], 999);\nconsole.log(bar);\n//=> {\n//=>   a: { x: 7 },\n//=>   b: [1, 999, 3],\n//=> }\n\ndset(bar, 'a.y.0', 8);\n// or: dset(bar, ['a', 'y', 0], 8);\n// or: dset(bar, ['a', 'y', '0'], 8);\nconsole.log(bar);\n//=> {\n//=>   a: {\n//=>     x: 7,\n//=>     y: [8],\n//=>   },\n//=>   b: [1, 999, 3],\n//=> }\n\nlet baz = {};\ndset(baz, 'a.0.b.0', 1);\ndset(baz, 'a.0.b.1', 2);\nconsole.log(baz);\n//=> {\n//=>   a: [{ b: [1, 2] }]\n//=> }\n```\n\n## Merging\n\nThe main/default `dset` module forcibly writes values at the assigned key-path. However, in some cases, you may prefer to _merge_ values at the key-path. For example, when using [GraphQL's `@stream` and `@defer` directives](https://foundation.graphql.org/news/2020/12/08/improving-latency-with-defer-and-stream-directives/), you will need to merge the response chunks into a single object/list. This is why `dset/merge` exists~!\n\nBelow is a quick illustration of the difference between `dset` and `dset/merge`:\n\n```js\nlet input = {\n  hello: {\n    abc: 123\n  }\n};\n\ndset(input, 'hello', { world: 123 });\nconsole.log(input);\n\n// via `dset`\n//=> {\n//=>   hello: {\n//=>     world: 123\n//=>   }\n//=> }\n\n// via `dset/merge`\n//=> {\n//=>   hello: {\n//=>     abc: 123,\n//=>     world: 123\n//=>   }\n//=> }\n```\n\n\n## Immutability\n\nAs shown in the examples above, all `dset` interactions mutate the source object.\n\nIf you need immutable writes, please visit [`clean-set`](https://github.com/fwilkerson/clean-set) (182B).<br>\nAlternatively, you may pair `dset` with [`klona`](https://github.com/lukeed/klona), a 366B utility to clone your source(s). Here's an example pairing:\n\n```js\nimport { dset } from 'dset';\nimport { klona } from 'klona';\n\nexport function deepset(obj, path, val) {\n  let copy = klona(obj);\n  dset(copy, path, val);\n  return copy;\n}\n```\n\n\n## API\n\n### dset(obj, path, val)\n\nReturns: `void`\n\n#### obj\n\nType: `Object`\n\nThe Object to traverse & mutate with a value.\n\n#### path\n\nType: `String` or `Array`\n\nThe key path that should receive the value. May be in `x.y.z` or `['x', 'y', 'z']` formats.\n\n> **Note:** Please be aware that only the _last_ key actually receives the value!\n\n> **Important:** New Objects are created at each segment if there is not an existing structure.<br>However, when integers are encounted, Arrays are created instead!\n\n#### value\n\nType: `Any`\n\nThe value that you want to set. Can be of any type!\n\n\n## Benchmarks\n\nFor benchmarks and full results, check out the [`bench`](/bench) directory!\n\n```\n# Node 10.13.0\n\nValidation:\n  ✔ set-value\n  ✔ lodash/set\n  ✔ dset\n\nBenchmark:\n  set-value    x 1,701,821 ops/sec ±1.81% (93 runs sampled)\n  lodash/set   x   975,530 ops/sec ±0.96% (91 runs sampled)\n  dset         x 1,797,922 ops/sec ±0.32% (94 runs sampled)\n```\n\n\n## Related\n\n- [dlv](https://github.com/developit/dlv) - safely read from deep properties in 120 bytes\n- [dequal](https://github.com/lukeed/dequal) - safely check for deep equality in 247 bytes\n- [klona](https://github.com/lukeed/klona) - quickly \"deep clone\" data in 200 to 330 bytes\n- [clean-set](https://github.com/fwilkerson/clean-set) - fast, immutable version of `dset` in 182 bytes\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","publish_time":1536438299353,"_cnpm_publish_time":1536438299353,"dist-tags":{"latest":"3.1.4"}}