es-toolkit 1.5.0-dev.107 → 1.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/dist/array/index.d.mts +0 -1
- package/dist/array/index.d.ts +0 -1
- package/dist/array/index.js +8 -21
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +11 -15
- package/dist/array/maxBy.d.mts +15 -8
- package/dist/array/maxBy.d.ts +15 -8
- package/dist/array/maxBy.js +4 -4
- package/dist/array/maxBy.js.map +1 -1
- package/dist/array/maxBy.mjs +1 -1
- package/dist/array/minBy.d.mts +8 -9
- package/dist/array/minBy.d.ts +8 -9
- package/dist/array/minBy.js +4 -4
- package/dist/array/minBy.js.map +1 -1
- package/dist/array/minBy.mjs +1 -1
- package/dist/chunk-7LAMAYGN.mjs +1 -0
- package/dist/{chunk-NOFHNJ5C.mjs → chunk-7OU22ENP.mjs} +1 -1
- package/dist/{chunk-NOFHNJ5C.mjs.map → chunk-7OU22ENP.mjs.map} +1 -1
- package/dist/chunk-H23GUJVF.mjs +18 -0
- package/dist/chunk-H23GUJVF.mjs.map +1 -0
- package/dist/chunk-KZ5JY7J3.mjs +18 -0
- package/dist/chunk-KZ5JY7J3.mjs.map +1 -0
- package/dist/chunk-NP6PDX3E.mjs +1 -0
- package/dist/index.d.mts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +17 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -30
- package/dist/math/index.d.mts +0 -1
- package/dist/math/index.d.ts +0 -1
- package/dist/math/index.js +9 -16
- package/dist/math/index.js.map +1 -1
- package/dist/math/index.mjs +7 -11
- package/dist/math/sum.d.mts +1 -1
- package/dist/math/sum.d.ts +1 -1
- package/dist/math/sum.js.map +1 -1
- package/dist/math/sum.mjs +1 -1
- package/dist/predicate/index.mjs +6 -6
- package/package.json +1 -1
- package/dist/array/compact.d.mts +0 -14
- package/dist/array/compact.d.ts +0 -14
- package/dist/array/compact.js +0 -39
- package/dist/array/compact.js.map +0 -1
- package/dist/array/compact.mjs +0 -8
- package/dist/chunk-FXOABQRO.mjs +0 -18
- package/dist/chunk-FXOABQRO.mjs.map +0 -1
- package/dist/chunk-KTL5FU5A.mjs +0 -1
- package/dist/chunk-NKTBEEIT.mjs +0 -15
- package/dist/chunk-NKTBEEIT.mjs.map +0 -1
- package/dist/chunk-OIHARMNM.mjs +0 -18
- package/dist/chunk-OIHARMNM.mjs.map +0 -1
- package/dist/chunk-QVHWSUEH.mjs +0 -1
- package/dist/chunk-QVHWSUEH.mjs.map +0 -1
- package/dist/chunk-S3GNYAM2.mjs +0 -13
- package/dist/chunk-S3GNYAM2.mjs.map +0 -1
- package/dist/math/mean.d.mts +0 -16
- package/dist/math/mean.d.ts +0 -16
- package/dist/math/mean.js +0 -44
- package/dist/math/mean.js.map +0 -1
- package/dist/math/mean.mjs +0 -9
- package/dist/math/mean.mjs.map +0 -1
- /package/dist/{array/compact.mjs.map → chunk-7LAMAYGN.mjs.map} +0 -0
- /package/dist/{chunk-KTL5FU5A.mjs.map → chunk-NP6PDX3E.mjs.map} +0 -0
package/dist/math/index.js
CHANGED
|
@@ -21,7 +21,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var math_exports = {};
|
|
22
22
|
__export(math_exports, {
|
|
23
23
|
clamp: () => clamp,
|
|
24
|
-
mean: () => mean,
|
|
25
24
|
random: () => random,
|
|
26
25
|
randomInt: () => randomInt,
|
|
27
26
|
range: () => range,
|
|
@@ -38,20 +37,6 @@ function clamp(value, bound1, bound2) {
|
|
|
38
37
|
return Math.min(Math.max(value, bound1), bound2);
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
// src/math/sum.ts
|
|
42
|
-
function sum(nums) {
|
|
43
|
-
let result = 0;
|
|
44
|
-
for (const num of nums) {
|
|
45
|
-
result += num;
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// src/math/mean.ts
|
|
51
|
-
function mean(nums) {
|
|
52
|
-
return sum(nums) / nums.length;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
40
|
// src/math/random.ts
|
|
56
41
|
function random(minimum, maximum) {
|
|
57
42
|
if (minimum >= maximum) {
|
|
@@ -74,6 +59,15 @@ function round(value, precision = 0) {
|
|
|
74
59
|
return Math.round(value * multiplier) / multiplier;
|
|
75
60
|
}
|
|
76
61
|
|
|
62
|
+
// src/math/sum.ts
|
|
63
|
+
function sum(nums) {
|
|
64
|
+
let result = 0;
|
|
65
|
+
for (const num of nums) {
|
|
66
|
+
result += num;
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
77
71
|
// src/math/range.ts
|
|
78
72
|
function range(start, end, step) {
|
|
79
73
|
if (end == null) {
|
|
@@ -96,7 +90,6 @@ function range(start, end, step) {
|
|
|
96
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
97
91
|
0 && (module.exports = {
|
|
98
92
|
clamp,
|
|
99
|
-
mean,
|
|
100
93
|
random,
|
|
101
94
|
randomInt,
|
|
102
95
|
range,
|
package/dist/math/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/
|
|
1
|
+
{"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/random.ts","../../src/math/randomInt.ts","../../src/math/round.ts","../../src/math/sum.ts","../../src/math/range.ts"],"sourcesContent":["export { clamp } from './clamp';\nexport { random } from './random';\nexport { randomInt } from './randomInt';\nexport { round } from './round';\nexport { sum } from './sum';\nexport { range } from './range';\n","/**\n * Clamps a number within the inclusive lower and upper bounds.\n *\n * This function takes a number and two bounds, and returns the number clamped within the specified bounds.\n * If only one bound is provided, it returns the minimum of the value and the bound.\n *\n * @param {number} value - The number to clamp.\n * @param {number} minimum - The minimum bound to clamp the number.\n * @param {number} maximum - The maximum bound to clamp the number.\n * @returns {number} The clamped number within the specified bounds.\n *\n * @example\n * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5\n * const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15\n * const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5\n * const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15\n */\nexport function clamp(value: number, maximum: number): number;\nexport function clamp(value: number, minimum: number, maximum: number): number;\nexport function clamp(value: number, bound1: number, bound2?: number): number {\n if (bound2 == null) {\n return Math.min(value, bound1);\n }\n\n return Math.min(Math.max(value, bound1), bound2);\n}\n","/**\n * Generate a random number within the given range.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result1 = random(0, 5); // Returns a random number between 0 and 5.\n * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown\n * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.\n */\nexport function random(minimum: number, maximum: number): number {\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n","import { random } from './random';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(minimum: number, maximum: number): number {\n return Math.floor(random(minimum, maximum));\n}\n","/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n * @throws {Error} Throws an error if `Precision` is not integer.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n * const result4 = round(1.2345, 3.1); // This will throw an error\n */\nexport function round(value: number, precision = 0): number {\n if (!Number.isInteger(precision)) {\n throw new Error('Precision must be an integer.');\n }\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n","/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums: number[]): number {\n let result = 0;\n\n for (const num of nums) {\n result += num;\n }\n\n return result;\n}\n","/**\n * Returns an array of numbers from `start` to `end`, incrementing by `step`.\n *\n * If `step` is not provided, it defaults to `1` for an\n * ascending range and `-1` for a descending range.\n *\n * @param {number} start - The starting number of the range.\n * @param {number} [end] - The end number of the range.\n * @param {number} [step] - The step value for the range.\n * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.\n *\n * @example\n * // Returns [0, 1, 2, 3]\n * range(4);\n *\n * @example\n * // Returns [0, 5, 10, 15]\n * range(0, 20, 5);\n *\n * @example\n * // Returns []\n * range(0, -4, -1);\n *\n * @example\n * // Throws an error: The step value must be a non-zero integer.\n * range(1, 4, 0);\n */\nexport function range(end: number): number[];\nexport function range(start: number, end: number): number[];\nexport function range(start: number, end: number, step: number): number[];\nexport function range(start: number, end?: number, step?: number): number[] {\n if (end == null) {\n end = start;\n start = 0;\n }\n\n if (step == null) {\n step = 1;\n }\n\n if (!Number.isInteger(step) || step === 0) {\n throw new Error(`The step value must be a non-zero integer.`);\n }\n\n const length = Math.max(Math.ceil((end - start) / step), 0);\n const result = new Array(length);\n\n for (let i = 0; i < length; i++) {\n result[i] = start + i * step;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBO,SAAS,MAAM,OAAe,QAAgB,QAAyB;AAC5E,MAAI,UAAU,MAAM;AAClB,WAAO,KAAK,IAAI,OAAO,MAAM;AAAA,EAC/B;AAEA,SAAO,KAAK,IAAI,KAAK,IAAI,OAAO,MAAM,GAAG,MAAM;AACjD;;;ACZO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ACLO,SAAS,UAAU,SAAiB,SAAyB;AAClE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAO,CAAC;AAC5C;;;ACCO,SAAS,MAAM,OAAe,YAAY,GAAW;AAC1D,MAAI,CAAC,OAAO,UAAU,SAAS,GAAG;AAChC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACA,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;;;ACVO,SAAS,IAAI,MAAwB;AAC1C,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,cAAU;AAAA,EACZ;AAEA,SAAO;AACT;;;ACSO,SAAS,MAAM,OAAe,KAAc,MAAyB;AAC1E,MAAI,OAAO,MAAM;AACf,UAAM;AACN,YAAQ;AAAA,EACV;AAEA,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,SAAS,GAAG;AACzC,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AAEA,QAAM,SAAS,KAAK,IAAI,KAAK,MAAM,MAAM,SAAS,IAAI,GAAG,CAAC;AAC1D,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,WAAO,CAAC,IAAI,QAAQ,IAAI;AAAA,EAC1B;AAEA,SAAO;AACT;","names":[]}
|
package/dist/math/index.mjs
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import "../chunk-
|
|
2
|
-
import {
|
|
3
|
-
round
|
|
4
|
-
} from "../chunk-5PMKOZ2F.mjs";
|
|
1
|
+
import "../chunk-7LAMAYGN.mjs";
|
|
5
2
|
import {
|
|
6
3
|
clamp
|
|
7
4
|
} from "../chunk-MLCL773E.mjs";
|
|
8
|
-
import {
|
|
9
|
-
mean
|
|
10
|
-
} from "../chunk-S3GNYAM2.mjs";
|
|
11
|
-
import {
|
|
12
|
-
sum
|
|
13
|
-
} from "../chunk-NOFHNJ5C.mjs";
|
|
14
5
|
import {
|
|
15
6
|
randomInt
|
|
16
7
|
} from "../chunk-5UT77WON.mjs";
|
|
@@ -20,10 +11,15 @@ import {
|
|
|
20
11
|
import {
|
|
21
12
|
range
|
|
22
13
|
} from "../chunk-UNLX2F2Y.mjs";
|
|
14
|
+
import {
|
|
15
|
+
round
|
|
16
|
+
} from "../chunk-5PMKOZ2F.mjs";
|
|
17
|
+
import {
|
|
18
|
+
sum
|
|
19
|
+
} from "../chunk-7OU22ENP.mjs";
|
|
23
20
|
import "../chunk-2MM5EJJX.mjs";
|
|
24
21
|
export {
|
|
25
22
|
clamp,
|
|
26
|
-
mean,
|
|
27
23
|
random,
|
|
28
24
|
randomInt,
|
|
29
25
|
range,
|
package/dist/math/sum.d.mts
CHANGED
package/dist/math/sum.d.ts
CHANGED
package/dist/math/sum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/sum.ts"],"sourcesContent":["/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums:
|
|
1
|
+
{"version":3,"sources":["../../src/math/sum.ts"],"sourcesContent":["/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums: number[]): number {\n let result = 0;\n\n for (const num of nums) {\n result += num;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,SAAS,IAAI,MAAwB;AAC1C,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,cAAU;AAAA,EACZ;AAEA,SAAO;AACT;","names":[]}
|
package/dist/math/sum.mjs
CHANGED
package/dist/predicate/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import "../chunk-MAJSPFA6.mjs";
|
|
2
|
-
import {
|
|
3
|
-
isNil
|
|
4
|
-
} from "../chunk-OHQAR5AU.mjs";
|
|
5
|
-
import {
|
|
6
|
-
isNotNil
|
|
7
|
-
} from "../chunk-ZQNAZPSK.mjs";
|
|
8
2
|
import {
|
|
9
3
|
isNull
|
|
10
4
|
} from "../chunk-AIRSKN47.mjs";
|
|
11
5
|
import {
|
|
12
6
|
isUndefined
|
|
13
7
|
} from "../chunk-VH2PV426.mjs";
|
|
8
|
+
import {
|
|
9
|
+
isNil
|
|
10
|
+
} from "../chunk-OHQAR5AU.mjs";
|
|
11
|
+
import {
|
|
12
|
+
isNotNil
|
|
13
|
+
} from "../chunk-ZQNAZPSK.mjs";
|
|
14
14
|
import "../chunk-2MM5EJJX.mjs";
|
|
15
15
|
export {
|
|
16
16
|
isNil,
|
package/package.json
CHANGED
package/dist/array/compact.d.mts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
type NotFalsey<T> = Exclude<T, false | null | 0 | '' | undefined>;
|
|
2
|
-
/**
|
|
3
|
-
* Removes falsey values (false, null, 0, '', undefined, NaN) from an array.
|
|
4
|
-
*
|
|
5
|
-
* @param {readonly T[]} arr - The input array to remove falsey values.
|
|
6
|
-
* @returns {Array<Exclude<T, false | null | 0 | '' | undefined>>} - A new array with all falsey values removed.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* compact([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
|
|
10
|
-
* Returns: [1, 2, 3, 4, 5]
|
|
11
|
-
*/
|
|
12
|
-
declare function compact<T>(arr: readonly T[]): Array<NotFalsey<T>>;
|
|
13
|
-
|
|
14
|
-
export { compact };
|
package/dist/array/compact.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
type NotFalsey<T> = Exclude<T, false | null | 0 | '' | undefined>;
|
|
2
|
-
/**
|
|
3
|
-
* Removes falsey values (false, null, 0, '', undefined, NaN) from an array.
|
|
4
|
-
*
|
|
5
|
-
* @param {readonly T[]} arr - The input array to remove falsey values.
|
|
6
|
-
* @returns {Array<Exclude<T, false | null | 0 | '' | undefined>>} - A new array with all falsey values removed.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* compact([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
|
|
10
|
-
* Returns: [1, 2, 3, 4, 5]
|
|
11
|
-
*/
|
|
12
|
-
declare function compact<T>(arr: readonly T[]): Array<NotFalsey<T>>;
|
|
13
|
-
|
|
14
|
-
export { compact };
|
package/dist/array/compact.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/array/compact.ts
|
|
21
|
-
var compact_exports = {};
|
|
22
|
-
__export(compact_exports, {
|
|
23
|
-
compact: () => compact
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(compact_exports);
|
|
26
|
-
function compact(arr) {
|
|
27
|
-
const result = [];
|
|
28
|
-
for (const item of arr) {
|
|
29
|
-
if (item) {
|
|
30
|
-
result.push(item);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
-
0 && (module.exports = {
|
|
37
|
-
compact
|
|
38
|
-
});
|
|
39
|
-
//# sourceMappingURL=compact.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/array/compact.ts"],"sourcesContent":["type NotFalsey<T> = Exclude<T, false | null | 0 | '' | undefined>;\n\n/**\n * Removes falsey values (false, null, 0, '', undefined, NaN) from an array.\n *\n * @param {readonly T[]} arr - The input array to remove falsey values.\n * @returns {Array<Exclude<T, false | null | 0 | '' | undefined>>} - A new array with all falsey values removed.\n *\n * @example\n * compact([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);\n * Returns: [1, 2, 3, 4, 5]\n */\nexport function compact<T>(arr: readonly T[]): Array<NotFalsey<T>> {\n const result: Array<NotFalsey<T>> = [];\n\n for (const item of arr) {\n if (item) {\n result.push(item as NotFalsey<T>);\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,QAAW,KAAwC;AACjE,QAAM,SAA8B,CAAC;AAErC,aAAW,QAAQ,KAAK;AACtB,QAAI,MAAM;AACR,aAAO,KAAK,IAAoB;AAAA,IAClC;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/array/compact.mjs
DELETED
package/dist/chunk-FXOABQRO.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// src/array/maxBy.ts
|
|
2
|
-
function maxBy(items, getValue) {
|
|
3
|
-
let maxElement = items[0];
|
|
4
|
-
let max = -Infinity;
|
|
5
|
-
for (const element of items) {
|
|
6
|
-
const value = getValue(element);
|
|
7
|
-
if (value > max) {
|
|
8
|
-
max = value;
|
|
9
|
-
maxElement = element;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return maxElement;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
maxBy
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=chunk-FXOABQRO.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/array/maxBy.ts"],"sourcesContent":["/**\n * Finds the element in an array that has the maximum value when applying\n * the `getValue` function to each element.\n *\n * @param {T[]} items The array of elements to search.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {T} The element with the maximum value as determined by the `getValue` function.\n * @example\n * maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }\n * maxBy([], x => x.a); // Returns: undefined\n */\nexport function maxBy<T>(items: T[], getValue: (element: T) => number): T {\n let maxElement = items[0];\n let max = -Infinity;\n\n for (const element of items) {\n const value = getValue(element);\n if (value > max) {\n max = value;\n maxElement = element;\n }\n }\n\n return maxElement;\n}\n"],"mappings":";AAWO,SAAS,MAAS,OAAY,UAAqC;AACxE,MAAI,aAAa,MAAM,CAAC;AACxB,MAAI,MAAM;AAEV,aAAW,WAAW,OAAO;AAC3B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/chunk-KTL5FU5A.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-KTL5FU5A.mjs.map
|
package/dist/chunk-NKTBEEIT.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/array/compact.ts"],"sourcesContent":["type NotFalsey<T> = Exclude<T, false | null | 0 | '' | undefined>;\n\n/**\n * Removes falsey values (false, null, 0, '', undefined, NaN) from an array.\n *\n * @param {readonly T[]} arr - The input array to remove falsey values.\n * @returns {Array<Exclude<T, false | null | 0 | '' | undefined>>} - A new array with all falsey values removed.\n *\n * @example\n * compact([0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);\n * Returns: [1, 2, 3, 4, 5]\n */\nexport function compact<T>(arr: readonly T[]): Array<NotFalsey<T>> {\n const result: Array<NotFalsey<T>> = [];\n\n for (const item of arr) {\n if (item) {\n result.push(item as NotFalsey<T>);\n }\n }\n\n return result;\n}\n"],"mappings":";AAYO,SAAS,QAAW,KAAwC;AACjE,QAAM,SAA8B,CAAC;AAErC,aAAW,QAAQ,KAAK;AACtB,QAAI,MAAM;AACR,aAAO,KAAK,IAAoB;AAAA,IAClC;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/chunk-OIHARMNM.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// src/array/minBy.ts
|
|
2
|
-
function minBy(items, getValue) {
|
|
3
|
-
let minElement = items[0];
|
|
4
|
-
let min = Infinity;
|
|
5
|
-
for (const element of items) {
|
|
6
|
-
const value = getValue(element);
|
|
7
|
-
if (value < min) {
|
|
8
|
-
min = value;
|
|
9
|
-
minElement = element;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return minElement;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
minBy
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=chunk-OIHARMNM.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/array/minBy.ts"],"sourcesContent":["/**\n * Finds the element in an array that has the minimum value when applying\n * the `getValue` function to each element.\n *\n * @param {T[]} items The array of elements to search.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {T} The element with the minimum value as determined by the `getValue` function.\n * @example\n * minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }\n * minBy([], x => x.a); // Returns: undefined\n */\nexport function minBy<T>(items: T[], getValue: (element: T) => number): T {\n let minElement = items[0];\n let min = Infinity;\n\n for (const element of items) {\n const value = getValue(element);\n if (value < min) {\n min = value;\n minElement = element;\n }\n }\n\n return minElement;\n}\n"],"mappings":";AAWO,SAAS,MAAS,OAAY,UAAqC;AACxE,MAAI,aAAa,MAAM,CAAC;AACxB,MAAI,MAAM;AAEV,aAAW,WAAW,OAAO;AAC3B,UAAM,QAAQ,SAAS,OAAO;AAC9B,QAAI,QAAQ,KAAK;AACf,YAAM;AACN,mBAAa;AAAA,IACf;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/chunk-QVHWSUEH.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-QVHWSUEH.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/chunk-S3GNYAM2.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/math/mean.ts"],"sourcesContent":["import { sum } from './sum';\n\n/**\n * Calculates the average of an array of numbers.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @param {number[]} nums - An array of numbers to calculate the avverage.\n * @returns {number} The average of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = average(numbers);\n * // result will be 3\n */\nexport function mean(nums: readonly number[]): number {\n return sum(nums) / nums.length;\n}\n"],"mappings":";;;;;AAeO,SAAS,KAAK,MAAiC;AACpD,SAAO,IAAI,IAAI,IAAI,KAAK;AAC1B;","names":[]}
|
package/dist/math/mean.d.mts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculates the average of an array of numbers.
|
|
3
|
-
*
|
|
4
|
-
* If the array is empty, this function returns `NaN`.
|
|
5
|
-
*
|
|
6
|
-
* @param {number[]} nums - An array of numbers to calculate the avverage.
|
|
7
|
-
* @returns {number} The average of all the numbers in the array.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* const numbers = [1, 2, 3, 4, 5];
|
|
11
|
-
* const result = average(numbers);
|
|
12
|
-
* // result will be 3
|
|
13
|
-
*/
|
|
14
|
-
declare function mean(nums: readonly number[]): number;
|
|
15
|
-
|
|
16
|
-
export { mean };
|
package/dist/math/mean.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculates the average of an array of numbers.
|
|
3
|
-
*
|
|
4
|
-
* If the array is empty, this function returns `NaN`.
|
|
5
|
-
*
|
|
6
|
-
* @param {number[]} nums - An array of numbers to calculate the avverage.
|
|
7
|
-
* @returns {number} The average of all the numbers in the array.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* const numbers = [1, 2, 3, 4, 5];
|
|
11
|
-
* const result = average(numbers);
|
|
12
|
-
* // result will be 3
|
|
13
|
-
*/
|
|
14
|
-
declare function mean(nums: readonly number[]): number;
|
|
15
|
-
|
|
16
|
-
export { mean };
|
package/dist/math/mean.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/math/mean.ts
|
|
21
|
-
var mean_exports = {};
|
|
22
|
-
__export(mean_exports, {
|
|
23
|
-
mean: () => mean
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(mean_exports);
|
|
26
|
-
|
|
27
|
-
// src/math/sum.ts
|
|
28
|
-
function sum(nums) {
|
|
29
|
-
let result = 0;
|
|
30
|
-
for (const num of nums) {
|
|
31
|
-
result += num;
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// src/math/mean.ts
|
|
37
|
-
function mean(nums) {
|
|
38
|
-
return sum(nums) / nums.length;
|
|
39
|
-
}
|
|
40
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
-
0 && (module.exports = {
|
|
42
|
-
mean
|
|
43
|
-
});
|
|
44
|
-
//# sourceMappingURL=mean.js.map
|
package/dist/math/mean.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/mean.ts","../../src/math/sum.ts"],"sourcesContent":["import { sum } from './sum';\n\n/**\n * Calculates the average of an array of numbers.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @param {number[]} nums - An array of numbers to calculate the avverage.\n * @returns {number} The average of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = average(numbers);\n * // result will be 3\n */\nexport function mean(nums: readonly number[]): number {\n return sum(nums) / nums.length;\n}\n","/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums: readonly number[]): number {\n let result = 0;\n\n for (const num of nums) {\n result += num;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,SAAS,IAAI,MAAiC;AACnD,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,cAAU;AAAA,EACZ;AAEA,SAAO;AACT;;;ADNO,SAAS,KAAK,MAAiC;AACpD,SAAO,IAAI,IAAI,IAAI,KAAK;AAC1B;","names":[]}
|
package/dist/math/mean.mjs
DELETED
package/dist/math/mean.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
File without changes
|
|
File without changes
|