@spscommerce/utils 5.20.0 → 5.20.3-ie
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/out-tsc/array/flatten.d.ts +1 -0
- package/dist/out-tsc/array/flatten.js +7 -0
- package/dist/out-tsc/array/flatten.js.map +1 -0
- package/dist/out-tsc/array/flatten.spec.d.ts +1 -0
- package/dist/out-tsc/array/flatten.spec.js +10 -0
- package/dist/out-tsc/array/flatten.spec.js.map +1 -0
- package/dist/out-tsc/array/index.d.ts +3 -0
- package/dist/out-tsc/array/index.js +4 -0
- package/dist/out-tsc/array/index.js.map +1 -0
- package/dist/out-tsc/array/is-subset.d.ts +4 -0
- package/dist/out-tsc/array/is-subset.js +41 -0
- package/dist/out-tsc/array/is-subset.js.map +1 -0
- package/dist/out-tsc/array/is-subset.spec.d.ts +1 -0
- package/dist/out-tsc/array/is-subset.spec.js +41 -0
- package/dist/out-tsc/array/is-subset.spec.js.map +1 -0
- package/dist/out-tsc/array/range.d.ts +5 -0
- package/dist/out-tsc/array/range.js +16 -0
- package/dist/out-tsc/array/range.js.map +1 -0
- package/dist/out-tsc/array/range.spec.d.ts +1 -0
- package/dist/out-tsc/array/range.spec.js +26 -0
- package/dist/out-tsc/array/range.spec.js.map +1 -0
- package/dist/out-tsc/classes/custom-event.d.ts +4 -0
- package/dist/out-tsc/classes/custom-event.js +87 -0
- package/dist/out-tsc/classes/custom-event.js.map +1 -0
- package/dist/out-tsc/classes/index.d.ts +1 -0
- package/dist/out-tsc/classes/index.js +2 -0
- package/dist/out-tsc/classes/index.js.map +1 -0
- package/dist/out-tsc/data/doctypes.d.ts +4 -0
- package/dist/out-tsc/data/doctypes.js +302 -0
- package/dist/out-tsc/data/doctypes.js.map +1 -0
- package/dist/out-tsc/data/index.d.ts +1 -0
- package/dist/out-tsc/data/index.js +2 -0
- package/dist/out-tsc/data/index.js.map +1 -0
- package/dist/out-tsc/decorators/cast-to-number.d.ts +5 -0
- package/dist/out-tsc/decorators/cast-to-number.js +29 -0
- package/dist/out-tsc/decorators/cast-to-number.js.map +1 -0
- package/dist/out-tsc/decorators/debounced.broken_spec.d.ts +0 -0
- package/dist/out-tsc/decorators/debounced.broken_spec.js +38 -0
- package/dist/out-tsc/decorators/debounced.broken_spec.js.map +1 -0
- package/dist/out-tsc/decorators/debounced.d.ts +11 -0
- package/dist/out-tsc/decorators/debounced.js +35 -0
- package/dist/out-tsc/decorators/debounced.js.map +1 -0
- package/dist/out-tsc/decorators/index.d.ts +5 -0
- package/dist/out-tsc/decorators/index.js +6 -0
- package/dist/out-tsc/decorators/index.js.map +1 -0
- package/dist/out-tsc/decorators/locked-to-animation-frames.d.ts +4 -0
- package/dist/out-tsc/decorators/locked-to-animation-frames.js +34 -0
- package/dist/out-tsc/decorators/locked-to-animation-frames.js.map +1 -0
- package/dist/out-tsc/decorators/locked-to-animation-frames.spec.d.ts +0 -0
- package/dist/out-tsc/decorators/locked-to-animation-frames.spec.js +63 -0
- package/dist/out-tsc/decorators/locked-to-animation-frames.spec.js.map +1 -0
- package/dist/out-tsc/decorators/simple-metadata-decorator-applicator.d.ts +11 -0
- package/dist/out-tsc/decorators/simple-metadata-decorator-applicator.js +80 -0
- package/dist/out-tsc/decorators/simple-metadata-decorator-applicator.js.map +1 -0
- package/dist/out-tsc/decorators/tick-delay.d.ts +6 -0
- package/dist/out-tsc/decorators/tick-delay.js +31 -0
- package/dist/out-tsc/decorators/tick-delay.js.map +1 -0
- package/dist/out-tsc/function/debounce.d.ts +9 -0
- package/dist/out-tsc/function/debounce.js +102 -0
- package/dist/out-tsc/function/debounce.js.map +1 -0
- package/dist/out-tsc/function/debounce.spec.d.ts +1 -0
- package/dist/out-tsc/function/debounce.spec.js +150 -0
- package/dist/out-tsc/function/debounce.spec.js.map +1 -0
- package/dist/out-tsc/function/debounced-function.interface.d.ts +10 -0
- package/dist/out-tsc/function/debounced-function.interface.js +2 -0
- package/dist/out-tsc/function/debounced-function.interface.js.map +1 -0
- package/dist/out-tsc/function/delayed-function.interface.d.ts +10 -0
- package/dist/out-tsc/function/delayed-function.interface.js +2 -0
- package/dist/out-tsc/function/delayed-function.interface.js.map +1 -0
- package/dist/out-tsc/function/index.d.ts +6 -0
- package/dist/out-tsc/function/index.js +7 -0
- package/dist/out-tsc/function/index.js.map +1 -0
- package/dist/out-tsc/function/lock-to-animation-frames.d.ts +7 -0
- package/dist/out-tsc/function/lock-to-animation-frames.js +43 -0
- package/dist/out-tsc/function/lock-to-animation-frames.js.map +1 -0
- package/dist/out-tsc/function/lock-to-animation-frames.spec.d.ts +0 -0
- package/dist/out-tsc/function/lock-to-animation-frames.spec.js +53 -0
- package/dist/out-tsc/function/lock-to-animation-frames.spec.js.map +1 -0
- package/dist/out-tsc/function/on-next-tick.d.ts +8 -0
- package/dist/out-tsc/function/on-next-tick.js +12 -0
- package/dist/out-tsc/function/on-next-tick.js.map +1 -0
- package/dist/out-tsc/function/on-next-tick.spec.d.ts +1 -0
- package/dist/out-tsc/function/on-next-tick.spec.js +13 -0
- package/dist/out-tsc/function/on-next-tick.spec.js.map +1 -0
- package/dist/out-tsc/function/op.d.ts +32 -0
- package/dist/out-tsc/function/op.js +34 -0
- package/dist/out-tsc/function/op.js.map +1 -0
- package/dist/out-tsc/function/op.spec.d.ts +1 -0
- package/dist/out-tsc/function/op.spec.js +94 -0
- package/dist/out-tsc/function/op.spec.js.map +1 -0
- package/dist/out-tsc/index.d.ts +9 -0
- package/dist/out-tsc/index.js +10 -0
- package/dist/out-tsc/index.js.map +1 -0
- package/dist/out-tsc/number/constrain.d.ts +7 -0
- package/dist/out-tsc/number/constrain.js +16 -0
- package/dist/out-tsc/number/constrain.js.map +1 -0
- package/dist/out-tsc/number/decimal-round.d.ts +7 -0
- package/dist/out-tsc/number/decimal-round.js +19 -0
- package/dist/out-tsc/number/decimal-round.js.map +1 -0
- package/dist/out-tsc/number/decimal-round.spec.d.ts +1 -0
- package/dist/out-tsc/number/decimal-round.spec.js +10 -0
- package/dist/out-tsc/number/decimal-round.spec.js.map +1 -0
- package/dist/out-tsc/number/index.d.ts +3 -0
- package/dist/out-tsc/number/index.js +4 -0
- package/dist/out-tsc/number/index.js.map +1 -0
- package/dist/out-tsc/number/to-file-size-string.d.ts +5 -0
- package/dist/out-tsc/number/to-file-size-string.js +24 -0
- package/dist/out-tsc/number/to-file-size-string.js.map +1 -0
- package/dist/out-tsc/object/copy-property.d.ts +6 -0
- package/dist/out-tsc/object/copy-property.js +9 -0
- package/dist/out-tsc/object/copy-property.js.map +1 -0
- package/dist/out-tsc/object/copy-property.spec.d.ts +1 -0
- package/dist/out-tsc/object/copy-property.spec.js +16 -0
- package/dist/out-tsc/object/copy-property.spec.js.map +1 -0
- package/dist/out-tsc/object/crumble-path.d.ts +6 -0
- package/dist/out-tsc/object/crumble-path.js +9 -0
- package/dist/out-tsc/object/crumble-path.js.map +1 -0
- package/dist/out-tsc/object/crumble-path.spec.d.ts +1 -0
- package/dist/out-tsc/object/crumble-path.spec.js +24 -0
- package/dist/out-tsc/object/crumble-path.spec.js.map +1 -0
- package/dist/out-tsc/object/deep-freeze.d.ts +1 -0
- package/dist/out-tsc/object/deep-freeze.js +36 -0
- package/dist/out-tsc/object/deep-freeze.js.map +1 -0
- package/dist/out-tsc/object/deep-freeze.spec.d.ts +1 -0
- package/dist/out-tsc/object/deep-freeze.spec.js +14 -0
- package/dist/out-tsc/object/deep-freeze.spec.js.map +1 -0
- package/dist/out-tsc/object/diff.d.ts +12 -0
- package/dist/out-tsc/object/diff.js +92 -0
- package/dist/out-tsc/object/diff.js.map +1 -0
- package/dist/out-tsc/object/diff.spec.d.ts +1 -0
- package/dist/out-tsc/object/diff.spec.js +40 -0
- package/dist/out-tsc/object/diff.spec.js.map +1 -0
- package/dist/out-tsc/object/for-each-entry-deep.d.ts +4 -0
- package/dist/out-tsc/object/for-each-entry-deep.js +38 -0
- package/dist/out-tsc/object/for-each-entry-deep.js.map +1 -0
- package/dist/out-tsc/object/for-each-entry-deep.spec.d.ts +1 -0
- package/dist/out-tsc/object/for-each-entry-deep.spec.js +24 -0
- package/dist/out-tsc/object/for-each-entry-deep.spec.js.map +1 -0
- package/dist/out-tsc/object/for-each-nested-object.d.ts +4 -0
- package/dist/out-tsc/object/for-each-nested-object.js +38 -0
- package/dist/out-tsc/object/for-each-nested-object.js.map +1 -0
- package/dist/out-tsc/object/for-each-nested-object.spec.d.ts +1 -0
- package/dist/out-tsc/object/for-each-nested-object.spec.js +46 -0
- package/dist/out-tsc/object/for-each-nested-object.spec.js.map +1 -0
- package/dist/out-tsc/object/get-path.d.ts +5 -0
- package/dist/out-tsc/object/get-path.js +67 -0
- package/dist/out-tsc/object/get-path.js.map +1 -0
- package/dist/out-tsc/object/get-path.spec.d.ts +1 -0
- package/dist/out-tsc/object/get-path.spec.js +44 -0
- package/dist/out-tsc/object/get-path.spec.js.map +1 -0
- package/dist/out-tsc/object/index.d.ts +13 -0
- package/dist/out-tsc/object/index.js +14 -0
- package/dist/out-tsc/object/index.js.map +1 -0
- package/dist/out-tsc/object/merge-deep.d.ts +4 -0
- package/dist/out-tsc/object/merge-deep.js +60 -0
- package/dist/out-tsc/object/merge-deep.js.map +1 -0
- package/dist/out-tsc/object/merge-deep.spec.d.ts +1 -0
- package/dist/out-tsc/object/merge-deep.spec.js +16 -0
- package/dist/out-tsc/object/merge-deep.spec.js.map +1 -0
- package/dist/out-tsc/object/merge-properties-deep.d.ts +4 -0
- package/dist/out-tsc/object/merge-properties-deep.js +61 -0
- package/dist/out-tsc/object/merge-properties-deep.js.map +1 -0
- package/dist/out-tsc/object/merge-properties-deep.spec.d.ts +1 -0
- package/dist/out-tsc/object/merge-properties-deep.spec.js +24 -0
- package/dist/out-tsc/object/merge-properties-deep.spec.js.map +1 -0
- package/dist/out-tsc/object/omit.d.ts +1 -0
- package/dist/out-tsc/object/omit.js +40 -0
- package/dist/out-tsc/object/omit.js.map +1 -0
- package/dist/out-tsc/object/omit.spec.d.ts +1 -0
- package/dist/out-tsc/object/omit.spec.js +10 -0
- package/dist/out-tsc/object/omit.spec.js.map +1 -0
- package/dist/out-tsc/object/set-path.d.ts +2 -0
- package/dist/out-tsc/object/set-path.js +45 -0
- package/dist/out-tsc/object/set-path.js.map +1 -0
- package/dist/out-tsc/object/set-path.spec.d.ts +1 -0
- package/dist/out-tsc/object/set-path.spec.js +36 -0
- package/dist/out-tsc/object/set-path.spec.js.map +1 -0
- package/dist/out-tsc/object/traverse-path.d.ts +2 -0
- package/dist/out-tsc/object/traverse-path.js +81 -0
- package/dist/out-tsc/object/traverse-path.js.map +1 -0
- package/dist/out-tsc/object/values.d.ts +2 -0
- package/dist/out-tsc/object/values.js +31 -0
- package/dist/out-tsc/object/values.js.map +1 -0
- package/dist/out-tsc/object/values.spec.d.ts +1 -0
- package/dist/out-tsc/object/values.spec.js +7 -0
- package/dist/out-tsc/object/values.spec.js.map +1 -0
- package/dist/out-tsc/string/code.template-tag.d.ts +2 -0
- package/dist/out-tsc/string/code.template-tag.js +38 -0
- package/dist/out-tsc/string/code.template-tag.js.map +1 -0
- package/dist/out-tsc/string/index.d.ts +3 -0
- package/dist/out-tsc/string/index.js +4 -0
- package/dist/out-tsc/string/index.js.map +1 -0
- package/dist/out-tsc/string/parse-file-size.d.ts +5 -0
- package/dist/out-tsc/string/parse-file-size.js +43 -0
- package/dist/out-tsc/string/parse-file-size.js.map +1 -0
- package/dist/out-tsc/string/template.d.ts +15 -0
- package/dist/out-tsc/string/template.js +28 -0
- package/dist/out-tsc/string/template.js.map +1 -0
- package/dist/out-tsc/string/template.spec.d.ts +1 -0
- package/dist/out-tsc/string/template.spec.js +39 -0
- package/dist/out-tsc/string/template.spec.js.map +1 -0
- package/dist/out-tsc/typings.d.ts +1 -0
- package/dist/out-tsc/typings.js +2 -0
- package/dist/out-tsc/typings.js.map +1 -0
- package/lib/index.cjs.js +2437 -1
- package/lib/index.es.js +2268 -893
- package/package.json +5 -5
- package/rollup.config.js +22 -0
- package/vite.config.js +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var __values = (this && this.__values) || function(o) {
|
|
2
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
3
|
+
if (m) return m.call(o);
|
|
4
|
+
if (o && typeof o.length === "number") return {
|
|
5
|
+
next: function () {
|
|
6
|
+
if (o && i >= o.length) o = void 0;
|
|
7
|
+
return { value: o && o[i++], done: !o };
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
|
+
};
|
|
12
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
+
if (!m) return o;
|
|
15
|
+
var i = m.call(o), r, ar = [], e;
|
|
16
|
+
try {
|
|
17
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) { e = { error: error }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e) throw e.error; }
|
|
25
|
+
}
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
import * as isNilImport from "lodash.isnil";
|
|
29
|
+
import * as isEmptyImport from "lodash.isempty";
|
|
30
|
+
import { crumblePath } from "./crumble-path";
|
|
31
|
+
var isNil = isNilImport.default || isNilImport;
|
|
32
|
+
var isEmpty = isEmptyImport.default || isEmptyImport;
|
|
33
|
+
/**
|
|
34
|
+
* Get the value at `path` starting from `object`.
|
|
35
|
+
* Allows optional chaining, e.g. `get(obj, 'a.b?.c')`
|
|
36
|
+
*/
|
|
37
|
+
export function getPath(object, path, defaultValue, allOptional) {
|
|
38
|
+
var e_1, _a, _b;
|
|
39
|
+
if (allOptional === void 0) { allOptional = false; }
|
|
40
|
+
if (isEmpty(path)) {
|
|
41
|
+
return object;
|
|
42
|
+
}
|
|
43
|
+
var value = object;
|
|
44
|
+
try {
|
|
45
|
+
for (var _c = __values(crumblePath(path)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
46
|
+
var crumb = _d.value;
|
|
47
|
+
var key = crumb;
|
|
48
|
+
var optional = void 0;
|
|
49
|
+
if (typeof crumb === "string") {
|
|
50
|
+
_b = __read(/^([^?]+)(\?)?$/.exec(crumb), 3), key = _b[1], optional = _b[2];
|
|
51
|
+
}
|
|
52
|
+
value = value[key];
|
|
53
|
+
if (isNil(value) && (optional || allOptional)) {
|
|
54
|
+
return defaultValue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
59
|
+
finally {
|
|
60
|
+
try {
|
|
61
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
62
|
+
}
|
|
63
|
+
finally { if (e_1) throw e_1.error; }
|
|
64
|
+
}
|
|
65
|
+
return isNil(value) ? defaultValue : value;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=get-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-path.js","sourceRoot":"","sources":["../../../src/object/get-path.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,aAAa,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,IAAM,KAAK,GAAI,WAAmB,CAAC,OAAO,IAAI,WAAW,CAAC;AAC1D,IAAM,OAAO,GAAI,aAAqB,CAAC,OAAO,IAAI,aAAa,CAAC;AAEhE;;;GAGG;AACH,MAAM,UAAU,OAAO,CACrB,MAAW,EACX,IAA0C,EAC1C,YAAgB,EAChB,WAAmB;;IAAnB,4BAAA,EAAA,mBAAmB;IAEnB,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE;QACjB,OAAO,MAAM,CAAC;KACf;IAED,IAAI,KAAK,GAAG,MAAM,CAAC;;QACnB,KAAoB,IAAA,KAAA,SAAA,WAAW,CAAC,IAAI,CAAC,CAAA,gBAAA,4BAAE;YAAlC,IAAM,KAAK,WAAA;YACd,IAAI,GAAG,GAAG,KAAK,CAAC;YAChB,IAAI,QAAQ,SAAA,CAAC;YACb,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;gBAC7B,KAAA,OACc,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAA,EADvC,GAAG,QAAA,EACJ,QAAQ,QAAA,CAAiC;aAC5C;YAED,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAEnB,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,IAAI,WAAW,CAAC,EAAE;gBAC7C,OAAO,YAAY,CAAC;aACrB;SACF;;;;;;;;;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getPath } from "./get-path";
|
|
2
|
+
describe("getPath", function () {
|
|
3
|
+
test("gets the value at a given dot path", function () {
|
|
4
|
+
var object = {
|
|
5
|
+
a: {
|
|
6
|
+
b: "c",
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
expect(getPath(object, "a.b")).toBe("c");
|
|
10
|
+
});
|
|
11
|
+
test("gets the value at a given array path", function () {
|
|
12
|
+
var object = [null,
|
|
13
|
+
[null,
|
|
14
|
+
null,
|
|
15
|
+
"foo"]];
|
|
16
|
+
expect(getPath(object, "[1][2]")).toBe("foo");
|
|
17
|
+
});
|
|
18
|
+
test("supports optional chaining", function () {
|
|
19
|
+
var object = {
|
|
20
|
+
a: {},
|
|
21
|
+
};
|
|
22
|
+
expect(getPath(object, "a.b?.c")).toBeUndefined();
|
|
23
|
+
});
|
|
24
|
+
test("errors when accessing property of missing key when not optional", function () {
|
|
25
|
+
var object = {
|
|
26
|
+
a: {},
|
|
27
|
+
};
|
|
28
|
+
expect(function () { return getPath(object, "a.b.c"); }).toThrow();
|
|
29
|
+
});
|
|
30
|
+
test("returns the given default value if path deadends", function () {
|
|
31
|
+
var object = {
|
|
32
|
+
a: {},
|
|
33
|
+
};
|
|
34
|
+
expect(getPath(object, "a.b", "foo")).toBe("foo");
|
|
35
|
+
expect(getPath(object, "a.b?.c", "bar")).toBe("bar");
|
|
36
|
+
});
|
|
37
|
+
test("returns the initial object if path is empty", function () {
|
|
38
|
+
var object = {
|
|
39
|
+
a: {},
|
|
40
|
+
};
|
|
41
|
+
expect(getPath(object, "")).toBe(object);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=get-path.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-path.spec.js","sourceRoot":"","sources":["../../../src/object/get-path.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,QAAQ,CAAC,SAAS,EAAE;IAClB,IAAI,CAAC,oCAAoC,EAAE;QACzC,IAAM,MAAM,GAAG;YACb,CAAC,EAAE;gBACD,CAAC,EAAE,GAAG;aACP;SACF,CAAC;QACF,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,sCAAsC,EAAE;QAC3C,IAAM,MAAM,GAAG,CAAC,IAAI;YAClB,CAAC,IAAI;gBACH,IAAI;gBACJ,KAAK,CAAC,CAAC,CAAC;QACZ,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,4BAA4B,EAAE;QACjC,IAAM,MAAM,GAAG;YACb,CAAC,EAAE,EAAE;SACN,CAAC;QACF,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,iEAAiE,EAAE;QACtE,IAAM,MAAM,GAAG;YACb,CAAC,EAAE,EAAE;SACN,CAAC;QACF,MAAM,CAAC,cAAM,OAAA,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,EAAxB,CAAwB,CAAC,CAAC,OAAO,EAAE,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,kDAAkD,EAAE;QACvD,IAAM,MAAM,GAAG;YACb,CAAC,EAAE,EAAE;SACN,CAAC;QACF,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClD,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,6CAA6C,EAAE;QAClD,IAAM,MAAM,GAAG;YACb,CAAC,EAAE,EAAE;SACN,CAAC;QACF,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./crumble-path";
|
|
2
|
+
export * from "./copy-property";
|
|
3
|
+
export * from "./deep-freeze";
|
|
4
|
+
export * from "./diff";
|
|
5
|
+
export * from "./for-each-entry-deep";
|
|
6
|
+
export * from "./for-each-nested-object";
|
|
7
|
+
export * from "./get-path";
|
|
8
|
+
export * from "./omit";
|
|
9
|
+
export * from "./set-path";
|
|
10
|
+
export * from "./traverse-path";
|
|
11
|
+
export * from "./merge-deep";
|
|
12
|
+
export * from "./merge-properties-deep";
|
|
13
|
+
export * from "./values";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./crumble-path";
|
|
2
|
+
export * from "./copy-property";
|
|
3
|
+
export * from "./deep-freeze";
|
|
4
|
+
export * from "./diff";
|
|
5
|
+
export * from "./for-each-entry-deep";
|
|
6
|
+
export * from "./for-each-nested-object";
|
|
7
|
+
export * from "./get-path";
|
|
8
|
+
export * from "./omit";
|
|
9
|
+
export * from "./set-path";
|
|
10
|
+
export * from "./traverse-path";
|
|
11
|
+
export * from "./merge-deep";
|
|
12
|
+
export * from "./merge-properties-deep";
|
|
13
|
+
export * from "./values";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/object/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC;AACxC,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __values = (this && this.__values) || function(o) {
|
|
2
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
3
|
+
if (m) return m.call(o);
|
|
4
|
+
if (o && typeof o.length === "number") return {
|
|
5
|
+
next: function () {
|
|
6
|
+
if (o && i >= o.length) o = void 0;
|
|
7
|
+
return { value: o && o[i++], done: !o };
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
|
+
};
|
|
12
|
+
import isPlainObject from "lodash.isplainobject";
|
|
13
|
+
/**
|
|
14
|
+
* Recursive merge of any number of objects
|
|
15
|
+
*/
|
|
16
|
+
export function mergeDeep() {
|
|
17
|
+
var e_1, _a, e_2, _b;
|
|
18
|
+
var objectsToMerge = [];
|
|
19
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
20
|
+
objectsToMerge[_i] = arguments[_i];
|
|
21
|
+
}
|
|
22
|
+
var result = {};
|
|
23
|
+
try {
|
|
24
|
+
for (var objectsToMerge_1 = __values(objectsToMerge), objectsToMerge_1_1 = objectsToMerge_1.next(); !objectsToMerge_1_1.done; objectsToMerge_1_1 = objectsToMerge_1.next()) {
|
|
25
|
+
var mergee = objectsToMerge_1_1.value;
|
|
26
|
+
try {
|
|
27
|
+
for (var _c = (e_2 = void 0, __values(Object.keys(mergee))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
28
|
+
var key = _d.value;
|
|
29
|
+
if (Object.prototype.hasOwnProperty.call(result, key)
|
|
30
|
+
&& Object.getOwnPropertyDescriptor(result, key).writable
|
|
31
|
+
&& isPlainObject(result[key])) {
|
|
32
|
+
result[key] = mergeDeep(result[key], mergee[key]);
|
|
33
|
+
}
|
|
34
|
+
else if (isPlainObject(mergee[key])) {
|
|
35
|
+
result[key] = mergeDeep({}, mergee[key]);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
result[key] = mergee[key];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
43
|
+
finally {
|
|
44
|
+
try {
|
|
45
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
46
|
+
}
|
|
47
|
+
finally { if (e_2) throw e_2.error; }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
52
|
+
finally {
|
|
53
|
+
try {
|
|
54
|
+
if (objectsToMerge_1_1 && !objectsToMerge_1_1.done && (_a = objectsToMerge_1.return)) _a.call(objectsToMerge_1);
|
|
55
|
+
}
|
|
56
|
+
finally { if (e_1) throw e_1.error; }
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=merge-deep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-deep.js","sourceRoot":"","sources":["../../../src/object/merge-deep.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,aAAa,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM,UAAU,SAAS;;IAAC,wBAAwB;SAAxB,UAAwB,EAAxB,qBAAwB,EAAxB,IAAwB;QAAxB,mCAAwB;;IAChD,IAAM,MAAM,GAAG,EAAE,CAAC;;QAClB,KAAqB,IAAA,mBAAA,SAAA,cAAc,CAAA,8CAAA,0EAAE;YAAhC,IAAM,MAAM,2BAAA;;gBACf,KAAkB,IAAA,oBAAA,SAAA,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,CAAA,gBAAA,4BAAE;oBAAlC,IAAM,GAAG,WAAA;oBACZ,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC;2BACxC,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,QAAQ;2BACrD,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EACrC;wBACA,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;qBACnD;yBAAM,IAAI,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;wBACrC,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;qBAC1C;yBAAM;wBACL,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;qBAC3B;iBACF;;;;;;;;;SACF;;;;;;;;;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { mergeDeep } from "./merge-deep";
|
|
2
|
+
describe("mergeDeep", function () {
|
|
3
|
+
test("should recursively merge objects", function () {
|
|
4
|
+
var obj1 = { a: 0, b: { c: 1 } };
|
|
5
|
+
var obj2 = { b: { d: 2 }, e: 3 };
|
|
6
|
+
expect(mergeDeep(obj1, obj2)).toEqual({
|
|
7
|
+
a: 0,
|
|
8
|
+
b: {
|
|
9
|
+
c: 1,
|
|
10
|
+
d: 2,
|
|
11
|
+
},
|
|
12
|
+
e: 3,
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=merge-deep.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-deep.spec.js","sourceRoot":"","sources":["../../../src/object/merge-deep.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,QAAQ,CAAC,WAAW,EAAE;IACpB,IAAI,CAAC,kCAAkC,EAAE;QACvC,IAAM,IAAI,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,IAAM,IAAI,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACnC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACpC,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE;gBACD,CAAC,EAAE,CAAC;gBACJ,CAAC,EAAE,CAAC;aACL;YACD,CAAC,EAAE,CAAC;SACL,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __values = (this && this.__values) || function(o) {
|
|
2
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
3
|
+
if (m) return m.call(o);
|
|
4
|
+
if (o && typeof o.length === "number") return {
|
|
5
|
+
next: function () {
|
|
6
|
+
if (o && i >= o.length) o = void 0;
|
|
7
|
+
return { value: o && o[i++], done: !o };
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
|
+
};
|
|
12
|
+
import isPlainObject from "lodash.isplainobject";
|
|
13
|
+
import { copyProperty } from "./copy-property";
|
|
14
|
+
/**
|
|
15
|
+
* Recursive merge of any number of objects using `copyProperty()` rather than assignment
|
|
16
|
+
*/
|
|
17
|
+
export function mergePropertiesDeep() {
|
|
18
|
+
var e_1, _a, e_2, _b;
|
|
19
|
+
var objectsToMerge = [];
|
|
20
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
21
|
+
objectsToMerge[_i] = arguments[_i];
|
|
22
|
+
}
|
|
23
|
+
var result = {};
|
|
24
|
+
try {
|
|
25
|
+
for (var objectsToMerge_1 = __values(objectsToMerge), objectsToMerge_1_1 = objectsToMerge_1.next(); !objectsToMerge_1_1.done; objectsToMerge_1_1 = objectsToMerge_1.next()) {
|
|
26
|
+
var mergee = objectsToMerge_1_1.value;
|
|
27
|
+
try {
|
|
28
|
+
for (var _c = (e_2 = void 0, __values(Object.keys(mergee))), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
29
|
+
var key = _d.value;
|
|
30
|
+
if (Object.prototype.hasOwnProperty.call(result, key)
|
|
31
|
+
&& Object.getOwnPropertyDescriptor(result, key).writable
|
|
32
|
+
&& isPlainObject(result[key])) {
|
|
33
|
+
result[key] = mergePropertiesDeep(result[key], mergee[key]);
|
|
34
|
+
}
|
|
35
|
+
else if (isPlainObject(mergee[key])) {
|
|
36
|
+
result[key] = mergePropertiesDeep({}, mergee[key]);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
copyProperty(key, mergee, result);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
44
|
+
finally {
|
|
45
|
+
try {
|
|
46
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
47
|
+
}
|
|
48
|
+
finally { if (e_2) throw e_2.error; }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
53
|
+
finally {
|
|
54
|
+
try {
|
|
55
|
+
if (objectsToMerge_1_1 && !objectsToMerge_1_1.done && (_a = objectsToMerge_1.return)) _a.call(objectsToMerge_1);
|
|
56
|
+
}
|
|
57
|
+
finally { if (e_1) throw e_1.error; }
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=merge-properties-deep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-properties-deep.js","sourceRoot":"","sources":["../../../src/object/merge-properties-deep.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,aAAa,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,mBAAmB;;IAAC,wBAAwB;SAAxB,UAAwB,EAAxB,qBAAwB,EAAxB,IAAwB;QAAxB,mCAAwB;;IAC1D,IAAM,MAAM,GAAG,EAAE,CAAC;;QAClB,KAAqB,IAAA,mBAAA,SAAA,cAAc,CAAA,8CAAA,0EAAE;YAAhC,IAAM,MAAM,2BAAA;;gBACf,KAAkB,IAAA,oBAAA,SAAA,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,CAAA,gBAAA,4BAAE;oBAAlC,IAAM,GAAG,WAAA;oBACZ,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC;2BACxC,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,QAAQ;2BACrD,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EACrC;wBACA,MAAM,CAAC,GAAG,CAAC,GAAG,mBAAmB,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;qBAC7D;yBAAM,IAAI,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;wBACrC,MAAM,CAAC,GAAG,CAAC,GAAG,mBAAmB,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;qBACpD;yBAAM;wBACL,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;qBACnC;iBACF;;;;;;;;;SACF;;;;;;;;;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { mergePropertiesDeep } from "./merge-properties-deep";
|
|
2
|
+
describe("mergePropertiesDeep", function () {
|
|
3
|
+
test("recursively merges properties using copyProperty()", function () {
|
|
4
|
+
var objectA = {
|
|
5
|
+
a: 1,
|
|
6
|
+
b: { n: 2 },
|
|
7
|
+
};
|
|
8
|
+
var objectB = {
|
|
9
|
+
a: 4,
|
|
10
|
+
b: {
|
|
11
|
+
get nn() {
|
|
12
|
+
return this.n * this.n;
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
c: 3,
|
|
16
|
+
};
|
|
17
|
+
var result = mergePropertiesDeep(objectA, objectB);
|
|
18
|
+
expect(result.a).toBe(4);
|
|
19
|
+
expect(result.b.n).toBe(2);
|
|
20
|
+
expect(result.b.nn).toBe(4);
|
|
21
|
+
expect(result.c).toBe(3);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=merge-properties-deep.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-properties-deep.spec.js","sourceRoot":"","sources":["../../../src/object/merge-properties-deep.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,QAAQ,CAAC,qBAAqB,EAAE;IAC9B,IAAI,CAAC,oDAAoD,EAAE;QACzD,IAAM,OAAO,GAAG;YACd,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE;SACZ,CAAC;QACF,IAAM,OAAO,GAAG;YACd,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE;gBACD,IAAI,EAAE;oBACJ,OAAO,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;gBACzB,CAAC;aACF;YACD,CAAC,EAAE,CAAC;SACL,CAAC;QACF,IAAM,MAAM,GAAG,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAErD,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC5B,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function omit(obj: any, ...keys: PropertyKey[]): {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __values = (this && this.__values) || function(o) {
|
|
2
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
3
|
+
if (m) return m.call(o);
|
|
4
|
+
if (o && typeof o.length === "number") return {
|
|
5
|
+
next: function () {
|
|
6
|
+
if (o && i >= o.length) o = void 0;
|
|
7
|
+
return { value: o && o[i++], done: !o };
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
|
+
};
|
|
12
|
+
/*
|
|
13
|
+
* Return a copy of `obj` without the key `key`
|
|
14
|
+
*/
|
|
15
|
+
export function omit(obj) {
|
|
16
|
+
var e_1, _a;
|
|
17
|
+
var keys = [];
|
|
18
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
19
|
+
keys[_i - 1] = arguments[_i];
|
|
20
|
+
}
|
|
21
|
+
var keySet = new Set(keys);
|
|
22
|
+
var result = {};
|
|
23
|
+
try {
|
|
24
|
+
for (var _b = __values(Object.keys(obj)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
25
|
+
var k = _c.value;
|
|
26
|
+
if (!keySet.has(k)) {
|
|
27
|
+
result[k] = obj[k];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
32
|
+
finally {
|
|
33
|
+
try {
|
|
34
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
35
|
+
}
|
|
36
|
+
finally { if (e_1) throw e_1.error; }
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=omit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omit.js","sourceRoot":"","sources":["../../../src/object/omit.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA;;GAEG;AACH,MAAM,UAAU,IAAI,CAAC,GAAG;;IAAE,cAAsB;SAAtB,UAAsB,EAAtB,qBAAsB,EAAtB,IAAsB;QAAtB,6BAAsB;;IAC9C,IAAM,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAM,MAAM,GAAG,EAAE,CAAC;;QAClB,KAAgB,IAAA,KAAA,SAAA,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA,gBAAA,4BAAE;YAA7B,IAAM,CAAC,WAAA;YACV,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;gBAClB,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;aACpB;SACF;;;;;;;;;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { omit } from "./omit";
|
|
2
|
+
describe("omit", function () {
|
|
3
|
+
test("should return a copy of the object with the specified keys omitted", function () {
|
|
4
|
+
var obj = { a: "a", b: "b", c: "c" };
|
|
5
|
+
expect(omit(obj, "a", "c")).toEqual({ b: "b" });
|
|
6
|
+
// Check that it was a copy and original is not mutated
|
|
7
|
+
expect(obj).toEqual({ a: "a", b: "b", c: "c" });
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=omit.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omit.spec.js","sourceRoot":"","sources":["../../../src/object/omit.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,QAAQ,CAAC,MAAM,EAAE;IACf,IAAI,CAAC,oEAAoE,EAAE;QACzE,IAAM,GAAG,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;QACvC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAChD,uDAAuD;QACvD,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __values = (this && this.__values) || function(o) {
|
|
2
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
3
|
+
if (m) return m.call(o);
|
|
4
|
+
if (o && typeof o.length === "number") return {
|
|
5
|
+
next: function () {
|
|
6
|
+
if (o && i >= o.length) o = void 0;
|
|
7
|
+
return { value: o && o[i++], done: !o };
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
|
+
};
|
|
12
|
+
import * as isEmptyImport from "lodash.isempty";
|
|
13
|
+
import { crumblePath } from "./crumble-path";
|
|
14
|
+
var isEmpty = isEmptyImport.default || isEmptyImport;
|
|
15
|
+
/** Set the value at `path` on `object`. */
|
|
16
|
+
export function setPath(object, path, newValue) {
|
|
17
|
+
var e_1, _a;
|
|
18
|
+
if (typeof object !== "object") {
|
|
19
|
+
throw new Error("object is required");
|
|
20
|
+
}
|
|
21
|
+
if (isEmpty(path)) {
|
|
22
|
+
throw new Error("path is required");
|
|
23
|
+
}
|
|
24
|
+
var crumbs = crumblePath(path);
|
|
25
|
+
var finalCrumb = crumbs.splice(crumbs.length - 1, 1)[0];
|
|
26
|
+
var current = object;
|
|
27
|
+
try {
|
|
28
|
+
for (var crumbs_1 = __values(crumbs), crumbs_1_1 = crumbs_1.next(); !crumbs_1_1.done; crumbs_1_1 = crumbs_1.next()) {
|
|
29
|
+
var crumb = crumbs_1_1.value;
|
|
30
|
+
current = current[crumb];
|
|
31
|
+
if (typeof current !== "object") {
|
|
32
|
+
throw new Error("Cannot set value at given path: Path deadends at " + String(crumb));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
37
|
+
finally {
|
|
38
|
+
try {
|
|
39
|
+
if (crumbs_1_1 && !crumbs_1_1.done && (_a = crumbs_1.return)) _a.call(crumbs_1);
|
|
40
|
+
}
|
|
41
|
+
finally { if (e_1) throw e_1.error; }
|
|
42
|
+
}
|
|
43
|
+
current[finalCrumb] = newValue;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=set-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-path.js","sourceRoot":"","sources":["../../../src/object/set-path.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,aAAa,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,IAAM,OAAO,GAAI,aAAqB,CAAC,OAAO,IAAI,aAAa,CAAC;AAEhE,2CAA2C;AAC3C,MAAM,UAAU,OAAO,CAAC,MAAW,EAAE,IAAiC,EAAE,QAAa;;IACnF,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;KACvC;IAED,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;KACrC;IAED,IAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACjC,IAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1D,IAAI,OAAO,GAAG,MAAM,CAAC;;QACrB,KAAoB,IAAA,WAAA,SAAA,MAAM,CAAA,8BAAA,kDAAE;YAAvB,IAAM,KAAK,mBAAA;YACd,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;gBAC/B,MAAM,IAAI,KAAK,CAAC,sDAAoD,MAAM,CAAC,KAAK,CAAG,CAAC,CAAC;aACtF;SACF;;;;;;;;;IAED,OAAO,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { setPath } from "./set-path";
|
|
2
|
+
describe("setPath", function () {
|
|
3
|
+
test("sets the value at the given path", function () {
|
|
4
|
+
var obj = {
|
|
5
|
+
a: { b: { c: false } },
|
|
6
|
+
};
|
|
7
|
+
setPath(obj, "a.b.c", true);
|
|
8
|
+
expect(obj.a.b.c).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
test("sets the value at the given path when an array is involved", function () {
|
|
11
|
+
var obj = {
|
|
12
|
+
a: {
|
|
13
|
+
b: {
|
|
14
|
+
c: [2,
|
|
15
|
+
4,
|
|
16
|
+
5],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
setPath(obj, "a.b.c[2]", 6);
|
|
21
|
+
expect(obj.a.b.c[2]).toBe(6);
|
|
22
|
+
});
|
|
23
|
+
test("errors if object isn't provided", function () {
|
|
24
|
+
expect(function () { return setPath(undefined, "foo", "bar"); }).toThrow();
|
|
25
|
+
});
|
|
26
|
+
test("errors if path isn't provided", function () {
|
|
27
|
+
expect(function () { return setPath({}, undefined, "bar"); }).toThrow();
|
|
28
|
+
});
|
|
29
|
+
test("errors if path deadends", function () {
|
|
30
|
+
var obj = {
|
|
31
|
+
a: {},
|
|
32
|
+
};
|
|
33
|
+
expect(function () { return setPath(obj, "a.b.c", true); }).toThrow();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=set-path.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-path.spec.js","sourceRoot":"","sources":["../../../src/object/set-path.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,QAAQ,CAAC,SAAS,EAAE;IAClB,IAAI,CAAC,kCAAkC,EAAE;QACvC,IAAM,GAAG,GAAG;YACV,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE;SACvB,CAAC;QACF,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAC5B,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,4DAA4D,EAAE;QACjE,IAAM,GAAG,GAAG;YACV,CAAC,EAAE;gBACD,CAAC,EAAE;oBACD,CAAC,EAAE,CAAC,CAAC;wBACH,CAAC;wBACD,CAAC,CAAC;iBACL;aACF;SACF,CAAC;QACF,OAAO,CAAC,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;QAC5B,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,iCAAiC,EAAE;QACtC,MAAM,CAAC,cAAM,OAAA,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,EAAhC,CAAgC,CAAC,CAAC,OAAO,EAAE,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,+BAA+B,EAAE;QACpC,MAAM,CAAC,cAAM,OAAA,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,EAA7B,CAA6B,CAAC,CAAC,OAAO,EAAE,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yBAAyB,EAAE;QAC9B,IAAM,GAAG,GAAG;YACV,CAAC,EAAE,EAAE;SACN,CAAC;QAEF,MAAM,CAAC,cAAM,OAAA,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,EAA3B,CAA2B,CAAC,CAAC,OAAO,EAAE,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
2
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
3
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
4
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
5
|
+
function step(op) {
|
|
6
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
7
|
+
while (_) try {
|
|
8
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
9
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
10
|
+
switch (op[0]) {
|
|
11
|
+
case 0: case 1: t = op; break;
|
|
12
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
13
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
14
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
15
|
+
default:
|
|
16
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
17
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
18
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
19
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
20
|
+
if (t[2]) _.ops.pop();
|
|
21
|
+
_.trys.pop(); continue;
|
|
22
|
+
}
|
|
23
|
+
op = body.call(thisArg, _);
|
|
24
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
25
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var __values = (this && this.__values) || function(o) {
|
|
29
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
30
|
+
if (m) return m.call(o);
|
|
31
|
+
if (o && typeof o.length === "number") return {
|
|
32
|
+
next: function () {
|
|
33
|
+
if (o && i >= o.length) o = void 0;
|
|
34
|
+
return { value: o && o[i++], done: !o };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
38
|
+
};
|
|
39
|
+
import { crumblePath } from "./crumble-path";
|
|
40
|
+
/** Generator for iterating down a path on an object. */
|
|
41
|
+
export function traversePath(object, path) {
|
|
42
|
+
var obj, _a, _b, crumb, e_1_1;
|
|
43
|
+
var e_1, _c;
|
|
44
|
+
return __generator(this, function (_d) {
|
|
45
|
+
switch (_d.label) {
|
|
46
|
+
case 0: return [4 /*yield*/, object];
|
|
47
|
+
case 1:
|
|
48
|
+
_d.sent();
|
|
49
|
+
obj = object;
|
|
50
|
+
_d.label = 2;
|
|
51
|
+
case 2:
|
|
52
|
+
_d.trys.push([2, 7, 8, 9]);
|
|
53
|
+
_a = __values(crumblePath(path)), _b = _a.next();
|
|
54
|
+
_d.label = 3;
|
|
55
|
+
case 3:
|
|
56
|
+
if (!!_b.done) return [3 /*break*/, 6];
|
|
57
|
+
crumb = _b.value;
|
|
58
|
+
obj = obj[crumb];
|
|
59
|
+
return [4 /*yield*/, obj];
|
|
60
|
+
case 4:
|
|
61
|
+
_d.sent();
|
|
62
|
+
_d.label = 5;
|
|
63
|
+
case 5:
|
|
64
|
+
_b = _a.next();
|
|
65
|
+
return [3 /*break*/, 3];
|
|
66
|
+
case 6: return [3 /*break*/, 9];
|
|
67
|
+
case 7:
|
|
68
|
+
e_1_1 = _d.sent();
|
|
69
|
+
e_1 = { error: e_1_1 };
|
|
70
|
+
return [3 /*break*/, 9];
|
|
71
|
+
case 8:
|
|
72
|
+
try {
|
|
73
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
74
|
+
}
|
|
75
|
+
finally { if (e_1) throw e_1.error; }
|
|
76
|
+
return [7 /*endfinally*/];
|
|
77
|
+
case 9: return [2 /*return*/];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=traverse-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traverse-path.js","sourceRoot":"","sources":["../../../src/object/traverse-path.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,wDAAwD;AACxD,MAAM,UAAW,YAAY,CAAC,MAAM,EAAE,IAAI;;;;;oBACxC,qBAAM,MAAM,EAAA;;gBAAZ,SAAY,CAAC;gBACT,GAAG,GAAG,MAAM,CAAC;;;;gBACG,KAAA,SAAA,WAAW,CAAC,IAAI,CAAC,CAAA;;;;gBAA1B,KAAK;gBACd,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;gBACjB,qBAAM,GAAG,EAAA;;gBAAT,SAAS,CAAC;;;;;;;;;;;;;;;;;;;CAEb"}
|