@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/array/limit.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Limit
|
|
3
|
+
*
|
|
4
|
+
* Returns first `n` children of an array
|
|
5
|
+
*
|
|
6
|
+
* * * *
|
|
7
|
+
* Example:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { limit } from "@telperion/js-utils/array";
|
|
10
|
+
*
|
|
11
|
+
* const array = ["a", "b", "c", "d", "e", "f"];
|
|
12
|
+
*
|
|
13
|
+
* limit(array, 3); // ["a", "b", "c"]
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Prototype Example:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import "@telperion/js-utils/array/proto/limit";
|
|
19
|
+
*
|
|
20
|
+
* const array = ["a", "b", "c", "d", "e", "f"];
|
|
21
|
+
*
|
|
22
|
+
* array.limit(3); // ["a", "b", "c"]
|
|
23
|
+
* ```
|
|
24
|
+
* * * *
|
|
25
|
+
* @param array: Array to return its children
|
|
26
|
+
* @param count Limiter
|
|
27
|
+
* @return New array
|
|
28
|
+
*/
|
|
29
|
+
export function limit(array, count) {
|
|
30
|
+
if (count < 0) {
|
|
31
|
+
count = Number.MAX_SAFE_INTEGER;
|
|
32
|
+
}
|
|
33
|
+
return array.slice(0, count);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=limit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/limit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,KAAK,CAAU,KAAU,EAAE,KAAa;IACtD,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAClC,CAAC;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAC/B,CAAC","file":"limit.js","sourcesContent":["/**\n * #### Limit\n *\n * Returns first `n` children of an array\n *\n * * * *\n * Example:\n * ```typescript\n * import { limit } from \"@telperion/js-utils/array\";\n *\n * const array = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"];\n *\n * limit(array, 3); // [\"a\", \"b\", \"c\"]\n * ```\n *\n * Prototype Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/limit\";\n *\n * const array = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"];\n *\n * array.limit(3); // [\"a\", \"b\", \"c\"]\n * ```\n * * * *\n * @param array: Array to return its children\n * @param count Limiter\n * @return New array\n */\nexport function limit<T = any>(array: T[], count: number): T[] {\n if (count < 0) {\n count = Number.MAX_SAFE_INTEGER;\n }\n\n return array.slice(0, count);\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const async_map_1 = require("@telperion/js-utils/array/async-map");
|
|
4
|
+
Array.prototype.asyncMap = async function (callbackFn) {
|
|
5
|
+
return await (0, async_map_1.asyncMap)(this, callbackFn);
|
|
6
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
export interface Array<T> {
|
|
3
|
+
/**
|
|
4
|
+
* #### Async Map
|
|
5
|
+
*
|
|
6
|
+
* Maps an array asynchronously
|
|
7
|
+
*
|
|
8
|
+
* * * *
|
|
9
|
+
* Example:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import "@telperion/js-utils/array/proto/async-map";
|
|
12
|
+
*
|
|
13
|
+
* const array = [1, 2, 3];
|
|
14
|
+
*
|
|
15
|
+
* const mapped = await array.asyncMap(async value => await addOneAfterASecond(value)); // [2, 3, 4]
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* * * *
|
|
19
|
+
* @param mapper Callback async function to map the array
|
|
20
|
+
* @return A promise contains asynchronusly mapped array result
|
|
21
|
+
*/
|
|
22
|
+
asyncMap<U>(callbackFn: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]>;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/async-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AA2B/D,KAAK,CAAC,SAAS,CAAC,QAAQ,GAAG,KAAK,WAA2B,UAA+D;IACxH,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAC1C,CAAC,CAAC","file":"async-map.js","sourcesContent":["import { asyncMap } from '@telperion/js-utils/array/async-map';\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Async Map\n *\n * Maps an array asynchronously\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/async-map\";\n *\n * const array = [1, 2, 3];\n *\n * const mapped = await array.asyncMap(async value => await addOneAfterASecond(value)); // [2, 3, 4]\n *\n * ```\n * * * *\n * @param mapper Callback async function to map the array\n * @return A promise contains asynchronusly mapped array result\n */\n asyncMap<U>(callbackFn: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]>;\n }\n}\n\nArray.prototype.asyncMap = async function<T, U>(this: T[], callbackFn: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]> {\n return await asyncMap(this, callbackFn);\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
export interface Array<T> {
|
|
3
|
+
/**
|
|
4
|
+
* Filters falsy values of the given array
|
|
5
|
+
*
|
|
6
|
+
* __Does not modify the original array__
|
|
7
|
+
*
|
|
8
|
+
* Values to be filtered: `[undefined, null, "", 0, false, NaN]`
|
|
9
|
+
*
|
|
10
|
+
* @returns T[] filtered array
|
|
11
|
+
*/
|
|
12
|
+
compact(): T[];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/compact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAiB5D,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG;IACxB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC,CAAC","file":"compact.js","sourcesContent":["import { compact } from '@telperion/js-utils/array/compact';\n\ndeclare global {\n export interface Array<T> {\n /**\n * Filters falsy values of the given array\n *\n * __Does not modify the original array__\n *\n * Values to be filtered: `[undefined, null, \"\", 0, false, NaN]`\n *\n * @returns T[] filtered array\n */\n compact(): T[];\n }\n}\n\nArray.prototype.compact = function() {\n return compact(this);\n};\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const difference_1 = require("@telperion/js-utils/array/difference");
|
|
4
|
+
Array.prototype.difference = function (substraction, allDiff = false) {
|
|
5
|
+
return (0, difference_1.difference)(this, substraction, allDiff);
|
|
6
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Substraction } from '@telperion/js-utils/array/difference';
|
|
2
|
+
declare global {
|
|
3
|
+
export interface Array<T> {
|
|
4
|
+
/**
|
|
5
|
+
* #### Difference
|
|
6
|
+
*
|
|
7
|
+
* Gets the difference of the arrays
|
|
8
|
+
*
|
|
9
|
+
* * * *
|
|
10
|
+
* Example:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import "@telperion/js-utils/array/proto/array-difference";
|
|
13
|
+
*
|
|
14
|
+
* const base = ["a", "b", "c", "d", "a", "b", "c", "d"];
|
|
15
|
+
*
|
|
16
|
+
* base.difference(["a", "b"]); // ["c", "d", "c", "d"]
|
|
17
|
+
* base.difference(["a", "b"], true); // ["c", "d", "a", "b", "c", "d"]
|
|
18
|
+
* ```
|
|
19
|
+
* * * *
|
|
20
|
+
* @param base Base Array
|
|
21
|
+
* @param substraction Set or Array to remove its values from the base
|
|
22
|
+
* @param allDiff By default all the same items encountered in substraction will be removed, set this argument as true to get real difference
|
|
23
|
+
* @returns Difference of base from substraction
|
|
24
|
+
*/
|
|
25
|
+
difference(substraction: Substraction, allDiff?: boolean): T[];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/difference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgB,MAAM,sCAAsC,CAAC;AA6BhF,KAAK,CAAC,SAAS,CAAC,UAAU,GAAG,UAAS,YAA0B,EAAE,OAAO,GAAG,KAAK;IAC/E,OAAO,UAAU,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC,CAAC","file":"difference.js","sourcesContent":["import { difference, Substraction } from '@telperion/js-utils/array/difference';\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Difference\n *\n * Gets the difference of the arrays\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/array-difference\";\n *\n * const base = [\"a\", \"b\", \"c\", \"d\", \"a\", \"b\", \"c\", \"d\"];\n *\n * base.difference([\"a\", \"b\"]); // [\"c\", \"d\", \"c\", \"d\"]\n * base.difference([\"a\", \"b\"], true); // [\"c\", \"d\", \"a\", \"b\", \"c\", \"d\"]\n * ```\n * * * *\n * @param base Base Array\n * @param substraction Set or Array to remove its values from the base\n * @param allDiff By default all the same items encountered in substraction will be removed, set this argument as true to get real difference\n * @returns Difference of base from substraction\n */\n difference(substraction: Substraction, allDiff?: boolean): T[];\n }\n}\n\nArray.prototype.difference = function(substraction: Substraction, allDiff = false) {\n return difference(this, substraction, allDiff);\n};\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
export interface Array<T> {
|
|
3
|
+
/**
|
|
4
|
+
* #### Find By Key
|
|
5
|
+
*
|
|
6
|
+
* Finds an object in an array by matching the value set on the key
|
|
7
|
+
*
|
|
8
|
+
* * * *
|
|
9
|
+
* Example:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import "@telperion/js-utils/array/proto/find-by-key";
|
|
12
|
+
*
|
|
13
|
+
* const array = [{a: 1}, {a: 2}, {a: 3}];
|
|
14
|
+
*
|
|
15
|
+
* array.findByKey("a", 2); // {a: 2}
|
|
16
|
+
* ```
|
|
17
|
+
* * * *
|
|
18
|
+
* @param key Key to search the value on
|
|
19
|
+
* @param value Value to match for the key
|
|
20
|
+
* @return Found object or undefined
|
|
21
|
+
*/
|
|
22
|
+
findByKey<K extends keyof T>(key: K, value: T[K]): T;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/find-by-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AA2BlE,KAAK,CAAC,SAAS,CAAC,SAAS,GAAG,UAA0C,GAAM,EAAE,KAAW;IACvF,OAAO,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAE,CAAC;AACtC,CAAC,CAAC","file":"find-by-key.js","sourcesContent":["import { findByKey } from '@telperion/js-utils/array/find-by-key';\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Find By Key\n *\n * Finds an object in an array by matching the value set on the key\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/find-by-key\";\n *\n * const array = [{a: 1}, {a: 2}, {a: 3}];\n *\n * array.findByKey(\"a\", 2); // {a: 2}\n * ```\n * * * *\n * @param key Key to search the value on\n * @param value Value to match for the key\n * @return Found object or undefined\n */\n findByKey<K extends keyof T>(key: K, value: T[K]): T;\n }\n}\n\nArray.prototype.findByKey = function<T, K extends keyof T>(this: T[], key: K, value: T[K]): T {\n return findByKey(this, key, value)!;\n};\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const intersection_1 = require("@telperion/js-utils/array/intersection");
|
|
4
|
+
Array.prototype.intersection = function (inclusion, allEquals = true) {
|
|
5
|
+
return (0, intersection_1.intersection)(this, inclusion, allEquals);
|
|
6
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Inclusion } from '@telperion/js-utils/array/intersection';
|
|
2
|
+
declare global {
|
|
3
|
+
export interface Array<T> {
|
|
4
|
+
/**
|
|
5
|
+
* #### Intersection
|
|
6
|
+
*
|
|
7
|
+
* Gets the intersection of the two arrays or sets
|
|
8
|
+
*
|
|
9
|
+
* * * *
|
|
10
|
+
* Example:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import "@telperion/js-utils/array/proto/intersection";
|
|
13
|
+
*
|
|
14
|
+
* const base = ["a", "b", "c", "d", "a", "b", "c", "d"];
|
|
15
|
+
*
|
|
16
|
+
* base.intersection(["a", "b"]); // ["a", "b", "a", "b"]
|
|
17
|
+
* base.intersection(["a", "b"], false); // ["a", "b"]
|
|
18
|
+
* ```
|
|
19
|
+
* * * *
|
|
20
|
+
* @param base Base Set or Array
|
|
21
|
+
* @param inclusion Set or Array to include its values
|
|
22
|
+
* @param allEquals By default all the same items encountered in the inclusion will be included, set this argument as false to get real intersection
|
|
23
|
+
* @returns Intersection of base and inclusion
|
|
24
|
+
*/
|
|
25
|
+
intersection(inclusion: Inclusion, allEquals?: boolean): T[];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/intersection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAa,MAAM,wCAAwC,CAAC;AA6BjF,KAAK,CAAC,SAAS,CAAC,YAAY,GAAG,UAAS,SAAoB,EAAE,SAAS,GAAG,IAAI;IAC5E,OAAO,YAAY,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAClD,CAAC,CAAC","file":"intersection.js","sourcesContent":["import { intersection, Inclusion } from '@telperion/js-utils/array/intersection';\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Intersection\n *\n * Gets the intersection of the two arrays or sets\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/intersection\";\n *\n * const base = [\"a\", \"b\", \"c\", \"d\", \"a\", \"b\", \"c\", \"d\"];\n *\n * base.intersection([\"a\", \"b\"]); // [\"a\", \"b\", \"a\", \"b\"]\n * base.intersection([\"a\", \"b\"], false); // [\"a\", \"b\"]\n * ```\n * * * *\n * @param base Base Set or Array\n * @param inclusion Set or Array to include its values\n * @param allEquals By default all the same items encountered in the inclusion will be included, set this argument as false to get real intersection\n * @returns Intersection of base and inclusion\n */\n intersection(inclusion: Inclusion, allEquals?: boolean): T[];\n }\n}\n\nArray.prototype.intersection = function(inclusion: Inclusion, allEquals = true) {\n return intersection(this, inclusion, allEquals);\n};\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
export interface Array<T> {
|
|
3
|
+
/**
|
|
4
|
+
* #### Limit
|
|
5
|
+
*
|
|
6
|
+
* Returns first `n` children of an array
|
|
7
|
+
*
|
|
8
|
+
* * * *
|
|
9
|
+
* Example:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import "@telperion/js-utils/array/proto/limit";
|
|
12
|
+
*
|
|
13
|
+
* const array = ["a", "b", "c", "d", "e", "f"];
|
|
14
|
+
*
|
|
15
|
+
* array.limit(3); // ["a", "b", "c"]
|
|
16
|
+
* ```
|
|
17
|
+
* * * *
|
|
18
|
+
* @param count Limiter
|
|
19
|
+
* @return New array
|
|
20
|
+
*/
|
|
21
|
+
limit(count: number): T[];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/limit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AA0BxD,KAAK,CAAC,SAAS,CAAC,KAAK,GAAG,UAAS,KAAa;IAC5C,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC5B,CAAC,CAAC","file":"limit.js","sourcesContent":["import { limit } from '@telperion/js-utils/array/limit';\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Limit\n *\n * Returns first `n` children of an array\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/limit\";\n *\n * const array = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"];\n *\n * array.limit(3); // [\"a\", \"b\", \"c\"]\n * ```\n * * * *\n * @param count Limiter\n * @return New array\n */\n limit(count: number): T[];\n }\n}\n\nArray.prototype.limit = function(count: number) {\n return limit(this, count);\n};\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Tail } from '@thalesrc/extra-ts-types';
|
|
2
|
+
import { remove } from '@telperion/js-utils/array/remove';
|
|
3
|
+
type FuncType<T> = typeof remove<T>;
|
|
4
|
+
type FuncArgs<T> = Parameters<FuncType<T>>;
|
|
5
|
+
type FuncReturn<T> = ReturnType<FuncType<T>>;
|
|
6
|
+
type ProtoArgs<T> = Tail<FuncArgs<T>>;
|
|
7
|
+
declare global {
|
|
8
|
+
export interface Array<T> {
|
|
9
|
+
/**
|
|
10
|
+
* #### Remove
|
|
11
|
+
*
|
|
12
|
+
* Removes an item from the array
|
|
13
|
+
*
|
|
14
|
+
* Removes all item references if multi is set to `true`
|
|
15
|
+
*
|
|
16
|
+
* * * *
|
|
17
|
+
* Example:
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import "@telperion/js-utils/array/proto/remove";
|
|
20
|
+
*
|
|
21
|
+
* const array = ["a", "b", "c", "a", "b", "c"];
|
|
22
|
+
*
|
|
23
|
+
* array.remove("b", true); // ["a", "c", "a", "c"]
|
|
24
|
+
* ```
|
|
25
|
+
* * * *
|
|
26
|
+
* @param itemToRemove Item to remove
|
|
27
|
+
* @return New array
|
|
28
|
+
*/
|
|
29
|
+
remove(...args: ProtoArgs<T>): FuncReturn<T>;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/remove.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAiC1D,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,UAAuB,GAAG,IAAkB;IACnE,OAAO,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;AAC/B,CAAC,CAAC","file":"remove.js","sourcesContent":["import type { Tail } from '@thalesrc/extra-ts-types';\n\nimport { remove } from '@telperion/js-utils/array/remove';\n\ntype FuncType<T> = typeof remove<T>;\ntype FuncArgs<T> = Parameters<FuncType<T>>;\ntype FuncReturn<T> = ReturnType<FuncType<T>>;\ntype ProtoArgs<T> = Tail<FuncArgs<T>>;\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Remove\n *\n * Removes an item from the array\n *\n * Removes all item references if multi is set to `true`\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/remove\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n *\n * array.remove(\"b\", true); // [\"a\", \"c\", \"a\", \"c\"]\n * ```\n * * * *\n * @param itemToRemove Item to remove\n * @return New array\n */\n remove(...args: ProtoArgs<T>): FuncReturn<T>;\n }\n}\n\nArray.prototype.remove = function<T>(this: T[], ...args: ProtoArgs<T>): FuncReturn<T> {\n return remove(this, ...args);\n};\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ReplaceItemsOptions, ReplaceByMapOptions } from '@telperion/js-utils/array/replace';
|
|
2
|
+
declare global {
|
|
3
|
+
export interface Array<T> {
|
|
4
|
+
/**
|
|
5
|
+
* #### Replace
|
|
6
|
+
*
|
|
7
|
+
* Replaces an item with passed one of an array
|
|
8
|
+
*
|
|
9
|
+
* * * *
|
|
10
|
+
* Example:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import "@telperion/js-utils/array/proto/replace";
|
|
13
|
+
*
|
|
14
|
+
* const array = ["a", "b", "c", "a", "b", "c"];
|
|
15
|
+
*
|
|
16
|
+
* array.replace("b", "x"); // ["a", "x", "c", "a", "b", "c"]
|
|
17
|
+
* ```
|
|
18
|
+
* * * *
|
|
19
|
+
* @param array Array to replace its item
|
|
20
|
+
* @param itemToRemove Item to remove
|
|
21
|
+
* @param itemToReplace Item to replace with
|
|
22
|
+
* @return New replaced array
|
|
23
|
+
*/
|
|
24
|
+
replace(itemToRemove: T, itemToReplace: T): T[];
|
|
25
|
+
/**
|
|
26
|
+
* #### Replace
|
|
27
|
+
*
|
|
28
|
+
* Deletes items and replaces new ones from passed starting index of an array
|
|
29
|
+
*
|
|
30
|
+
* * * *
|
|
31
|
+
* Example:
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import "@telperion/js-utils/array/proto/replace";
|
|
34
|
+
*
|
|
35
|
+
* const array = ["a", "b", "c", "a", "b", "c"];
|
|
36
|
+
*
|
|
37
|
+
* array.replace({startingIndex: 3, deleteCount: 1, itemsToReplace: ['x', 'y']}); // ["a", "b", "c", "x", "y", "b", "c"];
|
|
38
|
+
* ```
|
|
39
|
+
* * * *
|
|
40
|
+
* @param array Array to replace its item
|
|
41
|
+
* @param replaceOptions Replace options
|
|
42
|
+
* @template T Typeof array items
|
|
43
|
+
* @return New replaced array
|
|
44
|
+
*/
|
|
45
|
+
replace(replaceOptions: ReplaceItemsOptions<T>): T[];
|
|
46
|
+
/**
|
|
47
|
+
* #### Replace
|
|
48
|
+
*
|
|
49
|
+
* Deletes items and replaces new ones by passed matcher map
|
|
50
|
+
*
|
|
51
|
+
* * * *
|
|
52
|
+
* Example:
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import "@telperion/js-utils/array/proto/replace";
|
|
55
|
+
*
|
|
56
|
+
* const array = ["a", "b", "c", "a", "b", "c"];
|
|
57
|
+
* const map = new Map();
|
|
58
|
+
* map.set("a", "x")
|
|
59
|
+
* map.set("b", "y");
|
|
60
|
+
*
|
|
61
|
+
* array.replace({itemsToReplace: map}); // ["x", "y", "c", "a", "b", "c"];
|
|
62
|
+
* array.replace({itemsToReplace: map, multi: true}); // ["x", "y", "c", "x", "y", "c"];
|
|
63
|
+
* ```
|
|
64
|
+
* * * *
|
|
65
|
+
* @param array Array to replace its item
|
|
66
|
+
* @param replaceOptions Replace options
|
|
67
|
+
* @template T Typeof array items
|
|
68
|
+
* @return New replaced array
|
|
69
|
+
*/
|
|
70
|
+
replace(replaceOptions: ReplaceByMapOptions<T>): T[];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/replace.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAA4C,MAAM,mCAAmC,CAAC;AA4EtG,KAAK,CAAC,SAAS,CAAC,OAAO,GAA0B,UAAuB,GAAG,IAAyC;IAClH,OAAO,OAAO,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;AAChC,CAAC,CAAC","file":"replace.js","sourcesContent":["import type { Tail } from '@thalesrc/extra-ts-types';\n\nimport { replace, ReplaceItemsOptions, ReplaceByMapOptions } from '@telperion/js-utils/array/replace';\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Replace\n *\n * Replaces an item with passed one of an array\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/replace\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n *\n * array.replace(\"b\", \"x\"); // [\"a\", \"x\", \"c\", \"a\", \"b\", \"c\"]\n * ```\n * * * *\n * @param array Array to replace its item\n * @param itemToRemove Item to remove\n * @param itemToReplace Item to replace with\n * @return New replaced array\n */\n replace(itemToRemove: T, itemToReplace: T): T[];\n\n /**\n * #### Replace\n *\n * Deletes items and replaces new ones from passed starting index of an array\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/replace\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n *\n * array.replace({startingIndex: 3, deleteCount: 1, itemsToReplace: ['x', 'y']}); // [\"a\", \"b\", \"c\", \"x\", \"y\", \"b\", \"c\"];\n * ```\n * * * *\n * @param array Array to replace its item\n * @param replaceOptions Replace options\n * @template T Typeof array items\n * @return New replaced array\n */\n replace(replaceOptions: ReplaceItemsOptions<T>): T[];\n\n /**\n * #### Replace\n *\n * Deletes items and replaces new ones by passed matcher map\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/replace\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n * const map = new Map();\n * map.set(\"a\", \"x\")\n * map.set(\"b\", \"y\");\n *\n * array.replace({itemsToReplace: map}); // [\"x\", \"y\", \"c\", \"a\", \"b\", \"c\"];\n * array.replace({itemsToReplace: map, multi: true}); // [\"x\", \"y\", \"c\", \"x\", \"y\", \"c\"];\n * ```\n * * * *\n * @param array Array to replace its item\n * @param replaceOptions Replace options\n * @template T Typeof array items\n * @return New replaced array\n */\n replace(replaceOptions: ReplaceByMapOptions<T>): T[];\n }\n}\n\nArray.prototype.replace = <Array<any>['replace']>function<T>(this: T[], ...args: Tail<Parameters<typeof replace<T>>>): T[] {\n return replace(this, ...args);\n};\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const uniquify_by_key_1 = require("@telperion/js-utils/array/uniquify-by-key");
|
|
4
|
+
Array.prototype.uniquifyByKey = function (key) {
|
|
5
|
+
return (0, uniquify_by_key_1.uniquifyByKey)(this, key);
|
|
6
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
export interface Array<T> {
|
|
3
|
+
/**
|
|
4
|
+
* #### Uniquify By Key
|
|
5
|
+
*
|
|
6
|
+
* Removes objects from the array which the value of its specifed key included before by another
|
|
7
|
+
*
|
|
8
|
+
* * * *
|
|
9
|
+
* Example:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import "@telperion/js-utils/array/proto/uniquify-by-key";
|
|
12
|
+
*
|
|
13
|
+
* const array = [{a: 1}, {a: 1}, {a: 2}, {a: 3}, {a: 3}, {a: 4}];
|
|
14
|
+
*
|
|
15
|
+
* array.uniquifyByKey('a'); // [{a: 1}, {a: 2}, {a: 3}, {a: 4}]
|
|
16
|
+
* ```
|
|
17
|
+
* * * *
|
|
18
|
+
* @param key Key to search the value on
|
|
19
|
+
* @return The new uniquified array
|
|
20
|
+
*/
|
|
21
|
+
uniquifyByKey(key: keyof T): T[];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/uniquify-by-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AA0B1E,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,UAAsC,GAAY;IAChF,OAAO,aAAa,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC,CAAC","file":"uniquify-by-key.js","sourcesContent":["import { uniquifyByKey } from '@telperion/js-utils/array/uniquify-by-key';\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Uniquify By Key\n *\n * Removes objects from the array which the value of its specifed key included before by another\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/uniquify-by-key\";\n *\n * const array = [{a: 1}, {a: 1}, {a: 2}, {a: 3}, {a: 3}, {a: 4}];\n *\n * array.uniquifyByKey('a'); // [{a: 1}, {a: 2}, {a: 3}, {a: 4}]\n * ```\n * * * *\n * @param key Key to search the value on\n * @return The new uniquified array\n */\n uniquifyByKey(key: keyof T): T[];\n }\n}\n\nArray.prototype.uniquifyByKey = function<T extends object>(this: T[], key: keyof T): T[] {\n return uniquifyByKey(this, key);\n};\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
export interface Array<T> {
|
|
3
|
+
/**
|
|
4
|
+
* #### Uniquify
|
|
5
|
+
*
|
|
6
|
+
* Removes repeated items from the array
|
|
7
|
+
*
|
|
8
|
+
* * * *
|
|
9
|
+
* Example:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import "@telperion/js-utils/array/proto/uniquify";
|
|
12
|
+
*
|
|
13
|
+
* const array = ["a", "b", "c", "a", "b", "c"];
|
|
14
|
+
*
|
|
15
|
+
* array.uniquify(); // ["a", "b", "c"]
|
|
16
|
+
* ```
|
|
17
|
+
* * * *
|
|
18
|
+
* @return The new uniquified array
|
|
19
|
+
*/
|
|
20
|
+
uniquify(): T[];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/uniquify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAyB9D,KAAK,CAAC,SAAS,CAAC,QAAQ,GAAQ;IAC9B,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC,CAAC","file":"uniquify.js","sourcesContent":["import { uniquify } from '@telperion/js-utils/array/uniquify';\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Uniquify\n *\n * Removes repeated items from the array\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/uniquify\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n *\n * array.uniquify(); // [\"a\", \"b\", \"c\"]\n * ```\n * * * *\n * @return The new uniquified array\n */\n uniquify(): T[];\n }\n}\n\nArray.prototype.uniquify = <any>function<T>(this: T[]): T[] {\n return uniquify(this);\n};\n"]}
|
package/array/remove.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.remove = remove;
|
|
4
|
+
/**
|
|
5
|
+
* #### Remove
|
|
6
|
+
*
|
|
7
|
+
* Removes an item from the array
|
|
8
|
+
*
|
|
9
|
+
* Removes all item references if multi is set to `true`
|
|
10
|
+
*
|
|
11
|
+
* * * *
|
|
12
|
+
* Example:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { remove } from "@telperion/js-utils/array";
|
|
15
|
+
*
|
|
16
|
+
* const array = ["a", "b", "c", "a", "b", "c"];
|
|
17
|
+
*
|
|
18
|
+
* remove(array, "b"); // ["a", "c", "a", "b", "c"]
|
|
19
|
+
* remove(array, "b", true); // ["a", "c", "a", "c"]
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Prototype Example:
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import "@telperion/js-utils/array/proto/remove";
|
|
25
|
+
*
|
|
26
|
+
* const array = ["a", "b", "c", "a", "b", "c"];
|
|
27
|
+
*
|
|
28
|
+
* array.remove("b"); // ["a", "c", "a", "b", "c"]
|
|
29
|
+
* array.remove("b", true); // ["a", "c", "a", "c"]
|
|
30
|
+
* ```
|
|
31
|
+
* * * *
|
|
32
|
+
* @param array: Array to remove the item
|
|
33
|
+
* @param itemToRemove Item to remove
|
|
34
|
+
* @return New array
|
|
35
|
+
*/
|
|
36
|
+
function remove(array, item, multi = false) {
|
|
37
|
+
let index = array.indexOf(item);
|
|
38
|
+
if (index < 0) {
|
|
39
|
+
return [...array];
|
|
40
|
+
}
|
|
41
|
+
do {
|
|
42
|
+
array = [...array.slice(0, index), ...array.slice(index + 1)];
|
|
43
|
+
index = array.indexOf(item);
|
|
44
|
+
} while (multi && index > -1);
|
|
45
|
+
return array;
|
|
46
|
+
}
|