@telperion/js-utils 3.5.0
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/LICENSE +21 -0
- package/README.md +621 -0
- package/array/arrayize.cjs +22 -0
- package/array/arrayize.d.ts +17 -0
- package/array/arrayize.js +21 -0
- package/array/arrayize.js.map +1 -0
- package/array/async-map.cjs +40 -0
- package/array/async-map.d.ts +34 -0
- package/array/async-map.js +39 -0
- package/array/async-map.js.map +1 -0
- package/array/compact.cjs +34 -0
- package/array/compact.d.ts +28 -0
- package/array/compact.js +33 -0
- package/array/compact.js.map +1 -0
- package/array/difference.cjs +16 -0
- package/array/difference.d.ts +45 -0
- package/array/difference.js +15 -0
- package/array/difference.js.map +1 -0
- package/array/find-by-key.cjs +35 -0
- package/array/find-by-key.d.ts +30 -0
- package/array/find-by-key.js +34 -0
- package/array/find-by-key.js.map +1 -0
- package/array/index.cjs +14 -0
- package/array/index.d.ts +11 -0
- package/array/index.js +13 -0
- package/array/index.js.map +1 -0
- package/array/intersection.cjs +16 -0
- package/array/intersection.d.ts +45 -0
- package/array/intersection.js +15 -0
- package/array/intersection.js.map +1 -0
- package/array/limit.cjs +37 -0
- package/array/limit.d.ts +29 -0
- package/array/limit.js +36 -0
- package/array/limit.js.map +1 -0
- package/array/proto/async-map.cjs +6 -0
- package/array/proto/async-map.d.ts +25 -0
- package/array/proto/async-map.js +6 -0
- package/array/proto/async-map.js.map +1 -0
- package/array/proto/compact.cjs +6 -0
- package/array/proto/compact.d.ts +15 -0
- package/array/proto/compact.js +6 -0
- package/array/proto/compact.js.map +1 -0
- package/array/proto/difference.cjs +6 -0
- package/array/proto/difference.d.ts +27 -0
- package/array/proto/difference.js +6 -0
- package/array/proto/difference.js.map +1 -0
- package/array/proto/find-by-key.cjs +6 -0
- package/array/proto/find-by-key.d.ts +25 -0
- package/array/proto/find-by-key.js +6 -0
- package/array/proto/find-by-key.js.map +1 -0
- package/array/proto/intersection.cjs +6 -0
- package/array/proto/intersection.d.ts +27 -0
- package/array/proto/intersection.js +6 -0
- package/array/proto/intersection.js.map +1 -0
- package/array/proto/limit.cjs +6 -0
- package/array/proto/limit.d.ts +24 -0
- package/array/proto/limit.js +6 -0
- package/array/proto/limit.js.map +1 -0
- package/array/proto/remove.cjs +6 -0
- package/array/proto/remove.d.ts +32 -0
- package/array/proto/remove.js +6 -0
- package/array/proto/remove.js.map +1 -0
- package/array/proto/replace.cjs +6 -0
- package/array/proto/replace.d.ts +72 -0
- package/array/proto/replace.js +6 -0
- package/array/proto/replace.js.map +1 -0
- package/array/proto/uniquify-by-key.cjs +6 -0
- package/array/proto/uniquify-by-key.d.ts +24 -0
- package/array/proto/uniquify-by-key.js +6 -0
- package/array/proto/uniquify-by-key.js.map +1 -0
- package/array/proto/uniquify.cjs +6 -0
- package/array/proto/uniquify.d.ts +23 -0
- package/array/proto/uniquify.js +6 -0
- package/array/proto/uniquify.js.map +1 -0
- package/array/remove.cjs +46 -0
- package/array/remove.d.ts +33 -0
- package/array/remove.js +45 -0
- package/array/remove.js.map +1 -0
- package/array/replace.cjs +69 -0
- package/array/replace.d.ts +139 -0
- package/array/replace.js +68 -0
- package/array/replace.js.map +1 -0
- package/array/static/arrayize.cjs +4 -0
- package/array/static/arrayize.d.ts +6 -0
- package/array/static/arrayize.js +4 -0
- package/array/static/arrayize.js.map +1 -0
- package/array/uniquify-by-key.cjs +41 -0
- package/array/uniquify-by-key.d.ts +29 -0
- package/array/uniquify-by-key.js +40 -0
- package/array/uniquify-by-key.js.map +1 -0
- package/array/uniquify.cjs +32 -0
- package/array/uniquify.d.ts +27 -0
- package/array/uniquify.js +31 -0
- package/array/uniquify.js.map +1 -0
- package/boolean/static/is-falsy.cjs +4 -0
- package/boolean/static/is-falsy.d.ts +23 -0
- package/boolean/static/is-falsy.js +4 -0
- package/boolean/static/is-falsy.js.map +1 -0
- package/boolean/static/is-truthy.cjs +4 -0
- package/boolean/static/is-truthy.d.ts +23 -0
- package/boolean/static/is-truthy.js +4 -0
- package/boolean/static/is-truthy.js.map +1 -0
- package/class/index.cjs +4 -0
- package/class/index.d.ts +1 -0
- package/class/index.js +3 -0
- package/class/index.js.map +1 -0
- package/class/mixin.cjs +60 -0
- package/class/mixin.d.ts +50 -0
- package/class/mixin.js +59 -0
- package/class/mixin.js.map +1 -0
- package/compact.cjs +39 -0
- package/compact.d.ts +2 -0
- package/compact.js +38 -0
- package/compact.js.map +1 -0
- package/function/call.cjs +6 -0
- package/function/call.d.ts +1 -0
- package/function/call.js +5 -0
- package/function/call.js.map +1 -0
- package/function/debounce.cjs +85 -0
- package/function/debounce.d.ts +44 -0
- package/function/debounce.js +82 -0
- package/function/debounce.js.map +1 -0
- package/function/defer.cjs +42 -0
- package/function/defer.d.ts +26 -0
- package/function/defer.js +41 -0
- package/function/defer.js.map +1 -0
- package/function/index.cjs +8 -0
- package/function/index.d.ts +5 -0
- package/function/index.js +7 -0
- package/function/index.js.map +1 -0
- package/function/noop.cjs +23 -0
- package/function/noop.d.ts +20 -0
- package/function/noop.js +22 -0
- package/function/noop.js.map +1 -0
- package/function/of.cjs +44 -0
- package/function/of.d.ts +31 -0
- package/function/of.js +43 -0
- package/function/of.js.map +1 -0
- package/function/proto/debounce.cjs +6 -0
- package/function/proto/debounce.d.ts +30 -0
- package/function/proto/debounce.js +6 -0
- package/function/proto/debounce.js.map +1 -0
- package/function/static/call.cjs +4 -0
- package/function/static/call.d.ts +6 -0
- package/function/static/call.js +4 -0
- package/function/static/call.js.map +1 -0
- package/function/static/defer.cjs +4 -0
- package/function/static/defer.d.ts +23 -0
- package/function/static/defer.js +4 -0
- package/function/static/defer.js.map +1 -0
- package/function/static/noop.cjs +4 -0
- package/function/static/noop.d.ts +18 -0
- package/function/static/noop.js +4 -0
- package/function/static/noop.js.map +1 -0
- package/function/static/of.cjs +4 -0
- package/function/static/of.d.ts +26 -0
- package/function/static/of.js +4 -0
- package/function/static/of.js.map +1 -0
- package/index.cjs +31 -0
- package/index.d.ts +14 -0
- package/index.js +17 -0
- package/index.js.map +1 -0
- package/is-falsy.cjs +33 -0
- package/is-falsy.d.ts +28 -0
- package/is-falsy.js +32 -0
- package/is-falsy.js.map +1 -0
- package/is-truthy.cjs +33 -0
- package/is-truthy.d.ts +28 -0
- package/is-truthy.js +32 -0
- package/is-truthy.js.map +1 -0
- package/limit.cjs +34 -0
- package/limit.d.ts +2 -0
- package/limit.js +33 -0
- package/limit.js.map +1 -0
- package/map/index.cjs +4 -0
- package/map/index.d.ts +1 -0
- package/map/index.js +3 -0
- package/map/index.js.map +1 -0
- package/map/merge.cjs +33 -0
- package/map/merge.d.ts +24 -0
- package/map/merge.js +32 -0
- package/map/merge.js.map +1 -0
- package/math/index.cjs +4 -0
- package/math/index.d.ts +1 -0
- package/math/index.js +3 -0
- package/math/index.js.map +1 -0
- package/math/min-max.cjs +29 -0
- package/math/min-max.d.ts +24 -0
- package/math/min-max.js +28 -0
- package/math/min-max.js.map +1 -0
- package/math/static/min-max.cjs +4 -0
- package/math/static/min-max.d.ts +20 -0
- package/math/static/min-max.js +4 -0
- package/math/static/min-max.js.map +1 -0
- package/object/clone.cjs +157 -0
- package/object/clone.d.ts +161 -0
- package/object/clone.js +156 -0
- package/object/clone.js.map +1 -0
- package/object/compact.cjs +49 -0
- package/object/compact.d.ts +37 -0
- package/object/compact.js +48 -0
- package/object/compact.js.map +1 -0
- package/object/deep-freeze.cjs +16 -0
- package/object/deep-freeze.d.ts +1 -0
- package/object/deep-freeze.js +15 -0
- package/object/deep-freeze.js.map +1 -0
- package/object/deepest.cjs +55 -0
- package/object/deepest.d.ts +47 -0
- package/object/deepest.js +54 -0
- package/object/deepest.js.map +1 -0
- package/object/index.cjs +7 -0
- package/object/index.d.ts +4 -0
- package/object/index.js +6 -0
- package/object/index.js.map +1 -0
- package/object/static/clone.cjs +4 -0
- package/object/static/clone.d.ts +43 -0
- package/object/static/clone.js +4 -0
- package/object/static/clone.js.map +1 -0
- package/object/static/compact.cjs +4 -0
- package/object/static/compact.d.ts +26 -0
- package/object/static/compact.js +4 -0
- package/object/static/compact.js.map +1 -0
- package/object/static/deep-freeze.cjs +4 -0
- package/object/static/deep-freeze.d.ts +6 -0
- package/object/static/deep-freeze.js +4 -0
- package/object/static/deep-freeze.js.map +1 -0
- package/object/static/deepest.cjs +4 -0
- package/object/static/deepest.d.ts +32 -0
- package/object/static/deepest.js +4 -0
- package/object/static/deepest.js.map +1 -0
- package/open-promise.cjs +115 -0
- package/open-promise.d.ts +80 -0
- package/open-promise.js +113 -0
- package/open-promise.js.map +1 -0
- package/package.json +667 -0
- package/promise/chain.cjs +12 -0
- package/promise/chain.d.ts +7 -0
- package/promise/chain.js +11 -0
- package/promise/chain.js.map +1 -0
- package/promise/index.cjs +10 -0
- package/promise/index.d.ts +7 -0
- package/promise/index.js +9 -0
- package/promise/index.js.map +1 -0
- package/promise/never.cjs +41 -0
- package/promise/never.d.ts +34 -0
- package/promise/never.js +39 -0
- package/promise/never.js.map +1 -0
- package/promise/promisify.cjs +12 -0
- package/promise/promisify.d.ts +7 -0
- package/promise/promisify.js +11 -0
- package/promise/promisify.js.map +1 -0
- package/promise/proto/revert.cjs +6 -0
- package/promise/proto/revert.d.ts +29 -0
- package/promise/proto/revert.js +6 -0
- package/promise/proto/revert.js.map +1 -0
- package/promise/proto/try-catch.cjs +7 -0
- package/promise/proto/try-catch.d.ts +30 -0
- package/promise/proto/try-catch.js +7 -0
- package/promise/proto/try-catch.js.map +1 -0
- package/promise/revert.cjs +43 -0
- package/promise/revert.d.ts +38 -0
- package/promise/revert.js +42 -0
- package/promise/revert.js.map +1 -0
- package/promise/static/chain.cjs +4 -0
- package/promise/static/chain.d.ts +10 -0
- package/promise/static/chain.js +4 -0
- package/promise/static/chain.js.map +1 -0
- package/promise/static/never.cjs +5 -0
- package/promise/static/never.d.ts +39 -0
- package/promise/static/never.js +5 -0
- package/promise/static/never.js.map +1 -0
- package/promise/static/timeout.cjs +4 -0
- package/promise/static/timeout.d.ts +21 -0
- package/promise/static/timeout.js +4 -0
- package/promise/static/timeout.js.map +1 -0
- package/promise/static/try-one-by-one.cjs +4 -0
- package/promise/static/try-one-by-one.d.ts +27 -0
- package/promise/static/try-one-by-one.js +4 -0
- package/promise/static/try-one-by-one.js.map +1 -0
- package/promise/timeout.cjs +104 -0
- package/promise/timeout.d.ts +109 -0
- package/promise/timeout.js +103 -0
- package/promise/timeout.js.map +1 -0
- package/promise/try-catch.cjs +12 -0
- package/promise/try-catch.d.ts +45 -0
- package/promise/try-catch.js +11 -0
- package/promise/try-catch.js.map +1 -0
- package/promise/try-one-by-one.cjs +59 -0
- package/promise/try-one-by-one.d.ts +42 -0
- package/promise/try-one-by-one.js +58 -0
- package/promise/try-one-by-one.js.map +1 -0
- package/set/proto/difference.cjs +6 -0
- package/set/proto/difference.d.ts +26 -0
- package/set/proto/difference.js +6 -0
- package/set/proto/difference.js.map +1 -0
- package/set/proto/intersection.cjs +6 -0
- package/set/proto/intersection.d.ts +26 -0
- package/set/proto/intersection.js +6 -0
- package/set/proto/intersection.js.map +1 -0
- package/smart-map.cjs +108 -0
- package/smart-map.d.ts +81 -0
- package/smart-map.js +106 -0
- package/smart-map.js.map +1 -0
- package/string/index.cjs +4 -0
- package/string/index.d.ts +1 -0
- package/string/index.js +3 -0
- package/string/index.js.map +1 -0
- package/string/limit.cjs +35 -0
- package/string/limit.d.ts +29 -0
- package/string/limit.js +34 -0
- package/string/limit.js.map +1 -0
- package/string/proto/limit.cjs +6 -0
- package/string/proto/limit.d.ts +30 -0
- package/string/proto/limit.js +6 -0
- package/string/proto/limit.js.map +1 -0
- package/time/days.cjs +21 -0
- package/time/days.d.ts +15 -0
- package/time/days.js +20 -0
- package/time/days.js.map +1 -0
- package/time/hours.cjs +21 -0
- package/time/hours.d.ts +15 -0
- package/time/hours.js +20 -0
- package/time/hours.js.map +1 -0
- package/time/index.cjs +10 -0
- package/time/index.d.ts +7 -0
- package/time/index.js +9 -0
- package/time/index.js.map +1 -0
- package/time/minutes.cjs +21 -0
- package/time/minutes.d.ts +15 -0
- package/time/minutes.js +20 -0
- package/time/minutes.js.map +1 -0
- package/time/months.cjs +21 -0
- package/time/months.d.ts +15 -0
- package/time/months.js +20 -0
- package/time/months.js.map +1 -0
- package/time/seconds.cjs +20 -0
- package/time/seconds.d.ts +15 -0
- package/time/seconds.js +19 -0
- package/time/seconds.js.map +1 -0
- package/time/weeks.cjs +21 -0
- package/time/weeks.d.ts +15 -0
- package/time/weeks.js +20 -0
- package/time/weeks.js.map +1 -0
- package/time/years.cjs +21 -0
- package/time/years.d.ts +15 -0
- package/time/years.js +20 -0
- package/time/years.js.map +1 -0
- package/unique-id.cjs +24 -0
- package/unique-id.d.ts +21 -0
- package/unique-id.js +23 -0
- package/unique-id.js.map +1 -0
package/is-falsy.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Returns whether the entered value is falsy
|
|
3
|
+
*
|
|
4
|
+
* * * *
|
|
5
|
+
* Example usage:
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { isFalsy } from "@telperion/js-utils";
|
|
8
|
+
*
|
|
9
|
+
* isFalsy(undefined); // true
|
|
10
|
+
* isFalsy(true); // false
|
|
11
|
+
* isFalsy([]) // false
|
|
12
|
+
*
|
|
13
|
+
* const falsyValues = ["a", undefined, "b", "", "c"].filter(isFalsy); // [undefined, ""]
|
|
14
|
+
* ```
|
|
15
|
+
* Static usage example:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import "@telperion/js-utils/dist/as-static/is-falsy";
|
|
18
|
+
*
|
|
19
|
+
* Boolean.isFalsy(undefined); // true
|
|
20
|
+
* Boolean.isFalsy(true); // false
|
|
21
|
+
* Boolean.isFalsy([]) // false
|
|
22
|
+
*
|
|
23
|
+
* const falsyValues = ["a", undefined, "b", "", "c"].filter(Boolean.isFalsy); // [undefined, ""]
|
|
24
|
+
* ```
|
|
25
|
+
* * * *
|
|
26
|
+
* @param value value to be checked
|
|
27
|
+
*/
|
|
28
|
+
export function isFalsy(value) {
|
|
29
|
+
return !value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=is-falsy.js.map
|
package/is-falsy.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/is-falsy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,OAAO,CAAC,KAAU;IAChC,OAAO,CAAC,KAAK,CAAC;AAChB,CAAC","file":"is-falsy.js","sourcesContent":["/**\n * #### Returns whether the entered value is falsy\n *\n * * * *\n * Example usage:\n * ```typescript\n * import { isFalsy } from \"@telperion/js-utils\";\n *\n * isFalsy(undefined); // true\n * isFalsy(true); // false\n * isFalsy([]) // false\n *\n * const falsyValues = [\"a\", undefined, \"b\", \"\", \"c\"].filter(isFalsy); // [undefined, \"\"]\n * ```\n * Static usage example:\n * ```typescript\n * import \"@telperion/js-utils/dist/as-static/is-falsy\";\n *\n * Boolean.isFalsy(undefined); // true\n * Boolean.isFalsy(true); // false\n * Boolean.isFalsy([]) // false\n *\n * const falsyValues = [\"a\", undefined, \"b\", \"\", \"c\"].filter(Boolean.isFalsy); // [undefined, \"\"]\n * ```\n * * * *\n * @param value value to be checked\n */\nexport function isFalsy(value: any): boolean {\n return !value;\n}\n"]}
|
package/is-truthy.cjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTruthy = isTruthy;
|
|
4
|
+
/**
|
|
5
|
+
* #### Returns whether the entered value is truthy
|
|
6
|
+
*
|
|
7
|
+
* * * *
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { isTruthy } from "@telperion/js-utils";
|
|
11
|
+
*
|
|
12
|
+
* isTruthy(undefined); // false
|
|
13
|
+
* isTruthy(true); // true
|
|
14
|
+
* isTruthy([]) // true
|
|
15
|
+
*
|
|
16
|
+
* const truthyValues = ["a", undefined, "b", "", "c"].filter(isTruthy); // ["a", "b", "c"]
|
|
17
|
+
* ```
|
|
18
|
+
* Static usage example:
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import "@telperion/js-utils/dist/as-static/is-truthy";
|
|
21
|
+
*
|
|
22
|
+
* Boolean.isTruthy(undefined); // false
|
|
23
|
+
* Boolean.isTruthy(true); // true
|
|
24
|
+
* Boolean.isTruthy([]) // true
|
|
25
|
+
*
|
|
26
|
+
* const truthyValues = ["a", undefined, "b", "", "c"].filter(Boolean.isTruthy); // ["a", "b", "c"]
|
|
27
|
+
* ```
|
|
28
|
+
* * * *
|
|
29
|
+
* @param value value to be checked
|
|
30
|
+
*/
|
|
31
|
+
function isTruthy(value) {
|
|
32
|
+
return !!value;
|
|
33
|
+
}
|
package/is-truthy.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Returns whether the entered value is truthy
|
|
3
|
+
*
|
|
4
|
+
* * * *
|
|
5
|
+
* Example usage:
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { isTruthy } from "@telperion/js-utils";
|
|
8
|
+
*
|
|
9
|
+
* isTruthy(undefined); // false
|
|
10
|
+
* isTruthy(true); // true
|
|
11
|
+
* isTruthy([]) // true
|
|
12
|
+
*
|
|
13
|
+
* const truthyValues = ["a", undefined, "b", "", "c"].filter(isTruthy); // ["a", "b", "c"]
|
|
14
|
+
* ```
|
|
15
|
+
* Static usage example:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import "@telperion/js-utils/dist/as-static/is-truthy";
|
|
18
|
+
*
|
|
19
|
+
* Boolean.isTruthy(undefined); // false
|
|
20
|
+
* Boolean.isTruthy(true); // true
|
|
21
|
+
* Boolean.isTruthy([]) // true
|
|
22
|
+
*
|
|
23
|
+
* const truthyValues = ["a", undefined, "b", "", "c"].filter(Boolean.isTruthy); // ["a", "b", "c"]
|
|
24
|
+
* ```
|
|
25
|
+
* * * *
|
|
26
|
+
* @param value value to be checked
|
|
27
|
+
*/
|
|
28
|
+
export declare function isTruthy(value: any): boolean;
|
package/is-truthy.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Returns whether the entered value is truthy
|
|
3
|
+
*
|
|
4
|
+
* * * *
|
|
5
|
+
* Example usage:
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { isTruthy } from "@telperion/js-utils";
|
|
8
|
+
*
|
|
9
|
+
* isTruthy(undefined); // false
|
|
10
|
+
* isTruthy(true); // true
|
|
11
|
+
* isTruthy([]) // true
|
|
12
|
+
*
|
|
13
|
+
* const truthyValues = ["a", undefined, "b", "", "c"].filter(isTruthy); // ["a", "b", "c"]
|
|
14
|
+
* ```
|
|
15
|
+
* Static usage example:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import "@telperion/js-utils/dist/as-static/is-truthy";
|
|
18
|
+
*
|
|
19
|
+
* Boolean.isTruthy(undefined); // false
|
|
20
|
+
* Boolean.isTruthy(true); // true
|
|
21
|
+
* Boolean.isTruthy([]) // true
|
|
22
|
+
*
|
|
23
|
+
* const truthyValues = ["a", undefined, "b", "", "c"].filter(Boolean.isTruthy); // ["a", "b", "c"]
|
|
24
|
+
* ```
|
|
25
|
+
* * * *
|
|
26
|
+
* @param value value to be checked
|
|
27
|
+
*/
|
|
28
|
+
export function isTruthy(value) {
|
|
29
|
+
return !!value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=is-truthy.js.map
|
package/is-truthy.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/is-truthy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAU;IACjC,OAAO,CAAC,CAAC,KAAK,CAAC;AACjB,CAAC","file":"is-truthy.js","sourcesContent":["/**\n * #### Returns whether the entered value is truthy\n *\n * * * *\n * Example usage:\n * ```typescript\n * import { isTruthy } from \"@telperion/js-utils\";\n *\n * isTruthy(undefined); // false\n * isTruthy(true); // true\n * isTruthy([]) // true\n *\n * const truthyValues = [\"a\", undefined, \"b\", \"\", \"c\"].filter(isTruthy); // [\"a\", \"b\", \"c\"]\n * ```\n * Static usage example:\n * ```typescript\n * import \"@telperion/js-utils/dist/as-static/is-truthy\";\n *\n * Boolean.isTruthy(undefined); // false\n * Boolean.isTruthy(true); // true\n * Boolean.isTruthy([]) // true\n *\n * const truthyValues = [\"a\", undefined, \"b\", \"\", \"c\"].filter(Boolean.isTruthy); // [\"a\", \"b\", \"c\"]\n * ```\n * * * *\n * @param value value to be checked\n */\nexport function isTruthy(value: any): boolean {\n return !!value;\n}\n"]}
|
package/limit.cjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.limit = limit;
|
|
4
|
+
const limit_1 = require("@telperion/js-utils/string/limit");
|
|
5
|
+
const limit_2 = require("@telperion/js-utils/array/limit");
|
|
6
|
+
/**
|
|
7
|
+
* #### Limit
|
|
8
|
+
*
|
|
9
|
+
* Limits the string or array to `n` character
|
|
10
|
+
*
|
|
11
|
+
* * * *
|
|
12
|
+
* Example usage:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { limit } from "@telperion/js-utils";
|
|
15
|
+
*
|
|
16
|
+
* const str = 'foobarbaz';
|
|
17
|
+
* const array = ["a", "b", "c", "d", "e", "f"];
|
|
18
|
+
*
|
|
19
|
+
* limit(str, 3); // 'foo'
|
|
20
|
+
* limit(array, 3); // ["a", "b", "c"]
|
|
21
|
+
* ```
|
|
22
|
+
* * * *
|
|
23
|
+
* @param arrayOrString value to limit
|
|
24
|
+
* @param count Max count
|
|
25
|
+
*/
|
|
26
|
+
function limit(arrayOrString, count) {
|
|
27
|
+
if (typeof arrayOrString === 'string') {
|
|
28
|
+
return (0, limit_1.limit)(arrayOrString, count);
|
|
29
|
+
}
|
|
30
|
+
if (arrayOrString instanceof Array) {
|
|
31
|
+
return (0, limit_2.limit)(arrayOrString, count);
|
|
32
|
+
}
|
|
33
|
+
throw new Error('Value is not string nor array');
|
|
34
|
+
}
|
package/limit.d.ts
ADDED
package/limit.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { limit as strLimit } from '@telperion/js-utils/string/limit';
|
|
2
|
+
import { limit as arrLimit } from '@telperion/js-utils/array/limit';
|
|
3
|
+
/**
|
|
4
|
+
* #### Limit
|
|
5
|
+
*
|
|
6
|
+
* Limits the string or array to `n` character
|
|
7
|
+
*
|
|
8
|
+
* * * *
|
|
9
|
+
* Example usage:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { limit } from "@telperion/js-utils";
|
|
12
|
+
*
|
|
13
|
+
* const str = 'foobarbaz';
|
|
14
|
+
* const array = ["a", "b", "c", "d", "e", "f"];
|
|
15
|
+
*
|
|
16
|
+
* limit(str, 3); // 'foo'
|
|
17
|
+
* limit(array, 3); // ["a", "b", "c"]
|
|
18
|
+
* ```
|
|
19
|
+
* * * *
|
|
20
|
+
* @param arrayOrString value to limit
|
|
21
|
+
* @param count Max count
|
|
22
|
+
*/
|
|
23
|
+
export function limit(arrayOrString, count) {
|
|
24
|
+
if (typeof arrayOrString === 'string') {
|
|
25
|
+
return strLimit(arrayOrString, count);
|
|
26
|
+
}
|
|
27
|
+
if (arrayOrString instanceof Array) {
|
|
28
|
+
return arrLimit(arrayOrString, count);
|
|
29
|
+
}
|
|
30
|
+
throw new Error('Value is not string nor array');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=limit.js.map
|
package/limit.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/limit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAIpE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,KAAK,CAAU,aAA2B,EAAE,KAAa;IACvE,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE,CAAC;QACtC,OAAO,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,aAAa,YAAY,KAAK,EAAE,CAAC;QACnC,OAAO,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;AACnD,CAAC","file":"limit.js","sourcesContent":["import { limit as strLimit } from '@telperion/js-utils/string/limit';\nimport { limit as arrLimit } from '@telperion/js-utils/array/limit';\n\nexport function limit<T = any>(array: T[], count: number): T[];\nexport function limit(str: string, count: number): string;\n/**\n * #### Limit\n *\n * Limits the string or array to `n` character\n *\n * * * *\n * Example usage:\n * ```typescript\n * import { limit } from \"@telperion/js-utils\";\n *\n * const str = 'foobarbaz';\n * const array = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"];\n *\n * limit(str, 3); // 'foo'\n * limit(array, 3); // [\"a\", \"b\", \"c\"]\n * ```\n * * * *\n * @param arrayOrString value to limit\n * @param count Max count\n */\nexport function limit<T = any>(arrayOrString: T[] | string, count: number): T[] | string {\n if (typeof arrayOrString === 'string') {\n return strLimit(arrayOrString, count);\n }\n\n if (arrayOrString instanceof Array) {\n return arrLimit(arrayOrString, count);\n }\n\n throw new Error('Value is not string nor array');\n}\n"]}
|
package/map/index.cjs
ADDED
package/map/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@telperion/js-utils/map/merge';
|
package/map/index.js
ADDED
package/map/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/map/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC","file":"index.js","sourcesContent":["export * from '@telperion/js-utils/map/merge';\n"]}
|
package/map/merge.cjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.merge = merge;
|
|
4
|
+
/**
|
|
5
|
+
* #### Map Merge
|
|
6
|
+
*
|
|
7
|
+
* Merges two maps
|
|
8
|
+
*
|
|
9
|
+
* * * *
|
|
10
|
+
* Example usage:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { merge } from "@telperion/js-utils/map";
|
|
13
|
+
*
|
|
14
|
+
* const first = new Map();
|
|
15
|
+
* first.set("a", 1);
|
|
16
|
+
*
|
|
17
|
+
* const second = new Map();
|
|
18
|
+
* second.set("b", 2);
|
|
19
|
+
*
|
|
20
|
+
* merge(first, second); // [{key: "a", value: 1}, {key: "b", value: 2}]
|
|
21
|
+
* ```
|
|
22
|
+
* * * *
|
|
23
|
+
* @param first First map
|
|
24
|
+
* @param second Second map
|
|
25
|
+
* @returns A new merged map
|
|
26
|
+
*/
|
|
27
|
+
function merge(first, second) {
|
|
28
|
+
const newMap = new Map(first);
|
|
29
|
+
for (const key of second.keys()) {
|
|
30
|
+
newMap.set(key, second.get(key));
|
|
31
|
+
}
|
|
32
|
+
return newMap;
|
|
33
|
+
}
|
package/map/merge.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Map Merge
|
|
3
|
+
*
|
|
4
|
+
* Merges two maps
|
|
5
|
+
*
|
|
6
|
+
* * * *
|
|
7
|
+
* Example usage:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { merge } from "@telperion/js-utils/map";
|
|
10
|
+
*
|
|
11
|
+
* const first = new Map();
|
|
12
|
+
* first.set("a", 1);
|
|
13
|
+
*
|
|
14
|
+
* const second = new Map();
|
|
15
|
+
* second.set("b", 2);
|
|
16
|
+
*
|
|
17
|
+
* merge(first, second); // [{key: "a", value: 1}, {key: "b", value: 2}]
|
|
18
|
+
* ```
|
|
19
|
+
* * * *
|
|
20
|
+
* @param first First map
|
|
21
|
+
* @param second Second map
|
|
22
|
+
* @returns A new merged map
|
|
23
|
+
*/
|
|
24
|
+
export declare function merge<T, U, V, Y>(first: Map<T, U>, second: Map<V, Y>): Map<T | V, U | Y>;
|
package/map/merge.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Map Merge
|
|
3
|
+
*
|
|
4
|
+
* Merges two maps
|
|
5
|
+
*
|
|
6
|
+
* * * *
|
|
7
|
+
* Example usage:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { merge } from "@telperion/js-utils/map";
|
|
10
|
+
*
|
|
11
|
+
* const first = new Map();
|
|
12
|
+
* first.set("a", 1);
|
|
13
|
+
*
|
|
14
|
+
* const second = new Map();
|
|
15
|
+
* second.set("b", 2);
|
|
16
|
+
*
|
|
17
|
+
* merge(first, second); // [{key: "a", value: 1}, {key: "b", value: 2}]
|
|
18
|
+
* ```
|
|
19
|
+
* * * *
|
|
20
|
+
* @param first First map
|
|
21
|
+
* @param second Second map
|
|
22
|
+
* @returns A new merged map
|
|
23
|
+
*/
|
|
24
|
+
export function merge(first, second) {
|
|
25
|
+
const newMap = new Map(first);
|
|
26
|
+
for (const key of second.keys()) {
|
|
27
|
+
newMap.set(key, second.get(key));
|
|
28
|
+
}
|
|
29
|
+
return newMap;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=merge.js.map
|
package/map/merge.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/map/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,KAAK,CAAa,KAAgB,EAAE,MAAiB;IACnE,MAAM,MAAM,GAAG,IAAI,GAAG,CAAe,KAAK,CAAC,CAAC;IAE5C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","file":"merge.js","sourcesContent":["/**\n * #### Map Merge\n *\n * Merges two maps\n *\n * * * *\n * Example usage:\n * ```typescript\n * import { merge } from \"@telperion/js-utils/map\";\n *\n * const first = new Map();\n * first.set(\"a\", 1);\n *\n * const second = new Map();\n * second.set(\"b\", 2);\n *\n * merge(first, second); // [{key: \"a\", value: 1}, {key: \"b\", value: 2}]\n * ```\n * * * *\n * @param first First map\n * @param second Second map\n * @returns A new merged map\n */\nexport function merge<T, U, V, Y>(first: Map<T, U>, second: Map<V, Y>): Map<T | V, U | Y> {\n const newMap = new Map<T | V, U | Y>(first);\n\n for (const key of second.keys()) {\n newMap.set(key, second.get(key)!);\n }\n\n return newMap;\n}\n"]}
|
package/math/index.cjs
ADDED
package/math/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@telperion/js-utils/math/min-max';
|
package/math/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/math/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC","file":"index.js","sourcesContent":["export * from '@telperion/js-utils/math/min-max';\n"]}
|
package/math/min-max.cjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.minMax = minMax;
|
|
4
|
+
/**
|
|
5
|
+
* #### Limits the value by specified range
|
|
6
|
+
*
|
|
7
|
+
* * * *
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { minMax } from "@telperion/js-utils/math";
|
|
11
|
+
*
|
|
12
|
+
* const limitedValue = minMax(200, 300, Math.random() * 1000);
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Example as Math static:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import "@telperion/js-utils/math/static/min-max";
|
|
18
|
+
*
|
|
19
|
+
* const limitedValue = Math.minMax(200, 300, Math.random() * 1000);
|
|
20
|
+
* ```
|
|
21
|
+
* * * *
|
|
22
|
+
* @param min minimum limit
|
|
23
|
+
* @param max maximum limit
|
|
24
|
+
* @param value value to limit
|
|
25
|
+
* @return the limited value *(returns NaN if an argument is NaN)*
|
|
26
|
+
*/
|
|
27
|
+
function minMax(min, max, value) {
|
|
28
|
+
return Math.max(Math.min(max, value), min);
|
|
29
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Limits the value by specified range
|
|
3
|
+
*
|
|
4
|
+
* * * *
|
|
5
|
+
* Example usage:
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { minMax } from "@telperion/js-utils/math";
|
|
8
|
+
*
|
|
9
|
+
* const limitedValue = minMax(200, 300, Math.random() * 1000);
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Example as Math static:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import "@telperion/js-utils/math/static/min-max";
|
|
15
|
+
*
|
|
16
|
+
* const limitedValue = Math.minMax(200, 300, Math.random() * 1000);
|
|
17
|
+
* ```
|
|
18
|
+
* * * *
|
|
19
|
+
* @param min minimum limit
|
|
20
|
+
* @param max maximum limit
|
|
21
|
+
* @param value value to limit
|
|
22
|
+
* @return the limited value *(returns NaN if an argument is NaN)*
|
|
23
|
+
*/
|
|
24
|
+
export declare function minMax(min: number, max: number, value: number): number;
|
package/math/min-max.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Limits the value by specified range
|
|
3
|
+
*
|
|
4
|
+
* * * *
|
|
5
|
+
* Example usage:
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { minMax } from "@telperion/js-utils/math";
|
|
8
|
+
*
|
|
9
|
+
* const limitedValue = minMax(200, 300, Math.random() * 1000);
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Example as Math static:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import "@telperion/js-utils/math/static/min-max";
|
|
15
|
+
*
|
|
16
|
+
* const limitedValue = Math.minMax(200, 300, Math.random() * 1000);
|
|
17
|
+
* ```
|
|
18
|
+
* * * *
|
|
19
|
+
* @param min minimum limit
|
|
20
|
+
* @param max maximum limit
|
|
21
|
+
* @param value value to limit
|
|
22
|
+
* @return the limited value *(returns NaN if an argument is NaN)*
|
|
23
|
+
*/
|
|
24
|
+
export function minMax(min, max, value) {
|
|
25
|
+
return Math.max(Math.min(max, value), min);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=min-max.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/math/min-max.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW,EAAE,GAAW,EAAE,KAAa;IAC5D,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC","file":"min-max.js","sourcesContent":["/**\n * #### Limits the value by specified range\n *\n * * * *\n * Example usage:\n * ```typescript\n * import { minMax } from \"@telperion/js-utils/math\";\n *\n * const limitedValue = minMax(200, 300, Math.random() * 1000);\n * ```\n *\n * Example as Math static:\n * ```typescript\n * import \"@telperion/js-utils/math/static/min-max\";\n *\n * const limitedValue = Math.minMax(200, 300, Math.random() * 1000);\n * ```\n * * * *\n * @param min minimum limit\n * @param max maximum limit\n * @param value value to limit\n * @return the limited value *(returns NaN if an argument is NaN)*\n */\nexport function minMax(min: number, max: number, value: number): number {\n return Math.max(Math.min(max, value), min);\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { minMax } from '@telperion/js-utils/math/min-max';
|
|
2
|
+
declare global {
|
|
3
|
+
export interface Math {
|
|
4
|
+
/**
|
|
5
|
+
* #### Limits the value by given parameters
|
|
6
|
+
*
|
|
7
|
+
* * * *
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import "@telperion/js-utils/math/static/min-max";
|
|
10
|
+
*
|
|
11
|
+
* const limitedValue = Math.minMax(200, 300, Math.random() * 1000);
|
|
12
|
+
* ```
|
|
13
|
+
* * * *
|
|
14
|
+
* @param min minimum limit
|
|
15
|
+
* @param max maximum limit
|
|
16
|
+
* @param value value to limit
|
|
17
|
+
*/
|
|
18
|
+
minMax: typeof minMax;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/math/static/min-max.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAsB1D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC","file":"min-max.js","sourcesContent":["import { minMax } from '@telperion/js-utils/math/min-max';\n\ndeclare global {\n export interface Math {\n /**\n * #### Limits the value by given parameters\n *\n * * * *\n * ```typescript\n * import \"@telperion/js-utils/math/static/min-max\";\n *\n * const limitedValue = Math.minMax(200, 300, Math.random() * 1000);\n * ```\n * * * *\n * @param min minimum limit\n * @param max maximum limit\n * @param value value to limit\n */\n minMax: typeof minMax;\n }\n}\n\nMath.minMax = minMax;\n"]}
|
package/object/clone.cjs
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.clone = clone;
|
|
5
|
+
const difference_1 = require("@telperion/js-utils/array/difference");
|
|
6
|
+
const intersection_1 = require("@telperion/js-utils/array/intersection");
|
|
7
|
+
const merge_1 = require("@telperion/js-utils/map/merge");
|
|
8
|
+
/**
|
|
9
|
+
* A placeholder to symbolize the cloning progress of `objectToClone` hasn't finished yet
|
|
10
|
+
*/
|
|
11
|
+
const CLONING_IN_PROGRESS = Symbol('Cloning In Progress');
|
|
12
|
+
/**
|
|
13
|
+
* Function Map to clone specific objects types
|
|
14
|
+
*/
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
16
|
+
const DEFAULT_INSTANCE_CLONERS = new Map();
|
|
17
|
+
// Set cloning functions
|
|
18
|
+
DEFAULT_INSTANCE_CLONERS.set(Array, arrayCloner);
|
|
19
|
+
DEFAULT_INSTANCE_CLONERS.set(Map, mapCloner);
|
|
20
|
+
DEFAULT_INSTANCE_CLONERS.set(Set, setCloner);
|
|
21
|
+
DEFAULT_INSTANCE_CLONERS.set(Object, objectCloner);
|
|
22
|
+
/**
|
|
23
|
+
* Default Array Cloner
|
|
24
|
+
*/
|
|
25
|
+
function arrayCloner(objectToClone, options, internalData) {
|
|
26
|
+
return objectToClone.map((val, i, arr) => {
|
|
27
|
+
if (options.propsToRefer.indexOf(i) > -1) {
|
|
28
|
+
return val;
|
|
29
|
+
}
|
|
30
|
+
return cloner(val, options, { ...internalData, parent: arr, key: i });
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Default Map Cloner
|
|
35
|
+
*/
|
|
36
|
+
function mapCloner(objectToClone, options, internalData) {
|
|
37
|
+
const newMap = new Map();
|
|
38
|
+
(0, intersection_1.intersection)(options.propsToRefer, Array.from(objectToClone.keys())).forEach(key => {
|
|
39
|
+
newMap.set(key, objectToClone.get(key));
|
|
40
|
+
});
|
|
41
|
+
(0, difference_1.difference)(Array.from(objectToClone.keys()), options.propsToRefer).forEach(key => {
|
|
42
|
+
newMap.set(key, cloner(objectToClone.get(key), options, { ...internalData, key, parent: newMap }));
|
|
43
|
+
});
|
|
44
|
+
return newMap;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Default Set Cloner
|
|
48
|
+
*/
|
|
49
|
+
function setCloner(objectToClone) {
|
|
50
|
+
return new Set(objectToClone);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Default Object Cloner
|
|
54
|
+
*/
|
|
55
|
+
function objectCloner(objectToClone, options, internalData) {
|
|
56
|
+
const { propsToRefer } = options;
|
|
57
|
+
/**
|
|
58
|
+
* New Object Clone
|
|
59
|
+
*/
|
|
60
|
+
const _clone = {};
|
|
61
|
+
/**
|
|
62
|
+
* Object cloner
|
|
63
|
+
* @param key incoming property of object to clone
|
|
64
|
+
*/
|
|
65
|
+
function cloneObject(key) {
|
|
66
|
+
_clone[key] = cloner(objectToClone[key], options, { ...internalData, parent: _clone, key });
|
|
67
|
+
}
|
|
68
|
+
const allProperties = [...Object.keys(objectToClone), ...Object.getOwnPropertySymbols(objectToClone)];
|
|
69
|
+
// Pass unwanted props
|
|
70
|
+
(0, intersection_1.intersection)(propsToRefer, allProperties).forEach(prop => {
|
|
71
|
+
_clone[prop] = objectToClone[prop];
|
|
72
|
+
});
|
|
73
|
+
// Clone remaining properties
|
|
74
|
+
(0, difference_1.difference)(allProperties, propsToRefer).forEach(cloneObject);
|
|
75
|
+
return _clone;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* #### Deep Clone
|
|
79
|
+
*
|
|
80
|
+
* A function to recursively clone objects, arrays etc. with [cloning options]{@link ICloneOptions}
|
|
81
|
+
*
|
|
82
|
+
* *References Functions & Symbols by default*
|
|
83
|
+
*
|
|
84
|
+
* * * *
|
|
85
|
+
* Example:
|
|
86
|
+
* ```typescript
|
|
87
|
+
* import { clone } from "@telperion/js-utils/object";
|
|
88
|
+
*
|
|
89
|
+
* const object = {a: 1, b: {c: true, d: ["x", "y"]}};
|
|
90
|
+
*
|
|
91
|
+
* // Clone all
|
|
92
|
+
* const clonedObject = clone(object);
|
|
93
|
+
* // {a: 1, b: {c: true, d: ["x", "y"]}}
|
|
94
|
+
* // object.b.d === clonedObject.b.d // false
|
|
95
|
+
*
|
|
96
|
+
* // Clone all but reference "d"
|
|
97
|
+
* const clonedObject = clone(object, {propsToRefer: ["d"]});
|
|
98
|
+
* // {a: 1, b: {c: true, d: ["x", "y"]}}
|
|
99
|
+
* // object.b.d === clonedObject.b.d // true
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* Static usage example:
|
|
103
|
+
* ```typescript
|
|
104
|
+
* import "@telperion/js-utils/object/static/clone";
|
|
105
|
+
*
|
|
106
|
+
* const object = {a: 1, b: 2};
|
|
107
|
+
* const clonedObject = Object.clone(object); // {a: 1, b: 2}
|
|
108
|
+
* ```
|
|
109
|
+
* * * *
|
|
110
|
+
* @param objectToClone Object to clone
|
|
111
|
+
* @param options {ICloneOptions} Cloning Options
|
|
112
|
+
* @see {@link ICloneOptions} for more information.
|
|
113
|
+
*/
|
|
114
|
+
function clone(objectToClone, { instancesToRefer = [], propsToRefer = [], valueFiltererToRefer = () => false, customCloners = new Map() } = {}) {
|
|
115
|
+
/**
|
|
116
|
+
* Whole options with defaults
|
|
117
|
+
*/
|
|
118
|
+
const mergedCloners = (0, merge_1.merge)(customCloners, DEFAULT_INSTANCE_CLONERS);
|
|
119
|
+
const allOptions = { instancesToRefer, propsToRefer, valueFiltererToRefer, customCloners: mergedCloners };
|
|
120
|
+
const finalizers = [];
|
|
121
|
+
const cloned = cloner(objectToClone, allOptions, { clonedObjects: new Map(), finalizers });
|
|
122
|
+
finalizers.forEach(callback => { callback(); });
|
|
123
|
+
return cloned;
|
|
124
|
+
}
|
|
125
|
+
function cloner(objectToClone, allOptions, internalData) {
|
|
126
|
+
const { instancesToRefer, valueFiltererToRefer, customCloners } = allOptions;
|
|
127
|
+
const { clonedObjects, finalizers, parent, key } = internalData;
|
|
128
|
+
// Pass primitives & functions
|
|
129
|
+
if (objectToClone === null || !(objectToClone instanceof Object) || objectToClone instanceof Function) {
|
|
130
|
+
return objectToClone;
|
|
131
|
+
}
|
|
132
|
+
// Pass unwanted references
|
|
133
|
+
if (instancesToRefer.some(instance => objectToClone instanceof instance)) {
|
|
134
|
+
return objectToClone;
|
|
135
|
+
}
|
|
136
|
+
// Pass filterer results
|
|
137
|
+
if (valueFiltererToRefer(objectToClone)) {
|
|
138
|
+
return objectToClone;
|
|
139
|
+
}
|
|
140
|
+
// If cloned before, skip circular cloning
|
|
141
|
+
if (clonedObjects.has(objectToClone)) {
|
|
142
|
+
if (clonedObjects.get(objectToClone) === CLONING_IN_PROGRESS) {
|
|
143
|
+
finalizers.push(() => {
|
|
144
|
+
parent[key] = clonedObjects.get(objectToClone);
|
|
145
|
+
});
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
return clonedObjects.get(objectToClone);
|
|
149
|
+
}
|
|
150
|
+
// Mark object as cloning
|
|
151
|
+
clonedObjects.set(objectToClone, CLONING_IN_PROGRESS);
|
|
152
|
+
// Clone
|
|
153
|
+
const customCloner = Array.from(customCloners.keys()).find(val => objectToClone instanceof val);
|
|
154
|
+
const result = customCloners.get(customCloner)(objectToClone, allOptions, { ...internalData });
|
|
155
|
+
clonedObjects.set(objectToClone, result);
|
|
156
|
+
return result;
|
|
157
|
+
}
|