|
1 | 1 | # dset [](https://travis-ci.org/lukeed/dset) |
2 | 2 |
|
3 | | -> A tiny (161B) utility for safely writing deep Object values~! |
| 3 | +> A tiny (160B) utility for safely writing deep Object values~! |
4 | 4 |
|
5 | 5 | This module exposes two module definitions: |
6 | 6 |
|
@@ -48,6 +48,25 @@ console.log(qux); |
48 | 48 | //=> { a: [{ b: [1, 2] }] } |
49 | 49 | ``` |
50 | 50 |
|
| 51 | +## Mutability |
| 52 | + |
| 53 | +As shown in the examples above, all `dset` interactions mutate the source object. |
| 54 | + |
| 55 | +If you need immutable writes, please visit [`clean-set`](https://github.com/fwilkerson/clean-set) (182B).<br> |
| 56 | +Alternatively, you may pair `dset` with [`klona`](https://github.com/lukeed/klona), a 366B utility to clone your source(s). Here's an example pairing: |
| 57 | + |
| 58 | +```js |
| 59 | +import klona from 'klona'; |
| 60 | +import dset from 'dset'; |
| 61 | + |
| 62 | +export function deepset(obj, path, val) { |
| 63 | + let copy = klona(obj); |
| 64 | + dset(copy, path, val); |
| 65 | + return copy; |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | + |
51 | 70 | ## API |
52 | 71 |
|
53 | 72 | ### dset(obj, path, val) |
@@ -77,6 +96,19 @@ Type: `Any` |
77 | 96 | The value that you want to set. Can be of any type! |
78 | 97 |
|
79 | 98 |
|
| 99 | +## Benchmarks |
| 100 | + |
| 101 | +For benchmark results, check out the [`bench`](/bench) directory! |
| 102 | + |
| 103 | + |
| 104 | +## Related |
| 105 | + |
| 106 | +- [dlv](https://github.com/developit/dlv) - safely read from deep properties in 120 bytes |
| 107 | +- [dequal](https://github.com/lukeed/dequal) - safely check for deep equality in 247 bytes |
| 108 | +- [klona](https://github.com/lukeed/klona) - quickly "deep clone" data in 200 to 330 bytes |
| 109 | +- [clean-set](https://github.com/fwilkerson/clean-set) - fast, immutable version of `dset` in 182 bytes |
| 110 | + |
| 111 | + |
80 | 112 | ## License |
81 | 113 |
|
82 | 114 | MIT © [Luke Edwards](https://lukeed.com) |
0 commit comments