es-toolkit 0.0.1-dev.20
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/CHANGELOG.md +5 -0
- package/README.md +31 -0
- package/dist/array/chunk.d.ts +24 -0
- package/dist/array/chunk.spec.d.ts +1 -0
- package/dist/array/difference.d.ts +23 -0
- package/dist/array/difference.spec.d.ts +1 -0
- package/dist/array/differenceBy.d.ts +26 -0
- package/dist/array/differenceBy.spec.d.ts +1 -0
- package/dist/array/differenceWith.d.ts +22 -0
- package/dist/array/differenceWith.spec.d.ts +1 -0
- package/dist/array/drop.d.ts +16 -0
- package/dist/array/drop.spec.d.ts +1 -0
- package/dist/array/dropRight.d.ts +16 -0
- package/dist/array/dropRight.spec.d.ts +1 -0
- package/dist/array/dropRightWhile.d.ts +18 -0
- package/dist/array/dropRightWhile.spec.d.ts +1 -0
- package/dist/array/dropWhile.d.ts +18 -0
- package/dist/array/dropWhile.spec.d.ts +1 -0
- package/dist/array/groupBy.d.ts +31 -0
- package/dist/array/groupBy.spec.d.ts +1 -0
- package/dist/array/index.d.ts +30 -0
- package/dist/array/index.js +991 -0
- package/dist/array/intersection.d.ts +18 -0
- package/dist/array/intersection.spec.d.ts +1 -0
- package/dist/array/intersectionBy.d.ts +21 -0
- package/dist/array/intersectionBy.spec.d.ts +1 -0
- package/dist/array/intersectionWith.d.ts +22 -0
- package/dist/array/intersectionWith.spec.d.ts +1 -0
- package/dist/array/partition.d.ts +22 -0
- package/dist/array/partition.spec.d.ts +1 -0
- package/dist/array/sample.d.ts +14 -0
- package/dist/array/sample.spec.d.ts +1 -0
- package/dist/array/shuffle.d.ts +14 -0
- package/dist/array/shuffle.spec.d.ts +1 -0
- package/dist/array/take.d.ts +23 -0
- package/dist/array/take.spec.d.ts +1 -0
- package/dist/array/takeRight.d.ts +21 -0
- package/dist/array/takeRight.spec.d.ts +1 -0
- package/dist/array/takeRightWhile.d.ts +18 -0
- package/dist/array/takeRightWhile.spec.d.ts +1 -0
- package/dist/array/takeWhile.d.ts +19 -0
- package/dist/array/takeWhile.spec.d.ts +1 -0
- package/dist/array/union.d.ts +17 -0
- package/dist/array/union.spec.d.ts +1 -0
- package/dist/array/unionBy.d.ts +21 -0
- package/dist/array/unionBy.spec.d.ts +1 -0
- package/dist/array/unionWith.d.ts +20 -0
- package/dist/array/unionWith.spec.d.ts +1 -0
- package/dist/array/uniq.d.ts +15 -0
- package/dist/array/uniq.spec.d.ts +1 -0
- package/dist/array/uniqBy.d.ts +12 -0
- package/dist/array/uniqBy.spec.d.ts +1 -0
- package/dist/array/uniqWith.d.ts +12 -0
- package/dist/array/uniqWith.spec.d.ts +1 -0
- package/dist/array/xor.d.ts +17 -0
- package/dist/array/xor.spec.d.ts +1 -0
- package/dist/array/xorBy.d.ts +20 -0
- package/dist/array/xorBy.spec.d.ts +1 -0
- package/dist/array/xorWith.d.ts +19 -0
- package/dist/array/xorWith.spec.d.ts +1 -0
- package/dist/array/zip.d.ts +25 -0
- package/dist/array/zip.spec.d.ts +1 -0
- package/dist/array/zipWith.d.ts +32 -0
- package/dist/array/zipWith.spec.d.ts +1 -0
- package/dist/function/debounce.d.ts +24 -0
- package/dist/function/debounce.spec.d.ts +1 -0
- package/dist/function/index.d.ts +3 -0
- package/dist/function/index.js +112 -0
- package/dist/function/once.d.ts +17 -0
- package/dist/function/once.spec.d.ts +1 -0
- package/dist/function/throttle.d.ts +26 -0
- package/dist/function/throttle.spec.d.ts +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1514 -0
- package/dist/math/clamp.d.ts +19 -0
- package/dist/math/clamp.spec.d.ts +1 -0
- package/dist/math/index.d.ts +3 -0
- package/dist/math/index.js +148 -0
- package/dist/math/round.d.ts +16 -0
- package/dist/math/round.spec.d.ts +1 -0
- package/dist/math/sum.d.ts +14 -0
- package/dist/math/sum.spec.d.ts +1 -0
- package/dist/object/index.d.ts +4 -0
- package/dist/object/index.js +286 -0
- package/dist/object/omit.d.ts +16 -0
- package/dist/object/omit.spec.d.ts +1 -0
- package/dist/object/omitBy.d.ts +19 -0
- package/dist/object/omitBy.spec.d.ts +1 -0
- package/dist/object/pick.d.ts +16 -0
- package/dist/object/pick.spec.d.ts +1 -0
- package/dist/object/pickBy.d.ts +19 -0
- package/dist/object/pickBy.spec.d.ts +1 -0
- package/dist/predicate/index.d.ts +4 -0
- package/dist/predicate/index.js +98 -0
- package/dist/predicate/isNil.d.ts +20 -0
- package/dist/predicate/isNil.spec.d.ts +1 -0
- package/dist/predicate/isNotNil.d.ts +16 -0
- package/dist/predicate/isNotNil.spec.d.ts +1 -0
- package/dist/predicate/isNull.d.ts +21 -0
- package/dist/predicate/isNull.spec.d.ts +1 -0
- package/dist/predicate/isUndefined.d.ts +21 -0
- package/dist/predicate/isUndefined.spec.d.ts +1 -0
- package/dist/promise/delay.d.ts +19 -0
- package/dist/promise/delay.spec.d.ts +1 -0
- package/dist/promise/index.d.ts +1 -0
- package/dist/promise/index.js +29 -0
- package/esm/_virtual/_rollupPluginBabelHelpers.mjs +163 -0
- package/esm/array/_virtual/_rollupPluginBabelHelpers.mjs +78 -0
- package/esm/array/chunk.mjs +38 -0
- package/esm/array/difference.mjs +29 -0
- package/esm/array/differenceBy.mjs +35 -0
- package/esm/array/differenceWith.mjs +30 -0
- package/esm/array/drop.mjs +20 -0
- package/esm/array/dropRight.mjs +20 -0
- package/esm/array/dropRightWhile.mjs +26 -0
- package/esm/array/dropWhile.mjs +25 -0
- package/esm/array/groupBy.mjs +54 -0
- package/esm/array/index.mjs +30 -0
- package/esm/array/intersection.mjs +24 -0
- package/esm/array/intersectionBy.mjs +30 -0
- package/esm/array/intersectionWith.mjs +30 -0
- package/esm/array/partition.mjs +46 -0
- package/esm/array/sample.mjs +19 -0
- package/esm/array/shuffle.mjs +27 -0
- package/esm/array/take.mjs +27 -0
- package/esm/array/takeRight.mjs +28 -0
- package/esm/array/takeRightWhile.mjs +27 -0
- package/esm/array/takeWhile.mjs +41 -0
- package/esm/array/union.mjs +23 -0
- package/esm/array/unionBy.mjs +35 -0
- package/esm/array/unionWith.mjs +26 -0
- package/esm/array/uniq.mjs +37 -0
- package/esm/array/uniqBy.mjs +20 -0
- package/esm/array/uniqWith.mjs +39 -0
- package/esm/array/xor.mjs +25 -0
- package/esm/array/xorBy.mjs +30 -0
- package/esm/array/xorWith.mjs +29 -0
- package/esm/array/zip.mjs +52 -0
- package/esm/array/zipWith.mjs +54 -0
- package/esm/function/debounce.mjs +39 -0
- package/esm/function/index.mjs +3 -0
- package/esm/function/once.mjs +31 -0
- package/esm/function/throttle.mjs +38 -0
- package/esm/index.mjs +45 -0
- package/esm/math/_virtual/_rollupPluginBabelHelpers.mjs +66 -0
- package/esm/math/clamp.mjs +26 -0
- package/esm/math/index.mjs +3 -0
- package/esm/math/round.mjs +22 -0
- package/esm/math/sum.mjs +33 -0
- package/esm/object/_virtual/_rollupPluginBabelHelpers.mjs +151 -0
- package/esm/object/index.mjs +4 -0
- package/esm/object/omit.mjs +35 -0
- package/esm/object/omitBy.mjs +35 -0
- package/esm/object/pick.mjs +35 -0
- package/esm/object/pickBy.mjs +35 -0
- package/esm/predicate/index.mjs +4 -0
- package/esm/predicate/isNil.mjs +24 -0
- package/esm/predicate/isNotNil.mjs +20 -0
- package/esm/predicate/isNull.mjs +25 -0
- package/esm/predicate/isUndefined.mjs +25 -0
- package/esm/promise/delay.mjs +25 -0
- package/esm/promise/index.mjs +1 -0
- package/package.json +108 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a given value is null or undefined.
|
|
7
|
+
*
|
|
8
|
+
* This function tests whether the provided value is either `null` or `undefined`.
|
|
9
|
+
* It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
|
|
10
|
+
*
|
|
11
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
|
|
12
|
+
*
|
|
13
|
+
* @param {unknown} x - The value to test for null or undefined.
|
|
14
|
+
* @returns {boolean} `true` if the value is null or undefined, `false` otherwise.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* * const value1 = null;
|
|
18
|
+
* const value2 = undefined;
|
|
19
|
+
* const value3 = 42;
|
|
20
|
+
* const result1 = isNil(value1); // true
|
|
21
|
+
* const result2 = isNil(value2); // true
|
|
22
|
+
* const result3 = isNil(value3); // false
|
|
23
|
+
*/
|
|
24
|
+
function isNil(x) {
|
|
25
|
+
return x == null || x == undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Checks if the given value is not null nor undefined.
|
|
30
|
+
*
|
|
31
|
+
* The main use of this function is to be used with TypeScript as a type predicate.
|
|
32
|
+
*
|
|
33
|
+
* @param {T | null | undefined} x - The value to test if it is not null nor undefined.
|
|
34
|
+
* @returns {x is T} True if the value is not null nor undefined, false otherwise.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Here the type of `arr` is (number | undefined)[]
|
|
38
|
+
* const arr = [1, undefined, 3];
|
|
39
|
+
* // Here the type of `result` is number[]
|
|
40
|
+
* const result = arr.filter(isNotNil);
|
|
41
|
+
* // result will be [1, 3]
|
|
42
|
+
*/
|
|
43
|
+
function isNotNil(x) {
|
|
44
|
+
return x != null && x != undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Checks if the given value is null.
|
|
49
|
+
*
|
|
50
|
+
* This function tests whether the provided value is strictly equal to `null`.
|
|
51
|
+
* It returns `true` if the value is `null`, and `false` otherwise.
|
|
52
|
+
*
|
|
53
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`.
|
|
54
|
+
*
|
|
55
|
+
* @param {unknown} x - The value to test if it is null.
|
|
56
|
+
* @returns {x is null} True if the value is null, false otherwise.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* * const value1 = null;
|
|
60
|
+
* const value2 = undefined;
|
|
61
|
+
* const value3 = 42;
|
|
62
|
+
*
|
|
63
|
+
* console.log(isNull(value1)); // true
|
|
64
|
+
* console.log(isNull(value2)); // false
|
|
65
|
+
* console.log(isNull(value3)); // false
|
|
66
|
+
*/
|
|
67
|
+
function isNull(x) {
|
|
68
|
+
return x === null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Checks if the given value is undefined.
|
|
73
|
+
*
|
|
74
|
+
* This function tests whether the provided value is strictly equal to `undefined`.
|
|
75
|
+
* It returns `true` if the value is `undefined`, and `false` otherwise.
|
|
76
|
+
*
|
|
77
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `undefined`.
|
|
78
|
+
*
|
|
79
|
+
* @param {unknown} x - The value to test if it is undefined.
|
|
80
|
+
* @returns {x is undefined} true if the value is undefined, false otherwise.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* * const value1 = undefined;
|
|
84
|
+
* const value2 = null;
|
|
85
|
+
* const value3 = 42;
|
|
86
|
+
*
|
|
87
|
+
* console.log(isUndefined(value1)); // true
|
|
88
|
+
* console.log(isUndefined(value2)); // false
|
|
89
|
+
* console.log(isUndefined(value3)); // false
|
|
90
|
+
*/
|
|
91
|
+
function isUndefined(x) {
|
|
92
|
+
return x === undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
exports.isNil = isNil;
|
|
96
|
+
exports.isNotNil = isNotNil;
|
|
97
|
+
exports.isNull = isNull;
|
|
98
|
+
exports.isUndefined = isUndefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given value is null or undefined.
|
|
3
|
+
*
|
|
4
|
+
* This function tests whether the provided value is either `null` or `undefined`.
|
|
5
|
+
* It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} x - The value to test for null or undefined.
|
|
10
|
+
* @returns {boolean} `true` if the value is null or undefined, `false` otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* * const value1 = null;
|
|
14
|
+
* const value2 = undefined;
|
|
15
|
+
* const value3 = 42;
|
|
16
|
+
* const result1 = isNil(value1); // true
|
|
17
|
+
* const result2 = isNil(value2); // true
|
|
18
|
+
* const result3 = isNil(value3); // false
|
|
19
|
+
*/
|
|
20
|
+
export declare function isNil(x: unknown): x is null | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is not null nor undefined.
|
|
3
|
+
*
|
|
4
|
+
* The main use of this function is to be used with TypeScript as a type predicate.
|
|
5
|
+
*
|
|
6
|
+
* @param {T | null | undefined} x - The value to test if it is not null nor undefined.
|
|
7
|
+
* @returns {x is T} True if the value is not null nor undefined, false otherwise.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // Here the type of `arr` is (number | undefined)[]
|
|
11
|
+
* const arr = [1, undefined, 3];
|
|
12
|
+
* // Here the type of `result` is number[]
|
|
13
|
+
* const result = arr.filter(isNotNil);
|
|
14
|
+
* // result will be [1, 3]
|
|
15
|
+
*/
|
|
16
|
+
export declare function isNotNil<T>(x: T | null | undefined): x is T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is null.
|
|
3
|
+
*
|
|
4
|
+
* This function tests whether the provided value is strictly equal to `null`.
|
|
5
|
+
* It returns `true` if the value is `null`, and `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} x - The value to test if it is null.
|
|
10
|
+
* @returns {x is null} True if the value is null, false otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* * const value1 = null;
|
|
14
|
+
* const value2 = undefined;
|
|
15
|
+
* const value3 = 42;
|
|
16
|
+
*
|
|
17
|
+
* console.log(isNull(value1)); // true
|
|
18
|
+
* console.log(isNull(value2)); // false
|
|
19
|
+
* console.log(isNull(value3)); // false
|
|
20
|
+
*/
|
|
21
|
+
export declare function isNull(x: unknown): x is null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is undefined.
|
|
3
|
+
*
|
|
4
|
+
* This function tests whether the provided value is strictly equal to `undefined`.
|
|
5
|
+
* It returns `true` if the value is `undefined`, and `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `undefined`.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} x - The value to test if it is undefined.
|
|
10
|
+
* @returns {x is undefined} true if the value is undefined, false otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* * const value1 = undefined;
|
|
14
|
+
* const value2 = null;
|
|
15
|
+
* const value3 = 42;
|
|
16
|
+
*
|
|
17
|
+
* console.log(isUndefined(value1)); // true
|
|
18
|
+
* console.log(isUndefined(value2)); // false
|
|
19
|
+
* console.log(isUndefined(value3)); // false
|
|
20
|
+
*/
|
|
21
|
+
export declare function isUndefined(x: unknown): x is undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delays the execution of code for a specified number of milliseconds.
|
|
3
|
+
*
|
|
4
|
+
* This function returns a Promise that resolves after the specified delay, allowing you to use it
|
|
5
|
+
* with async/await to pause execution.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} ms - The number of milliseconds to delay.
|
|
8
|
+
* @returns {Promise<void>} A Promise that resolves after the specified delay.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* async function foo() {
|
|
12
|
+
* console.log('Start');
|
|
13
|
+
* await delay(1000); // Delays execution for 1 second
|
|
14
|
+
* console.log('End');
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* foo();
|
|
18
|
+
*/
|
|
19
|
+
export declare function delay(ms: number): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { delay } from './delay';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Delays the execution of code for a specified number of milliseconds.
|
|
7
|
+
*
|
|
8
|
+
* This function returns a Promise that resolves after the specified delay, allowing you to use it
|
|
9
|
+
* with async/await to pause execution.
|
|
10
|
+
*
|
|
11
|
+
* @param {number} ms - The number of milliseconds to delay.
|
|
12
|
+
* @returns {Promise<void>} A Promise that resolves after the specified delay.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* async function foo() {
|
|
16
|
+
* console.log('Start');
|
|
17
|
+
* await delay(1000); // Delays execution for 1 second
|
|
18
|
+
* console.log('End');
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* foo();
|
|
22
|
+
*/
|
|
23
|
+
function delay(ms) {
|
|
24
|
+
return new Promise(function (resolve) {
|
|
25
|
+
setTimeout(resolve, ms);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.delay = delay;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
function _iterableToArrayLimit(r, l) {
|
|
2
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
3
|
+
if (null != t) {
|
|
4
|
+
var e,
|
|
5
|
+
n,
|
|
6
|
+
i,
|
|
7
|
+
u,
|
|
8
|
+
a = [],
|
|
9
|
+
f = !0,
|
|
10
|
+
o = !1;
|
|
11
|
+
try {
|
|
12
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
13
|
+
if (Object(t) !== t) return;
|
|
14
|
+
f = !1;
|
|
15
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
16
|
+
} catch (r) {
|
|
17
|
+
o = !0, n = r;
|
|
18
|
+
} finally {
|
|
19
|
+
try {
|
|
20
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
21
|
+
} finally {
|
|
22
|
+
if (o) throw n;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return a;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function ownKeys(e, r) {
|
|
29
|
+
var t = Object.keys(e);
|
|
30
|
+
if (Object.getOwnPropertySymbols) {
|
|
31
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
32
|
+
r && (o = o.filter(function (r) {
|
|
33
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
34
|
+
})), t.push.apply(t, o);
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
}
|
|
38
|
+
function _objectSpread2(e) {
|
|
39
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
40
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
41
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
42
|
+
_defineProperty(e, r, t[r]);
|
|
43
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
44
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return e;
|
|
48
|
+
}
|
|
49
|
+
function _toPrimitive(t, r) {
|
|
50
|
+
if ("object" != typeof t || !t) return t;
|
|
51
|
+
var e = t[Symbol.toPrimitive];
|
|
52
|
+
if (void 0 !== e) {
|
|
53
|
+
var i = e.call(t, r || "default");
|
|
54
|
+
if ("object" != typeof i) return i;
|
|
55
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
56
|
+
}
|
|
57
|
+
return ("string" === r ? String : Number)(t);
|
|
58
|
+
}
|
|
59
|
+
function _toPropertyKey(t) {
|
|
60
|
+
var i = _toPrimitive(t, "string");
|
|
61
|
+
return "symbol" == typeof i ? i : i + "";
|
|
62
|
+
}
|
|
63
|
+
function _defineProperty(obj, key, value) {
|
|
64
|
+
key = _toPropertyKey(key);
|
|
65
|
+
if (key in obj) {
|
|
66
|
+
Object.defineProperty(obj, key, {
|
|
67
|
+
value: value,
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
writable: true
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
obj[key] = value;
|
|
74
|
+
}
|
|
75
|
+
return obj;
|
|
76
|
+
}
|
|
77
|
+
function _slicedToArray(arr, i) {
|
|
78
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
79
|
+
}
|
|
80
|
+
function _toConsumableArray(arr) {
|
|
81
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
82
|
+
}
|
|
83
|
+
function _arrayWithoutHoles(arr) {
|
|
84
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
85
|
+
}
|
|
86
|
+
function _arrayWithHoles(arr) {
|
|
87
|
+
if (Array.isArray(arr)) return arr;
|
|
88
|
+
}
|
|
89
|
+
function _iterableToArray(iter) {
|
|
90
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
91
|
+
}
|
|
92
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
93
|
+
if (!o) return;
|
|
94
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
95
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
96
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
97
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
98
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
99
|
+
}
|
|
100
|
+
function _arrayLikeToArray(arr, len) {
|
|
101
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
102
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
103
|
+
return arr2;
|
|
104
|
+
}
|
|
105
|
+
function _nonIterableSpread() {
|
|
106
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
107
|
+
}
|
|
108
|
+
function _nonIterableRest() {
|
|
109
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
110
|
+
}
|
|
111
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
112
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
113
|
+
if (!it) {
|
|
114
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
115
|
+
if (it) o = it;
|
|
116
|
+
var i = 0;
|
|
117
|
+
var F = function () {};
|
|
118
|
+
return {
|
|
119
|
+
s: F,
|
|
120
|
+
n: function () {
|
|
121
|
+
if (i >= o.length) return {
|
|
122
|
+
done: true
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
done: false,
|
|
126
|
+
value: o[i++]
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
e: function (e) {
|
|
130
|
+
throw e;
|
|
131
|
+
},
|
|
132
|
+
f: F
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
136
|
+
}
|
|
137
|
+
var normalCompletion = true,
|
|
138
|
+
didErr = false,
|
|
139
|
+
err;
|
|
140
|
+
return {
|
|
141
|
+
s: function () {
|
|
142
|
+
it = it.call(o);
|
|
143
|
+
},
|
|
144
|
+
n: function () {
|
|
145
|
+
var step = it.next();
|
|
146
|
+
normalCompletion = step.done;
|
|
147
|
+
return step;
|
|
148
|
+
},
|
|
149
|
+
e: function (e) {
|
|
150
|
+
didErr = true;
|
|
151
|
+
err = e;
|
|
152
|
+
},
|
|
153
|
+
f: function () {
|
|
154
|
+
try {
|
|
155
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
156
|
+
} finally {
|
|
157
|
+
if (didErr) throw err;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export { _arrayLikeToArray as arrayLikeToArray, _arrayWithHoles as arrayWithHoles, _arrayWithoutHoles as arrayWithoutHoles, _createForOfIteratorHelper as createForOfIteratorHelper, _defineProperty as defineProperty, _iterableToArray as iterableToArray, _iterableToArrayLimit as iterableToArrayLimit, _nonIterableRest as nonIterableRest, _nonIterableSpread as nonIterableSpread, _objectSpread2 as objectSpread2, _slicedToArray as slicedToArray, _toConsumableArray as toConsumableArray, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey, _unsupportedIterableToArray as unsupportedIterableToArray };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
function _toConsumableArray(arr) {
|
|
2
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
3
|
+
}
|
|
4
|
+
function _arrayWithoutHoles(arr) {
|
|
5
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
6
|
+
}
|
|
7
|
+
function _iterableToArray(iter) {
|
|
8
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
9
|
+
}
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
11
|
+
if (!o) return;
|
|
12
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
13
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
14
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
15
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
16
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
17
|
+
}
|
|
18
|
+
function _arrayLikeToArray(arr, len) {
|
|
19
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
20
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
21
|
+
return arr2;
|
|
22
|
+
}
|
|
23
|
+
function _nonIterableSpread() {
|
|
24
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
25
|
+
}
|
|
26
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
27
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
28
|
+
if (!it) {
|
|
29
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
30
|
+
if (it) o = it;
|
|
31
|
+
var i = 0;
|
|
32
|
+
var F = function () {};
|
|
33
|
+
return {
|
|
34
|
+
s: F,
|
|
35
|
+
n: function () {
|
|
36
|
+
if (i >= o.length) return {
|
|
37
|
+
done: true
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
done: false,
|
|
41
|
+
value: o[i++]
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
e: function (e) {
|
|
45
|
+
throw e;
|
|
46
|
+
},
|
|
47
|
+
f: F
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
51
|
+
}
|
|
52
|
+
var normalCompletion = true,
|
|
53
|
+
didErr = false,
|
|
54
|
+
err;
|
|
55
|
+
return {
|
|
56
|
+
s: function () {
|
|
57
|
+
it = it.call(o);
|
|
58
|
+
},
|
|
59
|
+
n: function () {
|
|
60
|
+
var step = it.next();
|
|
61
|
+
normalCompletion = step.done;
|
|
62
|
+
return step;
|
|
63
|
+
},
|
|
64
|
+
e: function (e) {
|
|
65
|
+
didErr = true;
|
|
66
|
+
err = e;
|
|
67
|
+
},
|
|
68
|
+
f: function () {
|
|
69
|
+
try {
|
|
70
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
71
|
+
} finally {
|
|
72
|
+
if (didErr) throw err;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { _arrayLikeToArray as arrayLikeToArray, _arrayWithoutHoles as arrayWithoutHoles, _createForOfIteratorHelper as createForOfIteratorHelper, _iterableToArray as iterableToArray, _nonIterableSpread as nonIterableSpread, _toConsumableArray as toConsumableArray, _unsupportedIterableToArray as unsupportedIterableToArray };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits an array into smaller arrays of a specified length.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an input array and divides it into multiple smaller arrays,
|
|
5
|
+
* each of a specified length. If the input array cannot be evenly divided,
|
|
6
|
+
* the final sub-array will contain the remaining elements.
|
|
7
|
+
*
|
|
8
|
+
* @template T The type of elements in the array.
|
|
9
|
+
* @param {T[]} arr - The array to be chunked into smaller arrays.
|
|
10
|
+
* @param {number} size - The size of each smaller array. Must be a positive integer.
|
|
11
|
+
* @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.
|
|
12
|
+
* @throws {Error} Throws an error if `size` is not a positive integer.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Splits an array of numbers into sub-arrays of length 2
|
|
16
|
+
* chunk([1, 2, 3, 4, 5], 2);
|
|
17
|
+
* // Returns: [[1, 2], [3, 4], [5]]
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Splits an array of strings into sub-arrays of length 3
|
|
21
|
+
* chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
|
|
22
|
+
* // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
|
|
23
|
+
*/
|
|
24
|
+
function chunk(arr, size) {
|
|
25
|
+
if (!Number.isInteger(size) || size <= 0) {
|
|
26
|
+
throw new Error('Size must be an integer greater than zero.');
|
|
27
|
+
}
|
|
28
|
+
var chunkLength = Math.ceil(arr.length / size);
|
|
29
|
+
var result = Array(chunkLength);
|
|
30
|
+
for (var index = 0; index < chunkLength; index++) {
|
|
31
|
+
var start = index * size;
|
|
32
|
+
var end = start + size;
|
|
33
|
+
result[index] = arr.slice(start, end);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { chunk };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the difference between two arrays.
|
|
3
|
+
*
|
|
4
|
+
* This function takes two arrays and returns a new array containing the elements
|
|
5
|
+
* that are present in the first array but not in the second array. It effectively
|
|
6
|
+
* filters out any elements from the first array that also appear in the second array.
|
|
7
|
+
*
|
|
8
|
+
* @template T
|
|
9
|
+
* @param {T[]} firstArr - The array from which to derive the difference. This is the primary array
|
|
10
|
+
* from which elements will be compared and filtered.
|
|
11
|
+
* @param {T[]} secondArr - The array containing elements to be excluded from the first array.
|
|
12
|
+
* Each element in this array will be checked against the first array, and if a match is found,
|
|
13
|
+
* that element will be excluded from the result.
|
|
14
|
+
* @returns {T[]} A new array containing the elements that are present in the first array but not
|
|
15
|
+
* in the second array.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* * const array1 = [1, 2, 3, 4, 5];
|
|
19
|
+
* const array2 = [2, 4];
|
|
20
|
+
* const result = difference(array1, array2);
|
|
21
|
+
* // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result.
|
|
22
|
+
*/
|
|
23
|
+
function difference(firstArr, secondArr) {
|
|
24
|
+
return firstArr.filter(function (item) {
|
|
25
|
+
return !secondArr.includes(item);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { difference };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the difference between two arrays after mapping their elements through a provided function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes two arrays and a mapper function. It returns a new array containing the elements
|
|
5
|
+
* that are present in the first array but not in the second array, based on the identity calculated
|
|
6
|
+
* by the mapper function.
|
|
7
|
+
*
|
|
8
|
+
* Essentially, it filters out any elements from the first array that, when
|
|
9
|
+
* mapped, match an element in the mapped version of the second array.
|
|
10
|
+
*
|
|
11
|
+
* @template T, U
|
|
12
|
+
* @param {T[]} firstArr - The primary array from which to derive the difference.
|
|
13
|
+
* @param {T[]} secondArr - The array containing elements to be excluded from the first array.
|
|
14
|
+
* @param {(value: T) => U} mapper - The function to map the elements of both arrays. This function
|
|
15
|
+
* is applied to each element in both arrays, and the comparison is made based on the mapped values.
|
|
16
|
+
* @returns {T[]} A new array containing the elements from the first array that do not have a corresponding
|
|
17
|
+
* mapped identity in the second array.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
21
|
+
* const array2 = [{ id: 2 }, { id: 4 }];
|
|
22
|
+
* const mapper = item => item.id;
|
|
23
|
+
* const result = differenceBy(array1, array2, mapper);
|
|
24
|
+
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.
|
|
25
|
+
*/
|
|
26
|
+
function differenceBy(firstArr, secondArr, mapper) {
|
|
27
|
+
var mappedSecondArr = secondArr.map(function (item) {
|
|
28
|
+
return mapper(item);
|
|
29
|
+
});
|
|
30
|
+
return firstArr.filter(function (item) {
|
|
31
|
+
return !mappedSecondArr.includes(mapper(item));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { differenceBy };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the difference between two arrays based on a custom equality function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes two arrays and a custom comparison function. It returns a new array containing
|
|
5
|
+
* the elements that are present in the first array but not in the second array. The comparison to determine
|
|
6
|
+
* if elements are equal is made using the provided custom function.
|
|
7
|
+
*
|
|
8
|
+
* @template T
|
|
9
|
+
* @param {T[]} firstArr - The array from which to get the difference.
|
|
10
|
+
* @param {T[]} secondArr - The array containing elements to exclude from the first array.
|
|
11
|
+
* @param {(x: T, y: T) => boolean} areItemsEqual - A function to determine if two items are equal.
|
|
12
|
+
* @returns {T[]} A new array containing the elements from the first array that do not match any elements in the second array
|
|
13
|
+
* according to the custom equality function.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
17
|
+
* const array2 = [{ id: 2 }, { id: 4 }];
|
|
18
|
+
* const areItemsEqual = (a, b) => a.id === b.id;
|
|
19
|
+
* const result = differenceWith(array1, array2, areItemsEqual);
|
|
20
|
+
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.
|
|
21
|
+
*/
|
|
22
|
+
function differenceWith(firstArr, secondArr, areItemsEqual) {
|
|
23
|
+
return firstArr.filter(function (firstItem) {
|
|
24
|
+
return secondArr.every(function (secondItem) {
|
|
25
|
+
return !areItemsEqual(firstItem, secondItem);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { differenceWith };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes a specified number of elements from the beginning of an array and returns the rest.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and a number, and returns a new array with the specified number
|
|
5
|
+
* of elements removed from the start.
|
|
6
|
+
*
|
|
7
|
+
* @param {T[]} arr - The array from which to drop elements.
|
|
8
|
+
* @param {number} itemsCount - The number of elements to drop from the beginning of the array.
|
|
9
|
+
* @returns {T[]} A new array with the specified number of elements removed from the start.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* * const array = [1, 2, 3, 4, 5];
|
|
13
|
+
* const result = drop(array, 2);
|
|
14
|
+
* // result will be [3, 4, 5] since the first two elements are dropped.
|
|
15
|
+
*/
|
|
16
|
+
function drop(arr, itemsCount) {
|
|
17
|
+
return arr.slice(itemsCount);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { drop };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes a specified number of elements from the end of an array and returns the rest.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and a number, and returns a new array with the specified number
|
|
5
|
+
* of elements removed from the end.
|
|
6
|
+
*
|
|
7
|
+
* @param {T[]} arr - The array from which to drop elements.
|
|
8
|
+
* @param {number} itemsCount - The number of elements to drop from the end of the array.
|
|
9
|
+
* @returns {T[]} A new array with the specified number of elements removed from the end.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* * const array = [1, 2, 3, 4, 5];
|
|
13
|
+
* const result = dropRight(array, 2);
|
|
14
|
+
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
15
|
+
*/
|
|
16
|
+
function dropRight(arr, itemsCount) {
|
|
17
|
+
return arr.slice(0, -itemsCount);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { dropRight };
|