@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/arrayize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,QAAQ,CAAI,KAAc;IACxC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC","file":"arrayize.js","sourcesContent":["/**\n * Encapsulates a non array value with an array that contains it unless the value is already an array\n *\n * * * *\n * Example usage:\n * ```typescript\n * import { arrayize } from \"@telperion/js-utils\";\n *\n * const foo = 'foo';\n * const bar = ['bar'];\n * const fooArr = arrayize(foo); // ['foo'];\n * const barArr = arrayize(bar); // ['bar'];\n * ```\n * * * *\n * @param value Array or single value to capsulate\n */\nexport function arrayize<T>(value: T | T[]): T[] {\n return value instanceof Array ? value : [value];\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asyncMap = asyncMap;
|
|
4
|
+
/**
|
|
5
|
+
* #### Async Map
|
|
6
|
+
*
|
|
7
|
+
* Maps an array asynchronously
|
|
8
|
+
*
|
|
9
|
+
* * * *
|
|
10
|
+
* Example:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { asyncMap } "@telperion/js-utils/array";
|
|
13
|
+
*
|
|
14
|
+
* const array = [1, 2, 3];
|
|
15
|
+
*
|
|
16
|
+
* asyncMap(array, async value => {
|
|
17
|
+
* return await addOneAfterASecond(value);
|
|
18
|
+
* }).then(result => {
|
|
19
|
+
* console.log(result); // [2, 3, 4]
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Example as Array Prototype:
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import "@telperion/js-utils/array/proto/async-map";
|
|
26
|
+
*
|
|
27
|
+
* const array = [1, 2, 3];
|
|
28
|
+
*
|
|
29
|
+
* const result = await array.asyncMap(async value => await addOneAfterASecond(value));
|
|
30
|
+
* // [2, 3, 4]
|
|
31
|
+
* ```
|
|
32
|
+
* * * *
|
|
33
|
+
* @param array Array to map
|
|
34
|
+
* @param mapper Callback async function to map the array
|
|
35
|
+
* @return A promise contains asynchronusly mapped array result
|
|
36
|
+
*/
|
|
37
|
+
async function asyncMap(array, mapper) {
|
|
38
|
+
const promises = array.map(mapper);
|
|
39
|
+
return await Promise.all(promises);
|
|
40
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Async Map
|
|
3
|
+
*
|
|
4
|
+
* Maps an array asynchronously
|
|
5
|
+
*
|
|
6
|
+
* * * *
|
|
7
|
+
* Example:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { asyncMap } "@telperion/js-utils/array";
|
|
10
|
+
*
|
|
11
|
+
* const array = [1, 2, 3];
|
|
12
|
+
*
|
|
13
|
+
* asyncMap(array, async value => {
|
|
14
|
+
* return await addOneAfterASecond(value);
|
|
15
|
+
* }).then(result => {
|
|
16
|
+
* console.log(result); // [2, 3, 4]
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Example as Array Prototype:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import "@telperion/js-utils/array/proto/async-map";
|
|
23
|
+
*
|
|
24
|
+
* const array = [1, 2, 3];
|
|
25
|
+
*
|
|
26
|
+
* const result = await array.asyncMap(async value => await addOneAfterASecond(value));
|
|
27
|
+
* // [2, 3, 4]
|
|
28
|
+
* ```
|
|
29
|
+
* * * *
|
|
30
|
+
* @param array Array to map
|
|
31
|
+
* @param mapper Callback async function to map the array
|
|
32
|
+
* @return A promise contains asynchronusly mapped array result
|
|
33
|
+
*/
|
|
34
|
+
export declare function asyncMap<T, U>(array: T[], mapper: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Async Map
|
|
3
|
+
*
|
|
4
|
+
* Maps an array asynchronously
|
|
5
|
+
*
|
|
6
|
+
* * * *
|
|
7
|
+
* Example:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { asyncMap } "@telperion/js-utils/array";
|
|
10
|
+
*
|
|
11
|
+
* const array = [1, 2, 3];
|
|
12
|
+
*
|
|
13
|
+
* asyncMap(array, async value => {
|
|
14
|
+
* return await addOneAfterASecond(value);
|
|
15
|
+
* }).then(result => {
|
|
16
|
+
* console.log(result); // [2, 3, 4]
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Example as Array Prototype:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import "@telperion/js-utils/array/proto/async-map";
|
|
23
|
+
*
|
|
24
|
+
* const array = [1, 2, 3];
|
|
25
|
+
*
|
|
26
|
+
* const result = await array.asyncMap(async value => await addOneAfterASecond(value));
|
|
27
|
+
* // [2, 3, 4]
|
|
28
|
+
* ```
|
|
29
|
+
* * * *
|
|
30
|
+
* @param array Array to map
|
|
31
|
+
* @param mapper Callback async function to map the array
|
|
32
|
+
* @return A promise contains asynchronusly mapped array result
|
|
33
|
+
*/
|
|
34
|
+
export async function asyncMap(array, mapper) {
|
|
35
|
+
const promises = array.map(mapper);
|
|
36
|
+
return await Promise.all(promises);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=async-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/async-map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAO,KAAU,EAAE,MAA2D;IAC1G,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAEnC,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC","file":"async-map.js","sourcesContent":["/**\n * #### Async Map\n *\n * Maps an array asynchronously\n *\n * * * *\n * Example:\n * ```typescript\n * import { asyncMap } \"@telperion/js-utils/array\";\n *\n * const array = [1, 2, 3];\n *\n * asyncMap(array, async value => {\n * return await addOneAfterASecond(value);\n * }).then(result => {\n * console.log(result); // [2, 3, 4]\n * });\n * ```\n *\n * Example as Array Prototype:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/async-map\";\n *\n * const array = [1, 2, 3];\n *\n * const result = await array.asyncMap(async value => await addOneAfterASecond(value));\n * // [2, 3, 4]\n * ```\n * * * *\n * @param array Array to map\n * @param mapper Callback async function to map the array\n * @return A promise contains asynchronusly mapped array result\n */\nexport async function asyncMap<T, U>(array: T[], mapper: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]> {\n const promises = array.map(mapper);\n\n return await Promise.all(promises);\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compact = compact;
|
|
4
|
+
const is_truthy_1 = require("@telperion/js-utils/is-truthy");
|
|
5
|
+
/**
|
|
6
|
+
* #### Filters falsy values of the given array
|
|
7
|
+
* * does not modify the original array
|
|
8
|
+
* * Values to be filtered: `[undefined, null, "", 0, false, NaN]`
|
|
9
|
+
*
|
|
10
|
+
* * * *
|
|
11
|
+
* Example usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { compact } from "@telperion/js-utils/array";
|
|
14
|
+
*
|
|
15
|
+
* const arr = [undefined, "", false, 0, 1, "1"];
|
|
16
|
+
* const compacted = compact(arr); // [1, "1"];
|
|
17
|
+
*
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Example as Array Prototype:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import "@telperion/js-utils/array/proto/compact";
|
|
23
|
+
*
|
|
24
|
+
* const arr = [undefined, "", false, 0, 1, "1"];
|
|
25
|
+
* const compacted = arr.compact(); // [1, "1"];
|
|
26
|
+
* ```
|
|
27
|
+
* * * *
|
|
28
|
+
* @param arrayToCompact array to compact
|
|
29
|
+
* @typeparam T type of array
|
|
30
|
+
* @returns __a new__ compacted array
|
|
31
|
+
*/
|
|
32
|
+
function compact(arrayToCompact) {
|
|
33
|
+
return arrayToCompact.filter(is_truthy_1.isTruthy);
|
|
34
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Filters falsy values of the given array
|
|
3
|
+
* * does not modify the original array
|
|
4
|
+
* * Values to be filtered: `[undefined, null, "", 0, false, NaN]`
|
|
5
|
+
*
|
|
6
|
+
* * * *
|
|
7
|
+
* Example usage:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { compact } from "@telperion/js-utils/array";
|
|
10
|
+
*
|
|
11
|
+
* const arr = [undefined, "", false, 0, 1, "1"];
|
|
12
|
+
* const compacted = compact(arr); // [1, "1"];
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Example as Array Prototype:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import "@telperion/js-utils/array/proto/compact";
|
|
19
|
+
*
|
|
20
|
+
* const arr = [undefined, "", false, 0, 1, "1"];
|
|
21
|
+
* const compacted = arr.compact(); // [1, "1"];
|
|
22
|
+
* ```
|
|
23
|
+
* * * *
|
|
24
|
+
* @param arrayToCompact array to compact
|
|
25
|
+
* @typeparam T type of array
|
|
26
|
+
* @returns __a new__ compacted array
|
|
27
|
+
*/
|
|
28
|
+
export declare function compact<T = any>(arrayToCompact: T[]): T[];
|
package/array/compact.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isTruthy } from '@telperion/js-utils/is-truthy';
|
|
2
|
+
/**
|
|
3
|
+
* #### Filters falsy values of the given array
|
|
4
|
+
* * does not modify the original array
|
|
5
|
+
* * Values to be filtered: `[undefined, null, "", 0, false, NaN]`
|
|
6
|
+
*
|
|
7
|
+
* * * *
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { compact } from "@telperion/js-utils/array";
|
|
11
|
+
*
|
|
12
|
+
* const arr = [undefined, "", false, 0, 1, "1"];
|
|
13
|
+
* const compacted = compact(arr); // [1, "1"];
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Example as Array Prototype:
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import "@telperion/js-utils/array/proto/compact";
|
|
20
|
+
*
|
|
21
|
+
* const arr = [undefined, "", false, 0, 1, "1"];
|
|
22
|
+
* const compacted = arr.compact(); // [1, "1"];
|
|
23
|
+
* ```
|
|
24
|
+
* * * *
|
|
25
|
+
* @param arrayToCompact array to compact
|
|
26
|
+
* @typeparam T type of array
|
|
27
|
+
* @returns __a new__ compacted array
|
|
28
|
+
*/
|
|
29
|
+
export function compact(arrayToCompact) {
|
|
30
|
+
return arrayToCompact.filter(isTruthy);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=compact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/compact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,OAAO,CAAU,cAAmB;IAClD,OAAO,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACzC,CAAC","file":"compact.js","sourcesContent":["import { isTruthy } from '@telperion/js-utils/is-truthy';\n\n/**\n * #### Filters falsy values of the given array\n * * does not modify the original array\n * * Values to be filtered: `[undefined, null, \"\", 0, false, NaN]`\n *\n * * * *\n * Example usage:\n * ```typescript\n * import { compact } from \"@telperion/js-utils/array\";\n *\n * const arr = [undefined, \"\", false, 0, 1, \"1\"];\n * const compacted = compact(arr); // [1, \"1\"];\n *\n * ```\n *\n * Example as Array Prototype:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/compact\";\n *\n * const arr = [undefined, \"\", false, 0, 1, \"1\"];\n * const compacted = arr.compact(); // [1, \"1\"];\n * ```\n * * * *\n * @param arrayToCompact array to compact\n * @typeparam T type of array\n * @returns __a\tnew__ compacted array\n */\nexport function compact<T = any>(arrayToCompact: T[]): T[] {\n return arrayToCompact.filter(isTruthy);\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.difference = difference;
|
|
4
|
+
function difference(base, substraction, allDiff = false) {
|
|
5
|
+
if (base instanceof Set) {
|
|
6
|
+
return new Set(difference(Array.from(base), substraction));
|
|
7
|
+
}
|
|
8
|
+
const subs = Array.from(substraction);
|
|
9
|
+
return base.filter(value => {
|
|
10
|
+
const index = subs.indexOf(value);
|
|
11
|
+
if (index > -1 && allDiff) {
|
|
12
|
+
subs.splice(index, 1);
|
|
13
|
+
}
|
|
14
|
+
return index === -1;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Difference Substraction Type
|
|
3
|
+
*/
|
|
4
|
+
export type Substraction<T = any> = T[] | Set<T>;
|
|
5
|
+
/**
|
|
6
|
+
* #### Difference
|
|
7
|
+
*
|
|
8
|
+
* Gets the difference of the two arrays or sets
|
|
9
|
+
*
|
|
10
|
+
* * * *
|
|
11
|
+
* Example:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { difference } from "@telperion/js-utils/array";
|
|
14
|
+
*
|
|
15
|
+
* const base = ["a", "b", "c", "d", "a", "b", "c", "d"];
|
|
16
|
+
*
|
|
17
|
+
* difference(base, ["a", "b"]); // ["c", "d", "c", "d"]
|
|
18
|
+
* difference(base, ["a", "b"], true); // ["c", "d", "a", "b", "c", "d"]
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Array Prototype Example:
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import "@telperion/js-utils/array/proto/difference";
|
|
24
|
+
*
|
|
25
|
+
* const base = ["a", "b", "c", "d", "a", "b", "c", "d"];
|
|
26
|
+
*
|
|
27
|
+
* base.difference(["a", "b"]); // ["c", "d", "c", "d"]
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Set Prototype Example:
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import "@telperion/js-utils/set/proto/difference";
|
|
33
|
+
*
|
|
34
|
+
* const base = new Set(["a", "b", "c", "d"]);
|
|
35
|
+
*
|
|
36
|
+
* base.difference(["a", "b"]); // Set(["c", "d"])
|
|
37
|
+
* ```
|
|
38
|
+
* * * *
|
|
39
|
+
* @param base Base Set or Array
|
|
40
|
+
* @param substraction Set or Array to remove its values from the base
|
|
41
|
+
* @param allDiff By default all the same items encountered in substraction will be removed, set this argument as true to get real difference
|
|
42
|
+
* @returns Difference of base from substraction
|
|
43
|
+
*/
|
|
44
|
+
export declare function difference<T>(base: T[], substraction: Substraction<T>, allDiff?: boolean): T[];
|
|
45
|
+
export declare function difference<T>(base: Set<T>, substraction: Substraction<T>, allDiff?: boolean): Set<T>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function difference(base, substraction, allDiff = false) {
|
|
2
|
+
if (base instanceof Set) {
|
|
3
|
+
return new Set(difference(Array.from(base), substraction));
|
|
4
|
+
}
|
|
5
|
+
const subs = Array.from(substraction);
|
|
6
|
+
return base.filter(value => {
|
|
7
|
+
const index = subs.indexOf(value);
|
|
8
|
+
if (index > -1 && allDiff) {
|
|
9
|
+
subs.splice(index, 1);
|
|
10
|
+
}
|
|
11
|
+
return index === -1;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=difference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/difference.ts"],"names":[],"mappings":"AA+CA,MAAM,UAAU,UAAU,CAAI,IAAkB,EAAE,YAA6B,EAAE,OAAO,GAAG,KAAK;IAC9F,IAAI,IAAI,YAAY,GAAG,EAAE,CAAC;QACxB,OAAO,IAAI,GAAG,CAAI,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAEtC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAElC,IAAI,KAAK,GAAG,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACxB,CAAC;QAED,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;AACL,CAAC","file":"difference.js","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/**\n * Difference Substraction Type\n */\nexport type Substraction<T = any> = T[] | Set<T>;\n\n/**\n * #### Difference\n *\n * Gets the difference of the two arrays or sets\n *\n * * * *\n * Example:\n * ```typescript\n * import { difference } from \"@telperion/js-utils/array\";\n *\n * const base = [\"a\", \"b\", \"c\", \"d\", \"a\", \"b\", \"c\", \"d\"];\n *\n * difference(base, [\"a\", \"b\"]); // [\"c\", \"d\", \"c\", \"d\"]\n * difference(base, [\"a\", \"b\"], true); // [\"c\", \"d\", \"a\", \"b\", \"c\", \"d\"]\n * ```\n *\n * Array Prototype Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/difference\";\n *\n * const base = [\"a\", \"b\", \"c\", \"d\", \"a\", \"b\", \"c\", \"d\"];\n *\n * base.difference([\"a\", \"b\"]); // [\"c\", \"d\", \"c\", \"d\"]\n * ```\n *\n * Set Prototype Example:\n * ```typescript\n * import \"@telperion/js-utils/set/proto/difference\";\n *\n * const base = new Set([\"a\", \"b\", \"c\", \"d\"]);\n *\n * base.difference([\"a\", \"b\"]); // Set([\"c\", \"d\"])\n * ```\n * * * *\n * @param base Base Set or 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 */\nexport function difference<T>(base: T[], substraction: Substraction<T>, allDiff?: boolean): T[];\nexport function difference<T>(base: Set<T>, substraction: Substraction<T>, allDiff?: boolean): Set<T>;\nexport function difference<T>(base: T[] | Set<T>, substraction: Substraction<T>, allDiff = false): T[] | Set<T> {\n if (base instanceof Set) {\n return new Set<T>(difference(Array.from(base), substraction));\n }\n\n const subs = Array.from(substraction);\n\n return base.filter(value => {\n const index = subs.indexOf(value);\n\n if (index > -1 && allDiff) {\n subs.splice(index, 1);\n }\n\n return index === -1;\n });\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findByKey = findByKey;
|
|
4
|
+
/**
|
|
5
|
+
* #### Find By Key
|
|
6
|
+
*
|
|
7
|
+
* Finds an object in an array by matching the value set on the key
|
|
8
|
+
*
|
|
9
|
+
* * * *
|
|
10
|
+
* Example:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { findByKey } from "@telperion/js-utils/array";
|
|
13
|
+
*
|
|
14
|
+
* const array = [{a: 1}, {a: 2}, {a: 3}];
|
|
15
|
+
*
|
|
16
|
+
* findByKey(array, "a", 2); // {a: 2}
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Prototype Example:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import "@telperion/js-utils/array/proto/find-by-key";
|
|
22
|
+
*
|
|
23
|
+
* const array = [{a: 1}, {a: 2}, {a: 3}];
|
|
24
|
+
*
|
|
25
|
+
* array.findByKey("a", 2); // {a: 2}
|
|
26
|
+
* ```
|
|
27
|
+
* * * *
|
|
28
|
+
* @param array Collection of the objects
|
|
29
|
+
* @param key Key to search the value on
|
|
30
|
+
* @param value Value to match for the key
|
|
31
|
+
* @return Found object or undefined
|
|
32
|
+
*/
|
|
33
|
+
function findByKey(array, key, value) {
|
|
34
|
+
return array.find(item => item[key] === value);
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Find By Key
|
|
3
|
+
*
|
|
4
|
+
* Finds an object in an array by matching the value set on the key
|
|
5
|
+
*
|
|
6
|
+
* * * *
|
|
7
|
+
* Example:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { findByKey } from "@telperion/js-utils/array";
|
|
10
|
+
*
|
|
11
|
+
* const array = [{a: 1}, {a: 2}, {a: 3}];
|
|
12
|
+
*
|
|
13
|
+
* findByKey(array, "a", 2); // {a: 2}
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Prototype Example:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import "@telperion/js-utils/array/proto/find-by-key";
|
|
19
|
+
*
|
|
20
|
+
* const array = [{a: 1}, {a: 2}, {a: 3}];
|
|
21
|
+
*
|
|
22
|
+
* array.findByKey("a", 2); // {a: 2}
|
|
23
|
+
* ```
|
|
24
|
+
* * * *
|
|
25
|
+
* @param array Collection of the objects
|
|
26
|
+
* @param key Key to search the value on
|
|
27
|
+
* @param value Value to match for the key
|
|
28
|
+
* @return Found object or undefined
|
|
29
|
+
*/
|
|
30
|
+
export declare function findByKey<T, K extends keyof T>(array: T[], key: K, value: T[K]): T | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Find By Key
|
|
3
|
+
*
|
|
4
|
+
* Finds an object in an array by matching the value set on the key
|
|
5
|
+
*
|
|
6
|
+
* * * *
|
|
7
|
+
* Example:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { findByKey } from "@telperion/js-utils/array";
|
|
10
|
+
*
|
|
11
|
+
* const array = [{a: 1}, {a: 2}, {a: 3}];
|
|
12
|
+
*
|
|
13
|
+
* findByKey(array, "a", 2); // {a: 2}
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Prototype Example:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import "@telperion/js-utils/array/proto/find-by-key";
|
|
19
|
+
*
|
|
20
|
+
* const array = [{a: 1}, {a: 2}, {a: 3}];
|
|
21
|
+
*
|
|
22
|
+
* array.findByKey("a", 2); // {a: 2}
|
|
23
|
+
* ```
|
|
24
|
+
* * * *
|
|
25
|
+
* @param array Collection of the objects
|
|
26
|
+
* @param key Key to search the value on
|
|
27
|
+
* @param value Value to match for the key
|
|
28
|
+
* @return Found object or undefined
|
|
29
|
+
*/
|
|
30
|
+
export function findByKey(array, key, value) {
|
|
31
|
+
return array.find(item => item[key] === value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=find-by-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/find-by-key.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,SAAS,CAAwB,KAAU,EAAE,GAAM,EAAE,KAAW;IAC9E,OAAO,KAAK,CAAC,IAAI,CAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,CAAE,CAAC;AACnD,CAAC","file":"find-by-key.js","sourcesContent":["/**\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 { findByKey } from \"@telperion/js-utils/array\";\n *\n * const array = [{a: 1}, {a: 2}, {a: 3}];\n *\n * findByKey(array, \"a\", 2); // {a: 2}\n * ```\n *\n * Prototype 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 array Collection of the objects\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 */\nexport function findByKey<T, K extends keyof T>( array: T[], key: K, value: T[K] ): T | undefined {\n return array.find( item => item[key] === value );\n}\n"]}
|
package/array/index.cjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("@telperion/js-utils/array/arrayize"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("@telperion/js-utils/array/async-map"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("@telperion/js-utils/array/compact"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("@telperion/js-utils/array/difference"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("@telperion/js-utils/array/find-by-key"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("@telperion/js-utils/array/intersection"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("@telperion/js-utils/array/limit"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("@telperion/js-utils/array/remove"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("@telperion/js-utils/array/replace"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("@telperion/js-utils/array/uniquify"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("@telperion/js-utils/array/uniquify-by-key"), exports);
|
package/array/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from '@telperion/js-utils/array/arrayize';
|
|
2
|
+
export * from '@telperion/js-utils/array/async-map';
|
|
3
|
+
export * from '@telperion/js-utils/array/compact';
|
|
4
|
+
export * from '@telperion/js-utils/array/difference';
|
|
5
|
+
export * from '@telperion/js-utils/array/find-by-key';
|
|
6
|
+
export * from '@telperion/js-utils/array/intersection';
|
|
7
|
+
export * from '@telperion/js-utils/array/limit';
|
|
8
|
+
export * from '@telperion/js-utils/array/remove';
|
|
9
|
+
export * from '@telperion/js-utils/array/replace';
|
|
10
|
+
export * from '@telperion/js-utils/array/uniquify';
|
|
11
|
+
export * from '@telperion/js-utils/array/uniquify-by-key';
|
package/array/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from '@telperion/js-utils/array/arrayize';
|
|
2
|
+
export * from '@telperion/js-utils/array/async-map';
|
|
3
|
+
export * from '@telperion/js-utils/array/compact';
|
|
4
|
+
export * from '@telperion/js-utils/array/difference';
|
|
5
|
+
export * from '@telperion/js-utils/array/find-by-key';
|
|
6
|
+
export * from '@telperion/js-utils/array/intersection';
|
|
7
|
+
export * from '@telperion/js-utils/array/limit';
|
|
8
|
+
export * from '@telperion/js-utils/array/remove';
|
|
9
|
+
export * from '@telperion/js-utils/array/replace';
|
|
10
|
+
export * from '@telperion/js-utils/array/uniquify';
|
|
11
|
+
export * from '@telperion/js-utils/array/uniquify-by-key';
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,qCAAqC,CAAC;AACpD,cAAc,mCAAmC,CAAC;AAClD,cAAc,sCAAsC,CAAC;AACrD,cAAc,uCAAuC,CAAC;AACtD,cAAc,wCAAwC,CAAC;AACvD,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,2CAA2C,CAAC","file":"index.js","sourcesContent":["export * from '@telperion/js-utils/array/arrayize';\nexport * from '@telperion/js-utils/array/async-map';\nexport * from '@telperion/js-utils/array/compact';\nexport * from '@telperion/js-utils/array/difference';\nexport * from '@telperion/js-utils/array/find-by-key';\nexport * from '@telperion/js-utils/array/intersection';\nexport * from '@telperion/js-utils/array/limit';\nexport * from '@telperion/js-utils/array/remove';\nexport * from '@telperion/js-utils/array/replace';\nexport * from '@telperion/js-utils/array/uniquify';\nexport * from '@telperion/js-utils/array/uniquify-by-key';\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.intersection = intersection;
|
|
4
|
+
function intersection(base, inclusion, allEquals = true) {
|
|
5
|
+
if (base instanceof Set) {
|
|
6
|
+
return new Set(intersection(Array.from(base), inclusion));
|
|
7
|
+
}
|
|
8
|
+
const incs = Array.from(inclusion);
|
|
9
|
+
return base.filter(value => {
|
|
10
|
+
const index = incs.indexOf(value);
|
|
11
|
+
if (index > -1 && !allEquals) {
|
|
12
|
+
incs.splice(index, 1);
|
|
13
|
+
}
|
|
14
|
+
return index > -1;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intersection Inclusion Type
|
|
3
|
+
*/
|
|
4
|
+
export type Inclusion = any[] | Set<any>;
|
|
5
|
+
/**
|
|
6
|
+
* Intersection
|
|
7
|
+
*
|
|
8
|
+
* Gets the intersection of the two arrays or sets
|
|
9
|
+
*
|
|
10
|
+
* * * *
|
|
11
|
+
* _Example:_
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { intersection } from "@telperion/js-utils/array";
|
|
14
|
+
*
|
|
15
|
+
* const base = ["a", "b", "c", "d", "a", "b", "c", "d"];
|
|
16
|
+
*
|
|
17
|
+
* intersection(base, ["a", "b", "x"]); // ["a", "b", "a", "b"]
|
|
18
|
+
* intersection(base, ["a", "b", "x"], false); // ["a", "b"]
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* _Array Prototype Example:_
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import "@telperion/js-utils/array/proto/intersection";
|
|
24
|
+
*
|
|
25
|
+
* const base = ["a", "b", "c", "d", "a", "b", "c", "d"];
|
|
26
|
+
*
|
|
27
|
+
* base.intersection(["a", "b"]); // ["a", "b", "a", "b"]
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* _Set Prototype Example:_
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import "@telperion/js-utils/set/proto/intersection";
|
|
33
|
+
*
|
|
34
|
+
* const base = new Set(["a", "b", "c", "d"]);
|
|
35
|
+
*
|
|
36
|
+
* base.intersection(["a", "b"]); // Set(["a", "b"])
|
|
37
|
+
* ```
|
|
38
|
+
* * * *
|
|
39
|
+
* @param base Base Set or Array
|
|
40
|
+
* @param inclusion Set or Array to include its values
|
|
41
|
+
* @param allEquals By default all the same items encountered in the inclusion will be included, set this argument as false to get real intersection
|
|
42
|
+
* @returns Intersection of base and inclusion
|
|
43
|
+
*/
|
|
44
|
+
export declare function intersection<T>(base: T[], inclusion: Inclusion, allEquals?: boolean): T[];
|
|
45
|
+
export declare function intersection<T>(base: Set<T>, inclusion: Inclusion, allEquals?: boolean): Set<T>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function intersection(base, inclusion, allEquals = true) {
|
|
2
|
+
if (base instanceof Set) {
|
|
3
|
+
return new Set(intersection(Array.from(base), inclusion));
|
|
4
|
+
}
|
|
5
|
+
const incs = Array.from(inclusion);
|
|
6
|
+
return base.filter(value => {
|
|
7
|
+
const index = incs.indexOf(value);
|
|
8
|
+
if (index > -1 && !allEquals) {
|
|
9
|
+
incs.splice(index, 1);
|
|
10
|
+
}
|
|
11
|
+
return index > -1;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=intersection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/array/intersection.ts"],"names":[],"mappings":"AA8CA,MAAM,UAAU,YAAY,CAAI,IAAkB,EAAE,SAAoB,EAAE,SAAS,GAAG,IAAI;IACxF,IAAI,IAAI,YAAY,GAAG,EAAE,CAAC;QACxB,OAAO,IAAI,GAAG,CAAI,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,IAAI,GAAQ,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAExC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAElC,IAAI,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACxB,CAAC;QAED,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC","file":"intersection.js","sourcesContent":["/**\n * Intersection Inclusion Type\n */\nexport type Inclusion = any[] | Set<any>;\n\n/**\n * Intersection\n *\n * Gets the intersection of the two arrays or sets\n *\n * * * *\n * _Example:_\n * ```typescript\n * import { intersection } from \"@telperion/js-utils/array\";\n *\n * const base = [\"a\", \"b\", \"c\", \"d\", \"a\", \"b\", \"c\", \"d\"];\n *\n * intersection(base, [\"a\", \"b\", \"x\"]); // [\"a\", \"b\", \"a\", \"b\"]\n * intersection(base, [\"a\", \"b\", \"x\"], false); // [\"a\", \"b\"]\n * ```\n *\n * _Array Prototype 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 * ```\n *\n * _Set Prototype Example:_\n * ```typescript\n * import \"@telperion/js-utils/set/proto/intersection\";\n *\n * const base = new Set([\"a\", \"b\", \"c\", \"d\"]);\n *\n * base.intersection([\"a\", \"b\"]); // Set([\"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 */\nexport function intersection<T>(base: T[], inclusion: Inclusion, allEquals?: boolean): T[];\nexport function intersection<T>(base: Set<T>, inclusion: Inclusion, allEquals?: boolean): Set<T>;\nexport function intersection<T>(base: T[] | Set<T>, inclusion: Inclusion, allEquals = true): T[] | Set<T> {\n if (base instanceof Set) {\n return new Set<T>(intersection(Array.from(base), inclusion));\n }\n\n const incs: T[] = Array.from(inclusion);\n\n return base.filter(value => {\n const index = incs.indexOf(value);\n\n if (index > -1 && !allEquals) {\n incs.splice(index, 1);\n }\n\n return index > -1;\n });\n}\n"]}
|
package/array/limit.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.limit = limit;
|
|
4
|
+
/**
|
|
5
|
+
* #### Limit
|
|
6
|
+
*
|
|
7
|
+
* Returns first `n` children of an array
|
|
8
|
+
*
|
|
9
|
+
* * * *
|
|
10
|
+
* Example:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { limit } from "@telperion/js-utils/array";
|
|
13
|
+
*
|
|
14
|
+
* const array = ["a", "b", "c", "d", "e", "f"];
|
|
15
|
+
*
|
|
16
|
+
* limit(array, 3); // ["a", "b", "c"]
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Prototype Example:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import "@telperion/js-utils/array/proto/limit";
|
|
22
|
+
*
|
|
23
|
+
* const array = ["a", "b", "c", "d", "e", "f"];
|
|
24
|
+
*
|
|
25
|
+
* array.limit(3); // ["a", "b", "c"]
|
|
26
|
+
* ```
|
|
27
|
+
* * * *
|
|
28
|
+
* @param array: Array to return its children
|
|
29
|
+
* @param count Limiter
|
|
30
|
+
* @return New array
|
|
31
|
+
*/
|
|
32
|
+
function limit(array, count) {
|
|
33
|
+
if (count < 0) {
|
|
34
|
+
count = Number.MAX_SAFE_INTEGER;
|
|
35
|
+
}
|
|
36
|
+
return array.slice(0, count);
|
|
37
|
+
}
|
package/array/limit.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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 declare function limit<T = any>(array: T[], count: number): T[];
|