es-toolkit 1.5.0 → 1.6.0-dev.113
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 +11 -0
- package/dist/array/compact.d.mts +14 -0
- package/dist/array/compact.d.ts +14 -0
- package/dist/array/compact.js +39 -0
- package/dist/array/compact.js.map +1 -0
- package/dist/array/compact.mjs +8 -0
- package/dist/array/index.d.mts +3 -0
- package/dist/array/index.d.ts +3 -0
- package/dist/array/index.js +44 -8
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +52 -40
- package/dist/array/keyBy.d.mts +28 -0
- package/dist/array/keyBy.d.ts +28 -0
- package/dist/array/keyBy.js +38 -0
- package/dist/array/keyBy.js.map +1 -0
- package/dist/array/keyBy.mjs +8 -0
- package/dist/array/maxBy.d.mts +8 -15
- package/dist/array/maxBy.d.ts +8 -15
- 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 +9 -8
- package/dist/array/minBy.d.ts +9 -8
- package/dist/array/minBy.js +4 -4
- package/dist/array/minBy.js.map +1 -1
- package/dist/array/minBy.mjs +1 -1
- package/dist/array/zipObject.d.mts +33 -0
- package/dist/array/zipObject.d.ts +33 -0
- package/dist/array/zipObject.js +37 -0
- package/dist/array/zipObject.js.map +1 -0
- package/dist/array/zipObject.mjs +8 -0
- package/dist/array/zipObject.mjs.map +1 -0
- package/dist/chunk-DA7GSKQ5.mjs +13 -0
- package/dist/chunk-DA7GSKQ5.mjs.map +1 -0
- package/dist/chunk-FXOABQRO.mjs +18 -0
- package/dist/chunk-FXOABQRO.mjs.map +1 -0
- package/dist/chunk-NKTBEEIT.mjs +15 -0
- package/dist/chunk-NKTBEEIT.mjs.map +1 -0
- package/dist/{chunk-7OU22ENP.mjs → chunk-NOFHNJ5C.mjs} +1 -1
- package/dist/{chunk-7OU22ENP.mjs.map → chunk-NOFHNJ5C.mjs.map} +1 -1
- package/dist/chunk-OIHARMNM.mjs +18 -0
- package/dist/chunk-OIHARMNM.mjs.map +1 -0
- package/dist/chunk-QVHWSUEH.mjs +1 -0
- package/dist/chunk-QVHWSUEH.mjs.map +1 -0
- package/dist/chunk-S3GNYAM2.mjs +13 -0
- package/dist/chunk-S3GNYAM2.mjs.map +1 -0
- package/dist/{chunk-LCP6FOCX.mjs → chunk-SYWMYQYJ.mjs} +5 -1
- package/dist/chunk-SYWMYQYJ.mjs.map +1 -0
- package/dist/chunk-V6MDTRGS.mjs +1 -0
- package/dist/chunk-V6MDTRGS.mjs.map +1 -0
- package/dist/{chunk-5UT77WON.mjs → chunk-WC5HFQXP.mjs} +2 -2
- package/dist/chunk-WC5HFQXP.mjs.map +1 -0
- package/dist/chunk-ZOTAORG3.mjs +14 -0
- package/dist/chunk-ZOTAORG3.mjs.map +1 -0
- package/dist/function/index.mjs +3 -3
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +64 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -69
- package/dist/math/index.d.mts +1 -0
- package/dist/math/index.d.ts +1 -0
- package/dist/math/index.js +20 -9
- package/dist/math/index.js.map +1 -1
- package/dist/math/index.mjs +13 -9
- package/dist/math/mean.d.mts +16 -0
- package/dist/math/mean.d.ts +16 -0
- package/dist/math/mean.js +44 -0
- package/dist/math/mean.js.map +1 -0
- package/dist/math/mean.mjs +9 -0
- package/dist/math/mean.mjs.map +1 -0
- package/dist/math/random.d.mts +3 -0
- package/dist/math/random.d.ts +3 -0
- package/dist/math/random.js +4 -0
- package/dist/math/random.js.map +1 -1
- package/dist/math/random.mjs +1 -1
- package/dist/math/randomInt.d.mts +3 -0
- package/dist/math/randomInt.d.ts +3 -0
- package/dist/math/randomInt.js +4 -0
- package/dist/math/randomInt.js.map +1 -1
- package/dist/math/randomInt.mjs +2 -2
- 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/object/index.mjs +3 -3
- package/dist/predicate/index.mjs +6 -6
- package/package.json +1 -1
- package/dist/chunk-5UT77WON.mjs.map +0 -1
- package/dist/chunk-7LAMAYGN.mjs +0 -1
- package/dist/chunk-H23GUJVF.mjs +0 -18
- package/dist/chunk-H23GUJVF.mjs.map +0 -1
- package/dist/chunk-KZ5JY7J3.mjs +0 -18
- package/dist/chunk-KZ5JY7J3.mjs.map +0 -1
- package/dist/chunk-LCP6FOCX.mjs.map +0 -1
- package/dist/chunk-NP6PDX3E.mjs +0 -1
- /package/dist/{chunk-7LAMAYGN.mjs.map → array/compact.mjs.map} +0 -0
- /package/dist/{chunk-NP6PDX3E.mjs.map → array/keyBy.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
import "./chunk-MAJSPFA6.mjs";
|
|
2
|
+
import {
|
|
3
|
+
isNil
|
|
4
|
+
} from "./chunk-OHQAR5AU.mjs";
|
|
5
|
+
import {
|
|
6
|
+
isNotNil
|
|
7
|
+
} from "./chunk-ZQNAZPSK.mjs";
|
|
8
|
+
import {
|
|
9
|
+
isNull
|
|
10
|
+
} from "./chunk-AIRSKN47.mjs";
|
|
11
|
+
import {
|
|
12
|
+
isUndefined
|
|
13
|
+
} from "./chunk-VH2PV426.mjs";
|
|
1
14
|
import "./chunk-ARZ5BDR6.mjs";
|
|
2
15
|
import {
|
|
3
16
|
delay
|
|
4
17
|
} from "./chunk-AL3GJBEI.mjs";
|
|
5
18
|
import "./chunk-T5JCRGXA.mjs";
|
|
19
|
+
import {
|
|
20
|
+
pickBy
|
|
21
|
+
} from "./chunk-MQWVBKUT.mjs";
|
|
6
22
|
import {
|
|
7
23
|
omit
|
|
8
24
|
} from "./chunk-PLTO44KM.mjs";
|
|
@@ -12,48 +28,42 @@ import {
|
|
|
12
28
|
import {
|
|
13
29
|
pick
|
|
14
30
|
} from "./chunk-OFWKFUFZ.mjs";
|
|
31
|
+
import "./chunk-N6EM6ETS.mjs";
|
|
15
32
|
import {
|
|
16
|
-
|
|
17
|
-
} from "./chunk-
|
|
18
|
-
import "./chunk-MAJSPFA6.mjs";
|
|
19
|
-
import {
|
|
20
|
-
isNull
|
|
21
|
-
} from "./chunk-AIRSKN47.mjs";
|
|
22
|
-
import {
|
|
23
|
-
isUndefined
|
|
24
|
-
} from "./chunk-VH2PV426.mjs";
|
|
25
|
-
import {
|
|
26
|
-
isNil
|
|
27
|
-
} from "./chunk-OHQAR5AU.mjs";
|
|
33
|
+
noop
|
|
34
|
+
} from "./chunk-LKXCOLNY.mjs";
|
|
28
35
|
import {
|
|
29
|
-
|
|
30
|
-
} from "./chunk-
|
|
31
|
-
import "./chunk-7LAMAYGN.mjs";
|
|
36
|
+
once
|
|
37
|
+
} from "./chunk-UFAA5WKR.mjs";
|
|
32
38
|
import {
|
|
33
|
-
|
|
34
|
-
} from "./chunk-
|
|
39
|
+
throttle
|
|
40
|
+
} from "./chunk-XLO3QZVY.mjs";
|
|
41
|
+
import "./chunk-QVHWSUEH.mjs";
|
|
35
42
|
import {
|
|
36
43
|
randomInt
|
|
37
|
-
} from "./chunk-
|
|
38
|
-
import {
|
|
39
|
-
random
|
|
40
|
-
} from "./chunk-LCP6FOCX.mjs";
|
|
44
|
+
} from "./chunk-WC5HFQXP.mjs";
|
|
41
45
|
import {
|
|
42
46
|
range
|
|
43
47
|
} from "./chunk-UNLX2F2Y.mjs";
|
|
44
48
|
import {
|
|
45
49
|
round
|
|
46
50
|
} from "./chunk-5PMKOZ2F.mjs";
|
|
51
|
+
import {
|
|
52
|
+
clamp
|
|
53
|
+
} from "./chunk-MLCL773E.mjs";
|
|
54
|
+
import {
|
|
55
|
+
mean
|
|
56
|
+
} from "./chunk-S3GNYAM2.mjs";
|
|
47
57
|
import {
|
|
48
58
|
sum
|
|
49
|
-
} from "./chunk-
|
|
50
|
-
import "./chunk-NP6PDX3E.mjs";
|
|
59
|
+
} from "./chunk-NOFHNJ5C.mjs";
|
|
51
60
|
import {
|
|
52
|
-
|
|
53
|
-
} from "./chunk-
|
|
61
|
+
random
|
|
62
|
+
} from "./chunk-SYWMYQYJ.mjs";
|
|
54
63
|
import {
|
|
55
|
-
|
|
56
|
-
} from "./chunk-
|
|
64
|
+
debounce
|
|
65
|
+
} from "./chunk-MKETZ2RP.mjs";
|
|
66
|
+
import "./chunk-V6MDTRGS.mjs";
|
|
57
67
|
import {
|
|
58
68
|
xor
|
|
59
69
|
} from "./chunk-G2TTBLLJ.mjs";
|
|
@@ -63,24 +73,15 @@ import {
|
|
|
63
73
|
import {
|
|
64
74
|
xorWith
|
|
65
75
|
} from "./chunk-UMDNWTJC.mjs";
|
|
66
|
-
import {
|
|
67
|
-
unionWith
|
|
68
|
-
} from "./chunk-642SWVKJ.mjs";
|
|
69
|
-
import {
|
|
70
|
-
uniqWith
|
|
71
|
-
} from "./chunk-2PFDLYQC.mjs";
|
|
72
76
|
import {
|
|
73
77
|
zip
|
|
74
78
|
} from "./chunk-IDCUZVJL.mjs";
|
|
75
79
|
import {
|
|
76
|
-
|
|
77
|
-
} from "./chunk-
|
|
78
|
-
import {
|
|
79
|
-
shuffle
|
|
80
|
-
} from "./chunk-DPLJQQFX.mjs";
|
|
80
|
+
zipObject
|
|
81
|
+
} from "./chunk-DA7GSKQ5.mjs";
|
|
81
82
|
import {
|
|
82
|
-
|
|
83
|
-
} from "./chunk-
|
|
83
|
+
zipWith
|
|
84
|
+
} from "./chunk-4KYXHZ4R.mjs";
|
|
84
85
|
import {
|
|
85
86
|
takeRight
|
|
86
87
|
} from "./chunk-XDKEPIUV.mjs";
|
|
@@ -93,45 +94,45 @@ import {
|
|
|
93
94
|
import {
|
|
94
95
|
union
|
|
95
96
|
} from "./chunk-DAJZ3JCI.mjs";
|
|
96
|
-
import {
|
|
97
|
-
uniq
|
|
98
|
-
} from "./chunk-XFCW7XJ4.mjs";
|
|
99
97
|
import {
|
|
100
98
|
unionBy
|
|
101
99
|
} from "./chunk-NRNKP6JF.mjs";
|
|
102
100
|
import {
|
|
103
|
-
|
|
104
|
-
} from "./chunk-
|
|
101
|
+
unionWith
|
|
102
|
+
} from "./chunk-642SWVKJ.mjs";
|
|
105
103
|
import {
|
|
106
|
-
|
|
107
|
-
} from "./chunk-
|
|
104
|
+
uniqWith
|
|
105
|
+
} from "./chunk-2PFDLYQC.mjs";
|
|
108
106
|
import {
|
|
109
|
-
|
|
110
|
-
} from "./chunk-
|
|
107
|
+
uniq
|
|
108
|
+
} from "./chunk-XFCW7XJ4.mjs";
|
|
109
|
+
import {
|
|
110
|
+
uniqBy
|
|
111
|
+
} from "./chunk-WPDDOUQT.mjs";
|
|
111
112
|
import {
|
|
112
113
|
intersectionWith
|
|
113
114
|
} from "./chunk-2EFS3VA3.mjs";
|
|
115
|
+
import {
|
|
116
|
+
keyBy
|
|
117
|
+
} from "./chunk-ZOTAORG3.mjs";
|
|
114
118
|
import {
|
|
115
119
|
maxBy
|
|
116
|
-
} from "./chunk-
|
|
120
|
+
} from "./chunk-FXOABQRO.mjs";
|
|
117
121
|
import {
|
|
118
122
|
minBy
|
|
119
|
-
} from "./chunk-
|
|
123
|
+
} from "./chunk-OIHARMNM.mjs";
|
|
120
124
|
import {
|
|
121
125
|
partition
|
|
122
126
|
} from "./chunk-5L2V7WD3.mjs";
|
|
123
127
|
import {
|
|
124
|
-
|
|
125
|
-
} from "./chunk-
|
|
126
|
-
import {
|
|
127
|
-
difference
|
|
128
|
-
} from "./chunk-JPUKH67K.mjs";
|
|
128
|
+
sample
|
|
129
|
+
} from "./chunk-DOOIIHT3.mjs";
|
|
129
130
|
import {
|
|
130
|
-
|
|
131
|
-
} from "./chunk-
|
|
131
|
+
shuffle
|
|
132
|
+
} from "./chunk-DPLJQQFX.mjs";
|
|
132
133
|
import {
|
|
133
|
-
|
|
134
|
-
} from "./chunk-
|
|
134
|
+
take
|
|
135
|
+
} from "./chunk-ME352XO7.mjs";
|
|
135
136
|
import {
|
|
136
137
|
drop
|
|
137
138
|
} from "./chunk-ACFP3XMB.mjs";
|
|
@@ -144,28 +145,40 @@ import {
|
|
|
144
145
|
import {
|
|
145
146
|
dropWhile
|
|
146
147
|
} from "./chunk-K2BAFL2T.mjs";
|
|
148
|
+
import {
|
|
149
|
+
groupBy
|
|
150
|
+
} from "./chunk-LWXZFXY5.mjs";
|
|
151
|
+
import {
|
|
152
|
+
intersection
|
|
153
|
+
} from "./chunk-PYLGHB3F.mjs";
|
|
154
|
+
import {
|
|
155
|
+
intersectionBy
|
|
156
|
+
} from "./chunk-GNSJP2AB.mjs";
|
|
147
157
|
import "./chunk-FZEZH22H.mjs";
|
|
148
158
|
import {
|
|
149
159
|
AbortError
|
|
150
160
|
} from "./chunk-VP2LXY75.mjs";
|
|
151
|
-
import "./chunk-N6EM6ETS.mjs";
|
|
152
161
|
import {
|
|
153
|
-
|
|
154
|
-
} from "./chunk-
|
|
162
|
+
chunk
|
|
163
|
+
} from "./chunk-E6C5EZQA.mjs";
|
|
155
164
|
import {
|
|
156
|
-
|
|
157
|
-
} from "./chunk-
|
|
165
|
+
compact
|
|
166
|
+
} from "./chunk-NKTBEEIT.mjs";
|
|
158
167
|
import {
|
|
159
|
-
|
|
160
|
-
} from "./chunk-
|
|
168
|
+
difference
|
|
169
|
+
} from "./chunk-JPUKH67K.mjs";
|
|
161
170
|
import {
|
|
162
|
-
|
|
163
|
-
} from "./chunk-
|
|
171
|
+
differenceBy
|
|
172
|
+
} from "./chunk-LVWX5B43.mjs";
|
|
173
|
+
import {
|
|
174
|
+
differenceWith
|
|
175
|
+
} from "./chunk-6NVQAHXP.mjs";
|
|
164
176
|
import "./chunk-2MM5EJJX.mjs";
|
|
165
177
|
export {
|
|
166
178
|
AbortError,
|
|
167
179
|
chunk,
|
|
168
180
|
clamp,
|
|
181
|
+
compact,
|
|
169
182
|
debounce,
|
|
170
183
|
delay,
|
|
171
184
|
difference,
|
|
@@ -183,7 +196,9 @@ export {
|
|
|
183
196
|
isNotNil,
|
|
184
197
|
isNull,
|
|
185
198
|
isUndefined,
|
|
199
|
+
keyBy,
|
|
186
200
|
maxBy,
|
|
201
|
+
mean,
|
|
187
202
|
minBy,
|
|
188
203
|
noop,
|
|
189
204
|
omit,
|
|
@@ -214,6 +229,7 @@ export {
|
|
|
214
229
|
xorBy,
|
|
215
230
|
xorWith,
|
|
216
231
|
zip,
|
|
232
|
+
zipObject,
|
|
217
233
|
zipWith
|
|
218
234
|
};
|
|
219
235
|
//# sourceMappingURL=index.mjs.map
|
package/dist/math/index.d.mts
CHANGED
package/dist/math/index.d.ts
CHANGED
package/dist/math/index.js
CHANGED
|
@@ -21,6 +21,7 @@ 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,
|
|
24
25
|
random: () => random,
|
|
25
26
|
randomInt: () => randomInt,
|
|
26
27
|
range: () => range,
|
|
@@ -37,8 +38,26 @@ function clamp(value, bound1, bound2) {
|
|
|
37
38
|
return Math.min(Math.max(value, bound1), bound2);
|
|
38
39
|
}
|
|
39
40
|
|
|
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
|
+
|
|
40
55
|
// src/math/random.ts
|
|
41
56
|
function random(minimum, maximum) {
|
|
57
|
+
if (maximum == null) {
|
|
58
|
+
maximum = minimum;
|
|
59
|
+
minimum = 0;
|
|
60
|
+
}
|
|
42
61
|
if (minimum >= maximum) {
|
|
43
62
|
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
44
63
|
}
|
|
@@ -59,15 +78,6 @@ function round(value, precision = 0) {
|
|
|
59
78
|
return Math.round(value * multiplier) / multiplier;
|
|
60
79
|
}
|
|
61
80
|
|
|
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
|
-
|
|
71
81
|
// src/math/range.ts
|
|
72
82
|
function range(start, end, step) {
|
|
73
83
|
if (end == null) {
|
|
@@ -90,6 +100,7 @@ function range(start, end, step) {
|
|
|
90
100
|
// Annotate the CommonJS export names for ESM import in node:
|
|
91
101
|
0 && (module.exports = {
|
|
92
102
|
clamp,
|
|
103
|
+
mean,
|
|
93
104
|
random,
|
|
94
105
|
randomInt,
|
|
95
106
|
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/sum.ts","../../src/math/mean.ts","../../src/math/random.ts","../../src/math/randomInt.ts","../../src/math/round.ts","../../src/math/range.ts"],"sourcesContent":["export { clamp } from './clamp';\nexport { mean } from './mean';\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 * 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","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 * Generate a random number within the given range.\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\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(maximum: number): number;\nexport function random(minimum: number, maximum: number): number;\nexport function random(minimum: number, maximum?: number): number {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\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 * If only one argument is provided, a number between `0` and the given number is returned.\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(maximum: number): number;\nexport function randomInt(minimum: number, maximum: number): number;\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 * 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;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,IAAI,MAAiC;AACnD,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,cAAU;AAAA,EACZ;AAEA,SAAO;AACT;;;ACNO,SAAS,KAAK,MAAiC;AACpD,SAAO,IAAI,IAAI,IAAI,KAAK;AAC1B;;;ACAO,SAAS,OAAO,SAAiB,SAA0B;AAChE,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ACVO,SAAS,UAAU,SAAiB,SAA0B;AACnE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAQ,CAAC;AAC7C;;;ACHO,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;;;ACOO,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,25 +1,29 @@
|
|
|
1
|
-
import "../chunk-
|
|
2
|
-
import {
|
|
3
|
-
clamp
|
|
4
|
-
} from "../chunk-MLCL773E.mjs";
|
|
1
|
+
import "../chunk-QVHWSUEH.mjs";
|
|
5
2
|
import {
|
|
6
3
|
randomInt
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import {
|
|
9
|
-
random
|
|
10
|
-
} from "../chunk-LCP6FOCX.mjs";
|
|
4
|
+
} from "../chunk-WC5HFQXP.mjs";
|
|
11
5
|
import {
|
|
12
6
|
range
|
|
13
7
|
} from "../chunk-UNLX2F2Y.mjs";
|
|
14
8
|
import {
|
|
15
9
|
round
|
|
16
10
|
} from "../chunk-5PMKOZ2F.mjs";
|
|
11
|
+
import {
|
|
12
|
+
clamp
|
|
13
|
+
} from "../chunk-MLCL773E.mjs";
|
|
14
|
+
import {
|
|
15
|
+
mean
|
|
16
|
+
} from "../chunk-S3GNYAM2.mjs";
|
|
17
17
|
import {
|
|
18
18
|
sum
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-NOFHNJ5C.mjs";
|
|
20
|
+
import {
|
|
21
|
+
random
|
|
22
|
+
} from "../chunk-SYWMYQYJ.mjs";
|
|
20
23
|
import "../chunk-2MM5EJJX.mjs";
|
|
21
24
|
export {
|
|
22
25
|
clamp,
|
|
26
|
+
mean,
|
|
23
27
|
random,
|
|
24
28
|
randomInt,
|
|
25
29
|
range,
|
|
@@ -0,0 +1,16 @@
|
|
|
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 };
|
|
@@ -0,0 +1,16 @@
|
|
|
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 };
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/math/random.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generate a random number within the given range.
|
|
3
3
|
*
|
|
4
|
+
* If only one argument is provided, a number between `0` and the given number is returned.
|
|
5
|
+
*
|
|
4
6
|
* @param {number} minimum - The lower bound (inclusive).
|
|
5
7
|
* @param {number} maximum - The upper bound (exclusive).
|
|
6
8
|
* @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
|
|
@@ -11,6 +13,7 @@
|
|
|
11
13
|
* const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown
|
|
12
14
|
* const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
|
|
13
15
|
*/
|
|
16
|
+
declare function random(maximum: number): number;
|
|
14
17
|
declare function random(minimum: number, maximum: number): number;
|
|
15
18
|
|
|
16
19
|
export { random };
|
package/dist/math/random.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generate a random number within the given range.
|
|
3
3
|
*
|
|
4
|
+
* If only one argument is provided, a number between `0` and the given number is returned.
|
|
5
|
+
*
|
|
4
6
|
* @param {number} minimum - The lower bound (inclusive).
|
|
5
7
|
* @param {number} maximum - The upper bound (exclusive).
|
|
6
8
|
* @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
|
|
@@ -11,6 +13,7 @@
|
|
|
11
13
|
* const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown
|
|
12
14
|
* const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
|
|
13
15
|
*/
|
|
16
|
+
declare function random(maximum: number): number;
|
|
14
17
|
declare function random(minimum: number, maximum: number): number;
|
|
15
18
|
|
|
16
19
|
export { random };
|
package/dist/math/random.js
CHANGED
|
@@ -24,6 +24,10 @@ __export(random_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(random_exports);
|
|
26
26
|
function random(minimum, maximum) {
|
|
27
|
+
if (maximum == null) {
|
|
28
|
+
maximum = minimum;
|
|
29
|
+
minimum = 0;
|
|
30
|
+
}
|
|
27
31
|
if (minimum >= maximum) {
|
|
28
32
|
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
29
33
|
}
|
package/dist/math/random.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/random.ts"],"sourcesContent":["/**\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../src/math/random.ts"],"sourcesContent":["/**\n * Generate a random number within the given range.\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\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(maximum: number): number;\nexport function random(minimum: number, maximum: number): number;\nexport function random(minimum: number, maximum?: number): number {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,SAAS,OAAO,SAAiB,SAA0B;AAChE,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;","names":[]}
|
package/dist/math/random.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates a random integer between minimum (inclusive) and maximum (exclusive).
|
|
3
3
|
*
|
|
4
|
+
* If only one argument is provided, a number between `0` and the given number is returned.
|
|
5
|
+
*
|
|
4
6
|
* @param {number} minimum - The lower bound (inclusive).
|
|
5
7
|
* @param {number} maximum - The upper bound (exclusive).
|
|
6
8
|
* @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).
|
|
@@ -10,6 +12,7 @@
|
|
|
10
12
|
* const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)
|
|
11
13
|
* const result2 = randomInt(5, 0); // This will throw an error
|
|
12
14
|
*/
|
|
15
|
+
declare function randomInt(maximum: number): number;
|
|
13
16
|
declare function randomInt(minimum: number, maximum: number): number;
|
|
14
17
|
|
|
15
18
|
export { randomInt };
|
package/dist/math/randomInt.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates a random integer between minimum (inclusive) and maximum (exclusive).
|
|
3
3
|
*
|
|
4
|
+
* If only one argument is provided, a number between `0` and the given number is returned.
|
|
5
|
+
*
|
|
4
6
|
* @param {number} minimum - The lower bound (inclusive).
|
|
5
7
|
* @param {number} maximum - The upper bound (exclusive).
|
|
6
8
|
* @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).
|
|
@@ -10,6 +12,7 @@
|
|
|
10
12
|
* const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)
|
|
11
13
|
* const result2 = randomInt(5, 0); // This will throw an error
|
|
12
14
|
*/
|
|
15
|
+
declare function randomInt(maximum: number): number;
|
|
13
16
|
declare function randomInt(minimum: number, maximum: number): number;
|
|
14
17
|
|
|
15
18
|
export { randomInt };
|
package/dist/math/randomInt.js
CHANGED
|
@@ -26,6 +26,10 @@ module.exports = __toCommonJS(randomInt_exports);
|
|
|
26
26
|
|
|
27
27
|
// src/math/random.ts
|
|
28
28
|
function random(minimum, maximum) {
|
|
29
|
+
if (maximum == null) {
|
|
30
|
+
maximum = minimum;
|
|
31
|
+
minimum = 0;
|
|
32
|
+
}
|
|
29
33
|
if (minimum >= maximum) {
|
|
30
34
|
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
31
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/randomInt.ts","../../src/math/random.ts"],"sourcesContent":["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 * 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;
|
|
1
|
+
{"version":3,"sources":["../../src/math/randomInt.ts","../../src/math/random.ts"],"sourcesContent":["import { random } from './random';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\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(maximum: number): number;\nexport function randomInt(minimum: number, maximum: number): number;\nexport function randomInt(minimum: number, maximum?: number): number {\n return Math.floor(random(minimum, maximum!));\n}\n","/**\n * Generate a random number within the given range.\n *\n * If only one argument is provided, a number between `0` and the given number is returned.\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(maximum: number): number;\nexport function random(minimum: number, maximum: number): number;\nexport function random(minimum: number, maximum?: number): number {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,OAAO,SAAiB,SAA0B;AAChE,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ADVO,SAAS,UAAU,SAAiB,SAA0B;AACnE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAQ,CAAC;AAC7C;","names":[]}
|
package/dist/math/randomInt.mjs
CHANGED
package/dist/math/sum.d.mts
CHANGED