es-toolkit 1.3.1 → 1.4.0-dev.101
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 +14 -0
- package/dist/array/difference.d.mts +1 -1
- package/dist/array/difference.d.ts +1 -1
- package/dist/array/difference.js.map +1 -1
- package/dist/array/difference.mjs +1 -1
- package/dist/array/differenceWith.js.map +1 -1
- package/dist/array/differenceWith.mjs +1 -1
- package/dist/array/dropRightWhile.js.map +1 -1
- package/dist/array/dropRightWhile.mjs +2 -2
- package/dist/array/dropWhile.js.map +1 -1
- package/dist/array/dropWhile.mjs +1 -1
- package/dist/array/index.d.mts +2 -0
- package/dist/array/index.d.ts +2 -0
- package/dist/array/index.js +41 -2
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +31 -23
- package/dist/array/intersectionWith.js.map +1 -1
- package/dist/array/intersectionWith.mjs +1 -1
- package/dist/array/maxBy.d.mts +21 -0
- package/dist/array/maxBy.d.ts +21 -0
- package/dist/array/maxBy.js +42 -0
- package/dist/array/maxBy.js.map +1 -0
- package/dist/array/maxBy.mjs +8 -0
- package/dist/array/minBy.d.mts +13 -0
- package/dist/array/minBy.d.ts +13 -0
- package/dist/array/minBy.js +42 -0
- package/dist/array/minBy.js.map +1 -0
- package/dist/array/minBy.mjs +8 -0
- package/dist/array/unionBy.js +1 -1
- package/dist/array/unionBy.js.map +1 -1
- package/dist/array/unionBy.mjs +1 -1
- package/dist/array/unionWith.js.map +1 -1
- package/dist/array/unionWith.mjs +1 -1
- package/dist/array/uniqBy.js +6 -13
- package/dist/array/uniqBy.js.map +1 -1
- package/dist/array/uniqBy.mjs +1 -2
- package/dist/array/xor.js.map +1 -1
- package/dist/array/xor.mjs +2 -2
- package/dist/array/xorBy.js +1 -1
- package/dist/array/xorBy.js.map +1 -1
- package/dist/array/xorBy.mjs +2 -2
- package/dist/array/xorWith.js.map +1 -1
- package/dist/array/xorWith.mjs +4 -4
- package/dist/array/zip.js.map +1 -1
- package/dist/array/zip.mjs +1 -1
- package/dist/array/zipWith.js.map +1 -1
- package/dist/array/zipWith.mjs +1 -1
- package/dist/{chunk-KLJRZJOR.mjs → chunk-2EFS3VA3.mjs} +1 -1
- package/dist/{chunk-KLJRZJOR.mjs.map → chunk-2EFS3VA3.mjs.map} +1 -1
- package/dist/{chunk-T5FDOBCA.mjs → chunk-4KYXHZ4R.mjs} +1 -1
- package/dist/{chunk-T5FDOBCA.mjs.map → chunk-4KYXHZ4R.mjs.map} +1 -1
- package/dist/{chunk-V7E5DGZP.mjs → chunk-5PMKOZ2F.mjs} +4 -1
- package/dist/chunk-5PMKOZ2F.mjs.map +1 -0
- package/dist/chunk-5UT77WON.mjs +13 -0
- package/dist/chunk-5UT77WON.mjs.map +1 -0
- package/dist/{chunk-3KHI4I2X.mjs → chunk-642SWVKJ.mjs} +1 -1
- package/dist/{chunk-3KHI4I2X.mjs.map → chunk-642SWVKJ.mjs.map} +1 -1
- package/dist/{chunk-FQ4K36VD.mjs → chunk-6NVQAHXP.mjs} +1 -1
- package/dist/{chunk-FQ4K36VD.mjs.map → chunk-6NVQAHXP.mjs.map} +1 -1
- package/dist/chunk-7LAMAYGN.mjs +1 -0
- package/dist/chunk-7LAMAYGN.mjs.map +1 -0
- package/dist/{chunk-SF3V7XXM.mjs → chunk-A67NF2C7.mjs} +1 -1
- package/dist/chunk-A67NF2C7.mjs.map +1 -0
- package/dist/chunk-AL3GJBEI.mjs +26 -0
- package/dist/chunk-AL3GJBEI.mjs.map +1 -0
- package/dist/{chunk-EW3RT4QW.mjs → chunk-AM2EGFCU.mjs} +2 -2
- package/dist/chunk-FZEZH22H.mjs +1 -0
- package/dist/chunk-FZEZH22H.mjs.map +1 -0
- package/dist/{chunk-WXIBCOES.mjs → chunk-G2TTBLLJ.mjs} +2 -2
- package/dist/chunk-H23GUJVF.mjs +18 -0
- package/dist/chunk-H23GUJVF.mjs.map +1 -0
- package/dist/{chunk-DD73BULA.mjs → chunk-IDCUZVJL.mjs} +1 -1
- package/dist/{chunk-DD73BULA.mjs.map → chunk-IDCUZVJL.mjs.map} +1 -1
- package/dist/{chunk-M7UI5ETO.mjs → chunk-JPUKH67K.mjs} +1 -1
- package/dist/{chunk-M7UI5ETO.mjs.map → chunk-JPUKH67K.mjs.map} +1 -1
- package/dist/{chunk-JFHM6EY2.mjs → chunk-K2BAFL2T.mjs} +1 -1
- package/dist/{chunk-JFHM6EY2.mjs.map → chunk-K2BAFL2T.mjs.map} +1 -1
- package/dist/chunk-KZ5JY7J3.mjs +18 -0
- package/dist/chunk-KZ5JY7J3.mjs.map +1 -0
- package/dist/chunk-LCP6FOCX.mjs +12 -0
- package/dist/chunk-LCP6FOCX.mjs.map +1 -0
- package/dist/{chunk-GOXQV6DX.mjs → chunk-MKETZ2RP.mjs} +2 -3
- package/dist/{chunk-GOXQV6DX.mjs.map → chunk-MKETZ2RP.mjs.map} +1 -1
- package/dist/{chunk-T2C2WVFL.mjs → chunk-MQWVBKUT.mjs} +1 -1
- package/dist/chunk-MQWVBKUT.mjs.map +1 -0
- package/dist/chunk-NP6PDX3E.mjs +1 -0
- package/dist/chunk-NP6PDX3E.mjs.map +1 -0
- package/dist/{chunk-JBDGK6X4.mjs → chunk-NRNKP6JF.mjs} +2 -2
- package/dist/{chunk-JBDGK6X4.mjs.map → chunk-NRNKP6JF.mjs.map} +1 -1
- package/dist/{chunk-CIRFWC7Y.mjs → chunk-RNJM5BHX.mjs} +2 -2
- package/dist/{chunk-FCF2RHPW.mjs → chunk-UMDNWTJC.mjs} +4 -4
- package/dist/{chunk-FCF2RHPW.mjs.map → chunk-UMDNWTJC.mjs.map} +1 -1
- package/dist/chunk-UNLX2F2Y.mjs +24 -0
- package/dist/chunk-UNLX2F2Y.mjs.map +1 -0
- package/dist/chunk-VP2LXY75.mjs +12 -0
- package/dist/chunk-VP2LXY75.mjs.map +1 -0
- package/dist/chunk-WPDDOUQT.mjs +16 -0
- package/dist/chunk-WPDDOUQT.mjs.map +1 -0
- package/dist/error/AbortError.d.mts +5 -0
- package/dist/error/AbortError.d.ts +5 -0
- package/dist/error/AbortError.js +36 -0
- package/dist/error/AbortError.js.map +1 -0
- package/dist/error/AbortError.mjs +8 -0
- package/dist/error/AbortError.mjs.map +1 -0
- package/dist/error/index.d.mts +1 -0
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +38 -0
- package/dist/error/index.js.map +1 -0
- package/dist/error/index.mjs +9 -0
- package/dist/error/index.mjs.map +1 -0
- package/dist/function/debounce.js +1 -2
- package/dist/function/debounce.js.map +1 -1
- package/dist/function/debounce.mjs +1 -1
- package/dist/function/index.js +1 -2
- package/dist/function/index.js.map +1 -1
- package/dist/function/index.mjs +4 -4
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +108 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -43
- package/dist/math/index.d.mts +3 -0
- package/dist/math/index.d.ts +3 -0
- package/dist/math/index.js +42 -0
- package/dist/math/index.js.map +1 -1
- package/dist/math/index.mjs +14 -2
- package/dist/math/random.d.mts +16 -0
- package/dist/math/random.d.ts +16 -0
- package/dist/math/random.js +36 -0
- package/dist/math/random.js.map +1 -0
- package/dist/math/random.mjs +8 -0
- package/dist/math/random.mjs.map +1 -0
- package/dist/math/randomInt.d.mts +15 -0
- package/dist/math/randomInt.d.ts +15 -0
- package/dist/math/randomInt.js +43 -0
- package/dist/math/randomInt.js.map +1 -0
- package/dist/math/randomInt.mjs +9 -0
- package/dist/math/randomInt.mjs.map +1 -0
- package/dist/math/range.d.mts +32 -0
- package/dist/math/range.d.ts +32 -0
- package/dist/math/range.js +48 -0
- package/dist/math/range.js.map +1 -0
- package/dist/math/range.mjs +8 -0
- package/dist/math/range.mjs.map +1 -0
- package/dist/math/round.d.mts +2 -0
- package/dist/math/round.d.ts +2 -0
- package/dist/math/round.js +3 -0
- package/dist/math/round.js.map +1 -1
- package/dist/math/round.mjs +1 -1
- package/dist/object/index.js.map +1 -1
- package/dist/object/index.mjs +2 -2
- package/dist/object/omitBy.d.mts +2 -2
- package/dist/object/omitBy.d.ts +2 -2
- package/dist/object/omitBy.js.map +1 -1
- package/dist/object/omitBy.mjs +1 -1
- package/dist/object/pickBy.d.mts +2 -2
- package/dist/object/pickBy.d.ts +2 -2
- package/dist/object/pickBy.js.map +1 -1
- package/dist/object/pickBy.mjs +1 -1
- package/dist/predicate/index.mjs +3 -3
- package/dist/promise/delay.d.mts +18 -1
- package/dist/promise/delay.d.ts +18 -1
- package/dist/promise/delay.js +24 -3
- package/dist/promise/delay.js.map +1 -1
- package/dist/promise/delay.mjs +2 -1
- package/dist/promise/index.js +22 -3
- package/dist/promise/index.js.map +1 -1
- package/dist/promise/index.mjs +2 -1
- package/package.json +3 -1
- package/dist/chunk-ASFOKYTY.mjs +0 -13
- package/dist/chunk-ASFOKYTY.mjs.map +0 -1
- package/dist/chunk-EJGAXTF7.mjs +0 -1
- package/dist/chunk-IJLQVGW4.mjs +0 -1
- package/dist/chunk-SF3V7XXM.mjs.map +0 -1
- package/dist/chunk-T2C2WVFL.mjs.map +0 -1
- package/dist/chunk-V7E5DGZP.mjs.map +0 -1
- package/dist/chunk-ZBG3EYM3.mjs +0 -11
- package/dist/chunk-ZBG3EYM3.mjs.map +0 -1
- /package/dist/{chunk-EJGAXTF7.mjs.map → array/maxBy.mjs.map} +0 -0
- /package/dist/{chunk-IJLQVGW4.mjs.map → array/minBy.mjs.map} +0 -0
- /package/dist/{chunk-EW3RT4QW.mjs.map → chunk-AM2EGFCU.mjs.map} +0 -0
- /package/dist/{chunk-WXIBCOES.mjs.map → chunk-G2TTBLLJ.mjs.map} +0 -0
- /package/dist/{chunk-CIRFWC7Y.mjs.map → chunk-RNJM5BHX.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import "./chunk-ARZ5BDR6.mjs";
|
|
2
2
|
import {
|
|
3
3
|
delay
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-AL3GJBEI.mjs";
|
|
5
5
|
import "./chunk-T5JCRGXA.mjs";
|
|
6
6
|
import {
|
|
7
7
|
omit
|
|
8
8
|
} from "./chunk-PLTO44KM.mjs";
|
|
9
9
|
import {
|
|
10
10
|
omitBy
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-A67NF2C7.mjs";
|
|
12
12
|
import {
|
|
13
13
|
pick
|
|
14
14
|
} from "./chunk-OFWKFUFZ.mjs";
|
|
15
15
|
import {
|
|
16
16
|
pickBy
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-MQWVBKUT.mjs";
|
|
18
18
|
import "./chunk-MAJSPFA6.mjs";
|
|
19
|
-
import {
|
|
20
|
-
isNotNil
|
|
21
|
-
} from "./chunk-ZQNAZPSK.mjs";
|
|
22
19
|
import {
|
|
23
20
|
isNull
|
|
24
21
|
} from "./chunk-AIRSKN47.mjs";
|
|
@@ -28,48 +25,56 @@ import {
|
|
|
28
25
|
import {
|
|
29
26
|
isNil
|
|
30
27
|
} from "./chunk-OHQAR5AU.mjs";
|
|
31
|
-
import
|
|
28
|
+
import {
|
|
29
|
+
isNotNil
|
|
30
|
+
} from "./chunk-ZQNAZPSK.mjs";
|
|
31
|
+
import "./chunk-7LAMAYGN.mjs";
|
|
32
32
|
import {
|
|
33
33
|
clamp
|
|
34
34
|
} from "./chunk-MLCL773E.mjs";
|
|
35
35
|
import {
|
|
36
|
-
|
|
37
|
-
} from "./chunk-
|
|
36
|
+
randomInt
|
|
37
|
+
} from "./chunk-5UT77WON.mjs";
|
|
38
38
|
import {
|
|
39
|
-
|
|
40
|
-
} from "./chunk-
|
|
41
|
-
import "./chunk-N6EM6ETS.mjs";
|
|
39
|
+
random
|
|
40
|
+
} from "./chunk-LCP6FOCX.mjs";
|
|
42
41
|
import {
|
|
43
|
-
|
|
44
|
-
} from "./chunk-
|
|
42
|
+
range
|
|
43
|
+
} from "./chunk-UNLX2F2Y.mjs";
|
|
45
44
|
import {
|
|
46
|
-
|
|
47
|
-
} from "./chunk-
|
|
45
|
+
round
|
|
46
|
+
} from "./chunk-5PMKOZ2F.mjs";
|
|
48
47
|
import {
|
|
49
|
-
|
|
50
|
-
} from "./chunk-
|
|
48
|
+
sum
|
|
49
|
+
} from "./chunk-7OU22ENP.mjs";
|
|
50
|
+
import "./chunk-NP6PDX3E.mjs";
|
|
51
51
|
import {
|
|
52
|
-
|
|
53
|
-
} from "./chunk-
|
|
54
|
-
import "./chunk-EJGAXTF7.mjs";
|
|
52
|
+
zipWith
|
|
53
|
+
} from "./chunk-4KYXHZ4R.mjs";
|
|
55
54
|
import {
|
|
56
55
|
uniqBy
|
|
57
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-WPDDOUQT.mjs";
|
|
58
57
|
import {
|
|
59
58
|
xor
|
|
60
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-G2TTBLLJ.mjs";
|
|
61
60
|
import {
|
|
62
61
|
xorBy
|
|
63
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-AM2EGFCU.mjs";
|
|
64
63
|
import {
|
|
65
64
|
xorWith
|
|
66
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-UMDNWTJC.mjs";
|
|
66
|
+
import {
|
|
67
|
+
unionWith
|
|
68
|
+
} from "./chunk-642SWVKJ.mjs";
|
|
69
|
+
import {
|
|
70
|
+
uniqWith
|
|
71
|
+
} from "./chunk-2PFDLYQC.mjs";
|
|
67
72
|
import {
|
|
68
73
|
zip
|
|
69
|
-
} from "./chunk-
|
|
74
|
+
} from "./chunk-IDCUZVJL.mjs";
|
|
70
75
|
import {
|
|
71
|
-
|
|
72
|
-
} from "./chunk-
|
|
76
|
+
sample
|
|
77
|
+
} from "./chunk-DOOIIHT3.mjs";
|
|
73
78
|
import {
|
|
74
79
|
shuffle
|
|
75
80
|
} from "./chunk-DPLJQQFX.mjs";
|
|
@@ -93,13 +98,7 @@ import {
|
|
|
93
98
|
} from "./chunk-XFCW7XJ4.mjs";
|
|
94
99
|
import {
|
|
95
100
|
unionBy
|
|
96
|
-
} from "./chunk-
|
|
97
|
-
import {
|
|
98
|
-
unionWith
|
|
99
|
-
} from "./chunk-3KHI4I2X.mjs";
|
|
100
|
-
import {
|
|
101
|
-
uniqWith
|
|
102
|
-
} from "./chunk-2PFDLYQC.mjs";
|
|
101
|
+
} from "./chunk-NRNKP6JF.mjs";
|
|
103
102
|
import {
|
|
104
103
|
groupBy
|
|
105
104
|
} from "./chunk-LWXZFXY5.mjs";
|
|
@@ -111,25 +110,28 @@ import {
|
|
|
111
110
|
} from "./chunk-GNSJP2AB.mjs";
|
|
112
111
|
import {
|
|
113
112
|
intersectionWith
|
|
114
|
-
} from "./chunk-
|
|
113
|
+
} from "./chunk-2EFS3VA3.mjs";
|
|
114
|
+
import {
|
|
115
|
+
maxBy
|
|
116
|
+
} from "./chunk-KZ5JY7J3.mjs";
|
|
117
|
+
import {
|
|
118
|
+
minBy
|
|
119
|
+
} from "./chunk-H23GUJVF.mjs";
|
|
115
120
|
import {
|
|
116
121
|
partition
|
|
117
122
|
} from "./chunk-5L2V7WD3.mjs";
|
|
118
|
-
import {
|
|
119
|
-
sample
|
|
120
|
-
} from "./chunk-DOOIIHT3.mjs";
|
|
121
123
|
import {
|
|
122
124
|
chunk
|
|
123
125
|
} from "./chunk-E6C5EZQA.mjs";
|
|
124
126
|
import {
|
|
125
127
|
difference
|
|
126
|
-
} from "./chunk-
|
|
128
|
+
} from "./chunk-JPUKH67K.mjs";
|
|
127
129
|
import {
|
|
128
130
|
differenceBy
|
|
129
131
|
} from "./chunk-LVWX5B43.mjs";
|
|
130
132
|
import {
|
|
131
133
|
differenceWith
|
|
132
|
-
} from "./chunk-
|
|
134
|
+
} from "./chunk-6NVQAHXP.mjs";
|
|
133
135
|
import {
|
|
134
136
|
drop
|
|
135
137
|
} from "./chunk-ACFP3XMB.mjs";
|
|
@@ -138,12 +140,30 @@ import {
|
|
|
138
140
|
} from "./chunk-Q75KEFW5.mjs";
|
|
139
141
|
import {
|
|
140
142
|
dropRightWhile
|
|
141
|
-
} from "./chunk-
|
|
143
|
+
} from "./chunk-RNJM5BHX.mjs";
|
|
142
144
|
import {
|
|
143
145
|
dropWhile
|
|
144
|
-
} from "./chunk-
|
|
146
|
+
} from "./chunk-K2BAFL2T.mjs";
|
|
147
|
+
import "./chunk-FZEZH22H.mjs";
|
|
148
|
+
import {
|
|
149
|
+
AbortError
|
|
150
|
+
} from "./chunk-VP2LXY75.mjs";
|
|
151
|
+
import "./chunk-N6EM6ETS.mjs";
|
|
152
|
+
import {
|
|
153
|
+
debounce
|
|
154
|
+
} from "./chunk-MKETZ2RP.mjs";
|
|
155
|
+
import {
|
|
156
|
+
noop
|
|
157
|
+
} from "./chunk-LKXCOLNY.mjs";
|
|
158
|
+
import {
|
|
159
|
+
once
|
|
160
|
+
} from "./chunk-UFAA5WKR.mjs";
|
|
161
|
+
import {
|
|
162
|
+
throttle
|
|
163
|
+
} from "./chunk-XLO3QZVY.mjs";
|
|
145
164
|
import "./chunk-2MM5EJJX.mjs";
|
|
146
165
|
export {
|
|
166
|
+
AbortError,
|
|
147
167
|
chunk,
|
|
148
168
|
clamp,
|
|
149
169
|
debounce,
|
|
@@ -163,6 +183,8 @@ export {
|
|
|
163
183
|
isNotNil,
|
|
164
184
|
isNull,
|
|
165
185
|
isUndefined,
|
|
186
|
+
maxBy,
|
|
187
|
+
minBy,
|
|
166
188
|
noop,
|
|
167
189
|
omit,
|
|
168
190
|
omitBy,
|
|
@@ -170,6 +192,9 @@ export {
|
|
|
170
192
|
partition,
|
|
171
193
|
pick,
|
|
172
194
|
pickBy,
|
|
195
|
+
random,
|
|
196
|
+
randomInt,
|
|
197
|
+
range,
|
|
173
198
|
round,
|
|
174
199
|
sample,
|
|
175
200
|
shuffle,
|
package/dist/math/index.d.mts
CHANGED
package/dist/math/index.d.ts
CHANGED
package/dist/math/index.js
CHANGED
|
@@ -21,6 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var math_exports = {};
|
|
22
22
|
__export(math_exports, {
|
|
23
23
|
clamp: () => clamp,
|
|
24
|
+
random: () => random,
|
|
25
|
+
randomInt: () => randomInt,
|
|
26
|
+
range: () => range,
|
|
24
27
|
round: () => round,
|
|
25
28
|
sum: () => sum
|
|
26
29
|
});
|
|
@@ -34,8 +37,24 @@ function clamp(value, bound1, bound2) {
|
|
|
34
37
|
return Math.min(Math.max(value, bound1), bound2);
|
|
35
38
|
}
|
|
36
39
|
|
|
40
|
+
// src/math/random.ts
|
|
41
|
+
function random(minimum, maximum) {
|
|
42
|
+
if (minimum >= maximum) {
|
|
43
|
+
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
44
|
+
}
|
|
45
|
+
return Math.random() * (maximum - minimum) + minimum;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/math/randomInt.ts
|
|
49
|
+
function randomInt(minimum, maximum) {
|
|
50
|
+
return Math.floor(random(minimum, maximum));
|
|
51
|
+
}
|
|
52
|
+
|
|
37
53
|
// src/math/round.ts
|
|
38
54
|
function round(value, precision = 0) {
|
|
55
|
+
if (!Number.isInteger(precision)) {
|
|
56
|
+
throw new Error("Precision must be an integer.");
|
|
57
|
+
}
|
|
39
58
|
const multiplier = Math.pow(10, precision);
|
|
40
59
|
return Math.round(value * multiplier) / multiplier;
|
|
41
60
|
}
|
|
@@ -48,9 +67,32 @@ function sum(nums) {
|
|
|
48
67
|
}
|
|
49
68
|
return result;
|
|
50
69
|
}
|
|
70
|
+
|
|
71
|
+
// src/math/range.ts
|
|
72
|
+
function range(start, end, step) {
|
|
73
|
+
if (end == null) {
|
|
74
|
+
end = start;
|
|
75
|
+
start = 0;
|
|
76
|
+
}
|
|
77
|
+
if (step == null) {
|
|
78
|
+
step = 1;
|
|
79
|
+
}
|
|
80
|
+
if (!Number.isInteger(step) || step === 0) {
|
|
81
|
+
throw new Error(`The step value must be a non-zero integer.`);
|
|
82
|
+
}
|
|
83
|
+
const length = Math.max(Math.ceil((end - start) / step), 0);
|
|
84
|
+
const result = new Array(length);
|
|
85
|
+
for (let i = 0; i < length; i++) {
|
|
86
|
+
result[i] = start + i * step;
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
51
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
52
91
|
0 && (module.exports = {
|
|
53
92
|
clamp,
|
|
93
|
+
random,
|
|
94
|
+
randomInt,
|
|
95
|
+
range,
|
|
54
96
|
round,
|
|
55
97
|
sum
|
|
56
98
|
});
|
package/dist/math/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/round.ts","../../src/math/sum.ts"],"sourcesContent":["export { clamp } from './clamp';\nexport { round } from './round';\nexport { sum } from './sum';\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 * 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 *\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 */\nexport function round(value: number, precision
|
|
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,28 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-7LAMAYGN.mjs";
|
|
2
2
|
import {
|
|
3
3
|
clamp
|
|
4
4
|
} from "../chunk-MLCL773E.mjs";
|
|
5
|
+
import {
|
|
6
|
+
randomInt
|
|
7
|
+
} from "../chunk-5UT77WON.mjs";
|
|
8
|
+
import {
|
|
9
|
+
random
|
|
10
|
+
} from "../chunk-LCP6FOCX.mjs";
|
|
11
|
+
import {
|
|
12
|
+
range
|
|
13
|
+
} from "../chunk-UNLX2F2Y.mjs";
|
|
5
14
|
import {
|
|
6
15
|
round
|
|
7
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-5PMKOZ2F.mjs";
|
|
8
17
|
import {
|
|
9
18
|
sum
|
|
10
19
|
} from "../chunk-7OU22ENP.mjs";
|
|
11
20
|
import "../chunk-2MM5EJJX.mjs";
|
|
12
21
|
export {
|
|
13
22
|
clamp,
|
|
23
|
+
random,
|
|
24
|
+
randomInt,
|
|
25
|
+
range,
|
|
14
26
|
round,
|
|
15
27
|
sum
|
|
16
28
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a random number within the given range.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} minimum - The lower bound (inclusive).
|
|
5
|
+
* @param {number} maximum - The upper bound (exclusive).
|
|
6
|
+
* @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
|
|
7
|
+
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result1 = random(0, 5); // Returns a random number between 0 and 5.
|
|
11
|
+
* const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown
|
|
12
|
+
* const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
|
|
13
|
+
*/
|
|
14
|
+
declare function random(minimum: number, maximum: number): number;
|
|
15
|
+
|
|
16
|
+
export { random };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a random number within the given range.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} minimum - The lower bound (inclusive).
|
|
5
|
+
* @param {number} maximum - The upper bound (exclusive).
|
|
6
|
+
* @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
|
|
7
|
+
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result1 = random(0, 5); // Returns a random number between 0 and 5.
|
|
11
|
+
* const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown
|
|
12
|
+
* const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
|
|
13
|
+
*/
|
|
14
|
+
declare function random(minimum: number, maximum: number): number;
|
|
15
|
+
|
|
16
|
+
export { random };
|
|
@@ -0,0 +1,36 @@
|
|
|
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/random.ts
|
|
21
|
+
var random_exports = {};
|
|
22
|
+
__export(random_exports, {
|
|
23
|
+
random: () => random
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(random_exports);
|
|
26
|
+
function random(minimum, maximum) {
|
|
27
|
+
if (minimum >= maximum) {
|
|
28
|
+
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
29
|
+
}
|
|
30
|
+
return Math.random() * (maximum - minimum) + minimum;
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
random
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=random.js.map
|
|
@@ -0,0 +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;AAaO,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;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random integer between minimum (inclusive) and maximum (exclusive).
|
|
3
|
+
*
|
|
4
|
+
* @param {number} minimum - The lower bound (inclusive).
|
|
5
|
+
* @param {number} maximum - The upper bound (exclusive).
|
|
6
|
+
* @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).
|
|
7
|
+
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)
|
|
11
|
+
* const result2 = randomInt(5, 0); // This will throw an error
|
|
12
|
+
*/
|
|
13
|
+
declare function randomInt(minimum: number, maximum: number): number;
|
|
14
|
+
|
|
15
|
+
export { randomInt };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random integer between minimum (inclusive) and maximum (exclusive).
|
|
3
|
+
*
|
|
4
|
+
* @param {number} minimum - The lower bound (inclusive).
|
|
5
|
+
* @param {number} maximum - The upper bound (exclusive).
|
|
6
|
+
* @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).
|
|
7
|
+
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)
|
|
11
|
+
* const result2 = randomInt(5, 0); // This will throw an error
|
|
12
|
+
*/
|
|
13
|
+
declare function randomInt(minimum: number, maximum: number): number;
|
|
14
|
+
|
|
15
|
+
export { randomInt };
|
|
@@ -0,0 +1,43 @@
|
|
|
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/randomInt.ts
|
|
21
|
+
var randomInt_exports = {};
|
|
22
|
+
__export(randomInt_exports, {
|
|
23
|
+
randomInt: () => randomInt
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(randomInt_exports);
|
|
26
|
+
|
|
27
|
+
// src/math/random.ts
|
|
28
|
+
function random(minimum, maximum) {
|
|
29
|
+
if (minimum >= maximum) {
|
|
30
|
+
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
31
|
+
}
|
|
32
|
+
return Math.random() * (maximum - minimum) + minimum;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/math/randomInt.ts
|
|
36
|
+
function randomInt(minimum, maximum) {
|
|
37
|
+
return Math.floor(random(minimum, maximum));
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
randomInt
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=randomInt.js.map
|
|
@@ -0,0 +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;;;ACaO,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;;;ADLO,SAAS,UAAU,SAAiB,SAAyB;AAClE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAO,CAAC;AAC5C;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns an array of numbers from `start` to `end`, incrementing by `step`.
|
|
3
|
+
*
|
|
4
|
+
* If `step` is not provided, it defaults to `1` for an
|
|
5
|
+
* ascending range and `-1` for a descending range.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} start - The starting number of the range.
|
|
8
|
+
* @param {number} [end] - The end number of the range.
|
|
9
|
+
* @param {number} [step] - The step value for the range.
|
|
10
|
+
* @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Returns [0, 1, 2, 3]
|
|
14
|
+
* range(4);
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Returns [0, 5, 10, 15]
|
|
18
|
+
* range(0, 20, 5);
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Returns []
|
|
22
|
+
* range(0, -4, -1);
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Throws an error: The step value must be a non-zero integer.
|
|
26
|
+
* range(1, 4, 0);
|
|
27
|
+
*/
|
|
28
|
+
declare function range(end: number): number[];
|
|
29
|
+
declare function range(start: number, end: number): number[];
|
|
30
|
+
declare function range(start: number, end: number, step: number): number[];
|
|
31
|
+
|
|
32
|
+
export { range };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns an array of numbers from `start` to `end`, incrementing by `step`.
|
|
3
|
+
*
|
|
4
|
+
* If `step` is not provided, it defaults to `1` for an
|
|
5
|
+
* ascending range and `-1` for a descending range.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} start - The starting number of the range.
|
|
8
|
+
* @param {number} [end] - The end number of the range.
|
|
9
|
+
* @param {number} [step] - The step value for the range.
|
|
10
|
+
* @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Returns [0, 1, 2, 3]
|
|
14
|
+
* range(4);
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Returns [0, 5, 10, 15]
|
|
18
|
+
* range(0, 20, 5);
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Returns []
|
|
22
|
+
* range(0, -4, -1);
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Throws an error: The step value must be a non-zero integer.
|
|
26
|
+
* range(1, 4, 0);
|
|
27
|
+
*/
|
|
28
|
+
declare function range(end: number): number[];
|
|
29
|
+
declare function range(start: number, end: number): number[];
|
|
30
|
+
declare function range(start: number, end: number, step: number): number[];
|
|
31
|
+
|
|
32
|
+
export { range };
|
|
@@ -0,0 +1,48 @@
|
|
|
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/range.ts
|
|
21
|
+
var range_exports = {};
|
|
22
|
+
__export(range_exports, {
|
|
23
|
+
range: () => range
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(range_exports);
|
|
26
|
+
function range(start, end, step) {
|
|
27
|
+
if (end == null) {
|
|
28
|
+
end = start;
|
|
29
|
+
start = 0;
|
|
30
|
+
}
|
|
31
|
+
if (step == null) {
|
|
32
|
+
step = 1;
|
|
33
|
+
}
|
|
34
|
+
if (!Number.isInteger(step) || step === 0) {
|
|
35
|
+
throw new Error(`The step value must be a non-zero integer.`);
|
|
36
|
+
}
|
|
37
|
+
const length = Math.max(Math.ceil((end - start) / step), 0);
|
|
38
|
+
const result = new Array(length);
|
|
39
|
+
for (let i = 0; i < length; i++) {
|
|
40
|
+
result[i] = start + i * step;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
range
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/math/range.ts"],"sourcesContent":["/**\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;AA8BO,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":[]}
|