|
@@ -205,7 +205,7 @@ using `new Map(obj)`, not using `{...obj}`.
|
|
|
|
|
|
Creates "`obj` as an index in a map".
|
|
|
|
|
|
-### `cowWorkshop(keys, fn = x => x)(obj, [options])`
|
|
|
+### `pathWorkshop(keys, fn = x => x)(obj, [options])`
|
|
|
|
|
|
This is multipurpose enumerate-and-act function to manipulate objects
|
|
|
using `atPath`. The `options` argument can contain these additional fields:
|
|
@@ -221,27 +221,27 @@ the result key and value is also put into `diff`.
|
|
|
It then returns `{result, diff}` object.
|
|
|
|
|
|
```js
|
|
|
-cowWorkshop(["a", "b.c"])();
|
|
|
+pathWorkshop(["a", "b.c"])();
|
|
|
// does nothing
|
|
|
// => {result: undefined, diff: undefined}
|
|
|
|
|
|
-cowWorkshop(["a", "b.c"], () => null)();
|
|
|
+pathWorkshop(["a", "b.c"], () => null)();
|
|
|
// sets a and b.c to null
|
|
|
// => {result: {a: null, b: {c: null}}, diff: {a: null, b: {c: null}}}
|
|
|
|
|
|
const data = {a: 'foo', b: {c: null}};
|
|
|
-cowWorkshop(["a", "b.c"], JSON.stringify)(data);
|
|
|
+pathWorkshop(["a", "b.c"], JSON.stringify)(data);
|
|
|
// changes a and b.c to string representation; change to a is noop
|
|
|
// => {result: {a: 'foo', b: {c: 'null'}}, diff: {b: {c: 'null'}}}
|
|
|
|
|
|
const stored = {ay: 'bar', beecee: 'baz', cee: 'quux'};
|
|
|
const data = {a: 'foo', b: {c: null}};
|
|
|
-cowWorkshop(["a", "b.c"])(data, {result: stored, resultKeys: ["ay", "beecee"]});
|
|
|
+pathWorkshop(["a", "b.c"])(data, {result: stored, resultKeys: ["ay", "beecee"]});
|
|
|
// "copies" a and b.c into `stored` under different keys
|
|
|
// => {result: {ay: 'foo', beecee: null, cee: 'quux'}, diff: {ay: 'foo', beecee: null}}
|
|
|
|
|
|
const data = {a: 'foo', b: {c: 'bar'}, c: 'quux'};
|
|
|
-cowWorkshop(["a", "b.c"], () => null)(data);
|
|
|
+pathWorkshop(["a", "b.c"], () => null)(data);
|
|
|
// "nulls" a few fields
|
|
|
// => {result: {a: null, b: {c: null}, c: 'quux'}, diff: {a: null, b: {c: null}}}
|
|
|
```
|