es-toolkit 1.3.1-dev.81 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array/index.js +2 -9
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +9 -9
- package/dist/array/unionBy.js +1 -1
- package/dist/array/unionBy.js.map +1 -1
- package/dist/array/unionBy.mjs +1 -1
- package/dist/array/uniqBy.js +13 -6
- package/dist/array/uniqBy.js.map +1 -1
- package/dist/array/uniqBy.mjs +2 -1
- package/dist/array/xorBy.js +1 -1
- package/dist/array/xorBy.js.map +1 -1
- package/dist/array/xorBy.mjs +2 -2
- package/dist/chunk-ASFOKYTY.mjs +13 -0
- package/dist/chunk-ASFOKYTY.mjs.map +1 -0
- package/dist/{chunk-AM2EGFCU.mjs → chunk-EW3RT4QW.mjs} +2 -2
- package/dist/{chunk-MKETZ2RP.mjs → chunk-GOXQV6DX.mjs} +3 -2
- package/dist/{chunk-MKETZ2RP.mjs.map → chunk-GOXQV6DX.mjs.map} +1 -1
- package/dist/chunk-IJLQVGW4.mjs +1 -0
- package/dist/{chunk-NRNKP6JF.mjs → chunk-JBDGK6X4.mjs} +2 -2
- package/dist/{chunk-NRNKP6JF.mjs.map → chunk-JBDGK6X4.mjs.map} +1 -1
- package/dist/chunk-ZBG3EYM3.mjs +11 -0
- package/dist/chunk-ZBG3EYM3.mjs.map +1 -0
- package/dist/function/debounce.js +2 -1
- package/dist/function/debounce.js.map +1 -1
- package/dist/function/debounce.mjs +1 -1
- package/dist/function/index.js +2 -1
- package/dist/function/index.js.map +1 -1
- package/dist/function/index.mjs +4 -4
- package/dist/index.d.mts +0 -3
- package/dist/index.d.ts +0 -3
- package/dist/index.js +7 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -52
- package/dist/math/index.d.mts +0 -2
- package/dist/math/index.d.ts +0 -2
- package/dist/math/index.js +0 -17
- package/dist/math/index.js.map +1 -1
- package/dist/math/index.mjs +3 -11
- package/dist/object/index.mjs +6 -6
- package/dist/predicate/index.mjs +3 -3
- package/dist/promise/delay.d.mts +1 -18
- package/dist/promise/delay.d.ts +1 -18
- package/dist/promise/delay.js +3 -24
- package/dist/promise/delay.js.map +1 -1
- package/dist/promise/delay.mjs +1 -2
- package/dist/promise/index.js +3 -22
- package/dist/promise/index.js.map +1 -1
- package/dist/promise/index.mjs +1 -2
- package/package.json +1 -1
- package/dist/chunk-AL3GJBEI.mjs +0 -26
- package/dist/chunk-AL3GJBEI.mjs.map +0 -1
- package/dist/chunk-FZEZH22H.mjs +0 -1
- package/dist/chunk-QWJDITYJ.mjs +0 -13
- package/dist/chunk-QWJDITYJ.mjs.map +0 -1
- package/dist/chunk-UGFVAAVO.mjs +0 -12
- package/dist/chunk-UGFVAAVO.mjs.map +0 -1
- package/dist/chunk-VAV4XHLO.mjs +0 -1
- package/dist/chunk-VAV4XHLO.mjs.map +0 -1
- package/dist/chunk-VP2LXY75.mjs +0 -12
- package/dist/chunk-VP2LXY75.mjs.map +0 -1
- package/dist/chunk-WPDDOUQT.mjs +0 -16
- package/dist/chunk-WPDDOUQT.mjs.map +0 -1
- package/dist/error/AbortError.d.mts +0 -5
- package/dist/error/AbortError.d.ts +0 -5
- package/dist/error/AbortError.js +0 -36
- package/dist/error/AbortError.js.map +0 -1
- package/dist/error/AbortError.mjs +0 -8
- package/dist/error/AbortError.mjs.map +0 -1
- package/dist/error/index.d.mts +0 -1
- package/dist/error/index.d.ts +0 -1
- package/dist/error/index.js +0 -38
- package/dist/error/index.js.map +0 -1
- package/dist/error/index.mjs +0 -9
- package/dist/error/index.mjs.map +0 -1
- package/dist/math/random.d.mts +0 -16
- package/dist/math/random.d.ts +0 -16
- package/dist/math/random.js +0 -36
- package/dist/math/random.js.map +0 -1
- package/dist/math/random.mjs +0 -8
- package/dist/math/random.mjs.map +0 -1
- package/dist/math/randomInt.d.mts +0 -15
- package/dist/math/randomInt.d.ts +0 -15
- package/dist/math/randomInt.js +0 -43
- package/dist/math/randomInt.js.map +0 -1
- package/dist/math/randomInt.mjs +0 -9
- package/dist/math/randomInt.mjs.map +0 -1
- /package/dist/{chunk-AM2EGFCU.mjs.map → chunk-EW3RT4QW.mjs.map} +0 -0
- /package/dist/{chunk-FZEZH22H.mjs.map → chunk-IJLQVGW4.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,8 +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-ZBG3EYM3.mjs";
|
|
5
|
+
import "./chunk-T5JCRGXA.mjs";
|
|
6
|
+
import {
|
|
7
|
+
omit
|
|
8
|
+
} from "./chunk-PLTO44KM.mjs";
|
|
9
|
+
import {
|
|
10
|
+
omitBy
|
|
11
|
+
} from "./chunk-SF3V7XXM.mjs";
|
|
12
|
+
import {
|
|
13
|
+
pick
|
|
14
|
+
} from "./chunk-OFWKFUFZ.mjs";
|
|
15
|
+
import {
|
|
16
|
+
pickBy
|
|
17
|
+
} from "./chunk-T2C2WVFL.mjs";
|
|
18
|
+
import "./chunk-MAJSPFA6.mjs";
|
|
6
19
|
import {
|
|
7
20
|
isNotNil
|
|
8
21
|
} from "./chunk-ZQNAZPSK.mjs";
|
|
@@ -13,47 +26,41 @@ import {
|
|
|
13
26
|
isUndefined
|
|
14
27
|
} from "./chunk-VH2PV426.mjs";
|
|
15
28
|
import {
|
|
16
|
-
|
|
17
|
-
} from "./chunk-
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import {
|
|
20
|
-
randomInt
|
|
21
|
-
} from "./chunk-QWJDITYJ.mjs";
|
|
29
|
+
isNil
|
|
30
|
+
} from "./chunk-OHQAR5AU.mjs";
|
|
31
|
+
import "./chunk-IJLQVGW4.mjs";
|
|
22
32
|
import {
|
|
23
|
-
|
|
24
|
-
} from "./chunk-
|
|
33
|
+
clamp
|
|
34
|
+
} from "./chunk-MLCL773E.mjs";
|
|
25
35
|
import {
|
|
26
36
|
round
|
|
27
37
|
} from "./chunk-V7E5DGZP.mjs";
|
|
28
38
|
import {
|
|
29
39
|
sum
|
|
30
40
|
} from "./chunk-7OU22ENP.mjs";
|
|
31
|
-
import "./chunk-
|
|
32
|
-
import {
|
|
33
|
-
pick
|
|
34
|
-
} from "./chunk-OFWKFUFZ.mjs";
|
|
41
|
+
import "./chunk-N6EM6ETS.mjs";
|
|
35
42
|
import {
|
|
36
|
-
|
|
37
|
-
} from "./chunk-
|
|
43
|
+
throttle
|
|
44
|
+
} from "./chunk-XLO3QZVY.mjs";
|
|
38
45
|
import {
|
|
39
|
-
|
|
40
|
-
} from "./chunk-
|
|
46
|
+
debounce
|
|
47
|
+
} from "./chunk-GOXQV6DX.mjs";
|
|
41
48
|
import {
|
|
42
|
-
|
|
43
|
-
} from "./chunk-
|
|
49
|
+
noop
|
|
50
|
+
} from "./chunk-LKXCOLNY.mjs";
|
|
44
51
|
import {
|
|
45
|
-
|
|
46
|
-
} from "./chunk-
|
|
52
|
+
once
|
|
53
|
+
} from "./chunk-UFAA5WKR.mjs";
|
|
47
54
|
import "./chunk-EJGAXTF7.mjs";
|
|
48
55
|
import {
|
|
49
56
|
uniqBy
|
|
50
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-ASFOKYTY.mjs";
|
|
51
58
|
import {
|
|
52
59
|
xor
|
|
53
60
|
} from "./chunk-WXIBCOES.mjs";
|
|
54
61
|
import {
|
|
55
62
|
xorBy
|
|
56
|
-
} from "./chunk-
|
|
63
|
+
} from "./chunk-EW3RT4QW.mjs";
|
|
57
64
|
import {
|
|
58
65
|
xorWith
|
|
59
66
|
} from "./chunk-FCF2RHPW.mjs";
|
|
@@ -63,6 +70,9 @@ import {
|
|
|
63
70
|
import {
|
|
64
71
|
zipWith
|
|
65
72
|
} from "./chunk-T5FDOBCA.mjs";
|
|
73
|
+
import {
|
|
74
|
+
shuffle
|
|
75
|
+
} from "./chunk-DPLJQQFX.mjs";
|
|
66
76
|
import {
|
|
67
77
|
take
|
|
68
78
|
} from "./chunk-ME352XO7.mjs";
|
|
@@ -78,18 +88,18 @@ import {
|
|
|
78
88
|
import {
|
|
79
89
|
union
|
|
80
90
|
} from "./chunk-DAJZ3JCI.mjs";
|
|
91
|
+
import {
|
|
92
|
+
uniq
|
|
93
|
+
} from "./chunk-XFCW7XJ4.mjs";
|
|
81
94
|
import {
|
|
82
95
|
unionBy
|
|
83
|
-
} from "./chunk-
|
|
96
|
+
} from "./chunk-JBDGK6X4.mjs";
|
|
84
97
|
import {
|
|
85
98
|
unionWith
|
|
86
99
|
} from "./chunk-3KHI4I2X.mjs";
|
|
87
100
|
import {
|
|
88
101
|
uniqWith
|
|
89
102
|
} from "./chunk-2PFDLYQC.mjs";
|
|
90
|
-
import {
|
|
91
|
-
uniq
|
|
92
|
-
} from "./chunk-XFCW7XJ4.mjs";
|
|
93
103
|
import {
|
|
94
104
|
groupBy
|
|
95
105
|
} from "./chunk-LWXZFXY5.mjs";
|
|
@@ -108,9 +118,6 @@ import {
|
|
|
108
118
|
import {
|
|
109
119
|
sample
|
|
110
120
|
} from "./chunk-DOOIIHT3.mjs";
|
|
111
|
-
import {
|
|
112
|
-
shuffle
|
|
113
|
-
} from "./chunk-DPLJQQFX.mjs";
|
|
114
121
|
import {
|
|
115
122
|
chunk
|
|
116
123
|
} from "./chunk-E6C5EZQA.mjs";
|
|
@@ -135,26 +142,8 @@ import {
|
|
|
135
142
|
import {
|
|
136
143
|
dropWhile
|
|
137
144
|
} from "./chunk-JFHM6EY2.mjs";
|
|
138
|
-
import "./chunk-FZEZH22H.mjs";
|
|
139
|
-
import {
|
|
140
|
-
AbortError
|
|
141
|
-
} from "./chunk-VP2LXY75.mjs";
|
|
142
|
-
import "./chunk-N6EM6ETS.mjs";
|
|
143
|
-
import {
|
|
144
|
-
debounce
|
|
145
|
-
} from "./chunk-MKETZ2RP.mjs";
|
|
146
|
-
import {
|
|
147
|
-
noop
|
|
148
|
-
} from "./chunk-LKXCOLNY.mjs";
|
|
149
|
-
import {
|
|
150
|
-
once
|
|
151
|
-
} from "./chunk-UFAA5WKR.mjs";
|
|
152
|
-
import {
|
|
153
|
-
throttle
|
|
154
|
-
} from "./chunk-XLO3QZVY.mjs";
|
|
155
145
|
import "./chunk-2MM5EJJX.mjs";
|
|
156
146
|
export {
|
|
157
|
-
AbortError,
|
|
158
147
|
chunk,
|
|
159
148
|
clamp,
|
|
160
149
|
debounce,
|
|
@@ -181,8 +170,6 @@ export {
|
|
|
181
170
|
partition,
|
|
182
171
|
pick,
|
|
183
172
|
pickBy,
|
|
184
|
-
random,
|
|
185
|
-
randomInt,
|
|
186
173
|
round,
|
|
187
174
|
sample,
|
|
188
175
|
shuffle,
|
package/dist/math/index.d.mts
CHANGED
package/dist/math/index.d.ts
CHANGED
package/dist/math/index.js
CHANGED
|
@@ -21,8 +21,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var math_exports = {};
|
|
22
22
|
__export(math_exports, {
|
|
23
23
|
clamp: () => clamp,
|
|
24
|
-
random: () => random,
|
|
25
|
-
randomInt: () => randomInt,
|
|
26
24
|
round: () => round,
|
|
27
25
|
sum: () => sum
|
|
28
26
|
});
|
|
@@ -36,19 +34,6 @@ function clamp(value, bound1, bound2) {
|
|
|
36
34
|
return Math.min(Math.max(value, bound1), bound2);
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
// src/math/random.ts
|
|
40
|
-
function random(minimum, maximum) {
|
|
41
|
-
if (minimum >= maximum) {
|
|
42
|
-
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
43
|
-
}
|
|
44
|
-
return Math.random() * (maximum - minimum) + minimum;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// src/math/randomInt.ts
|
|
48
|
-
function randomInt(minimum, maximum) {
|
|
49
|
-
return Math.floor(random(minimum, maximum));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
37
|
// src/math/round.ts
|
|
53
38
|
function round(value, precision = 0) {
|
|
54
39
|
const multiplier = Math.pow(10, precision);
|
|
@@ -66,8 +51,6 @@ function sum(nums) {
|
|
|
66
51
|
// Annotate the CommonJS export names for ESM import in node:
|
|
67
52
|
0 && (module.exports = {
|
|
68
53
|
clamp,
|
|
69
|
-
random,
|
|
70
|
-
randomInt,
|
|
71
54
|
round,
|
|
72
55
|
sum
|
|
73
56
|
});
|
package/dist/math/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/
|
|
1
|
+
{"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/round.ts","../../src/math/sum.ts"],"sourcesContent":["export { clamp } from './clamp';\nexport { round } from './round';\nexport { sum } from './sum';\n","/**\n * Clamps a number within the inclusive lower and upper bounds.\n *\n * This function takes a number and two bounds, and returns the number clamped within the specified bounds.\n * If only one bound is provided, it returns the minimum of the value and the bound.\n *\n * @param {number} value - The number to clamp.\n * @param {number} minimum - The minimum bound to clamp the number.\n * @param {number} maximum - The maximum bound to clamp the number.\n * @returns {number} The clamped number within the specified bounds.\n *\n * @example\n * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5\n * const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15\n * const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5\n * const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15\n */\nexport function clamp(value: number, maximum: number): number;\nexport function clamp(value: number, minimum: number, maximum: number): number;\nexport function clamp(value: number, bound1: number, bound2?: number): number {\n if (bound2 == null) {\n return Math.min(value, bound1);\n }\n\n return Math.min(Math.max(value, bound1), bound2);\n}\n","/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n */\nexport function round(value: number, precision: number = 0): number {\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"],"mappings":";;;;;;;;;;;;;;;;;;;;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;;;ACVO,SAAS,MAAM,OAAe,YAAoB,GAAW;AAClE,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;;;ACLO,SAAS,IAAI,MAAwB;AAC1C,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,cAAU;AAAA,EACZ;AAEA,SAAO;AACT;","names":[]}
|
package/dist/math/index.mjs
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-IJLQVGW4.mjs";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import {
|
|
6
|
-
random
|
|
7
|
-
} from "../chunk-UGFVAAVO.mjs";
|
|
3
|
+
clamp
|
|
4
|
+
} from "../chunk-MLCL773E.mjs";
|
|
8
5
|
import {
|
|
9
6
|
round
|
|
10
7
|
} from "../chunk-V7E5DGZP.mjs";
|
|
11
8
|
import {
|
|
12
9
|
sum
|
|
13
10
|
} from "../chunk-7OU22ENP.mjs";
|
|
14
|
-
import {
|
|
15
|
-
clamp
|
|
16
|
-
} from "../chunk-MLCL773E.mjs";
|
|
17
11
|
import "../chunk-2MM5EJJX.mjs";
|
|
18
12
|
export {
|
|
19
13
|
clamp,
|
|
20
|
-
random,
|
|
21
|
-
randomInt,
|
|
22
14
|
round,
|
|
23
15
|
sum
|
|
24
16
|
};
|
package/dist/object/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import "../chunk-T5JCRGXA.mjs";
|
|
2
|
-
import {
|
|
3
|
-
pick
|
|
4
|
-
} from "../chunk-OFWKFUFZ.mjs";
|
|
5
|
-
import {
|
|
6
|
-
pickBy
|
|
7
|
-
} from "../chunk-T2C2WVFL.mjs";
|
|
8
2
|
import {
|
|
9
3
|
omit
|
|
10
4
|
} from "../chunk-PLTO44KM.mjs";
|
|
11
5
|
import {
|
|
12
6
|
omitBy
|
|
13
7
|
} from "../chunk-SF3V7XXM.mjs";
|
|
8
|
+
import {
|
|
9
|
+
pick
|
|
10
|
+
} from "../chunk-OFWKFUFZ.mjs";
|
|
11
|
+
import {
|
|
12
|
+
pickBy
|
|
13
|
+
} from "../chunk-T2C2WVFL.mjs";
|
|
14
14
|
import "../chunk-2MM5EJJX.mjs";
|
|
15
15
|
export {
|
|
16
16
|
omit,
|
package/dist/predicate/index.mjs
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import "../chunk-MAJSPFA6.mjs";
|
|
2
|
-
import {
|
|
3
|
-
isNil
|
|
4
|
-
} from "../chunk-OHQAR5AU.mjs";
|
|
5
2
|
import {
|
|
6
3
|
isNotNil
|
|
7
4
|
} from "../chunk-ZQNAZPSK.mjs";
|
|
@@ -11,6 +8,9 @@ import {
|
|
|
11
8
|
import {
|
|
12
9
|
isUndefined
|
|
13
10
|
} from "../chunk-VH2PV426.mjs";
|
|
11
|
+
import {
|
|
12
|
+
isNil
|
|
13
|
+
} from "../chunk-OHQAR5AU.mjs";
|
|
14
14
|
import "../chunk-2MM5EJJX.mjs";
|
|
15
15
|
export {
|
|
16
16
|
isNil,
|
package/dist/promise/delay.d.mts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
interface DelayOptions {
|
|
2
|
-
signal?: AbortSignal;
|
|
3
|
-
}
|
|
4
1
|
/**
|
|
5
2
|
* Delays the execution of code for a specified number of milliseconds.
|
|
6
3
|
*
|
|
@@ -8,8 +5,6 @@ interface DelayOptions {
|
|
|
8
5
|
* with async/await to pause execution.
|
|
9
6
|
*
|
|
10
7
|
* @param {number} ms - The number of milliseconds to delay.
|
|
11
|
-
* @param {DelayOptions} options - The options object.
|
|
12
|
-
* @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.
|
|
13
8
|
* @returns {Promise<void>} A Promise that resolves after the specified delay.
|
|
14
9
|
*
|
|
15
10
|
* @example
|
|
@@ -20,19 +15,7 @@ interface DelayOptions {
|
|
|
20
15
|
* }
|
|
21
16
|
*
|
|
22
17
|
* foo();
|
|
23
|
-
*
|
|
24
|
-
* // With AbortSignal
|
|
25
|
-
* const controller = new AbortController();
|
|
26
|
-
* const { signal } = controller;
|
|
27
|
-
*
|
|
28
|
-
* setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms
|
|
29
|
-
* try {
|
|
30
|
-
* await delay(100, { signal });
|
|
31
|
-
* } catch (error) {
|
|
32
|
-
* console.error(error); // Will log 'AbortError'
|
|
33
|
-
* }
|
|
34
|
-
* }
|
|
35
18
|
*/
|
|
36
|
-
declare function delay(ms: number
|
|
19
|
+
declare function delay(ms: number): Promise<void>;
|
|
37
20
|
|
|
38
21
|
export { delay };
|
package/dist/promise/delay.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
interface DelayOptions {
|
|
2
|
-
signal?: AbortSignal;
|
|
3
|
-
}
|
|
4
1
|
/**
|
|
5
2
|
* Delays the execution of code for a specified number of milliseconds.
|
|
6
3
|
*
|
|
@@ -8,8 +5,6 @@ interface DelayOptions {
|
|
|
8
5
|
* with async/await to pause execution.
|
|
9
6
|
*
|
|
10
7
|
* @param {number} ms - The number of milliseconds to delay.
|
|
11
|
-
* @param {DelayOptions} options - The options object.
|
|
12
|
-
* @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.
|
|
13
8
|
* @returns {Promise<void>} A Promise that resolves after the specified delay.
|
|
14
9
|
*
|
|
15
10
|
* @example
|
|
@@ -20,19 +15,7 @@ interface DelayOptions {
|
|
|
20
15
|
* }
|
|
21
16
|
*
|
|
22
17
|
* foo();
|
|
23
|
-
*
|
|
24
|
-
* // With AbortSignal
|
|
25
|
-
* const controller = new AbortController();
|
|
26
|
-
* const { signal } = controller;
|
|
27
|
-
*
|
|
28
|
-
* setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms
|
|
29
|
-
* try {
|
|
30
|
-
* await delay(100, { signal });
|
|
31
|
-
* } catch (error) {
|
|
32
|
-
* console.error(error); // Will log 'AbortError'
|
|
33
|
-
* }
|
|
34
|
-
* }
|
|
35
18
|
*/
|
|
36
|
-
declare function delay(ms: number
|
|
19
|
+
declare function delay(ms: number): Promise<void>;
|
|
37
20
|
|
|
38
21
|
export { delay };
|
package/dist/promise/delay.js
CHANGED
|
@@ -23,30 +23,9 @@ __export(delay_exports, {
|
|
|
23
23
|
delay: () => delay
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(delay_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
constructor(message = "The operation was aborted") {
|
|
30
|
-
super(message);
|
|
31
|
-
this.name = "AbortError";
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// src/promise/delay.ts
|
|
36
|
-
function delay(ms, { signal } = {}) {
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
const abortError = () => {
|
|
39
|
-
reject(new AbortError());
|
|
40
|
-
};
|
|
41
|
-
const abortHandler = () => {
|
|
42
|
-
clearTimeout(timeoutId);
|
|
43
|
-
abortError();
|
|
44
|
-
};
|
|
45
|
-
if (signal == null ? void 0 : signal.aborted) {
|
|
46
|
-
return abortError();
|
|
47
|
-
}
|
|
48
|
-
const timeoutId = setTimeout(resolve, ms);
|
|
49
|
-
signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
|
|
26
|
+
function delay(ms) {
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
setTimeout(resolve, ms);
|
|
50
29
|
});
|
|
51
30
|
}
|
|
52
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/promise/delay.ts"
|
|
1
|
+
{"version":3,"sources":["../../src/promise/delay.ts"],"sourcesContent":["/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n */\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,MAAM,IAA2B;AAC/C,SAAO,IAAI,QAAQ,aAAW;AAC5B,eAAW,SAAS,EAAE;AAAA,EACxB,CAAC;AACH;","names":[]}
|
package/dist/promise/delay.mjs
CHANGED
package/dist/promise/index.js
CHANGED
|
@@ -24,29 +24,10 @@ __export(promise_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(promise_exports);
|
|
26
26
|
|
|
27
|
-
// src/error/AbortError.ts
|
|
28
|
-
var AbortError = class extends Error {
|
|
29
|
-
constructor(message = "The operation was aborted") {
|
|
30
|
-
super(message);
|
|
31
|
-
this.name = "AbortError";
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
27
|
// src/promise/delay.ts
|
|
36
|
-
function delay(ms
|
|
37
|
-
return new Promise((resolve
|
|
38
|
-
|
|
39
|
-
reject(new AbortError());
|
|
40
|
-
};
|
|
41
|
-
const abortHandler = () => {
|
|
42
|
-
clearTimeout(timeoutId);
|
|
43
|
-
abortError();
|
|
44
|
-
};
|
|
45
|
-
if (signal == null ? void 0 : signal.aborted) {
|
|
46
|
-
return abortError();
|
|
47
|
-
}
|
|
48
|
-
const timeoutId = setTimeout(resolve, ms);
|
|
49
|
-
signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
|
|
28
|
+
function delay(ms) {
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
setTimeout(resolve, ms);
|
|
50
31
|
});
|
|
51
32
|
}
|
|
52
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/promise/index.ts","../../src/
|
|
1
|
+
{"version":3,"sources":["../../src/promise/index.ts","../../src/promise/delay.ts"],"sourcesContent":["export { delay } from './delay';\n","/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n */\nexport function delay(ms: number): Promise<void> {\n return new Promise(resolve => {\n setTimeout(resolve, ms);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkBO,SAAS,MAAM,IAA2B;AAC/C,SAAO,IAAI,QAAQ,aAAW;AAC5B,eAAW,SAAS,EAAE;AAAA,EACxB,CAAC;AACH;","names":[]}
|
package/dist/promise/index.mjs
CHANGED
package/package.json
CHANGED
package/dist/chunk-AL3GJBEI.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AbortError
|
|
3
|
-
} from "./chunk-VP2LXY75.mjs";
|
|
4
|
-
|
|
5
|
-
// src/promise/delay.ts
|
|
6
|
-
function delay(ms, { signal } = {}) {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
const abortError = () => {
|
|
9
|
-
reject(new AbortError());
|
|
10
|
-
};
|
|
11
|
-
const abortHandler = () => {
|
|
12
|
-
clearTimeout(timeoutId);
|
|
13
|
-
abortError();
|
|
14
|
-
};
|
|
15
|
-
if (signal == null ? void 0 : signal.aborted) {
|
|
16
|
-
return abortError();
|
|
17
|
-
}
|
|
18
|
-
const timeoutId = setTimeout(resolve, ms);
|
|
19
|
-
signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
delay
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=chunk-AL3GJBEI.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/promise/delay.ts"],"sourcesContent":["import { AbortError } from '../error/AbortError';\n\ninterface DelayOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Delays the execution of code for a specified number of milliseconds.\n *\n * This function returns a Promise that resolves after the specified delay, allowing you to use it\n * with async/await to pause execution.\n *\n * @param {number} ms - The number of milliseconds to delay.\n * @param {DelayOptions} options - The options object.\n * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the delay.\n * @returns {Promise<void>} A Promise that resolves after the specified delay.\n *\n * @example\n * async function foo() {\n * console.log('Start');\n * await delay(1000); // Delays execution for 1 second\n * console.log('End');\n * }\n *\n * foo();\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * const { signal } = controller;\n *\n * setTimeout(() => controller.abort(), 50); // Will cancel the delay after 50ms\n * try {\n * await delay(100, { signal });\n * } catch (error) {\n * console.error(error); // Will log 'AbortError'\n * }\n * }\n */\nexport function delay(ms: number, { signal }: DelayOptions = {}): Promise<void> {\n return new Promise((resolve, reject) => {\n const abortError = () => {\n reject(new AbortError());\n };\n\n const abortHandler = () => {\n clearTimeout(timeoutId);\n abortError();\n };\n\n if (signal?.aborted) {\n return abortError();\n }\n\n const timeoutId = setTimeout(resolve, ms);\n\n signal?.addEventListener('abort', abortHandler, { once: true });\n });\n}\n"],"mappings":";;;;;AAsCO,SAAS,MAAM,IAAY,EAAE,OAAO,IAAkB,CAAC,GAAkB;AAC9E,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,aAAa,MAAM;AACvB,aAAO,IAAI,WAAW,CAAC;AAAA,IACzB;AAEA,UAAM,eAAe,MAAM;AACzB,mBAAa,SAAS;AACtB,iBAAW;AAAA,IACb;AAEA,QAAI,iCAAQ,SAAS;AACnB,aAAO,WAAW;AAAA,IACpB;AAEA,UAAM,YAAY,WAAW,SAAS,EAAE;AAExC,qCAAQ,iBAAiB,SAAS,cAAc,EAAE,MAAM,KAAK;AAAA,EAC/D,CAAC;AACH;","names":[]}
|
package/dist/chunk-FZEZH22H.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-FZEZH22H.mjs.map
|
package/dist/chunk-QWJDITYJ.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/math/randomInt.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"],"mappings":";;;;;AAcO,SAAS,UAAU,SAAiB,SAAyB;AAClE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAO,CAAC;AAC5C;","names":[]}
|
package/dist/chunk-UGFVAAVO.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// src/math/random.ts
|
|
2
|
-
function random(minimum, maximum) {
|
|
3
|
-
if (minimum >= maximum) {
|
|
4
|
-
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
5
|
-
}
|
|
6
|
-
return Math.random() * (maximum - minimum) + minimum;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
random
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=chunk-UGFVAAVO.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/math/random.ts"],"sourcesContent":["/**\n * Generates a random floating-point number between minimum (inclusive) and maximum (exclusive).\n * If min is greater than maximum, the values are swapped.\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 = random(0, 5); // result will be a random floating-point number between 0 (inclusive) and 5 (exclusive)\n * const result2 = random(5, 0); // This will throw an error\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":";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/chunk-VAV4XHLO.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-VAV4XHLO.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/chunk-VP2LXY75.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// src/error/AbortError.ts
|
|
2
|
-
var AbortError = class extends Error {
|
|
3
|
-
constructor(message = "The operation was aborted") {
|
|
4
|
-
super(message);
|
|
5
|
-
this.name = "AbortError";
|
|
6
|
-
}
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
AbortError
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=chunk-VP2LXY75.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error/AbortError.ts"],"sourcesContent":["export class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n"],"mappings":";AAAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
|
package/dist/chunk-WPDDOUQT.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// src/array/uniqBy.ts
|
|
2
|
-
function uniqBy(arr, mapper) {
|
|
3
|
-
const map = /* @__PURE__ */ new Map();
|
|
4
|
-
for (const item of arr) {
|
|
5
|
-
const key = mapper(item);
|
|
6
|
-
if (!map.has(key)) {
|
|
7
|
-
map.set(key, item);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
return Array.from(map.values());
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
uniqBy
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=chunk-WPDDOUQT.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/array/uniqBy.ts"],"sourcesContent":["/**\n * Returns a new array containing only the unique elements from the original array,\n * based on the values returned by the mapper function.\n *\n * @param {T[]} arr - The array to process.\n * @param {(item: T) => U} mapper - The function used to convert the array elements.\n * @returns {T[]} A new array containing only the unique elements from the original array, based on the values returned by the mapper function.\n *\n * @example\n * ```ts\n * uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);\n * // [1.2, 2.1, 3.3, 5.7, 7.19]\n * ```\n */\nexport function uniqBy<T, U>(arr: readonly T[], mapper: (item: T) => U): T[] {\n const map = new Map<U, T>();\n\n for (const item of arr) {\n const key = mapper(item);\n\n if (!map.has(key)) {\n map.set(key, item);\n }\n }\n\n return Array.from(map.values());\n}\n"],"mappings":";AAcO,SAAS,OAAa,KAAmB,QAA6B;AAC3E,QAAM,MAAM,oBAAI,IAAU;AAE1B,aAAW,QAAQ,KAAK;AACtB,UAAM,MAAM,OAAO,IAAI;AAEvB,QAAI,CAAC,IAAI,IAAI,GAAG,GAAG;AACjB,UAAI,IAAI,KAAK,IAAI;AAAA,IACnB;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,IAAI,OAAO,CAAC;AAChC;","names":[]}
|