es-toolkit 1.4.0 → 1.5.0-dev.104
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 +16 -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 +32 -0
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +28 -20
- package/dist/array/intersectionWith.js.map +1 -1
- package/dist/array/intersectionWith.mjs +1 -1
- package/dist/array/maxBy.d.mts +14 -0
- package/dist/array/maxBy.d.ts +14 -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 +14 -0
- package/dist/array/minBy.d.ts +14 -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/unionWith.js.map +1 -1
- package/dist/array/unionWith.mjs +1 -1
- package/dist/array/xor.js.map +1 -1
- package/dist/array/xor.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-QWJDITYJ.mjs → chunk-5UT77WON.mjs} +2 -2
- 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-FXOABQRO.mjs +18 -0
- package/dist/chunk-FXOABQRO.mjs.map +1 -0
- package/dist/{chunk-WXIBCOES.mjs → chunk-G2TTBLLJ.mjs} +2 -2
- 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-UGFVAAVO.mjs → chunk-LCP6FOCX.mjs} +1 -1
- package/dist/chunk-LCP6FOCX.mjs.map +1 -0
- 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-OIHARMNM.mjs +18 -0
- package/dist/chunk-OIHARMNM.mjs.map +1 -0
- 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/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -63
- package/dist/math/index.d.mts +1 -0
- package/dist/math/index.d.ts +1 -0
- package/dist/math/index.js +25 -0
- package/dist/math/index.js.map +1 -1
- package/dist/math/index.mjs +11 -7
- package/dist/math/random.d.mts +5 -5
- package/dist/math/random.d.ts +5 -5
- package/dist/math/random.js.map +1 -1
- package/dist/math/random.mjs +1 -1
- package/dist/math/randomInt.js.map +1 -1
- package/dist/math/randomInt.mjs +2 -2
- 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 +7 -7
- 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 +6 -6
- package/package.json +3 -1
- package/dist/chunk-EJGAXTF7.mjs +0 -1
- package/dist/chunk-SF3V7XXM.mjs.map +0 -1
- package/dist/chunk-T2C2WVFL.mjs.map +0 -1
- package/dist/chunk-UGFVAAVO.mjs.map +0 -1
- package/dist/chunk-V7E5DGZP.mjs.map +0 -1
- package/dist/chunk-VAV4XHLO.mjs +0 -1
- /package/dist/{chunk-EJGAXTF7.mjs.map → array/maxBy.mjs.map} +0 -0
- /package/dist/{chunk-VAV4XHLO.mjs.map → array/minBy.mjs.map} +0 -0
- /package/dist/{chunk-QWJDITYJ.mjs.map → chunk-5UT77WON.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,11 +1,21 @@
|
|
|
1
1
|
import "./chunk-ARZ5BDR6.mjs";
|
|
2
|
-
import "./chunk-MAJSPFA6.mjs";
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
} from "./chunk-
|
|
3
|
+
delay
|
|
4
|
+
} from "./chunk-AL3GJBEI.mjs";
|
|
5
|
+
import "./chunk-T5JCRGXA.mjs";
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
} from "./chunk-
|
|
7
|
+
omit
|
|
8
|
+
} from "./chunk-PLTO44KM.mjs";
|
|
9
|
+
import {
|
|
10
|
+
omitBy
|
|
11
|
+
} from "./chunk-A67NF2C7.mjs";
|
|
12
|
+
import {
|
|
13
|
+
pick
|
|
14
|
+
} from "./chunk-OFWKFUFZ.mjs";
|
|
15
|
+
import {
|
|
16
|
+
pickBy
|
|
17
|
+
} from "./chunk-MQWVBKUT.mjs";
|
|
18
|
+
import "./chunk-MAJSPFA6.mjs";
|
|
9
19
|
import {
|
|
10
20
|
isNull
|
|
11
21
|
} from "./chunk-AIRSKN47.mjs";
|
|
@@ -13,73 +23,58 @@ import {
|
|
|
13
23
|
isUndefined
|
|
14
24
|
} from "./chunk-VH2PV426.mjs";
|
|
15
25
|
import {
|
|
16
|
-
|
|
17
|
-
} from "./chunk-
|
|
18
|
-
import
|
|
26
|
+
isNil
|
|
27
|
+
} from "./chunk-OHQAR5AU.mjs";
|
|
28
|
+
import {
|
|
29
|
+
isNotNil
|
|
30
|
+
} from "./chunk-ZQNAZPSK.mjs";
|
|
31
|
+
import "./chunk-7LAMAYGN.mjs";
|
|
32
|
+
import {
|
|
33
|
+
clamp
|
|
34
|
+
} from "./chunk-MLCL773E.mjs";
|
|
19
35
|
import {
|
|
20
36
|
randomInt
|
|
21
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-5UT77WON.mjs";
|
|
22
38
|
import {
|
|
23
39
|
random
|
|
24
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-LCP6FOCX.mjs";
|
|
41
|
+
import {
|
|
42
|
+
range
|
|
43
|
+
} from "./chunk-UNLX2F2Y.mjs";
|
|
25
44
|
import {
|
|
26
45
|
round
|
|
27
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-5PMKOZ2F.mjs";
|
|
28
47
|
import {
|
|
29
48
|
sum
|
|
30
49
|
} from "./chunk-7OU22ENP.mjs";
|
|
31
|
-
import "./chunk-
|
|
32
|
-
import {
|
|
33
|
-
pick
|
|
34
|
-
} from "./chunk-OFWKFUFZ.mjs";
|
|
35
|
-
import {
|
|
36
|
-
pickBy
|
|
37
|
-
} from "./chunk-T2C2WVFL.mjs";
|
|
38
|
-
import {
|
|
39
|
-
omit
|
|
40
|
-
} from "./chunk-PLTO44KM.mjs";
|
|
41
|
-
import {
|
|
42
|
-
omitBy
|
|
43
|
-
} from "./chunk-SF3V7XXM.mjs";
|
|
44
|
-
import "./chunk-N6EM6ETS.mjs";
|
|
45
|
-
import {
|
|
46
|
-
debounce
|
|
47
|
-
} from "./chunk-MKETZ2RP.mjs";
|
|
48
|
-
import {
|
|
49
|
-
noop
|
|
50
|
-
} from "./chunk-LKXCOLNY.mjs";
|
|
50
|
+
import "./chunk-NP6PDX3E.mjs";
|
|
51
51
|
import {
|
|
52
|
-
|
|
53
|
-
} from "./chunk-
|
|
54
|
-
import {
|
|
55
|
-
throttle
|
|
56
|
-
} from "./chunk-XLO3QZVY.mjs";
|
|
57
|
-
import "./chunk-FZEZH22H.mjs";
|
|
58
|
-
import {
|
|
59
|
-
AbortError
|
|
60
|
-
} from "./chunk-VP2LXY75.mjs";
|
|
61
|
-
import {
|
|
62
|
-
clamp
|
|
63
|
-
} from "./chunk-MLCL773E.mjs";
|
|
64
|
-
import "./chunk-EJGAXTF7.mjs";
|
|
52
|
+
zipWith
|
|
53
|
+
} from "./chunk-4KYXHZ4R.mjs";
|
|
65
54
|
import {
|
|
66
55
|
uniqBy
|
|
67
56
|
} from "./chunk-WPDDOUQT.mjs";
|
|
68
57
|
import {
|
|
69
58
|
xor
|
|
70
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-G2TTBLLJ.mjs";
|
|
71
60
|
import {
|
|
72
61
|
xorBy
|
|
73
62
|
} from "./chunk-AM2EGFCU.mjs";
|
|
74
63
|
import {
|
|
75
64
|
xorWith
|
|
76
|
-
} 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";
|
|
77
72
|
import {
|
|
78
73
|
zip
|
|
79
|
-
} from "./chunk-
|
|
74
|
+
} from "./chunk-IDCUZVJL.mjs";
|
|
80
75
|
import {
|
|
81
|
-
|
|
82
|
-
} from "./chunk-
|
|
76
|
+
sample
|
|
77
|
+
} from "./chunk-DOOIIHT3.mjs";
|
|
83
78
|
import {
|
|
84
79
|
shuffle
|
|
85
80
|
} from "./chunk-DPLJQQFX.mjs";
|
|
@@ -104,12 +99,6 @@ import {
|
|
|
104
99
|
import {
|
|
105
100
|
unionBy
|
|
106
101
|
} from "./chunk-NRNKP6JF.mjs";
|
|
107
|
-
import {
|
|
108
|
-
unionWith
|
|
109
|
-
} from "./chunk-3KHI4I2X.mjs";
|
|
110
|
-
import {
|
|
111
|
-
uniqWith
|
|
112
|
-
} from "./chunk-2PFDLYQC.mjs";
|
|
113
102
|
import {
|
|
114
103
|
groupBy
|
|
115
104
|
} from "./chunk-LWXZFXY5.mjs";
|
|
@@ -121,25 +110,28 @@ import {
|
|
|
121
110
|
} from "./chunk-GNSJP2AB.mjs";
|
|
122
111
|
import {
|
|
123
112
|
intersectionWith
|
|
124
|
-
} from "./chunk-
|
|
113
|
+
} from "./chunk-2EFS3VA3.mjs";
|
|
114
|
+
import {
|
|
115
|
+
maxBy
|
|
116
|
+
} from "./chunk-FXOABQRO.mjs";
|
|
117
|
+
import {
|
|
118
|
+
minBy
|
|
119
|
+
} from "./chunk-OIHARMNM.mjs";
|
|
125
120
|
import {
|
|
126
121
|
partition
|
|
127
122
|
} from "./chunk-5L2V7WD3.mjs";
|
|
128
|
-
import {
|
|
129
|
-
sample
|
|
130
|
-
} from "./chunk-DOOIIHT3.mjs";
|
|
131
123
|
import {
|
|
132
124
|
chunk
|
|
133
125
|
} from "./chunk-E6C5EZQA.mjs";
|
|
134
126
|
import {
|
|
135
127
|
difference
|
|
136
|
-
} from "./chunk-
|
|
128
|
+
} from "./chunk-JPUKH67K.mjs";
|
|
137
129
|
import {
|
|
138
130
|
differenceBy
|
|
139
131
|
} from "./chunk-LVWX5B43.mjs";
|
|
140
132
|
import {
|
|
141
133
|
differenceWith
|
|
142
|
-
} from "./chunk-
|
|
134
|
+
} from "./chunk-6NVQAHXP.mjs";
|
|
143
135
|
import {
|
|
144
136
|
drop
|
|
145
137
|
} from "./chunk-ACFP3XMB.mjs";
|
|
@@ -148,10 +140,27 @@ import {
|
|
|
148
140
|
} from "./chunk-Q75KEFW5.mjs";
|
|
149
141
|
import {
|
|
150
142
|
dropRightWhile
|
|
151
|
-
} from "./chunk-
|
|
143
|
+
} from "./chunk-RNJM5BHX.mjs";
|
|
152
144
|
import {
|
|
153
145
|
dropWhile
|
|
154
|
-
} 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";
|
|
155
164
|
import "./chunk-2MM5EJJX.mjs";
|
|
156
165
|
export {
|
|
157
166
|
AbortError,
|
|
@@ -174,6 +183,8 @@ export {
|
|
|
174
183
|
isNotNil,
|
|
175
184
|
isNull,
|
|
176
185
|
isUndefined,
|
|
186
|
+
maxBy,
|
|
187
|
+
minBy,
|
|
177
188
|
noop,
|
|
178
189
|
omit,
|
|
179
190
|
omitBy,
|
|
@@ -183,6 +194,7 @@ export {
|
|
|
183
194
|
pickBy,
|
|
184
195
|
random,
|
|
185
196
|
randomInt,
|
|
197
|
+
range,
|
|
186
198
|
round,
|
|
187
199
|
sample,
|
|
188
200
|
shuffle,
|
package/dist/math/index.d.mts
CHANGED
package/dist/math/index.d.ts
CHANGED
package/dist/math/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(math_exports, {
|
|
|
23
23
|
clamp: () => clamp,
|
|
24
24
|
random: () => random,
|
|
25
25
|
randomInt: () => randomInt,
|
|
26
|
+
range: () => range,
|
|
26
27
|
round: () => round,
|
|
27
28
|
sum: () => sum
|
|
28
29
|
});
|
|
@@ -51,6 +52,9 @@ function randomInt(minimum, maximum) {
|
|
|
51
52
|
|
|
52
53
|
// src/math/round.ts
|
|
53
54
|
function round(value, precision = 0) {
|
|
55
|
+
if (!Number.isInteger(precision)) {
|
|
56
|
+
throw new Error("Precision must be an integer.");
|
|
57
|
+
}
|
|
54
58
|
const multiplier = Math.pow(10, precision);
|
|
55
59
|
return Math.round(value * multiplier) / multiplier;
|
|
56
60
|
}
|
|
@@ -63,11 +67,32 @@ function sum(nums) {
|
|
|
63
67
|
}
|
|
64
68
|
return result;
|
|
65
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
|
+
}
|
|
66
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
67
91
|
0 && (module.exports = {
|
|
68
92
|
clamp,
|
|
69
93
|
random,
|
|
70
94
|
randomInt,
|
|
95
|
+
range,
|
|
71
96
|
round,
|
|
72
97
|
sum
|
|
73
98
|
});
|
package/dist/math/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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"],"sourcesContent":["export { clamp } from './clamp';\nexport { random } from './random';\nexport { randomInt } from './randomInt';\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 *
|
|
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,24 +1,28 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-7LAMAYGN.mjs";
|
|
2
|
+
import {
|
|
3
|
+
clamp
|
|
4
|
+
} from "../chunk-MLCL773E.mjs";
|
|
2
5
|
import {
|
|
3
6
|
randomInt
|
|
4
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-5UT77WON.mjs";
|
|
5
8
|
import {
|
|
6
9
|
random
|
|
7
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-LCP6FOCX.mjs";
|
|
11
|
+
import {
|
|
12
|
+
range
|
|
13
|
+
} from "../chunk-UNLX2F2Y.mjs";
|
|
8
14
|
import {
|
|
9
15
|
round
|
|
10
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-5PMKOZ2F.mjs";
|
|
11
17
|
import {
|
|
12
18
|
sum
|
|
13
19
|
} from "../chunk-7OU22ENP.mjs";
|
|
14
|
-
import {
|
|
15
|
-
clamp
|
|
16
|
-
} from "../chunk-MLCL773E.mjs";
|
|
17
20
|
import "../chunk-2MM5EJJX.mjs";
|
|
18
21
|
export {
|
|
19
22
|
clamp,
|
|
20
23
|
random,
|
|
21
24
|
randomInt,
|
|
25
|
+
range,
|
|
22
26
|
round,
|
|
23
27
|
sum
|
|
24
28
|
};
|
package/dist/math/random.d.mts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* If min is greater than maximum, the values are swapped.
|
|
2
|
+
* Generate a random number within the given range.
|
|
4
3
|
*
|
|
5
4
|
* @param {number} minimum - The lower bound (inclusive).
|
|
6
5
|
* @param {number} maximum - The upper bound (exclusive).
|
|
7
|
-
* @returns {number} A random
|
|
6
|
+
* @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
|
|
8
7
|
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
|
-
* const
|
|
12
|
-
* const result2 = random(5, 0); //
|
|
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
13
|
*/
|
|
14
14
|
declare function random(minimum: number, maximum: number): number;
|
|
15
15
|
|
package/dist/math/random.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* If min is greater than maximum, the values are swapped.
|
|
2
|
+
* Generate a random number within the given range.
|
|
4
3
|
*
|
|
5
4
|
* @param {number} minimum - The lower bound (inclusive).
|
|
6
5
|
* @param {number} maximum - The upper bound (exclusive).
|
|
7
|
-
* @returns {number} A random
|
|
6
|
+
* @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
|
|
8
7
|
* @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
|
-
* const
|
|
12
|
-
* const result2 = random(5, 0); //
|
|
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
13
|
*/
|
|
14
14
|
declare function random(minimum: number, maximum: number): number;
|
|
15
15
|
|
package/dist/math/random.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/random.ts"],"sourcesContent":["/**\n *
|
|
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":[]}
|
package/dist/math/random.mjs
CHANGED
|
@@ -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 *
|
|
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":[]}
|
package/dist/math/randomInt.mjs
CHANGED
|
@@ -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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/math/round.d.mts
CHANGED
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
* @param {number} value - The number to round.
|
|
8
8
|
* @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.
|
|
9
9
|
* @returns {number} The rounded number.
|
|
10
|
+
* @throws {Error} Throws an error if `Precision` is not integer.
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
12
13
|
* const result1 = round(1.2345); // result1 will be 1
|
|
13
14
|
* const result2 = round(1.2345, 2); // result2 will be 1.23
|
|
14
15
|
* const result3 = round(1.2345, 3); // result3 will be 1.235
|
|
16
|
+
* const result4 = round(1.2345, 3.1); // This will throw an error
|
|
15
17
|
*/
|
|
16
18
|
declare function round(value: number, precision?: number): number;
|
|
17
19
|
|
package/dist/math/round.d.ts
CHANGED
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
* @param {number} value - The number to round.
|
|
8
8
|
* @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.
|
|
9
9
|
* @returns {number} The rounded number.
|
|
10
|
+
* @throws {Error} Throws an error if `Precision` is not integer.
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
12
13
|
* const result1 = round(1.2345); // result1 will be 1
|
|
13
14
|
* const result2 = round(1.2345, 2); // result2 will be 1.23
|
|
14
15
|
* const result3 = round(1.2345, 3); // result3 will be 1.235
|
|
16
|
+
* const result4 = round(1.2345, 3.1); // This will throw an error
|
|
15
17
|
*/
|
|
16
18
|
declare function round(value: number, precision?: number): number;
|
|
17
19
|
|
package/dist/math/round.js
CHANGED
|
@@ -24,6 +24,9 @@ __export(round_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(round_exports);
|
|
26
26
|
function round(value, precision = 0) {
|
|
27
|
+
if (!Number.isInteger(precision)) {
|
|
28
|
+
throw new Error("Precision must be an integer.");
|
|
29
|
+
}
|
|
27
30
|
const multiplier = Math.pow(10, precision);
|
|
28
31
|
return Math.round(value * multiplier) / multiplier;
|
|
29
32
|
}
|
package/dist/math/round.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/round.ts"],"sourcesContent":["/**\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/round.ts"],"sourcesContent":["/**\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,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;","names":[]}
|