es-toolkit 1.50.0-dev.1991 → 1.50.0-dev.1993
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/bigint.d.ts +1 -0
- package/bigint.js +1 -0
- package/dist/_internal/bigIntRangeLength.js +19 -0
- package/dist/_internal/bigIntRangeLength.mjs +19 -0
- package/dist/bigint/clamp.d.mts +37 -0
- package/dist/bigint/clamp.d.ts +37 -0
- package/dist/bigint/clamp.js +16 -0
- package/dist/bigint/clamp.mjs +16 -0
- package/dist/bigint/inRange.d.mts +37 -0
- package/dist/bigint/inRange.d.ts +37 -0
- package/dist/bigint/inRange.js +20 -0
- package/dist/bigint/inRange.mjs +20 -0
- package/dist/bigint/index.d.mts +14 -0
- package/dist/bigint/index.d.ts +14 -0
- package/dist/bigint/index.js +27 -0
- package/dist/bigint/index.mjs +14 -0
- package/dist/bigint/max.d.mts +21 -0
- package/dist/bigint/max.d.ts +21 -0
- package/dist/bigint/max.js +26 -0
- package/dist/bigint/max.mjs +26 -0
- package/dist/bigint/maxBy.d.mts +21 -0
- package/dist/bigint/maxBy.d.ts +21 -0
- package/dist/bigint/maxBy.js +34 -0
- package/dist/bigint/maxBy.mjs +34 -0
- package/dist/bigint/median.d.mts +22 -0
- package/dist/bigint/median.d.ts +22 -0
- package/dist/bigint/median.js +28 -0
- package/dist/bigint/median.mjs +28 -0
- package/dist/bigint/medianBy.d.mts +21 -0
- package/dist/bigint/medianBy.d.ts +21 -0
- package/dist/bigint/medianBy.js +24 -0
- package/dist/bigint/medianBy.mjs +24 -0
- package/dist/bigint/min.d.mts +18 -0
- package/dist/bigint/min.d.ts +18 -0
- package/dist/bigint/min.js +23 -0
- package/dist/bigint/min.mjs +23 -0
- package/dist/bigint/minBy.d.mts +21 -0
- package/dist/bigint/minBy.d.ts +21 -0
- package/dist/bigint/minBy.js +34 -0
- package/dist/bigint/minBy.mjs +34 -0
- package/dist/bigint/percentile.d.mts +23 -0
- package/dist/bigint/percentile.d.ts +23 -0
- package/dist/bigint/percentile.js +31 -0
- package/dist/bigint/percentile.mjs +31 -0
- package/dist/bigint/range.d.mts +45 -0
- package/dist/bigint/range.d.ts +45 -0
- package/dist/bigint/range.js +24 -0
- package/dist/bigint/range.mjs +24 -0
- package/dist/bigint/rangeRight.d.mts +43 -0
- package/dist/bigint/rangeRight.d.ts +43 -0
- package/dist/bigint/rangeRight.js +25 -0
- package/dist/bigint/rangeRight.mjs +25 -0
- package/dist/bigint/sum.d.mts +18 -0
- package/dist/bigint/sum.d.ts +18 -0
- package/dist/bigint/sum.js +22 -0
- package/dist/bigint/sum.mjs +22 -0
- package/dist/bigint/sumBy.d.mts +20 -0
- package/dist/bigint/sumBy.d.ts +20 -0
- package/dist/bigint/sumBy.js +24 -0
- package/dist/bigint/sumBy.mjs +24 -0
- package/package.json +22 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/bigint/rangeRight.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array of bigints from `0n` up to, but not including, `end`, in descending order.
|
|
4
|
+
*
|
|
5
|
+
* @param end - The exclusive end of the range.
|
|
6
|
+
* @returns An array of bigints.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const result = rangeRight(4n);
|
|
10
|
+
* // result will be [3n, 2n, 1n, 0n]
|
|
11
|
+
*/
|
|
12
|
+
declare function rangeRight(end: bigint): bigint[];
|
|
13
|
+
/**
|
|
14
|
+
* Returns an array of bigints from `start` up to, but not including, `end`, in descending order.
|
|
15
|
+
*
|
|
16
|
+
* @param start - The inclusive start of the range.
|
|
17
|
+
* @param end - The exclusive end of the range.
|
|
18
|
+
* @returns An array of bigints.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const result = rangeRight(2n, 5n);
|
|
22
|
+
* // result will be [4n, 3n, 2n]
|
|
23
|
+
*/
|
|
24
|
+
declare function rangeRight(start: bigint, end: bigint): bigint[];
|
|
25
|
+
/**
|
|
26
|
+
* Returns an array of bigints from `start` up to, but not including, `end`, incrementing by `step`,
|
|
27
|
+
* in descending order.
|
|
28
|
+
*
|
|
29
|
+
* A negative `step` counts down. If `step` points away from `end`, an empty array is returned.
|
|
30
|
+
*
|
|
31
|
+
* @param start - The inclusive start of the range.
|
|
32
|
+
* @param end - The exclusive end of the range.
|
|
33
|
+
* @param step - The amount to increment by. Must not be `0n`.
|
|
34
|
+
* @returns An array of bigints.
|
|
35
|
+
* @throws {Error} If `step` is `0n`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const result = rangeRight(0n, 10n, 2n);
|
|
39
|
+
* // result will be [8n, 6n, 4n, 2n, 0n]
|
|
40
|
+
*/
|
|
41
|
+
declare function rangeRight(start: bigint, end: bigint, step: bigint): bigint[];
|
|
42
|
+
//#endregion
|
|
43
|
+
export { rangeRight };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const require_bigIntRangeLength = require("../_internal/bigIntRangeLength.js");
|
|
2
|
+
//#region src/bigint/rangeRight.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns an array of bigints from `start` up to, but not including, `end`, incrementing by `step`,
|
|
5
|
+
* in descending order.
|
|
6
|
+
*
|
|
7
|
+
* @param start - The exclusive end of the range when called with one argument, otherwise the inclusive start.
|
|
8
|
+
* @param end - The exclusive end of the range.
|
|
9
|
+
* @param step - The amount to increment by. Must not be `0n`.
|
|
10
|
+
* @returns An array of bigints.
|
|
11
|
+
* @throws {Error} If `step` is `0n`.
|
|
12
|
+
*/
|
|
13
|
+
function rangeRight(start, end, step = 1n) {
|
|
14
|
+
if (end == null) {
|
|
15
|
+
end = start;
|
|
16
|
+
start = 0n;
|
|
17
|
+
}
|
|
18
|
+
if (step === 0n) throw new Error("The step value must be a non-zero bigint.");
|
|
19
|
+
const length = require_bigIntRangeLength.bigIntRangeLength(start, end, step);
|
|
20
|
+
const result = new Array(length);
|
|
21
|
+
for (let i = 0; i < length; i++) result[i] = start + BigInt(length - i - 1) * step;
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.rangeRight = rangeRight;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { bigIntRangeLength } from "../_internal/bigIntRangeLength.mjs";
|
|
2
|
+
//#region src/bigint/rangeRight.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns an array of bigints from `start` up to, but not including, `end`, incrementing by `step`,
|
|
5
|
+
* in descending order.
|
|
6
|
+
*
|
|
7
|
+
* @param start - The exclusive end of the range when called with one argument, otherwise the inclusive start.
|
|
8
|
+
* @param end - The exclusive end of the range.
|
|
9
|
+
* @param step - The amount to increment by. Must not be `0n`.
|
|
10
|
+
* @returns An array of bigints.
|
|
11
|
+
* @throws {Error} If `step` is `0n`.
|
|
12
|
+
*/
|
|
13
|
+
function rangeRight(start, end, step = 1n) {
|
|
14
|
+
if (end == null) {
|
|
15
|
+
end = start;
|
|
16
|
+
start = 0n;
|
|
17
|
+
}
|
|
18
|
+
if (step === 0n) throw new Error("The step value must be a non-zero bigint.");
|
|
19
|
+
const length = bigIntRangeLength(start, end, step);
|
|
20
|
+
const result = new Array(length);
|
|
21
|
+
for (let i = 0; i < length; i++) result[i] = start + BigInt(length - i - 1) * step;
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { rangeRight };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/bigint/sum.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the sum of an array of bigints.
|
|
4
|
+
*
|
|
5
|
+
* This function takes an array of bigints and returns the sum of all the elements in the array.
|
|
6
|
+
* An empty array returns `0n`, so `sum(a) + sum(b)` always equals `sum([...a, ...b])`.
|
|
7
|
+
*
|
|
8
|
+
* @param nums - An array of bigints to be summed.
|
|
9
|
+
* @returns The sum of all the bigints in the array. Returns `0n` for an empty array.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const numbers = [1n, 2n, 3n, 4n, 5n];
|
|
13
|
+
* const result = sum(numbers);
|
|
14
|
+
* // result will be 15n
|
|
15
|
+
*/
|
|
16
|
+
declare function sum(nums: readonly bigint[]): bigint;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { sum };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/bigint/sum.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the sum of an array of bigints.
|
|
4
|
+
*
|
|
5
|
+
* This function takes an array of bigints and returns the sum of all the elements in the array.
|
|
6
|
+
* An empty array returns `0n`, so `sum(a) + sum(b)` always equals `sum([...a, ...b])`.
|
|
7
|
+
*
|
|
8
|
+
* @param nums - An array of bigints to be summed.
|
|
9
|
+
* @returns The sum of all the bigints in the array. Returns `0n` for an empty array.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const numbers = [1n, 2n, 3n, 4n, 5n];
|
|
13
|
+
* const result = sum(numbers);
|
|
14
|
+
* // result will be 15n
|
|
15
|
+
*/
|
|
16
|
+
declare function sum(nums: readonly bigint[]): bigint;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { sum };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/bigint/sum.ts
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the sum of an array of bigints.
|
|
4
|
+
*
|
|
5
|
+
* This function takes an array of bigints and returns the sum of all the elements in the array.
|
|
6
|
+
* An empty array returns `0n`, so `sum(a) + sum(b)` always equals `sum([...a, ...b])`.
|
|
7
|
+
*
|
|
8
|
+
* @param nums - An array of bigints to be summed.
|
|
9
|
+
* @returns The sum of all the bigints in the array. Returns `0n` for an empty array.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const numbers = [1n, 2n, 3n, 4n, 5n];
|
|
13
|
+
* const result = sum(numbers);
|
|
14
|
+
* // result will be 15n
|
|
15
|
+
*/
|
|
16
|
+
function sum(nums) {
|
|
17
|
+
let result = 0n;
|
|
18
|
+
for (let i = 0; i < nums.length; i++) result += nums[i];
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.sum = sum;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/bigint/sum.ts
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the sum of an array of bigints.
|
|
4
|
+
*
|
|
5
|
+
* This function takes an array of bigints and returns the sum of all the elements in the array.
|
|
6
|
+
* An empty array returns `0n`, so `sum(a) + sum(b)` always equals `sum([...a, ...b])`.
|
|
7
|
+
*
|
|
8
|
+
* @param nums - An array of bigints to be summed.
|
|
9
|
+
* @returns The sum of all the bigints in the array. Returns `0n` for an empty array.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const numbers = [1n, 2n, 3n, 4n, 5n];
|
|
13
|
+
* const result = sum(numbers);
|
|
14
|
+
* // result will be 15n
|
|
15
|
+
*/
|
|
16
|
+
function sum(nums) {
|
|
17
|
+
let result = 0n;
|
|
18
|
+
for (let i = 0; i < nums.length; i++) result += nums[i];
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { sum };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/bigint/sumBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the sum of an array by mapping each element to a bigint.
|
|
4
|
+
*
|
|
5
|
+
* This function takes an array and a function that maps each element to a bigint,
|
|
6
|
+
* and returns the sum of the mapped values. An empty array returns `0n`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param items - An array of elements to be summed.
|
|
10
|
+
* @param getValue - A function that maps an element to the bigint to add.
|
|
11
|
+
* @returns The sum of the mapped bigints. Returns `0n` for an empty array.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const items = [{ balance: 10n }, { balance: 20n }, { balance: 30n }];
|
|
15
|
+
* const result = sumBy(items, item => item.balance);
|
|
16
|
+
* // result will be 60n
|
|
17
|
+
*/
|
|
18
|
+
declare function sumBy<T>(items: readonly T[], getValue: (element: T, index: number) => bigint): bigint;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { sumBy };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/bigint/sumBy.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the sum of an array by mapping each element to a bigint.
|
|
4
|
+
*
|
|
5
|
+
* This function takes an array and a function that maps each element to a bigint,
|
|
6
|
+
* and returns the sum of the mapped values. An empty array returns `0n`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param items - An array of elements to be summed.
|
|
10
|
+
* @param getValue - A function that maps an element to the bigint to add.
|
|
11
|
+
* @returns The sum of the mapped bigints. Returns `0n` for an empty array.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const items = [{ balance: 10n }, { balance: 20n }, { balance: 30n }];
|
|
15
|
+
* const result = sumBy(items, item => item.balance);
|
|
16
|
+
* // result will be 60n
|
|
17
|
+
*/
|
|
18
|
+
declare function sumBy<T>(items: readonly T[], getValue: (element: T, index: number) => bigint): bigint;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { sumBy };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/bigint/sumBy.ts
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the sum of an array by mapping each element to a bigint.
|
|
4
|
+
*
|
|
5
|
+
* This function takes an array and a function that maps each element to a bigint,
|
|
6
|
+
* and returns the sum of the mapped values. An empty array returns `0n`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param items - An array of elements to be summed.
|
|
10
|
+
* @param getValue - A function that maps an element to the bigint to add.
|
|
11
|
+
* @returns The sum of the mapped bigints. Returns `0n` for an empty array.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const items = [{ balance: 10n }, { balance: 20n }, { balance: 30n }];
|
|
15
|
+
* const result = sumBy(items, item => item.balance);
|
|
16
|
+
* // result will be 60n
|
|
17
|
+
*/
|
|
18
|
+
function sumBy(items, getValue) {
|
|
19
|
+
let result = 0n;
|
|
20
|
+
for (let i = 0; i < items.length; i++) result += getValue(items[i], i);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.sumBy = sumBy;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/bigint/sumBy.ts
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the sum of an array by mapping each element to a bigint.
|
|
4
|
+
*
|
|
5
|
+
* This function takes an array and a function that maps each element to a bigint,
|
|
6
|
+
* and returns the sum of the mapped values. An empty array returns `0n`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the array.
|
|
9
|
+
* @param items - An array of elements to be summed.
|
|
10
|
+
* @param getValue - A function that maps an element to the bigint to add.
|
|
11
|
+
* @returns The sum of the mapped bigints. Returns `0n` for an empty array.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const items = [{ balance: 10n }, { balance: 20n }, { balance: 30n }];
|
|
15
|
+
* const result = sumBy(items, item => item.balance);
|
|
16
|
+
* // result will be 60n
|
|
17
|
+
*/
|
|
18
|
+
function sumBy(items, getValue) {
|
|
19
|
+
let result = 0n;
|
|
20
|
+
for (let i = 0; i < items.length; i++) result += getValue(items[i], i);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { sumBy };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
|
-
"version": "1.50.0-dev.
|
|
3
|
+
"version": "1.50.0-dev.1993+54a5104a",
|
|
4
4
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
5
5
|
"homepage": "https://es-toolkit.dev",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
@@ -34,6 +34,16 @@
|
|
|
34
34
|
"default": "./dist/array/index.js"
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
+
"./bigint": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/bigint/index.d.mts",
|
|
40
|
+
"default": "./dist/bigint/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/bigint/index.d.ts",
|
|
44
|
+
"default": "./dist/bigint/index.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
37
47
|
"./compat": {
|
|
38
48
|
"import": {
|
|
39
49
|
"types": "./dist/compat/index.d.mts",
|
|
@@ -189,6 +199,7 @@
|
|
|
189
199
|
"compat",
|
|
190
200
|
"*.d.ts",
|
|
191
201
|
"array.js",
|
|
202
|
+
"bigint.js",
|
|
192
203
|
"compat.js",
|
|
193
204
|
"error.js",
|
|
194
205
|
"fp.js",
|
|
@@ -283,6 +294,16 @@
|
|
|
283
294
|
"default": "./dist/array/index.js"
|
|
284
295
|
}
|
|
285
296
|
},
|
|
297
|
+
"./bigint": {
|
|
298
|
+
"import": {
|
|
299
|
+
"types": "./dist/bigint/index.d.mts",
|
|
300
|
+
"default": "./dist/bigint/index.mjs"
|
|
301
|
+
},
|
|
302
|
+
"require": {
|
|
303
|
+
"types": "./dist/bigint/index.d.ts",
|
|
304
|
+
"default": "./dist/bigint/index.js"
|
|
305
|
+
}
|
|
306
|
+
},
|
|
286
307
|
"./compat": {
|
|
287
308
|
"import": {
|
|
288
309
|
"types": "./dist/compat/index.d.mts",
|