{"_id":"@akkuma/dset","_rev":"1-02c2c1089e2c6766d810a2eadde7e3d7","name":"@akkuma/dset","dist-tags":{"latest":"3.1.4"},"versions":{"3.1.3":{"name":"@akkuma/dset","version":"3.1.3","repository":{"type":"git","url":"git+https://github.com/akkuma/dset.git"},"description":"A tiny (194B) utility for safely writing deep Object values~!","unpkg":"dist/index.min.js","umd:main":"dist/index.min.js","module":"dist/index.mjs","main":"dist/index.js","types":"index.d.ts","license":"MIT","exports":{".":{"import":{"types":"./index.d.ts","default":"./dist/index.mjs"},"require":{"types":"./index.d.ts","default":"./dist/index.js"}},"./merge":{"import":{"types":"./merge/index.d.ts","default":"./merge/index.mjs"},"require":{"types":"./merge/index.d.ts","default":"./merge/index.js"}},"./package.json":"./package.json"},"author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"engines":{"node":">=4"},"scripts":{"build":"bundt","test":"uvu test -r esm -i suites"},"modes":{"merge":"src/merge.js","default":"src/index.js"},"keywords":["deepset","values","object","write","deep","safe","set"],"devDependencies":{"bundt":"1.1.2","esm":"3.2.25","uvu":"0.5.1"},"_id":"@akkuma/dset@3.1.3","gitHead":"330032378d83eb4e173d28da5bca743f3a9547e4","bugs":{"url":"https://github.com/akkuma/dset/issues"},"homepage":"https://github.com/akkuma/dset#readme","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-Cbw1qFAd4vtmUvM4A0qCe2LDrLrOJubBrmp340Z3UIOpZYuVLlOjCqf8LYdtxA2VQ5W9llgU5zsMUgkWXvcrJA==","shasum":"4516180e0c353cb02a1eec7ef4a9e0ed5e638326","tarball":"https://registry.npmjs.org/@akkuma/dset/-/dset-3.1.3.tgz","fileCount":11,"unpackedSize":11048,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDqiq93dIuWesNskI7tIkAlUK1wTbf8WcQaI+1lGA4cUQIgBqr+y8ceQbKgkkIR31ICdmVIyoLw0k3ea4+iYPdAc4U="}]},"_npmUser":{"name":"akkuma","email":"akkuma+npmjs@gmail.com"},"directories":{},"maintainers":[{"name":"akkuma","email":"akkuma+npmjs@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dset_3.1.3_1698165637403_0.39094852279129366"},"_hasShrinkwrap":false},"3.1.4":{"name":"@akkuma/dset","version":"3.1.4","repository":{"type":"git","url":"git+https://github.com/akkuma/dset.git"},"description":"A tiny (194B) utility for safely writing deep Object values~!","unpkg":"dist/index.min.js","umd:main":"dist/index.min.js","module":"dist/index.mjs","main":"dist/index.js","types":"index.d.ts","license":"MIT","exports":{".":{"types":"./index.d.ts","import":"./dist/index.mjs","require":"./index.d.ts"},"./merge":{"types":"./merge/index.d.ts","import":"./merge/index.mjs","require":"./merge/index.js"},"./package.json":"./package.json"},"author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"engines":{"node":">=4"},"scripts":{"build":"bundt","test":"uvu test -r esm -i suites"},"modes":{"merge":"src/merge.js","default":"src/index.js"},"keywords":["deepset","values","object","write","deep","safe","set"],"devDependencies":{"bundt":"1.1.2","esm":"3.2.25","uvu":"0.5.1"},"_id":"@akkuma/dset@3.1.4","gitHead":"330032378d83eb4e173d28da5bca743f3a9547e4","bugs":{"url":"https://github.com/akkuma/dset/issues"},"homepage":"https://github.com/akkuma/dset#readme","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-Tgy9nDP1YBzmfKJqeUeTdDgfsH3Ig0SSuOZFdUPatGArJQ4uf5q8f+B36N7Y1rR3PmbNNAQPwFyHjIVkV7EOmA==","shasum":"38c1714957dd5a3521249bef60fddc32bf7dbd81","tarball":"https://registry.npmjs.org/@akkuma/dset/-/dset-3.1.4.tgz","fileCount":11,"unpackedSize":10853,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICZmSt11APOy2bSPCRrpRPsnZB5/+eLppE3DnqabGDhJAiEA0VDMMxfU4ocEtu8c1YpqddggT9wLMwi6QwLRXg8vsA4="}]},"_npmUser":{"name":"akkuma","email":"akkuma+npmjs@gmail.com"},"directories":{},"maintainers":[{"name":"akkuma","email":"akkuma+npmjs@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dset_3.1.4_1698257716513_0.15122706788584073"},"_hasShrinkwrap":false}},"time":{"created":"2023-10-24T16:40:37.345Z","3.1.3":"2023-10-24T16:40:37.687Z","modified":"2023-10-25T18:15:16.855Z","3.1.4":"2023-10-25T18:15:16.681Z"},"maintainers":[{"name":"akkuma","email":"akkuma+npmjs@gmail.com"}],"description":"A tiny (194B) utility for safely writing deep Object values~!","homepage":"https://github.com/akkuma/dset#readme","keywords":["deepset","values","object","write","deep","safe","set"],"repository":{"type":"git","url":"git+https://github.com/akkuma/dset.git"},"author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"bugs":{"url":"https://github.com/akkuma/dset/issues"},"license":"MIT","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","readmeFilename":"readme.md"}