es-toolkit 0.0.1 → 1.0.0-dev.24
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 +21 -5
- package/dist/array/difference.d.ts +20 -4
- package/dist/array/differenceBy.d.ts +23 -5
- package/dist/array/differenceWith.d.ts +19 -5
- package/dist/array/drop.d.ts +13 -4
- package/dist/array/dropRight.d.ts +13 -4
- package/dist/array/dropRightWhile.d.ts +15 -4
- package/dist/array/dropWhile.d.ts +15 -4
- package/dist/array/groupBy.d.ts +31 -1
- package/dist/array/groupBy.spec.d.ts +1 -0
- package/dist/array/index.js +437 -224
- package/dist/array/intersection.d.ts +13 -6
- package/dist/array/intersectionBy.d.ts +17 -8
- package/dist/array/intersectionWith.d.ts +18 -8
- package/dist/array/partition.d.ts +19 -5
- package/dist/array/sample.d.ts +10 -3
- package/dist/array/shuffle.d.ts +11 -4
- package/dist/array/takeRight.d.ts +0 -2
- package/dist/array/union.d.ts +13 -6
- package/dist/array/unionBy.d.ts +0 -3
- package/dist/array/unionWith.d.ts +15 -9
- package/dist/array/uniq.d.ts +9 -8
- package/dist/array/xor.d.ts +0 -2
- package/dist/array/zip.d.ts +18 -6
- package/dist/array/zipWith.d.ts +26 -3
- package/dist/function/debounce.d.ts +4 -4
- package/dist/function/index.js +4 -5
- package/dist/function/once.d.ts +0 -1
- package/dist/index.js +651 -248
- package/dist/math/clamp.d.ts +16 -8
- package/dist/math/index.js +114 -29
- package/dist/math/round.d.ts +11 -8
- package/dist/math/sum.d.ts +10 -9
- package/dist/object/index.js +122 -12
- package/dist/object/omit.d.ts +13 -4
- package/dist/object/omitBy.d.ts +19 -1
- package/dist/object/omitBy.spec.d.ts +1 -0
- package/dist/object/pick.d.ts +13 -4
- package/dist/object/pickBy.d.ts +19 -1
- package/dist/object/pickBy.spec.d.ts +1 -0
- package/dist/predicate/index.js +58 -10
- package/dist/predicate/isNil.d.ts +17 -3
- package/dist/predicate/isNotNil.d.ts +7 -3
- package/dist/predicate/isNull.d.ts +17 -2
- package/dist/predicate/isUndefined.d.ts +17 -2
- package/dist/promise/delay.d.ts +17 -4
- package/dist/promise/index.js +16 -3
- package/esm/array/_virtual/_rollupPluginBabelHelpers.mjs +1 -37
- package/esm/array/chunk.mjs +28 -25
- package/esm/array/difference.mjs +20 -4
- package/esm/array/differenceBy.mjs +23 -5
- package/esm/array/differenceWith.mjs +19 -5
- package/esm/array/drop.mjs +13 -4
- package/esm/array/dropRight.mjs +13 -4
- package/esm/array/dropRightWhile.mjs +15 -4
- package/esm/array/dropWhile.mjs +15 -4
- package/esm/array/groupBy.mjs +51 -2
- package/esm/array/intersection.mjs +13 -6
- package/esm/array/intersectionBy.mjs +17 -8
- package/esm/array/intersectionWith.mjs +18 -8
- package/esm/array/partition.mjs +19 -5
- package/esm/array/sample.mjs +10 -3
- package/esm/array/shuffle.mjs +12 -5
- package/esm/array/takeRight.mjs +0 -2
- package/esm/array/union.mjs +14 -10
- package/esm/array/unionBy.mjs +0 -3
- package/esm/array/unionWith.mjs +16 -11
- package/esm/array/uniq.mjs +28 -9
- package/esm/array/xor.mjs +0 -2
- package/esm/array/zip.mjs +18 -6
- package/esm/array/zipWith.mjs +26 -3
- package/esm/function/debounce.mjs +4 -4
- package/esm/function/once.mjs +0 -1
- package/esm/math/_virtual/_rollupPluginBabelHelpers.mjs +66 -0
- package/esm/math/clamp.mjs +15 -7
- package/esm/math/round.mjs +11 -8
- package/esm/math/sum.mjs +25 -14
- package/esm/object/_virtual/_rollupPluginBabelHelpers.mjs +37 -1
- package/esm/object/omit.mjs +13 -4
- package/esm/object/omitBy.mjs +32 -2
- package/esm/object/pick.mjs +13 -4
- package/esm/object/pickBy.mjs +32 -2
- package/esm/predicate/isNil.mjs +17 -3
- package/esm/predicate/isNotNil.mjs +7 -3
- package/esm/predicate/isNull.mjs +17 -2
- package/esm/predicate/isUndefined.mjs +17 -2
- package/esm/promise/delay.mjs +16 -3
- package/package.json +17 -3
- package/.vscode/extensions.json +0 -7
- package/.vscode/settings.json +0 -10
- package/.yarn/sdks/eslint/bin/eslint.js +0 -20
- package/.yarn/sdks/eslint/lib/api.js +0 -20
- package/.yarn/sdks/eslint/lib/unsupported-api.js +0 -20
- package/.yarn/sdks/eslint/package.json +0 -14
- package/.yarn/sdks/integrations.yml +0 -5
- package/.yarn/sdks/prettier/bin/prettier.cjs +0 -20
- package/.yarn/sdks/prettier/index.cjs +0 -20
- package/.yarn/sdks/prettier/package.json +0 -7
- package/.yarn/sdks/typescript/bin/tsc +0 -20
- package/.yarn/sdks/typescript/bin/tsserver +0 -20
- package/.yarn/sdks/typescript/lib/tsc.js +0 -20
- package/.yarn/sdks/typescript/lib/tsserver.js +0 -225
- package/.yarn/sdks/typescript/lib/tsserverlibrary.js +0 -225
- package/.yarn/sdks/typescript/lib/typescript.js +0 -20
- package/.yarn/sdks/typescript/package.json +0 -10
- package/babel.config.js +0 -6
- package/coverage/.tmp/coverage-0.json +0 -1
- package/coverage/.tmp/coverage-1.json +0 -1
- package/coverage/.tmp/coverage-10.json +0 -1
- package/coverage/.tmp/coverage-11.json +0 -1
- package/coverage/.tmp/coverage-12.json +0 -1
- package/coverage/.tmp/coverage-13.json +0 -1
- package/coverage/.tmp/coverage-14.json +0 -1
- package/coverage/.tmp/coverage-15.json +0 -1
- package/coverage/.tmp/coverage-16.json +0 -1
- package/coverage/.tmp/coverage-17.json +0 -1
- package/coverage/.tmp/coverage-18.json +0 -1
- package/coverage/.tmp/coverage-19.json +0 -1
- package/coverage/.tmp/coverage-2.json +0 -1
- package/coverage/.tmp/coverage-20.json +0 -1
- package/coverage/.tmp/coverage-21.json +0 -1
- package/coverage/.tmp/coverage-22.json +0 -1
- package/coverage/.tmp/coverage-23.json +0 -1
- package/coverage/.tmp/coverage-24.json +0 -1
- package/coverage/.tmp/coverage-25.json +0 -1
- package/coverage/.tmp/coverage-26.json +0 -1
- package/coverage/.tmp/coverage-27.json +0 -1
- package/coverage/.tmp/coverage-28.json +0 -1
- package/coverage/.tmp/coverage-29.json +0 -1
- package/coverage/.tmp/coverage-3.json +0 -1
- package/coverage/.tmp/coverage-30.json +0 -1
- package/coverage/.tmp/coverage-4.json +0 -1
- package/coverage/.tmp/coverage-5.json +0 -1
- package/coverage/.tmp/coverage-6.json +0 -1
- package/coverage/.tmp/coverage-7.json +0 -1
- package/coverage/.tmp/coverage-8.json +0 -1
- package/coverage/.tmp/coverage-9.json +0 -1
- package/rollup.config.js +0 -5
- package/src/array/chunk.spec.ts +0 -27
- package/src/array/chunk.ts +0 -24
- package/src/array/difference.spec.ts +0 -10
- package/src/array/difference.ts +0 -11
- package/src/array/differenceBy.spec.ts +0 -9
- package/src/array/differenceBy.ts +0 -14
- package/src/array/differenceWith.spec.ts +0 -8
- package/src/array/differenceWith.ts +0 -14
- package/src/array/drop.spec.ts +0 -9
- package/src/array/drop.ts +0 -9
- package/src/array/dropRight.spec.ts +0 -9
- package/src/array/dropRight.ts +0 -9
- package/src/array/dropRightWhile.spec.ts +0 -16
- package/src/array/dropRightWhile.ts +0 -13
- package/src/array/dropWhile.spec.ts +0 -14
- package/src/array/dropWhile.ts +0 -10
- package/src/array/groupBy.ts +0 -3
- package/src/array/index.ts +0 -30
- package/src/array/intersection.spec.ts +0 -11
- package/src/array/intersection.ts +0 -15
- package/src/array/intersectionBy.spec.ts +0 -9
- package/src/array/intersectionBy.ts +0 -18
- package/src/array/intersectionWith.spec.ts +0 -9
- package/src/array/intersectionWith.ts +0 -18
- package/src/array/partition.spec.ts +0 -23
- package/src/array/partition.ts +0 -21
- package/src/array/sample.spec.ts +0 -11
- package/src/array/sample.ts +0 -10
- package/src/array/shuffle.spec.ts +0 -11
- package/src/array/shuffle.ts +0 -18
- package/src/array/take.spec.ts +0 -25
- package/src/array/take.ts +0 -25
- package/src/array/takeRight.spec.ts +0 -25
- package/src/array/takeRight.ts +0 -29
- package/src/array/takeRightWhile.spec.ts +0 -16
- package/src/array/takeRightWhile.ts +0 -26
- package/src/array/takeWhile.spec.ts +0 -34
- package/src/array/takeWhile.ts +0 -31
- package/src/array/union.spec.ts +0 -10
- package/src/array/union.ts +0 -14
- package/src/array/unionBy.spec.ts +0 -12
- package/src/array/unionBy.ts +0 -35
- package/src/array/unionWith.spec.ts +0 -23
- package/src/array/unionWith.ts +0 -18
- package/src/array/uniq.spec.ts +0 -8
- package/src/array/uniq.ts +0 -16
- package/src/array/uniqBy.spec.ts +0 -8
- package/src/array/uniqBy.ts +0 -17
- package/src/array/uniqWith.spec.ts +0 -16
- package/src/array/uniqWith.ts +0 -29
- package/src/array/xor.spec.ts +0 -13
- package/src/array/xor.ts +0 -25
- package/src/array/xorBy.spec.ts +0 -16
- package/src/array/xorBy.ts +0 -29
- package/src/array/xorWith.spec.ts +0 -16
- package/src/array/xorWith.ts +0 -28
- package/src/array/zip.spec.ts +0 -14
- package/src/array/zip.ts +0 -34
- package/src/array/zipWith.spec.ts +0 -13
- package/src/array/zipWith.ts +0 -23
- package/src/function/debounce.spec.ts +0 -76
- package/src/function/debounce.ts +0 -42
- package/src/function/index.ts +0 -3
- package/src/function/once.spec.ts +0 -31
- package/src/function/once.ts +0 -34
- package/src/function/throttle.spec.ts +0 -32
- package/src/function/throttle.ts +0 -39
- package/src/index.ts +0 -6
- package/src/math/clamp.spec.ts +0 -18
- package/src/math/clamp.ts +0 -17
- package/src/math/index.ts +0 -3
- package/src/math/round.spec.ts +0 -53
- package/src/math/round.ts +0 -16
- package/src/math/sum.spec.ts +0 -29
- package/src/math/sum.ts +0 -17
- package/src/object/index.ts +0 -4
- package/src/object/omit.spec.ts +0 -10
- package/src/object/omit.ts +0 -15
- package/src/object/omitBy.ts +0 -3
- package/src/object/pick.spec.ts +0 -10
- package/src/object/pick.ts +0 -15
- package/src/object/pickBy.ts +0 -3
- package/src/predicate/index.ts +0 -4
- package/src/predicate/isNil.spec.ts +0 -23
- package/src/predicate/isNil.ts +0 -8
- package/src/predicate/isNotNil.spec.ts +0 -29
- package/src/predicate/isNotNil.ts +0 -14
- package/src/predicate/isNull.spec.ts +0 -23
- package/src/predicate/isNull.ts +0 -8
- package/src/predicate/isUndefined.spec.ts +0 -23
- package/src/predicate/isUndefined.ts +0 -8
- package/src/promise/delay.spec.ts +0 -13
- package/src/promise/delay.ts +0 -10
- package/src/promise/index.ts +0 -1
- package/tsconfig.json +0 -12
- package/vitest.config.mts +0 -13
package/dist/math/clamp.d.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* function
|
|
2
|
+
* Clamps a number within the inclusive lower and upper bounds.
|
|
3
|
+
*
|
|
4
|
+
* This function takes a number and two bounds, and returns the number clamped within the specified bounds.
|
|
5
|
+
* If only one bound is provided, it returns the minimum of the value and the bound.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} value - The number to clamp.
|
|
8
|
+
* @param {number} minimum - The minimum bound to clamp the number.
|
|
9
|
+
* @param {number} maximum - The maximum bound to clamp the number.
|
|
10
|
+
* @returns {number} The clamped number within the specified bounds.
|
|
11
|
+
*
|
|
5
12
|
* @example
|
|
6
|
-
* clamp(
|
|
7
|
-
* clamp(
|
|
8
|
-
* clamp(
|
|
9
|
-
* clamp(
|
|
13
|
+
* * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5
|
|
14
|
+
* const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15
|
|
15
|
+
* const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5
|
|
16
|
+
* const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15
|
|
10
17
|
*/
|
|
11
|
-
export declare function clamp(value: number,
|
|
18
|
+
export declare function clamp(value: number, maximum: number): number;
|
|
19
|
+
export declare function clamp(value: number, minimum: number, maximum: number): number;
|
package/dist/math/index.js
CHANGED
|
@@ -3,15 +3,23 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* function
|
|
6
|
+
* Clamps a number within the inclusive lower and upper bounds.
|
|
7
|
+
*
|
|
8
|
+
* This function takes a number and two bounds, and returns the number clamped within the specified bounds.
|
|
9
|
+
* If only one bound is provided, it returns the minimum of the value and the bound.
|
|
10
|
+
*
|
|
11
|
+
* @param {number} value - The number to clamp.
|
|
12
|
+
* @param {number} minimum - The minimum bound to clamp the number.
|
|
13
|
+
* @param {number} maximum - The maximum bound to clamp the number.
|
|
14
|
+
* @returns {number} The clamped number within the specified bounds.
|
|
15
|
+
*
|
|
9
16
|
* @example
|
|
10
|
-
* clamp(
|
|
11
|
-
* clamp(
|
|
12
|
-
* clamp(
|
|
13
|
-
* clamp(
|
|
17
|
+
* * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5
|
|
18
|
+
* const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15
|
|
19
|
+
* const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5
|
|
20
|
+
* const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15
|
|
14
21
|
*/
|
|
22
|
+
|
|
15
23
|
function clamp(value, bound1, bound2) {
|
|
16
24
|
if (bound2 == null) {
|
|
17
25
|
return Math.min(value, bound1);
|
|
@@ -20,16 +28,19 @@ function clamp(value, bound1, bound2) {
|
|
|
20
28
|
}
|
|
21
29
|
|
|
22
30
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @description Rounds given number to given precision
|
|
25
|
-
* ```typescript
|
|
26
|
-
* function round(value: number, precision: number = 0): number
|
|
27
|
-
* ```
|
|
31
|
+
* Rounds a number to a specified precision.
|
|
28
32
|
*
|
|
33
|
+
* This function takes a number and an optional precision value, and returns the number rounded
|
|
34
|
+
* to the specified number of decimal places.
|
|
35
|
+
*
|
|
36
|
+
* @param {number} value - The number to round.
|
|
37
|
+
* @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.
|
|
38
|
+
* @returns {number} The rounded number.
|
|
39
|
+
*
|
|
29
40
|
* @example
|
|
30
|
-
* round(1.
|
|
31
|
-
* round(
|
|
32
|
-
* round(
|
|
41
|
+
* * const result1 = round(1.2345); // result1 will be 1
|
|
42
|
+
* const result2 = round(1.2345, 2); // result2 will be 1.23
|
|
43
|
+
* const result3 = round(1.2345, 3); // result3 will be 1.235
|
|
33
44
|
*/
|
|
34
45
|
function round(value) {
|
|
35
46
|
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
@@ -37,25 +48,99 @@ function round(value) {
|
|
|
37
48
|
return Math.round(value * multiplier) / multiplier;
|
|
38
49
|
}
|
|
39
50
|
|
|
51
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
52
|
+
if (!o) return;
|
|
53
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
54
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
55
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
56
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
57
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
58
|
+
}
|
|
59
|
+
function _arrayLikeToArray(arr, len) {
|
|
60
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
61
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
62
|
+
return arr2;
|
|
63
|
+
}
|
|
64
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
65
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
66
|
+
if (!it) {
|
|
67
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
68
|
+
if (it) o = it;
|
|
69
|
+
var i = 0;
|
|
70
|
+
var F = function () {};
|
|
71
|
+
return {
|
|
72
|
+
s: F,
|
|
73
|
+
n: function () {
|
|
74
|
+
if (i >= o.length) return {
|
|
75
|
+
done: true
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
done: false,
|
|
79
|
+
value: o[i++]
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
e: function (e) {
|
|
83
|
+
throw e;
|
|
84
|
+
},
|
|
85
|
+
f: F
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
89
|
+
}
|
|
90
|
+
var normalCompletion = true,
|
|
91
|
+
didErr = false,
|
|
92
|
+
err;
|
|
93
|
+
return {
|
|
94
|
+
s: function () {
|
|
95
|
+
it = it.call(o);
|
|
96
|
+
},
|
|
97
|
+
n: function () {
|
|
98
|
+
var step = it.next();
|
|
99
|
+
normalCompletion = step.done;
|
|
100
|
+
return step;
|
|
101
|
+
},
|
|
102
|
+
e: function (e) {
|
|
103
|
+
didErr = true;
|
|
104
|
+
err = e;
|
|
105
|
+
},
|
|
106
|
+
f: function () {
|
|
107
|
+
try {
|
|
108
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
109
|
+
} finally {
|
|
110
|
+
if (didErr) throw err;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
40
116
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
117
|
+
* Calculates the sum of an array of numbers.
|
|
118
|
+
*
|
|
119
|
+
* This function takes an array of numbers and returns the sum of all the elements in the array.
|
|
120
|
+
*
|
|
121
|
+
* @param {number[]} nums - An array of numbers to be summed.
|
|
122
|
+
* @returns {number} The sum of all the numbers in the array.
|
|
46
123
|
*
|
|
47
124
|
* @example
|
|
48
|
-
*
|
|
49
|
-
* sum(
|
|
50
|
-
*
|
|
125
|
+
* * const numbers = [1, 2, 3, 4, 5];
|
|
126
|
+
* const result = sum(numbers);
|
|
127
|
+
* // result will be 15
|
|
51
128
|
*/
|
|
52
|
-
function sum() {
|
|
53
|
-
|
|
54
|
-
|
|
129
|
+
function sum(nums) {
|
|
130
|
+
var result = 0;
|
|
131
|
+
var _iterator = _createForOfIteratorHelper(nums),
|
|
132
|
+
_step;
|
|
133
|
+
try {
|
|
134
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
135
|
+
var num = _step.value;
|
|
136
|
+
result += num;
|
|
137
|
+
}
|
|
138
|
+
} catch (err) {
|
|
139
|
+
_iterator.e(err);
|
|
140
|
+
} finally {
|
|
141
|
+
_iterator.f();
|
|
55
142
|
}
|
|
56
|
-
return
|
|
57
|
-
return acc + curr;
|
|
58
|
-
}, 0);
|
|
143
|
+
return result;
|
|
59
144
|
}
|
|
60
145
|
|
|
61
146
|
exports.clamp = clamp;
|
package/dist/math/round.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Rounds a number to a specified precision.
|
|
3
|
+
*
|
|
4
|
+
* This function takes a number and an optional precision value, and returns the number rounded
|
|
5
|
+
* to the specified number of decimal places.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} value - The number to round.
|
|
8
|
+
* @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.
|
|
9
|
+
* @returns {number} The rounded number.
|
|
7
10
|
*
|
|
8
11
|
* @example
|
|
9
|
-
* round(1.
|
|
10
|
-
* round(
|
|
11
|
-
* round(
|
|
12
|
+
* * const result1 = round(1.2345); // result1 will be 1
|
|
13
|
+
* const result2 = round(1.2345, 2); // result2 will be 1.23
|
|
14
|
+
* const result3 = round(1.2345, 3); // result3 will be 1.235
|
|
12
15
|
*/
|
|
13
16
|
export declare function round(value: number, precision?: number): number;
|
package/dist/math/sum.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Calculates the sum of an array of numbers.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array of numbers and returns the sum of all the elements in the array.
|
|
5
|
+
*
|
|
6
|
+
* @param {number[]} nums - An array of numbers to be summed.
|
|
7
|
+
* @returns {number} The sum of all the numbers in the array.
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
|
-
*
|
|
10
|
-
* sum(
|
|
11
|
-
*
|
|
10
|
+
* * const numbers = [1, 2, 3, 4, 5];
|
|
11
|
+
* const result = sum(numbers);
|
|
12
|
+
* // result will be 15
|
|
12
13
|
*/
|
|
13
|
-
export declare function sum(
|
|
14
|
+
export declare function sum(nums: number[]): number;
|
package/dist/object/index.js
CHANGED
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
function _iterableToArrayLimit(r, l) {
|
|
6
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
7
|
+
if (null != t) {
|
|
8
|
+
var e,
|
|
9
|
+
n,
|
|
10
|
+
i,
|
|
11
|
+
u,
|
|
12
|
+
a = [],
|
|
13
|
+
f = !0,
|
|
14
|
+
o = !1;
|
|
15
|
+
try {
|
|
16
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
17
|
+
if (Object(t) !== t) return;
|
|
18
|
+
f = !1;
|
|
19
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
20
|
+
} catch (r) {
|
|
21
|
+
o = !0, n = r;
|
|
22
|
+
} finally {
|
|
23
|
+
try {
|
|
24
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
25
|
+
} finally {
|
|
26
|
+
if (o) throw n;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return a;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
5
32
|
function ownKeys(e, r) {
|
|
6
33
|
var t = Object.keys(e);
|
|
7
34
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -51,6 +78,12 @@ function _defineProperty(obj, key, value) {
|
|
|
51
78
|
}
|
|
52
79
|
return obj;
|
|
53
80
|
}
|
|
81
|
+
function _slicedToArray(arr, i) {
|
|
82
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
83
|
+
}
|
|
84
|
+
function _arrayWithHoles(arr) {
|
|
85
|
+
if (Array.isArray(arr)) return arr;
|
|
86
|
+
}
|
|
54
87
|
function _unsupportedIterableToArray(o, minLen) {
|
|
55
88
|
if (!o) return;
|
|
56
89
|
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
@@ -64,6 +97,9 @@ function _arrayLikeToArray(arr, len) {
|
|
|
64
97
|
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
65
98
|
return arr2;
|
|
66
99
|
}
|
|
100
|
+
function _nonIterableRest() {
|
|
101
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
102
|
+
}
|
|
67
103
|
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
68
104
|
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
69
105
|
if (!it) {
|
|
@@ -117,10 +153,19 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
|
117
153
|
}
|
|
118
154
|
|
|
119
155
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
156
|
+
* Creates a new object with specified keys omitted.
|
|
157
|
+
*
|
|
158
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
159
|
+
* excludes the properties corresponding to the specified keys.
|
|
160
|
+
*
|
|
161
|
+
* @param {T} obj - The object to omit keys from.
|
|
162
|
+
* @param {K[]} keys - An array of keys to be omitted from the object.
|
|
163
|
+
* @returns {Omit<T, K>} A new object with the specified keys omitted.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* * const obj = { a: 1, b: 2, c: 3 };
|
|
167
|
+
* const result = omit(obj, ['b', 'c']);
|
|
168
|
+
* // result will be { a: 1 }
|
|
124
169
|
*/
|
|
125
170
|
function omit(obj, keys) {
|
|
126
171
|
var result = _objectSpread2({}, obj);
|
|
@@ -139,15 +184,52 @@ function omit(obj, keys) {
|
|
|
139
184
|
return result;
|
|
140
185
|
}
|
|
141
186
|
|
|
142
|
-
|
|
143
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Creates a new object composed of the properties that do not satisfy the predicate function.
|
|
189
|
+
*
|
|
190
|
+
* This function takes an object and a predicate function, and returns a new object that
|
|
191
|
+
* includes only the properties for which the predicate function returns false.
|
|
192
|
+
*
|
|
193
|
+
* @param {T} obj - The object to omit properties from.
|
|
194
|
+
* @param {(value: T[string], key: string) => boolean} shouldOmit - A predicate function that determines
|
|
195
|
+
* whether a property should be omitted. It takes the property's key and value as arguments and returns `true`
|
|
196
|
+
* if the property should be omitted, and `false` otherwise.
|
|
197
|
+
* @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* const obj = { a: 1, b: 'omit', c: 3 };
|
|
201
|
+
* const shouldOmit = (key, value) => typeof value === 'string';
|
|
202
|
+
* const result = omitBy(obj, shouldOmit);
|
|
203
|
+
* // result will be { a: 1, c: 3 }
|
|
204
|
+
*/
|
|
205
|
+
function omitBy(obj, shouldOmit) {
|
|
206
|
+
var result = {};
|
|
207
|
+
for (var _i = 0, _Object$entries = Object.entries(obj); _i < _Object$entries.length; _i++) {
|
|
208
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
209
|
+
key = _Object$entries$_i[0],
|
|
210
|
+
value = _Object$entries$_i[1];
|
|
211
|
+
if (shouldOmit(value, key)) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
result[key] = value;
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
144
217
|
}
|
|
145
218
|
|
|
146
219
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
220
|
+
* Creates a new object composed of the picked object properties.
|
|
221
|
+
*
|
|
222
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
223
|
+
* includes only the properties corresponding to the specified keys.
|
|
224
|
+
*
|
|
225
|
+
* @param {T} obj - The object to pick keys from.
|
|
226
|
+
* @param {K[]} keys - An array of keys to be picked from the object.
|
|
227
|
+
* @returns {Pick<T, K>} A new object with the specified keys picked.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* * const obj = { a: 1, b: 2, c: 3 };
|
|
231
|
+
* const result = pick(obj, ['a', 'c']);
|
|
232
|
+
* // result will be { a: 1, c: 3 }
|
|
151
233
|
*/
|
|
152
234
|
function pick(obj, keys) {
|
|
153
235
|
var result = {};
|
|
@@ -166,8 +248,36 @@ function pick(obj, keys) {
|
|
|
166
248
|
return result;
|
|
167
249
|
}
|
|
168
250
|
|
|
169
|
-
|
|
170
|
-
|
|
251
|
+
/**
|
|
252
|
+
* Creates a new object composed of the properties that satisfy the predicate function.
|
|
253
|
+
*
|
|
254
|
+
* This function takes an object and a predicate function, and returns a new object that
|
|
255
|
+
* includes only the properties for which the predicate function returns true.
|
|
256
|
+
*
|
|
257
|
+
* @param {T} obj - The object to pick properties from.
|
|
258
|
+
* @param {(value: T[keyof T], key: string) => boolean} shouldPick - A predicate function that determines
|
|
259
|
+
* whether a property should be picked. It takes the property's key and value as arguments and returns `true`
|
|
260
|
+
* if the property should be picked, and `false` otherwise.
|
|
261
|
+
* @returns {Partial<T>} A new object with the properties that satisfy the predicate function.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* const obj = { a: 1, b: 'pick', c: 3 };
|
|
265
|
+
* const shouldPick = (value) => typeof value === 'string';
|
|
266
|
+
* const result = pickBy(obj, shouldPick);
|
|
267
|
+
* // result will be { b: 'pick' }
|
|
268
|
+
*/
|
|
269
|
+
function pickBy(obj, shouldPick) {
|
|
270
|
+
var result = {};
|
|
271
|
+
for (var _i = 0, _Object$entries = Object.entries(obj); _i < _Object$entries.length; _i++) {
|
|
272
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
273
|
+
key = _Object$entries$_i[0],
|
|
274
|
+
value = _Object$entries$_i[1];
|
|
275
|
+
if (!shouldPick(value, key)) {
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
result[key] = value;
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
171
281
|
}
|
|
172
282
|
|
|
173
283
|
exports.omit = omit;
|
package/dist/object/omit.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Creates a new object with specified keys omitted.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
5
|
+
* excludes the properties corresponding to the specified keys.
|
|
6
|
+
*
|
|
7
|
+
* @param {T} obj - The object to omit keys from.
|
|
8
|
+
* @param {K[]} keys - An array of keys to be omitted from the object.
|
|
9
|
+
* @returns {Omit<T, K>} A new object with the specified keys omitted.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* * const obj = { a: 1, b: 2, c: 3 };
|
|
13
|
+
* const result = omit(obj, ['b', 'c']);
|
|
14
|
+
* // result will be { a: 1 }
|
|
6
15
|
*/
|
|
7
16
|
export declare function omit<T, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
package/dist/object/omitBy.d.ts
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object composed of the properties that do not satisfy the predicate function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and a predicate function, and returns a new object that
|
|
5
|
+
* includes only the properties for which the predicate function returns false.
|
|
6
|
+
*
|
|
7
|
+
* @param {T} obj - The object to omit properties from.
|
|
8
|
+
* @param {(value: T[string], key: string) => boolean} shouldOmit - A predicate function that determines
|
|
9
|
+
* whether a property should be omitted. It takes the property's key and value as arguments and returns `true`
|
|
10
|
+
* if the property should be omitted, and `false` otherwise.
|
|
11
|
+
* @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: 1, b: 'omit', c: 3 };
|
|
15
|
+
* const shouldOmit = (key, value) => typeof value === 'string';
|
|
16
|
+
* const result = omitBy(obj, shouldOmit);
|
|
17
|
+
* // result will be { a: 1, c: 3 }
|
|
18
|
+
*/
|
|
19
|
+
export declare function omitBy<T extends Record<string, any>>(obj: T, shouldOmit: (value: T[keyof T], key: string) => boolean): Partial<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/object/pick.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Creates a new object composed of the picked object properties.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
5
|
+
* includes only the properties corresponding to the specified keys.
|
|
6
|
+
*
|
|
7
|
+
* @param {T} obj - The object to pick keys from.
|
|
8
|
+
* @param {K[]} keys - An array of keys to be picked from the object.
|
|
9
|
+
* @returns {Pick<T, K>} A new object with the specified keys picked.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* * const obj = { a: 1, b: 2, c: 3 };
|
|
13
|
+
* const result = pick(obj, ['a', 'c']);
|
|
14
|
+
* // result will be { a: 1, c: 3 }
|
|
6
15
|
*/
|
|
7
16
|
export declare function pick<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
package/dist/object/pickBy.d.ts
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object composed of the properties that satisfy the predicate function.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and a predicate function, and returns a new object that
|
|
5
|
+
* includes only the properties for which the predicate function returns true.
|
|
6
|
+
*
|
|
7
|
+
* @param {T} obj - The object to pick properties from.
|
|
8
|
+
* @param {(value: T[keyof T], key: string) => boolean} shouldPick - A predicate function that determines
|
|
9
|
+
* whether a property should be picked. It takes the property's key and value as arguments and returns `true`
|
|
10
|
+
* if the property should be picked, and `false` otherwise.
|
|
11
|
+
* @returns {Partial<T>} A new object with the properties that satisfy the predicate function.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: 1, b: 'pick', c: 3 };
|
|
15
|
+
* const shouldPick = (value) => typeof value === 'string';
|
|
16
|
+
* const result = pickBy(obj, shouldPick);
|
|
17
|
+
* // result will be { b: 'pick' }
|
|
18
|
+
*/
|
|
19
|
+
export declare function pickBy<T extends Record<string, any>>(obj: T, shouldPick: (value: T[keyof T], key: string) => boolean): Partial<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/predicate/index.js
CHANGED
|
@@ -3,42 +3,90 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
|
9
23
|
*/
|
|
10
24
|
function isNil(x) {
|
|
11
25
|
return x == null || x == undefined;
|
|
12
26
|
}
|
|
13
27
|
|
|
14
28
|
/**
|
|
15
|
-
* @name isNotNil
|
|
16
29
|
* Checks if the given value is not null nor undefined.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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
|
+
*
|
|
19
36
|
* @example
|
|
20
37
|
* // Here the type of `arr` is (number | undefined)[]
|
|
21
38
|
* const arr = [1, undefined, 3];
|
|
22
39
|
* // Here the type of `result` is number[]
|
|
23
40
|
* const result = arr.filter(isNotNil);
|
|
41
|
+
* // result will be [1, 3]
|
|
24
42
|
*/
|
|
25
43
|
function isNotNil(x) {
|
|
26
44
|
return x != null && x != undefined;
|
|
27
45
|
}
|
|
28
46
|
|
|
29
47
|
/**
|
|
30
|
-
* @name isNull
|
|
31
48
|
* Checks if the given value is null.
|
|
32
|
-
*
|
|
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
|
|
33
66
|
*/
|
|
34
67
|
function isNull(x) {
|
|
35
68
|
return x === null;
|
|
36
69
|
}
|
|
37
70
|
|
|
38
71
|
/**
|
|
39
|
-
* @name isUndefined
|
|
40
72
|
* Checks if the given value is undefined.
|
|
41
|
-
*
|
|
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
|
|
42
90
|
*/
|
|
43
91
|
function isUndefined(x) {
|
|
44
92
|
return x === undefined;
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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
|
|
5
19
|
*/
|
|
6
20
|
export declare function isNil(x: unknown): x is null | undefined;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @name isNotNil
|
|
3
2
|
* Checks if the given value is not null nor undefined.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
|
+
*
|
|
6
9
|
* @example
|
|
7
10
|
* // Here the type of `arr` is (number | undefined)[]
|
|
8
11
|
* const arr = [1, undefined, 3];
|
|
9
12
|
* // Here the type of `result` is number[]
|
|
10
13
|
* const result = arr.filter(isNotNil);
|
|
14
|
+
* // result will be [1, 3]
|
|
11
15
|
*/
|
|
12
16
|
export declare function isNotNil<T>(x: T | null | undefined): x is T;
|