{"name":"dset","version":"2.1.0","repository":{"type":"git","url":"git+https://github.com/lukeed/dset.git"},"description":"A tiny (190B) 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","types":"index.d.ts","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"engines":{"node":">=4"},"scripts":{"build":"bundt","pretest":"npm run build","test":"uvu test"},"keywords":["deepset","values","object","write","deep","safe","set"],"devDependencies":{"bundt":"1.1.2","uvu":"0.5.1"},"gitHead":"113244b13bb34d383a1e72385c83a89616239741","bugs":{"url":"https://github.com/lukeed/dset/issues"},"homepage":"https://github.com/lukeed/dset#readme","_id":"dset@2.1.0","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"dist":{"integrity":"sha512-hlQYwNEdW7Qf8zxysy+yN1E8C/SxRst3Z9n+IvXOR35D9bPVwNHhnL8ZBeoZjvinuGrlvGg6pAMDwhmjqFDgjA==","shasum":"cd1e99e55cf32366d8f144f906c42f7fb3bf431e","tarball":"http://registry-npm.ywwl.com/dset/download/dset-2.1.0.tgz","fileCount":7,"unpackedSize":6337,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgESJ/CRA9TVsSAnZWagAAk8kP/2AFEf8WsPihr8td7drE\noU9txlT50TcaO5PXrhW+paEnjDqu+QinoiAvxu++Ypss4obMK++SN5B6R8kU\n+1dezF/OXlJC4RcLpRcv/eHCe9LwoCHzKvMjW85PMPRBTCuNv/oBE6a0CaQw\n3Sl+Vb1ubt3dG2+dlWZ7bdD1ANsLsW+zwsG6TlCgJtXQ7WTexZaiM6GskpeI\n5kGAEm27dr2EbPxUJ7iooBEuhhjoJ5tYKTA9QknCEgUTNMF9usoxXg9Bikrs\nIlBxm+r6GBJ5luzlavvl4eqJJLeBdjNb3OsbZh8OsMPizCgPwJc5iwUBXUGC\nKi94nvBRD9MXBOOulnAQI1OC9oUNxGXxL0LmUKkiiwKKjBfUZZhDHZfml0Z5\nfbZ6CRNg8PkTkscf0KZAWwdU/6kuFHkmALuM1zRiFchVRjhbTHjq5LKZc/r2\nMxLS8lFuf1Plowr1wzpM+OClsmM97wn7FCXwv0UEuDHLIRg5OxaAY9t6E1JL\nAYiq5O2zFhq6QNJGPkhmHeWPzwOyU67RounVFwN836PqaOZWzC9CLfuT/B2n\n4vLVdIq4UCN58cFfxRMmmk3B7MiSCGxvGyMZu4WljSoUQBLtRL6oj3zIa03I\nMTUkhLBOWrVLiySo4R5qto5yKdEHxIhtQDEUrLYqAZCxJNaYX8dVUMTHOI8i\n2uBQ\r\n=giMn\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCm6eSTFFQVO7vVYNukCp7eU0dTf27G4f5kUasKk/bYUwIhAK7sUOSDQWRsgk4Cl5MMAgYL3bJfTKODXp1/VVNGDEIN"}],"size":3042,"noattachment":false,"key":"/dset/-/dset-2.1.0.tgz"},"directories":{},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dset_2.1.0_1611735678943_0.2364839475517686"},"_hasShrinkwrap":false,"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":1611735679065,"_cnpm_publish_time":1611735679065,"dist-tags":{"latest":"3.1.4"}}