es-toolkit 1.10.1 → 1.11.0-dev.261
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 +33 -0
- package/compat.d.ts +1 -0
- package/dist/array/chunk.mjs +1 -1
- package/dist/array/compact.mjs +1 -1
- package/dist/array/countBy.mjs +1 -1
- package/dist/array/difference.mjs +1 -1
- package/dist/array/differenceBy.mjs +1 -1
- package/dist/array/differenceWith.mjs +1 -1
- package/dist/array/drop.js +1 -0
- package/dist/array/drop.js.map +1 -1
- package/dist/array/drop.mjs +2 -2
- package/dist/array/dropRight.js +5 -1
- package/dist/array/dropRight.js.map +1 -1
- package/dist/array/dropRight.mjs +2 -2
- package/dist/array/dropRightWhile.js +6 -14
- package/dist/array/dropRightWhile.js.map +1 -1
- package/dist/array/dropRightWhile.mjs +2 -3
- package/dist/array/dropWhile.mjs +1 -1
- package/dist/array/fill.d.mts +10 -7
- package/dist/array/fill.d.ts +10 -7
- package/dist/array/fill.js +7 -6
- package/dist/array/fill.js.map +1 -1
- package/dist/array/fill.mjs +2 -2
- package/dist/array/flatMap.d.mts +23 -0
- package/dist/array/flatMap.d.ts +23 -0
- package/dist/array/flatMap.js +52 -0
- package/dist/array/flatMap.js.map +1 -0
- package/dist/array/flatMap.mjs +9 -0
- package/dist/array/flatten.mjs +1 -1
- package/dist/array/flattenDeep.mjs +1 -1
- package/dist/array/forEachRight.mjs +1 -1
- package/dist/array/groupBy.mjs +1 -1
- package/dist/array/head.mjs +1 -1
- package/dist/array/index.d.mts +1 -0
- package/dist/array/index.d.ts +1 -0
- package/dist/array/index.js +30 -14
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +41 -37
- package/dist/array/initial.mjs +1 -1
- package/dist/array/intersection.mjs +1 -1
- package/dist/array/intersectionBy.mjs +1 -1
- package/dist/array/intersectionWith.mjs +1 -1
- package/dist/array/keyBy.mjs +1 -1
- package/dist/array/last.mjs +1 -1
- package/dist/array/maxBy.mjs +1 -1
- package/dist/array/minBy.mjs +1 -1
- package/dist/array/orderBy.mjs +1 -1
- package/dist/array/partition.mjs +1 -1
- package/dist/array/sample.mjs +1 -1
- package/dist/array/sampleSize.mjs +1 -1
- package/dist/array/shuffle.mjs +1 -1
- package/dist/array/tail.mjs +1 -1
- package/dist/array/take.mjs +1 -1
- package/dist/array/takeRight.mjs +1 -1
- package/dist/array/takeRightWhile.mjs +1 -1
- package/dist/array/takeWhile.mjs +1 -1
- package/dist/array/toFilled.mjs +1 -1
- package/dist/array/union.mjs +1 -1
- package/dist/array/unionBy.mjs +1 -1
- package/dist/array/unionWith.mjs +1 -1
- package/dist/array/uniq.mjs +1 -1
- package/dist/array/uniqBy.d.mts +1 -1
- package/dist/array/uniqBy.d.ts +1 -1
- package/dist/array/uniqBy.js.map +1 -1
- package/dist/array/uniqBy.mjs +2 -2
- package/dist/array/uniqWith.mjs +1 -1
- package/dist/array/unzip.mjs +1 -1
- package/dist/array/unzipWith.mjs +1 -1
- package/dist/array/without.mjs +1 -1
- package/dist/array/xor.mjs +1 -1
- package/dist/array/xorBy.mjs +1 -1
- package/dist/array/xorWith.mjs +1 -1
- package/dist/array/zip.mjs +1 -1
- package/dist/array/zipObject.mjs +1 -1
- package/dist/array/zipWith.mjs +1 -1
- package/dist/{chunk-S3CORED5.mjs → chunk-3EZAFZG3.mjs} +2 -1
- package/dist/{chunk-S3CORED5.mjs.map → chunk-3EZAFZG3.mjs.map} +1 -1
- package/dist/{chunk-2MM5EJJX.mjs → chunk-424M7IR7.mjs} +23 -2
- package/dist/chunk-4OIZM4HS.mjs +1 -0
- package/dist/{chunk-GDC64SYJ.mjs → chunk-5ASRKEB4.mjs} +1 -1
- package/dist/{chunk-GDC64SYJ.mjs.map → chunk-5ASRKEB4.mjs.map} +1 -1
- package/dist/{chunk-OXAZEEGP.mjs → chunk-B4COTK4K.mjs} +1 -1
- package/dist/{chunk-OXAZEEGP.mjs.map → chunk-B4COTK4K.mjs.map} +1 -1
- package/dist/chunk-DDH7K4QM.mjs +1 -0
- package/dist/chunk-F47GLYUU.mjs +1 -0
- package/dist/chunk-J3GE7DEU.mjs +22 -0
- package/dist/chunk-J3GE7DEU.mjs.map +1 -0
- package/dist/chunk-KIOYQRMQ.mjs +12 -0
- package/dist/chunk-KIOYQRMQ.mjs.map +1 -0
- package/dist/chunk-M7SBBYV2.mjs +14 -0
- package/dist/chunk-M7SBBYV2.mjs.map +1 -0
- package/dist/{chunk-IZAD2S7R.mjs → chunk-MY4G7R3I.mjs} +2 -2
- package/dist/{chunk-74WWMNZS.mjs → chunk-OLX53VEF.mjs} +4 -2
- package/dist/{chunk-74WWMNZS.mjs.map → chunk-OLX53VEF.mjs.map} +1 -1
- package/dist/chunk-OXZCMC5I.mjs +13 -0
- package/dist/{chunk-JEKUA56R.mjs.map → chunk-OXZCMC5I.mjs.map} +1 -1
- package/dist/chunk-QXTNZR7B.mjs +25 -0
- package/dist/chunk-QXTNZR7B.mjs.map +1 -0
- package/dist/{chunk-QZITBKWX.mjs → chunk-U7V3G7CR.mjs} +2 -2
- package/dist/chunk-UY76KTPE.mjs +13 -0
- package/dist/chunk-UY76KTPE.mjs.map +1 -0
- package/dist/chunk-XT74R35S.mjs +1 -0
- package/dist/chunk-XT74R35S.mjs.map +1 -0
- package/dist/chunk-XWPCDIFC.mjs +18 -0
- package/dist/chunk-XWPCDIFC.mjs.map +1 -0
- package/dist/chunk-YFN6KOC4.mjs +15 -0
- package/dist/chunk-YFN6KOC4.mjs.map +1 -0
- package/dist/compat/index.d.mts +360 -1
- package/dist/compat/index.d.ts +360 -1
- package/dist/compat/index.js +240 -15
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/index.mjs +235 -82
- package/dist/compat/index.mjs.map +1 -1
- package/dist/error/AbortError.mjs +1 -1
- package/dist/error/TimeoutError.d.mts +9 -0
- package/dist/error/TimeoutError.d.ts +9 -0
- package/dist/error/TimeoutError.js +36 -0
- package/dist/error/TimeoutError.js.map +1 -0
- package/dist/error/TimeoutError.mjs +8 -0
- package/dist/error/TimeoutError.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 +12 -2
- package/dist/error/index.js.map +1 -1
- package/dist/error/index.mjs +7 -3
- package/dist/function/debounce.mjs +1 -1
- package/dist/function/index.mjs +4 -4
- package/dist/function/negate.mjs +1 -1
- package/dist/function/noop.mjs +1 -1
- package/dist/function/once.mjs +1 -1
- package/dist/function/throttle.mjs +1 -1
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +99 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -82
- package/dist/math/clamp.mjs +1 -1
- package/dist/math/inRange.mjs +1 -1
- package/dist/math/index.js.map +1 -1
- package/dist/math/index.mjs +12 -12
- package/dist/math/mean.d.mts +1 -1
- package/dist/math/mean.d.ts +1 -1
- package/dist/math/mean.js.map +1 -1
- package/dist/math/mean.mjs +2 -2
- package/dist/math/meanBy.js.map +1 -1
- package/dist/math/meanBy.mjs +3 -3
- package/dist/math/random.mjs +1 -1
- package/dist/math/randomInt.mjs +1 -1
- package/dist/math/range.mjs +1 -1
- package/dist/math/round.mjs +1 -1
- package/dist/math/sum.mjs +1 -1
- package/dist/math/sumBy.mjs +1 -1
- package/dist/object/clone.mjs +1 -1
- package/dist/object/index.js +3 -1
- package/dist/object/index.js.map +1 -1
- package/dist/object/index.mjs +6 -6
- package/dist/object/invert.js +3 -1
- package/dist/object/invert.js.map +1 -1
- package/dist/object/invert.mjs +2 -2
- package/dist/object/omit.mjs +2 -2
- package/dist/object/omitBy.mjs +1 -1
- package/dist/object/pick.mjs +1 -1
- package/dist/object/pickBy.mjs +1 -1
- package/dist/predicate/index.mjs +1 -1
- package/dist/predicate/isEqual.mjs +1 -1
- package/dist/predicate/isNil.mjs +1 -1
- package/dist/predicate/isNotNil.mjs +1 -1
- package/dist/predicate/isNull.mjs +1 -1
- package/dist/predicate/isUndefined.mjs +1 -1
- package/dist/promise/delay.mjs +1 -1
- package/dist/promise/index.d.mts +1 -0
- package/dist/promise/index.d.ts +1 -0
- package/dist/promise/index.js +47 -2
- package/dist/promise/index.js.map +1 -1
- package/dist/promise/index.mjs +9 -3
- package/dist/promise/timeout.d.mts +10 -0
- package/dist/promise/timeout.d.ts +10 -0
- package/dist/promise/timeout.js +92 -0
- package/dist/promise/timeout.js.map +1 -0
- package/dist/promise/timeout.mjs +11 -0
- package/dist/promise/timeout.mjs.map +1 -0
- package/dist/promise/withTimeout.d.mts +22 -0
- package/dist/promise/withTimeout.d.ts +22 -0
- package/dist/promise/withTimeout.js +99 -0
- package/dist/promise/withTimeout.js.map +1 -0
- package/dist/promise/withTimeout.mjs +12 -0
- package/dist/promise/withTimeout.mjs.map +1 -0
- package/dist/string/camelCase.mjs +1 -1
- package/dist/string/capitalize.mjs +1 -1
- package/dist/string/index.d.mts +1 -0
- package/dist/string/index.d.ts +1 -0
- package/dist/string/index.js +21 -2
- package/dist/string/index.js.map +1 -1
- package/dist/string/index.mjs +13 -9
- package/dist/string/kebabCase.mjs +1 -1
- package/dist/string/lowerCase.mjs +1 -1
- package/dist/string/snakeCase.mjs +1 -1
- package/dist/string/startCase.d.mts +16 -0
- package/dist/string/startCase.d.ts +16 -0
- package/dist/string/startCase.js +54 -0
- package/dist/string/startCase.js.map +1 -0
- package/dist/string/startCase.mjs +9 -0
- package/dist/string/startCase.mjs.map +1 -0
- package/package.json +3 -5
- package/dist/chunk-2MRZANXZ.mjs +0 -1
- package/dist/chunk-ARZ5BDR6.mjs +0 -1
- package/dist/chunk-C4WE4GLC.mjs +0 -14
- package/dist/chunk-C4WE4GLC.mjs.map +0 -1
- package/dist/chunk-FZEZH22H.mjs +0 -1
- package/dist/chunk-JE6JKZU3.mjs +0 -15
- package/dist/chunk-JE6JKZU3.mjs.map +0 -1
- package/dist/chunk-JEKUA56R.mjs +0 -9
- package/dist/chunk-QKYYOLJ6.mjs +0 -1
- /package/dist/{chunk-2MM5EJJX.mjs.map → array/flatMap.mjs.map} +0 -0
- /package/dist/{chunk-2MRZANXZ.mjs.map → chunk-424M7IR7.mjs.map} +0 -0
- /package/dist/{chunk-ARZ5BDR6.mjs.map → chunk-4OIZM4HS.mjs.map} +0 -0
- /package/dist/{chunk-FZEZH22H.mjs.map → chunk-DDH7K4QM.mjs.map} +0 -0
- /package/dist/{chunk-QKYYOLJ6.mjs.map → chunk-F47GLYUU.mjs.map} +0 -0
- /package/dist/{chunk-IZAD2S7R.mjs.map → chunk-MY4G7R3I.mjs.map} +0 -0
- /package/dist/{chunk-QZITBKWX.mjs.map → chunk-U7V3G7CR.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,44 +1,29 @@
|
|
|
1
1
|
import "./chunk-NKLIE2OI.mjs";
|
|
2
|
-
import "./chunk-
|
|
2
|
+
import "./chunk-4OIZM4HS.mjs";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
} from "./chunk-5IKVJGHO.mjs";
|
|
4
|
+
withTimeout
|
|
5
|
+
} from "./chunk-XWPCDIFC.mjs";
|
|
6
|
+
import "./chunk-J3GE7DEU.mjs";
|
|
7
|
+
import "./chunk-XT74R35S.mjs";
|
|
9
8
|
import {
|
|
10
9
|
snakeCase
|
|
11
10
|
} from "./chunk-F3WCQQET.mjs";
|
|
12
|
-
import "./chunk-ARZ5BDR6.mjs";
|
|
13
11
|
import {
|
|
14
|
-
|
|
15
|
-
} from "./chunk-
|
|
12
|
+
startCase
|
|
13
|
+
} from "./chunk-QXTNZR7B.mjs";
|
|
16
14
|
import {
|
|
17
15
|
camelCase
|
|
18
16
|
} from "./chunk-Y5V7UAZZ.mjs";
|
|
19
17
|
import {
|
|
20
18
|
capitalize
|
|
21
19
|
} from "./chunk-U56ZOM7L.mjs";
|
|
22
|
-
import "./chunk-WVQ7YVRK.mjs";
|
|
23
|
-
import "./chunk-OSOLEQLZ.mjs";
|
|
24
20
|
import {
|
|
25
|
-
|
|
26
|
-
} from "./chunk-
|
|
27
|
-
import {
|
|
28
|
-
invert
|
|
29
|
-
} from "./chunk-74WWMNZS.mjs";
|
|
30
|
-
import {
|
|
31
|
-
omit
|
|
32
|
-
} from "./chunk-QZITBKWX.mjs";
|
|
33
|
-
import {
|
|
34
|
-
omitBy
|
|
35
|
-
} from "./chunk-BCTYOXT7.mjs";
|
|
36
|
-
import {
|
|
37
|
-
pick
|
|
38
|
-
} from "./chunk-HPFDYUGP.mjs";
|
|
21
|
+
kebabCase
|
|
22
|
+
} from "./chunk-EYYZQFOP.mjs";
|
|
39
23
|
import {
|
|
40
|
-
|
|
41
|
-
} from "./chunk-
|
|
24
|
+
lowerCase
|
|
25
|
+
} from "./chunk-5IKVJGHO.mjs";
|
|
26
|
+
import "./chunk-WVQ7YVRK.mjs";
|
|
42
27
|
import "./chunk-ASJF5D6C.mjs";
|
|
43
28
|
import {
|
|
44
29
|
isEqual
|
|
@@ -55,32 +40,60 @@ import {
|
|
|
55
40
|
import {
|
|
56
41
|
isUndefined
|
|
57
42
|
} from "./chunk-VH2PV426.mjs";
|
|
43
|
+
import {
|
|
44
|
+
delay
|
|
45
|
+
} from "./chunk-O64NE2P4.mjs";
|
|
46
|
+
import "./chunk-OSOLEQLZ.mjs";
|
|
47
|
+
import {
|
|
48
|
+
pickBy
|
|
49
|
+
} from "./chunk-6CLH5YZ2.mjs";
|
|
50
|
+
import {
|
|
51
|
+
clone
|
|
52
|
+
} from "./chunk-U4JGKZ56.mjs";
|
|
53
|
+
import {
|
|
54
|
+
invert
|
|
55
|
+
} from "./chunk-OLX53VEF.mjs";
|
|
56
|
+
import {
|
|
57
|
+
omit
|
|
58
|
+
} from "./chunk-U7V3G7CR.mjs";
|
|
59
|
+
import {
|
|
60
|
+
omitBy
|
|
61
|
+
} from "./chunk-BCTYOXT7.mjs";
|
|
62
|
+
import {
|
|
63
|
+
pick
|
|
64
|
+
} from "./chunk-HPFDYUGP.mjs";
|
|
58
65
|
import "./chunk-FUS75PJ7.mjs";
|
|
66
|
+
import {
|
|
67
|
+
sumBy
|
|
68
|
+
} from "./chunk-5L4VWRFX.mjs";
|
|
69
|
+
import {
|
|
70
|
+
inRange
|
|
71
|
+
} from "./chunk-BH6HLGBA.mjs";
|
|
59
72
|
import {
|
|
60
73
|
meanBy
|
|
61
|
-
} from "./chunk-
|
|
74
|
+
} from "./chunk-MY4G7R3I.mjs";
|
|
62
75
|
import {
|
|
63
76
|
mean
|
|
64
|
-
} from "./chunk-
|
|
77
|
+
} from "./chunk-5ASRKEB4.mjs";
|
|
78
|
+
import {
|
|
79
|
+
sum
|
|
80
|
+
} from "./chunk-2SLTL4KL.mjs";
|
|
65
81
|
import {
|
|
66
82
|
range
|
|
67
83
|
} from "./chunk-DPH2KE6O.mjs";
|
|
68
84
|
import {
|
|
69
85
|
round
|
|
70
86
|
} from "./chunk-5PMKOZ2F.mjs";
|
|
71
|
-
import {
|
|
72
|
-
sumBy
|
|
73
|
-
} from "./chunk-5L4VWRFX.mjs";
|
|
74
|
-
import {
|
|
75
|
-
sum
|
|
76
|
-
} from "./chunk-2SLTL4KL.mjs";
|
|
77
87
|
import {
|
|
78
88
|
clamp
|
|
79
89
|
} from "./chunk-MLCL773E.mjs";
|
|
90
|
+
import "./chunk-DDH7K4QM.mjs";
|
|
80
91
|
import {
|
|
81
|
-
|
|
82
|
-
} from "./chunk-
|
|
83
|
-
import
|
|
92
|
+
without
|
|
93
|
+
} from "./chunk-PYEYV7BY.mjs";
|
|
94
|
+
import {
|
|
95
|
+
xor
|
|
96
|
+
} from "./chunk-L7FQX5MN.mjs";
|
|
84
97
|
import {
|
|
85
98
|
xorBy
|
|
86
99
|
} from "./chunk-Q47NGNXT.mjs";
|
|
@@ -96,12 +109,21 @@ import {
|
|
|
96
109
|
import {
|
|
97
110
|
zipWith
|
|
98
111
|
} from "./chunk-4KYXHZ4R.mjs";
|
|
112
|
+
import {
|
|
113
|
+
union
|
|
114
|
+
} from "./chunk-R6QA7PLZ.mjs";
|
|
115
|
+
import {
|
|
116
|
+
unionBy
|
|
117
|
+
} from "./chunk-NFS7RWWE.mjs";
|
|
99
118
|
import {
|
|
100
119
|
unionWith
|
|
101
120
|
} from "./chunk-2ZCITDMK.mjs";
|
|
121
|
+
import {
|
|
122
|
+
uniq
|
|
123
|
+
} from "./chunk-DVK2N4KC.mjs";
|
|
102
124
|
import {
|
|
103
125
|
uniqBy
|
|
104
|
-
} from "./chunk-
|
|
126
|
+
} from "./chunk-B4COTK4K.mjs";
|
|
105
127
|
import {
|
|
106
128
|
uniqWith
|
|
107
129
|
} from "./chunk-237HGSZS.mjs";
|
|
@@ -112,11 +134,17 @@ import {
|
|
|
112
134
|
unzipWith
|
|
113
135
|
} from "./chunk-IFNXROZR.mjs";
|
|
114
136
|
import {
|
|
115
|
-
|
|
116
|
-
} from "./chunk-
|
|
137
|
+
sampleSize
|
|
138
|
+
} from "./chunk-EHSKB6DF.mjs";
|
|
117
139
|
import {
|
|
118
|
-
|
|
119
|
-
} from "./chunk-
|
|
140
|
+
randomInt
|
|
141
|
+
} from "./chunk-GIWAOOFY.mjs";
|
|
142
|
+
import {
|
|
143
|
+
random
|
|
144
|
+
} from "./chunk-SYWMYQYJ.mjs";
|
|
145
|
+
import {
|
|
146
|
+
shuffle
|
|
147
|
+
} from "./chunk-G7UQ5PUR.mjs";
|
|
120
148
|
import {
|
|
121
149
|
tail
|
|
122
150
|
} from "./chunk-OF6NM4G7.mjs";
|
|
@@ -136,14 +164,11 @@ import {
|
|
|
136
164
|
toFilled
|
|
137
165
|
} from "./chunk-OP4OAKQJ.mjs";
|
|
138
166
|
import {
|
|
139
|
-
|
|
140
|
-
} from "./chunk-
|
|
141
|
-
import {
|
|
142
|
-
uniq
|
|
143
|
-
} from "./chunk-DVK2N4KC.mjs";
|
|
167
|
+
intersectionWith
|
|
168
|
+
} from "./chunk-XI7KRD2C.mjs";
|
|
144
169
|
import {
|
|
145
|
-
|
|
146
|
-
} from "./chunk-
|
|
170
|
+
keyBy
|
|
171
|
+
} from "./chunk-AJKZMN2V.mjs";
|
|
147
172
|
import {
|
|
148
173
|
last
|
|
149
174
|
} from "./chunk-KPBQ7OUY.mjs";
|
|
@@ -163,17 +188,11 @@ import {
|
|
|
163
188
|
sample
|
|
164
189
|
} from "./chunk-2KNLZB7V.mjs";
|
|
165
190
|
import {
|
|
166
|
-
|
|
167
|
-
} from "./chunk-
|
|
168
|
-
import {
|
|
169
|
-
randomInt
|
|
170
|
-
} from "./chunk-GIWAOOFY.mjs";
|
|
171
|
-
import {
|
|
172
|
-
random
|
|
173
|
-
} from "./chunk-SYWMYQYJ.mjs";
|
|
191
|
+
flattenDeep
|
|
192
|
+
} from "./chunk-ML727RRJ.mjs";
|
|
174
193
|
import {
|
|
175
|
-
|
|
176
|
-
} from "./chunk-
|
|
194
|
+
forEachRight
|
|
195
|
+
} from "./chunk-IEA53J7P.mjs";
|
|
177
196
|
import {
|
|
178
197
|
groupBy
|
|
179
198
|
} from "./chunk-E6E4RZLN.mjs";
|
|
@@ -190,35 +209,29 @@ import {
|
|
|
190
209
|
intersectionBy
|
|
191
210
|
} from "./chunk-O6UXZR3U.mjs";
|
|
192
211
|
import {
|
|
193
|
-
|
|
194
|
-
} from "./chunk-
|
|
195
|
-
import {
|
|
196
|
-
keyBy
|
|
197
|
-
} from "./chunk-AJKZMN2V.mjs";
|
|
212
|
+
differenceWith
|
|
213
|
+
} from "./chunk-6NVQAHXP.mjs";
|
|
198
214
|
import {
|
|
199
215
|
drop
|
|
200
|
-
} from "./chunk-
|
|
216
|
+
} from "./chunk-3EZAFZG3.mjs";
|
|
201
217
|
import {
|
|
202
218
|
dropRight
|
|
203
|
-
} from "./chunk-
|
|
219
|
+
} from "./chunk-OXZCMC5I.mjs";
|
|
204
220
|
import {
|
|
205
221
|
dropRightWhile
|
|
206
|
-
} from "./chunk-
|
|
222
|
+
} from "./chunk-M7SBBYV2.mjs";
|
|
207
223
|
import {
|
|
208
224
|
dropWhile
|
|
209
225
|
} from "./chunk-LJ2C6MVP.mjs";
|
|
210
226
|
import {
|
|
211
227
|
fill
|
|
212
|
-
} from "./chunk-
|
|
228
|
+
} from "./chunk-YFN6KOC4.mjs";
|
|
213
229
|
import {
|
|
214
|
-
|
|
215
|
-
} from "./chunk-
|
|
230
|
+
flatMap
|
|
231
|
+
} from "./chunk-UY76KTPE.mjs";
|
|
216
232
|
import {
|
|
217
233
|
flatten
|
|
218
234
|
} from "./chunk-33MSBDC6.mjs";
|
|
219
|
-
import {
|
|
220
|
-
forEachRight
|
|
221
|
-
} from "./chunk-IEA53J7P.mjs";
|
|
222
235
|
import {
|
|
223
236
|
chunk
|
|
224
237
|
} from "./chunk-E6C5EZQA.mjs";
|
|
@@ -234,14 +247,17 @@ import {
|
|
|
234
247
|
import {
|
|
235
248
|
differenceBy
|
|
236
249
|
} from "./chunk-LVWX5B43.mjs";
|
|
237
|
-
import
|
|
238
|
-
differenceWith
|
|
239
|
-
} from "./chunk-6NVQAHXP.mjs";
|
|
240
|
-
import "./chunk-FZEZH22H.mjs";
|
|
250
|
+
import "./chunk-F47GLYUU.mjs";
|
|
241
251
|
import {
|
|
242
252
|
AbortError
|
|
243
253
|
} from "./chunk-DXB7EZUQ.mjs";
|
|
254
|
+
import {
|
|
255
|
+
TimeoutError
|
|
256
|
+
} from "./chunk-KIOYQRMQ.mjs";
|
|
244
257
|
import "./chunk-236H5JZJ.mjs";
|
|
258
|
+
import {
|
|
259
|
+
noop
|
|
260
|
+
} from "./chunk-LKXCOLNY.mjs";
|
|
245
261
|
import {
|
|
246
262
|
once
|
|
247
263
|
} from "./chunk-CMBC4MXG.mjs";
|
|
@@ -254,12 +270,10 @@ import {
|
|
|
254
270
|
import {
|
|
255
271
|
negate
|
|
256
272
|
} from "./chunk-BOOQBJN2.mjs";
|
|
257
|
-
import
|
|
258
|
-
noop
|
|
259
|
-
} from "./chunk-LKXCOLNY.mjs";
|
|
260
|
-
import "./chunk-2MM5EJJX.mjs";
|
|
273
|
+
import "./chunk-424M7IR7.mjs";
|
|
261
274
|
export {
|
|
262
275
|
AbortError,
|
|
276
|
+
TimeoutError,
|
|
263
277
|
camelCase,
|
|
264
278
|
capitalize,
|
|
265
279
|
chunk,
|
|
@@ -277,6 +291,7 @@ export {
|
|
|
277
291
|
dropRightWhile,
|
|
278
292
|
dropWhile,
|
|
279
293
|
fill,
|
|
294
|
+
flatMap,
|
|
280
295
|
flatten,
|
|
281
296
|
flattenDeep,
|
|
282
297
|
forEachRight,
|
|
@@ -318,6 +333,7 @@ export {
|
|
|
318
333
|
sampleSize,
|
|
319
334
|
shuffle,
|
|
320
335
|
snakeCase,
|
|
336
|
+
startCase,
|
|
321
337
|
sum,
|
|
322
338
|
sumBy,
|
|
323
339
|
tail,
|
|
@@ -335,6 +351,7 @@ export {
|
|
|
335
351
|
uniqWith,
|
|
336
352
|
unzip,
|
|
337
353
|
unzipWith,
|
|
354
|
+
withTimeout,
|
|
338
355
|
without,
|
|
339
356
|
xor,
|
|
340
357
|
xorBy,
|
package/dist/math/clamp.mjs
CHANGED
package/dist/math/inRange.mjs
CHANGED
package/dist/math/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/inRange.ts","../../src/math/sum.ts","../../src/math/mean.ts","../../src/math/meanBy.ts","../../src/math/random.ts","../../src/math/randomInt.ts","../../src/math/round.ts","../../src/math/sumBy.ts","../../src/math/range.ts"],"sourcesContent":["export { clamp } from './clamp.ts';\nexport { inRange } from './inRange.ts';\nexport { mean } from './mean.ts';\nexport { meanBy } from './meanBy.ts';\nexport { random } from './random.ts';\nexport { randomInt } from './randomInt.ts';\nexport { round } from './round.ts';\nexport { sum } from './sum.ts';\nexport { sumBy } from './sumBy.ts';\nexport { range } from './range.ts';\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","export function inRange(value: number, maximum: number): boolean;\nexport function inRange(value: number, minimum: number, maximum: number): boolean;\n/**\n * Checks if the value is within a specified range.\n *\n * @param {number} value The value to check.\n * @param {number} minimum The lower bound of the range (inclusive).\n * @param {number} maximum The upper bound of the range (exclusive).\n * @returns {boolean} `true` if the value is within the specified range, otherwise `false`.\n * @throws {Error} Throws an error if the `minimum` is greater or equal than the `maximum`.\n *\n * @example\n * const result1 = inRange(3, 5); // result1 will be true.\n * const result2 = inRange(1, 2, 5); // result2 will be false.\n * const result3 = inRange(1, 5, 2); // If the minimum is greater or equal than the maximum, an error is thrown.\n */\nexport function inRange(value: number, minimum: number, maximum?: number): boolean {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\n if (minimum >= maximum) {\n throw new Error('The maximum value must be greater than the minimum value.');\n }\n\n return minimum <= value && value < maximum;\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 (let i = 0; i < nums.length; i++) {\n result += nums[i];\n }\n\n return result;\n}\n","import { sum } from './sum.ts';\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 average.\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","import { mean } from './mean.ts';\n\n/**\n * Calculates the average of an array of numbers when applying\n * the `getValue` function to each element.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @template T - The type of elements in the array.\n * @param {T[]} items An array to calculate the average.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {number} The average of all the numbers as determined by the `getValue` function.\n *\n * @example\n * meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2\n * meanBy([], x => x.a); // Returns: NaN\n */\nexport function meanBy<T>(items: readonly T[], getValue: (element: T) => number): number {\n const nums = items.map(x => getValue(x));\n\n return mean(nums);\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.ts';\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","import { sum } from './sum.ts';\n\n/**\n * Calculates the sum of an array of numbers when applying\n * the `getValue` function to each element.\n *\n * If the array is empty, this function returns `0`.\n *\n * @template T - The type of elements in the array.\n * @param {T[]} items An array to calculate the average.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {number} The average of all the numbers as determined by the `getValue` function.\n *\n * @example\n * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 6\n * sumBy([], x => x.a); // Returns: 0\n */\nexport function sumBy<T>(items: readonly T[], getValue: (element: T) => number): number {\n const nums = items.map(x => getValue(x));\n\n return sum(nums);\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`.\n *\n * @param {number} start - The starting number of the range (inclusive).\n * @param {number} [end] - The end number of the range (exclusive).\n * @param {number} [step] - The step value for the range. (default: 1)\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 [0, -1, -2, -3]\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;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;;;ACTO,SAAS,QAAQ,OAAe,SAAiB,SAA2B;AACjF,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AAEA,SAAO,WAAW,SAAS,QAAQ;AACrC;;;ACdO,SAAS,IAAI,MAAiC;AACnD,MAAI,SAAS;AAEb,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,cAAU,KAAK,CAAC;AAAA,EAClB;AAEA,SAAO;AACT;;;ACNO,SAAS,KAAK,MAAiC;AACpD,SAAO,IAAI,IAAI,IAAI,KAAK;AAC1B;;;ACAO,SAAS,OAAU,OAAqB,UAA0C;AACvF,QAAM,OAAO,MAAM,IAAI,OAAK,SAAS,CAAC,CAAC;AAEvC,SAAO,KAAK,IAAI;AAClB;;;ACJO,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;;;ACNO,SAAS,MAAS,OAAqB,UAA0C;AACtF,QAAM,OAAO,MAAM,IAAI,OAAK,SAAS,CAAC,CAAC;AAEvC,SAAO,IAAI,IAAI;AACjB;;;ACQO,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":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/inRange.ts","../../src/math/sum.ts","../../src/math/mean.ts","../../src/math/meanBy.ts","../../src/math/random.ts","../../src/math/randomInt.ts","../../src/math/round.ts","../../src/math/sumBy.ts","../../src/math/range.ts"],"sourcesContent":["export { clamp } from './clamp.ts';\nexport { inRange } from './inRange.ts';\nexport { mean } from './mean.ts';\nexport { meanBy } from './meanBy.ts';\nexport { random } from './random.ts';\nexport { randomInt } from './randomInt.ts';\nexport { round } from './round.ts';\nexport { sum } from './sum.ts';\nexport { sumBy } from './sumBy.ts';\nexport { range } from './range.ts';\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","export function inRange(value: number, maximum: number): boolean;\nexport function inRange(value: number, minimum: number, maximum: number): boolean;\n/**\n * Checks if the value is within a specified range.\n *\n * @param {number} value The value to check.\n * @param {number} minimum The lower bound of the range (inclusive).\n * @param {number} maximum The upper bound of the range (exclusive).\n * @returns {boolean} `true` if the value is within the specified range, otherwise `false`.\n * @throws {Error} Throws an error if the `minimum` is greater or equal than the `maximum`.\n *\n * @example\n * const result1 = inRange(3, 5); // result1 will be true.\n * const result2 = inRange(1, 2, 5); // result2 will be false.\n * const result3 = inRange(1, 5, 2); // If the minimum is greater or equal than the maximum, an error is thrown.\n */\nexport function inRange(value: number, minimum: number, maximum?: number): boolean {\n if (maximum == null) {\n maximum = minimum;\n minimum = 0;\n }\n\n if (minimum >= maximum) {\n throw new Error('The maximum value must be greater than the minimum value.');\n }\n\n return minimum <= value && value < maximum;\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 (let i = 0; i < nums.length; i++) {\n result += nums[i];\n }\n\n return result;\n}\n","import { sum } from './sum.ts';\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 average.\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 = mean(numbers);\n * // result will be 3\n */\nexport function mean(nums: readonly number[]): number {\n return sum(nums) / nums.length;\n}\n","import { mean } from './mean.ts';\n\n/**\n * Calculates the average of an array of numbers when applying\n * the `getValue` function to each element.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @template T - The type of elements in the array.\n * @param {T[]} items An array to calculate the average.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {number} The average of all the numbers as determined by the `getValue` function.\n *\n * @example\n * meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2\n * meanBy([], x => x.a); // Returns: NaN\n */\nexport function meanBy<T>(items: readonly T[], getValue: (element: T) => number): number {\n const nums = items.map(x => getValue(x));\n\n return mean(nums);\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.ts';\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","import { sum } from './sum.ts';\n\n/**\n * Calculates the sum of an array of numbers when applying\n * the `getValue` function to each element.\n *\n * If the array is empty, this function returns `0`.\n *\n * @template T - The type of elements in the array.\n * @param {T[]} items An array to calculate the average.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {number} The average of all the numbers as determined by the `getValue` function.\n *\n * @example\n * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 6\n * sumBy([], x => x.a); // Returns: 0\n */\nexport function sumBy<T>(items: readonly T[], getValue: (element: T) => number): number {\n const nums = items.map(x => getValue(x));\n\n return sum(nums);\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`.\n *\n * @param {number} start - The starting number of the range (inclusive).\n * @param {number} [end] - The end number of the range (exclusive).\n * @param {number} [step] - The step value for the range. (default: 1)\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 [0, -1, -2, -3]\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;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;;;ACTO,SAAS,QAAQ,OAAe,SAAiB,SAA2B;AACjF,MAAI,WAAW,MAAM;AACnB,cAAU;AACV,cAAU;AAAA,EACZ;AAEA,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AAEA,SAAO,WAAW,SAAS,QAAQ;AACrC;;;ACdO,SAAS,IAAI,MAAiC;AACnD,MAAI,SAAS;AAEb,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,cAAU,KAAK,CAAC;AAAA,EAClB;AAEA,SAAO;AACT;;;ACNO,SAAS,KAAK,MAAiC;AACpD,SAAO,IAAI,IAAI,IAAI,KAAK;AAC1B;;;ACAO,SAAS,OAAU,OAAqB,UAA0C;AACvF,QAAM,OAAO,MAAM,IAAI,OAAK,SAAS,CAAC,CAAC;AAEvC,SAAO,KAAK,IAAI;AAClB;;;ACJO,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;;;ACNO,SAAS,MAAS,OAAqB,UAA0C;AACtF,QAAM,OAAO,MAAM,IAAI,OAAK,SAAS,CAAC,CAAC;AAEvC,SAAO,IAAI,IAAI;AACjB;;;ACQO,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,35 +1,35 @@
|
|
|
1
1
|
import "../chunk-FUS75PJ7.mjs";
|
|
2
|
+
import {
|
|
3
|
+
sumBy
|
|
4
|
+
} from "../chunk-5L4VWRFX.mjs";
|
|
5
|
+
import {
|
|
6
|
+
inRange
|
|
7
|
+
} from "../chunk-BH6HLGBA.mjs";
|
|
2
8
|
import {
|
|
3
9
|
meanBy
|
|
4
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-MY4G7R3I.mjs";
|
|
5
11
|
import {
|
|
6
12
|
mean
|
|
7
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-5ASRKEB4.mjs";
|
|
14
|
+
import {
|
|
15
|
+
sum
|
|
16
|
+
} from "../chunk-2SLTL4KL.mjs";
|
|
8
17
|
import {
|
|
9
18
|
range
|
|
10
19
|
} from "../chunk-DPH2KE6O.mjs";
|
|
11
20
|
import {
|
|
12
21
|
round
|
|
13
22
|
} from "../chunk-5PMKOZ2F.mjs";
|
|
14
|
-
import {
|
|
15
|
-
sumBy
|
|
16
|
-
} from "../chunk-5L4VWRFX.mjs";
|
|
17
|
-
import {
|
|
18
|
-
sum
|
|
19
|
-
} from "../chunk-2SLTL4KL.mjs";
|
|
20
23
|
import {
|
|
21
24
|
clamp
|
|
22
25
|
} from "../chunk-MLCL773E.mjs";
|
|
23
|
-
import {
|
|
24
|
-
inRange
|
|
25
|
-
} from "../chunk-BH6HLGBA.mjs";
|
|
26
26
|
import {
|
|
27
27
|
randomInt
|
|
28
28
|
} from "../chunk-GIWAOOFY.mjs";
|
|
29
29
|
import {
|
|
30
30
|
random
|
|
31
31
|
} from "../chunk-SYWMYQYJ.mjs";
|
|
32
|
-
import "../chunk-
|
|
32
|
+
import "../chunk-424M7IR7.mjs";
|
|
33
33
|
export {
|
|
34
34
|
clamp,
|
|
35
35
|
inRange,
|
package/dist/math/mean.d.mts
CHANGED
package/dist/math/mean.d.ts
CHANGED
package/dist/math/mean.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/mean.ts","../../src/math/sum.ts"],"sourcesContent":["import { sum } from './sum.ts';\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 average.\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 =
|
|
1
|
+
{"version":3,"sources":["../../src/math/mean.ts","../../src/math/sum.ts"],"sourcesContent":["import { sum } from './sum.ts';\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 average.\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 = mean(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 (let i = 0; i < nums.length; i++) {\n result += nums[i];\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,SAAS,IAAI,MAAiC;AACnD,MAAI,SAAS;AAEb,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,cAAU,KAAK,CAAC;AAAA,EAClB;AAEA,SAAO;AACT;;;ADNO,SAAS,KAAK,MAAiC;AACpD,SAAO,IAAI,IAAI,IAAI,KAAK;AAC1B;","names":[]}
|
package/dist/math/mean.mjs
CHANGED
package/dist/math/meanBy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/meanBy.ts","../../src/math/sum.ts","../../src/math/mean.ts"],"sourcesContent":["import { mean } from './mean.ts';\n\n/**\n * Calculates the average of an array of numbers when applying\n * the `getValue` function to each element.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @template T - The type of elements in the array.\n * @param {T[]} items An array to calculate the average.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {number} The average of all the numbers as determined by the `getValue` function.\n *\n * @example\n * meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2\n * meanBy([], x => x.a); // Returns: NaN\n */\nexport function meanBy<T>(items: readonly T[], getValue: (element: T) => number): number {\n const nums = items.map(x => getValue(x));\n\n return mean(nums);\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 (let i = 0; i < nums.length; i++) {\n result += nums[i];\n }\n\n return result;\n}\n","import { sum } from './sum.ts';\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 average.\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 =
|
|
1
|
+
{"version":3,"sources":["../../src/math/meanBy.ts","../../src/math/sum.ts","../../src/math/mean.ts"],"sourcesContent":["import { mean } from './mean.ts';\n\n/**\n * Calculates the average of an array of numbers when applying\n * the `getValue` function to each element.\n *\n * If the array is empty, this function returns `NaN`.\n *\n * @template T - The type of elements in the array.\n * @param {T[]} items An array to calculate the average.\n * @param {(element: T) => number} getValue A function that selects a numeric value from each element.\n * @returns {number} The average of all the numbers as determined by the `getValue` function.\n *\n * @example\n * meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2\n * meanBy([], x => x.a); // Returns: NaN\n */\nexport function meanBy<T>(items: readonly T[], getValue: (element: T) => number): number {\n const nums = items.map(x => getValue(x));\n\n return mean(nums);\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 (let i = 0; i < nums.length; i++) {\n result += nums[i];\n }\n\n return result;\n}\n","import { sum } from './sum.ts';\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 average.\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 = mean(numbers);\n * // result will be 3\n */\nexport function mean(nums: readonly number[]): number {\n return sum(nums) / nums.length;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,SAAS,IAAI,MAAiC;AACnD,MAAI,SAAS;AAEb,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,cAAU,KAAK,CAAC;AAAA,EAClB;AAEA,SAAO;AACT;;;ACNO,SAAS,KAAK,MAAiC;AACpD,SAAO,IAAI,IAAI,IAAI,KAAK;AAC1B;;;AFAO,SAAS,OAAU,OAAqB,UAA0C;AACvF,QAAM,OAAO,MAAM,IAAI,OAAK,SAAS,CAAC,CAAC;AAEvC,SAAO,KAAK,IAAI;AAClB;","names":[]}
|
package/dist/math/meanBy.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
meanBy
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-MY4G7R3I.mjs";
|
|
4
|
+
import "../chunk-5ASRKEB4.mjs";
|
|
5
5
|
import "../chunk-2SLTL4KL.mjs";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-424M7IR7.mjs";
|
|
7
7
|
export {
|
|
8
8
|
meanBy
|
|
9
9
|
};
|
package/dist/math/random.mjs
CHANGED
package/dist/math/randomInt.mjs
CHANGED
package/dist/math/range.mjs
CHANGED
package/dist/math/round.mjs
CHANGED
package/dist/math/sum.mjs
CHANGED
package/dist/math/sumBy.mjs
CHANGED
package/dist/object/clone.mjs
CHANGED
package/dist/object/index.js
CHANGED
|
@@ -88,7 +88,9 @@ function pickBy(obj, shouldPick) {
|
|
|
88
88
|
// src/object/invert.ts
|
|
89
89
|
function invert(obj) {
|
|
90
90
|
const result = {};
|
|
91
|
-
|
|
91
|
+
const keys = Object.keys(obj);
|
|
92
|
+
for (let i = 0; i < keys.length; i++) {
|
|
93
|
+
const key = keys[i];
|
|
92
94
|
const value = obj[key];
|
|
93
95
|
result[value] = key;
|
|
94
96
|
}
|
package/dist/object/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts","../../src/object/invert.ts","../../src/object/clone.ts"],"sourcesContent":["export { omit } from './omit.ts';\nexport { omitBy } from './omitBy.ts';\nexport { pick } from './pick.ts';\nexport { pickBy } from './pickBy.ts';\nexport { invert } from './invert.ts';\nexport { clone } from './clone.ts';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.\n *\n * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,\n * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping\n * of the input object's key-value pairs.\n *\n * @template K - Type of the keys in the input object (string, number, symbol)\n * @template V - Type of the values in the input object (string, number, symbol)\n * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted\n * @returns {{ [key in V]: K }} - A new object with keys and values inverted\n *\n * @example\n * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }\n * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }\n * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }\n * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }\n */\nexport function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {\n const result = {} as { [key in V]: K };\n\n for (
|
|
1
|
+
{"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts","../../src/object/invert.ts","../../src/object/clone.ts"],"sourcesContent":["export { omit } from './omit.ts';\nexport { omitBy } from './omitBy.ts';\nexport { pick } from './pick.ts';\nexport { pickBy } from './pickBy.ts';\nexport { invert } from './invert.ts';\nexport { clone } from './clone.ts';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.\n *\n * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,\n * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping\n * of the input object's key-value pairs.\n *\n * @template K - Type of the keys in the input object (string, number, symbol)\n * @template V - Type of the values in the input object (string, number, symbol)\n * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted\n * @returns {{ [key in V]: K }} - A new object with keys and values inverted\n *\n * @example\n * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }\n * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }\n * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }\n * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }\n */\nexport function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {\n const result = {} as { [key in V]: K };\n\n const keys = Object.keys(obj) as K[];\n \n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = obj[key];\n result[value] = key;\n }\n\n return result;\n}\n","/**\n * Creates a shallow clone of the given object.\n *\n * @template T - The type of the object.\n * @param {T} obj - The object to clone.\n * @returns {T} - A shallow clone of the given object.\n *\n * @example\n * // Clone a primitive values\n * const num = 29;\n * const clonedNum = clone(num);\n * console.log(clonedNum); // 29\n * console.log(clonedNum === num) ; // true\n *\n * @example\n * // Clone an array\n * const arr = [1, 2, 3];\n * const clonedArr = clone(arr);\n * console.log(clonedArr); // [1, 2, 3]\n * console.log(clonedArr === arr); // false\n *\n * @example\n * // Clone an object\n * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };\n * const clonedObj = clone(obj);\n * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }\n * console.log(clonedObj === obj); // false\n */\nexport function clone<T>(obj: T): T {\n if (isPrimitive(obj)) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.slice() as T;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as T;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as T;\n }\n\n if (obj instanceof Map) {\n const result = new Map();\n for (const [key, value] of obj) {\n result.set(key, value);\n }\n return result as T;\n }\n\n if (obj instanceof Set) {\n const result = new Set();\n for (const value of obj) {\n result.add(value);\n }\n return result as T;\n }\n\n if (typeof obj === \"object\") {\n return Object.assign({}, obj) as T;\n }\n return obj;\n}\n\ntype Primitive = null | undefined | string | number | boolean | symbol | bigint;\n\nfunction isPrimitive(value: unknown): value is Primitive {\n return value == null ||\n (typeof value !== \"object\" && typeof value !== \"function\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;ACjBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,MAAM;AACtB,WAAO,GAAG,IAAI,IAAI,GAAG;AAAA,EACvB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;AChBO,SAAS,OAAqD,KAAsC;AACzG,QAAM,SAAS,CAAC;AAEhB,QAAM,OAAO,OAAO,KAAK,GAAG;AAE5B,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,MAAM,KAAK,CAAC;AAClB,UAAM,QAAQ,IAAI,GAAG;AACrB,WAAO,KAAK,IAAI;AAAA,EAClB;AAEA,SAAO;AACT;;;ACFO,SAAS,MAAS,KAAW;AAClC,MAAI,YAAY,GAAG,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAO,IAAI,MAAM;AAAA,EACnB;AAEA,MAAI,eAAe,MAAM;AACvB,WAAO,IAAI,KAAK,IAAI,QAAQ,CAAC;AAAA,EAC/B;AAEA,MAAI,eAAe,QAAQ;AACzB,WAAO,IAAI,OAAO,IAAI,QAAQ,IAAI,KAAK;AAAA,EACzC;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,SAAS,oBAAI,IAAI;AACvB,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK;AAC9B,aAAO,IAAI,KAAK,KAAK;AAAA,IACvB;AACA,WAAO;AAAA,EACT;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,SAAS,oBAAI,IAAI;AACvB,eAAW,SAAS,KAAK;AACvB,aAAO,IAAI,KAAK;AAAA,IAClB;AACA,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,OAAO,OAAO,CAAC,GAAG,GAAG;AAAA,EAC9B;AACA,SAAO;AACT;AAIA,SAAS,YAAY,OAAoC;AACvD,SAAO,SAAS,QACb,OAAO,UAAU,YAAY,OAAO,UAAU;AACnD;","names":[]}
|