es-toolkit 1.3.1-dev.80 → 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.
Files changed (80) hide show
  1. package/dist/array/index.js +2 -9
  2. package/dist/array/index.js.map +1 -1
  3. package/dist/array/index.mjs +27 -27
  4. package/dist/array/unionBy.js +1 -1
  5. package/dist/array/unionBy.js.map +1 -1
  6. package/dist/array/unionBy.mjs +1 -1
  7. package/dist/array/uniqBy.js +13 -6
  8. package/dist/array/uniqBy.js.map +1 -1
  9. package/dist/array/uniqBy.mjs +2 -1
  10. package/dist/array/xorBy.js +1 -1
  11. package/dist/array/xorBy.js.map +1 -1
  12. package/dist/array/xorBy.mjs +2 -2
  13. package/dist/chunk-ASFOKYTY.mjs +13 -0
  14. package/dist/chunk-ASFOKYTY.mjs.map +1 -0
  15. package/dist/{chunk-AM2EGFCU.mjs → chunk-EW3RT4QW.mjs} +2 -2
  16. package/dist/{chunk-MKETZ2RP.mjs → chunk-GOXQV6DX.mjs} +3 -2
  17. package/dist/{chunk-MKETZ2RP.mjs.map → chunk-GOXQV6DX.mjs.map} +1 -1
  18. package/dist/chunk-IJLQVGW4.mjs +1 -0
  19. package/dist/{chunk-NRNKP6JF.mjs → chunk-JBDGK6X4.mjs} +2 -2
  20. package/dist/{chunk-NRNKP6JF.mjs.map → chunk-JBDGK6X4.mjs.map} +1 -1
  21. package/dist/chunk-ZBG3EYM3.mjs +11 -0
  22. package/dist/chunk-ZBG3EYM3.mjs.map +1 -0
  23. package/dist/function/debounce.js +2 -1
  24. package/dist/function/debounce.js.map +1 -1
  25. package/dist/function/debounce.mjs +1 -1
  26. package/dist/function/index.js +2 -1
  27. package/dist/function/index.js.map +1 -1
  28. package/dist/function/index.mjs +4 -4
  29. package/dist/index.d.mts +0 -2
  30. package/dist/index.d.ts +0 -2
  31. package/dist/index.js +7 -44
  32. package/dist/index.js.map +1 -1
  33. package/dist/index.mjs +52 -61
  34. package/dist/math/index.d.mts +0 -1
  35. package/dist/math/index.d.ts +0 -1
  36. package/dist/math/index.js +0 -10
  37. package/dist/math/index.js.map +1 -1
  38. package/dist/math/index.mjs +3 -7
  39. package/dist/object/index.mjs +3 -3
  40. package/dist/predicate/index.mjs +3 -3
  41. package/dist/promise/delay.d.mts +1 -18
  42. package/dist/promise/delay.d.ts +1 -18
  43. package/dist/promise/delay.js +3 -24
  44. package/dist/promise/delay.js.map +1 -1
  45. package/dist/promise/delay.mjs +1 -2
  46. package/dist/promise/index.js +3 -22
  47. package/dist/promise/index.js.map +1 -1
  48. package/dist/promise/index.mjs +1 -2
  49. package/package.json +1 -1
  50. package/dist/chunk-AL3GJBEI.mjs +0 -26
  51. package/dist/chunk-AL3GJBEI.mjs.map +0 -1
  52. package/dist/chunk-FZEZH22H.mjs +0 -1
  53. package/dist/chunk-LJHSPVPM.mjs +0 -12
  54. package/dist/chunk-LJHSPVPM.mjs.map +0 -1
  55. package/dist/chunk-NNIW65CD.mjs +0 -1
  56. package/dist/chunk-NNIW65CD.mjs.map +0 -1
  57. package/dist/chunk-VP2LXY75.mjs +0 -12
  58. package/dist/chunk-VP2LXY75.mjs.map +0 -1
  59. package/dist/chunk-WPDDOUQT.mjs +0 -16
  60. package/dist/chunk-WPDDOUQT.mjs.map +0 -1
  61. package/dist/error/AbortError.d.mts +0 -5
  62. package/dist/error/AbortError.d.ts +0 -5
  63. package/dist/error/AbortError.js +0 -36
  64. package/dist/error/AbortError.js.map +0 -1
  65. package/dist/error/AbortError.mjs +0 -8
  66. package/dist/error/AbortError.mjs.map +0 -1
  67. package/dist/error/index.d.mts +0 -1
  68. package/dist/error/index.d.ts +0 -1
  69. package/dist/error/index.js +0 -38
  70. package/dist/error/index.js.map +0 -1
  71. package/dist/error/index.mjs +0 -9
  72. package/dist/error/index.mjs.map +0 -1
  73. package/dist/math/random.d.mts +0 -15
  74. package/dist/math/random.d.ts +0 -15
  75. package/dist/math/random.js +0 -36
  76. package/dist/math/random.js.map +0 -1
  77. package/dist/math/random.mjs +0 -8
  78. package/dist/math/random.mjs.map +0 -1
  79. /package/dist/{chunk-AM2EGFCU.mjs.map → chunk-EW3RT4QW.mjs.map} +0 -0
  80. /package/dist/{chunk-FZEZH22H.mjs.map → chunk-IJLQVGW4.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,7 +1,21 @@
1
- import "./chunk-MAJSPFA6.mjs";
1
+ import "./chunk-ARZ5BDR6.mjs";
2
2
  import {
3
- isNil
4
- } from "./chunk-OHQAR5AU.mjs";
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";
5
19
  import {
6
20
  isNotNil
7
21
  } from "./chunk-ZQNAZPSK.mjs";
@@ -11,83 +25,51 @@ import {
11
25
  import {
12
26
  isUndefined
13
27
  } from "./chunk-VH2PV426.mjs";
14
- import "./chunk-ARZ5BDR6.mjs";
15
28
  import {
16
- delay
17
- } from "./chunk-AL3GJBEI.mjs";
18
- import "./chunk-NNIW65CD.mjs";
29
+ isNil
30
+ } from "./chunk-OHQAR5AU.mjs";
31
+ import "./chunk-IJLQVGW4.mjs";
19
32
  import {
20
- random
21
- } from "./chunk-LJHSPVPM.mjs";
33
+ clamp
34
+ } from "./chunk-MLCL773E.mjs";
22
35
  import {
23
36
  round
24
37
  } from "./chunk-V7E5DGZP.mjs";
25
38
  import {
26
39
  sum
27
40
  } from "./chunk-7OU22ENP.mjs";
28
- import "./chunk-T5JCRGXA.mjs";
29
- import {
30
- pickBy
31
- } from "./chunk-T2C2WVFL.mjs";
32
- import {
33
- omit
34
- } from "./chunk-PLTO44KM.mjs";
35
- import {
36
- omitBy
37
- } from "./chunk-SF3V7XXM.mjs";
38
- import {
39
- pick
40
- } from "./chunk-OFWKFUFZ.mjs";
41
41
  import "./chunk-N6EM6ETS.mjs";
42
+ import {
43
+ throttle
44
+ } from "./chunk-XLO3QZVY.mjs";
42
45
  import {
43
46
  debounce
44
- } from "./chunk-MKETZ2RP.mjs";
47
+ } from "./chunk-GOXQV6DX.mjs";
45
48
  import {
46
49
  noop
47
50
  } from "./chunk-LKXCOLNY.mjs";
48
51
  import {
49
52
  once
50
53
  } from "./chunk-UFAA5WKR.mjs";
51
- import {
52
- throttle
53
- } from "./chunk-XLO3QZVY.mjs";
54
- import {
55
- clamp
56
- } from "./chunk-MLCL773E.mjs";
57
54
  import "./chunk-EJGAXTF7.mjs";
58
- import {
59
- zip
60
- } from "./chunk-DD73BULA.mjs";
61
- import {
62
- zipWith
63
- } from "./chunk-T5FDOBCA.mjs";
64
55
  import {
65
56
  uniqBy
66
- } from "./chunk-WPDDOUQT.mjs";
57
+ } from "./chunk-ASFOKYTY.mjs";
67
58
  import {
68
59
  xor
69
60
  } from "./chunk-WXIBCOES.mjs";
70
61
  import {
71
62
  xorBy
72
- } from "./chunk-AM2EGFCU.mjs";
73
- import {
74
- unionBy
75
- } from "./chunk-NRNKP6JF.mjs";
63
+ } from "./chunk-EW3RT4QW.mjs";
76
64
  import {
77
65
  xorWith
78
66
  } from "./chunk-FCF2RHPW.mjs";
79
67
  import {
80
- unionWith
81
- } from "./chunk-3KHI4I2X.mjs";
82
- import {
83
- uniqWith
84
- } from "./chunk-2PFDLYQC.mjs";
85
- import {
86
- partition
87
- } from "./chunk-5L2V7WD3.mjs";
68
+ zip
69
+ } from "./chunk-DD73BULA.mjs";
88
70
  import {
89
- sample
90
- } from "./chunk-DOOIIHT3.mjs";
71
+ zipWith
72
+ } from "./chunk-T5FDOBCA.mjs";
91
73
  import {
92
74
  shuffle
93
75
  } from "./chunk-DPLJQQFX.mjs";
@@ -110,14 +92,14 @@ import {
110
92
  uniq
111
93
  } from "./chunk-XFCW7XJ4.mjs";
112
94
  import {
113
- dropRight
114
- } from "./chunk-Q75KEFW5.mjs";
95
+ unionBy
96
+ } from "./chunk-JBDGK6X4.mjs";
115
97
  import {
116
- dropRightWhile
117
- } from "./chunk-CIRFWC7Y.mjs";
98
+ unionWith
99
+ } from "./chunk-3KHI4I2X.mjs";
118
100
  import {
119
- dropWhile
120
- } from "./chunk-JFHM6EY2.mjs";
101
+ uniqWith
102
+ } from "./chunk-2PFDLYQC.mjs";
121
103
  import {
122
104
  groupBy
123
105
  } from "./chunk-LWXZFXY5.mjs";
@@ -130,10 +112,12 @@ import {
130
112
  import {
131
113
  intersectionWith
132
114
  } from "./chunk-KLJRZJOR.mjs";
133
- import "./chunk-FZEZH22H.mjs";
134
115
  import {
135
- AbortError
136
- } from "./chunk-VP2LXY75.mjs";
116
+ partition
117
+ } from "./chunk-5L2V7WD3.mjs";
118
+ import {
119
+ sample
120
+ } from "./chunk-DOOIIHT3.mjs";
137
121
  import {
138
122
  chunk
139
123
  } from "./chunk-E6C5EZQA.mjs";
@@ -149,9 +133,17 @@ import {
149
133
  import {
150
134
  drop
151
135
  } from "./chunk-ACFP3XMB.mjs";
136
+ import {
137
+ dropRight
138
+ } from "./chunk-Q75KEFW5.mjs";
139
+ import {
140
+ dropRightWhile
141
+ } from "./chunk-CIRFWC7Y.mjs";
142
+ import {
143
+ dropWhile
144
+ } from "./chunk-JFHM6EY2.mjs";
152
145
  import "./chunk-2MM5EJJX.mjs";
153
146
  export {
154
- AbortError,
155
147
  chunk,
156
148
  clamp,
157
149
  debounce,
@@ -178,7 +170,6 @@ export {
178
170
  partition,
179
171
  pick,
180
172
  pickBy,
181
- random,
182
173
  round,
183
174
  sample,
184
175
  shuffle,
@@ -1,4 +1,3 @@
1
1
  export { clamp } from './clamp.mjs';
2
- export { random } from './random.mjs';
3
2
  export { round } from './round.mjs';
4
3
  export { sum } from './sum.mjs';
@@ -1,4 +1,3 @@
1
1
  export { clamp } from './clamp.js';
2
- export { random } from './random.js';
3
2
  export { round } from './round.js';
4
3
  export { sum } from './sum.js';
@@ -21,7 +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
24
  round: () => round,
26
25
  sum: () => sum
27
26
  });
@@ -35,14 +34,6 @@ function clamp(value, bound1, bound2) {
35
34
  return Math.min(Math.max(value, bound1), bound2);
36
35
  }
37
36
 
38
- // src/math/random.ts
39
- function random(minimum, maximum) {
40
- if (minimum >= maximum) {
41
- throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
42
- }
43
- return Math.random() * (maximum - minimum) + minimum;
44
- }
45
-
46
37
  // src/math/round.ts
47
38
  function round(value, precision = 0) {
48
39
  const multiplier = Math.pow(10, precision);
@@ -60,7 +51,6 @@ function sum(nums) {
60
51
  // Annotate the CommonJS export names for ESM import in node:
61
52
  0 && (module.exports = {
62
53
  clamp,
63
- random,
64
54
  round,
65
55
  sum
66
56
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/random.ts","../../src/math/round.ts","../../src/math/sum.ts"],"sourcesContent":["export { clamp } from './clamp';\nexport { random } from './random';\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 * 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 *\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","/**\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;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;;;ACbO,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;;;ACHO,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":[]}
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":[]}
@@ -1,20 +1,16 @@
1
- import "../chunk-NNIW65CD.mjs";
1
+ import "../chunk-IJLQVGW4.mjs";
2
2
  import {
3
- random
4
- } from "../chunk-LJHSPVPM.mjs";
3
+ clamp
4
+ } from "../chunk-MLCL773E.mjs";
5
5
  import {
6
6
  round
7
7
  } from "../chunk-V7E5DGZP.mjs";
8
8
  import {
9
9
  sum
10
10
  } from "../chunk-7OU22ENP.mjs";
11
- import {
12
- clamp
13
- } from "../chunk-MLCL773E.mjs";
14
11
  import "../chunk-2MM5EJJX.mjs";
15
12
  export {
16
13
  clamp,
17
- random,
18
14
  round,
19
15
  sum
20
16
  };
@@ -1,7 +1,4 @@
1
1
  import "../chunk-T5JCRGXA.mjs";
2
- import {
3
- pickBy
4
- } from "../chunk-T2C2WVFL.mjs";
5
2
  import {
6
3
  omit
7
4
  } from "../chunk-PLTO44KM.mjs";
@@ -11,6 +8,9 @@ import {
11
8
  import {
12
9
  pick
13
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,
@@ -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,
@@ -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, { signal }?: DelayOptions): Promise<void>;
19
+ declare function delay(ms: number): Promise<void>;
37
20
 
38
21
  export { delay };
@@ -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, { signal }?: DelayOptions): Promise<void>;
19
+ declare function delay(ms: number): Promise<void>;
37
20
 
38
21
  export { delay };
@@ -23,30 +23,9 @@ __export(delay_exports, {
23
23
  delay: () => delay
24
24
  });
25
25
  module.exports = __toCommonJS(delay_exports);
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
- // 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","../../src/error/AbortError.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","export class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ADiCO,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":[]}
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":[]}
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  delay
3
- } from "../chunk-AL3GJBEI.mjs";
4
- import "../chunk-VP2LXY75.mjs";
3
+ } from "../chunk-ZBG3EYM3.mjs";
5
4
  import "../chunk-2MM5EJJX.mjs";
6
5
  export {
7
6
  delay
@@ -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, { 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 });
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/error/AbortError.ts","../../src/promise/delay.ts"],"sourcesContent":["export { delay } from './delay';\n","export class AbortError extends Error {\n constructor(message = 'The operation was aborted') {\n super(message);\n this.name = 'AbortError';\n }\n}\n","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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpC,YAAY,UAAU,6BAA6B;AACjD,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ACiCO,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":[]}
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":[]}
@@ -1,8 +1,7 @@
1
1
  import "../chunk-ARZ5BDR6.mjs";
2
2
  import {
3
3
  delay
4
- } from "../chunk-AL3GJBEI.mjs";
5
- import "../chunk-VP2LXY75.mjs";
4
+ } from "../chunk-ZBG3EYM3.mjs";
6
5
  import "../chunk-2MM5EJJX.mjs";
7
6
  export {
8
7
  delay
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.3.1-dev.80+60e79741",
4
+ "version": "1.3.1",
5
5
  "workspaces": [
6
6
  "docs"
7
7
  ],
@@ -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":[]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-FZEZH22H.mjs.map
@@ -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-LJHSPVPM.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 *\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":";AAYO,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":[]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-NNIW65CD.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -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":[]}
@@ -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":[]}
@@ -1,5 +0,0 @@
1
- declare class AbortError extends Error {
2
- constructor(message?: string);
3
- }
4
-
5
- export { AbortError };
@@ -1,5 +0,0 @@
1
- declare class AbortError extends Error {
2
- constructor(message?: string);
3
- }
4
-
5
- export { AbortError };
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/error/AbortError.ts
21
- var AbortError_exports = {};
22
- __export(AbortError_exports, {
23
- AbortError: () => AbortError
24
- });
25
- module.exports = __toCommonJS(AbortError_exports);
26
- var AbortError = class extends Error {
27
- constructor(message = "The operation was aborted") {
28
- super(message);
29
- this.name = "AbortError";
30
- }
31
- };
32
- // Annotate the CommonJS export names for ESM import in node:
33
- 0 && (module.exports = {
34
- AbortError
35
- });
36
- //# sourceMappingURL=AbortError.js.map