es-toolkit 1.4.0 → 1.5.0-dev.102

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 (125) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/array/difference.d.mts +1 -1
  3. package/dist/array/difference.d.ts +1 -1
  4. package/dist/array/difference.js.map +1 -1
  5. package/dist/array/difference.mjs +1 -1
  6. package/dist/array/differenceWith.js.map +1 -1
  7. package/dist/array/differenceWith.mjs +1 -1
  8. package/dist/array/dropRightWhile.js.map +1 -1
  9. package/dist/array/dropRightWhile.mjs +2 -2
  10. package/dist/array/dropWhile.js.map +1 -1
  11. package/dist/array/dropWhile.mjs +1 -1
  12. package/dist/array/index.d.mts +2 -0
  13. package/dist/array/index.d.ts +2 -0
  14. package/dist/array/index.js +32 -0
  15. package/dist/array/index.js.map +1 -1
  16. package/dist/array/index.mjs +33 -25
  17. package/dist/array/intersectionWith.js.map +1 -1
  18. package/dist/array/intersectionWith.mjs +1 -1
  19. package/dist/array/maxBy.d.mts +21 -0
  20. package/dist/array/maxBy.d.ts +21 -0
  21. package/dist/array/maxBy.js +42 -0
  22. package/dist/array/maxBy.js.map +1 -0
  23. package/dist/array/maxBy.mjs +8 -0
  24. package/dist/array/minBy.d.mts +13 -0
  25. package/dist/array/minBy.d.ts +13 -0
  26. package/dist/array/minBy.js +42 -0
  27. package/dist/array/minBy.js.map +1 -0
  28. package/dist/array/minBy.mjs +8 -0
  29. package/dist/array/unionWith.js.map +1 -1
  30. package/dist/array/unionWith.mjs +1 -1
  31. package/dist/array/xor.js.map +1 -1
  32. package/dist/array/xor.mjs +2 -2
  33. package/dist/array/xorWith.js.map +1 -1
  34. package/dist/array/xorWith.mjs +4 -4
  35. package/dist/array/zip.js.map +1 -1
  36. package/dist/array/zip.mjs +1 -1
  37. package/dist/array/zipWith.js.map +1 -1
  38. package/dist/array/zipWith.mjs +1 -1
  39. package/dist/{chunk-KLJRZJOR.mjs → chunk-2EFS3VA3.mjs} +1 -1
  40. package/dist/{chunk-KLJRZJOR.mjs.map → chunk-2EFS3VA3.mjs.map} +1 -1
  41. package/dist/{chunk-T5FDOBCA.mjs → chunk-4KYXHZ4R.mjs} +1 -1
  42. package/dist/{chunk-T5FDOBCA.mjs.map → chunk-4KYXHZ4R.mjs.map} +1 -1
  43. package/dist/{chunk-V7E5DGZP.mjs → chunk-5PMKOZ2F.mjs} +4 -1
  44. package/dist/chunk-5PMKOZ2F.mjs.map +1 -0
  45. package/dist/{chunk-QWJDITYJ.mjs → chunk-5UT77WON.mjs} +2 -2
  46. package/dist/{chunk-3KHI4I2X.mjs → chunk-642SWVKJ.mjs} +1 -1
  47. package/dist/{chunk-3KHI4I2X.mjs.map → chunk-642SWVKJ.mjs.map} +1 -1
  48. package/dist/{chunk-FQ4K36VD.mjs → chunk-6NVQAHXP.mjs} +1 -1
  49. package/dist/{chunk-FQ4K36VD.mjs.map → chunk-6NVQAHXP.mjs.map} +1 -1
  50. package/dist/chunk-7LAMAYGN.mjs +1 -0
  51. package/dist/chunk-7LAMAYGN.mjs.map +1 -0
  52. package/dist/{chunk-SF3V7XXM.mjs → chunk-A67NF2C7.mjs} +1 -1
  53. package/dist/chunk-A67NF2C7.mjs.map +1 -0
  54. package/dist/{chunk-WXIBCOES.mjs → chunk-G2TTBLLJ.mjs} +2 -2
  55. package/dist/chunk-H23GUJVF.mjs +18 -0
  56. package/dist/chunk-H23GUJVF.mjs.map +1 -0
  57. package/dist/{chunk-DD73BULA.mjs → chunk-IDCUZVJL.mjs} +1 -1
  58. package/dist/{chunk-DD73BULA.mjs.map → chunk-IDCUZVJL.mjs.map} +1 -1
  59. package/dist/{chunk-M7UI5ETO.mjs → chunk-JPUKH67K.mjs} +1 -1
  60. package/dist/{chunk-M7UI5ETO.mjs.map → chunk-JPUKH67K.mjs.map} +1 -1
  61. package/dist/{chunk-JFHM6EY2.mjs → chunk-K2BAFL2T.mjs} +1 -1
  62. package/dist/{chunk-JFHM6EY2.mjs.map → chunk-K2BAFL2T.mjs.map} +1 -1
  63. package/dist/chunk-KZ5JY7J3.mjs +18 -0
  64. package/dist/chunk-KZ5JY7J3.mjs.map +1 -0
  65. package/dist/{chunk-UGFVAAVO.mjs → chunk-LCP6FOCX.mjs} +1 -1
  66. package/dist/chunk-LCP6FOCX.mjs.map +1 -0
  67. package/dist/{chunk-T2C2WVFL.mjs → chunk-MQWVBKUT.mjs} +1 -1
  68. package/dist/chunk-MQWVBKUT.mjs.map +1 -0
  69. package/dist/chunk-NP6PDX3E.mjs +1 -0
  70. package/dist/chunk-NP6PDX3E.mjs.map +1 -0
  71. package/dist/{chunk-CIRFWC7Y.mjs → chunk-RNJM5BHX.mjs} +2 -2
  72. package/dist/{chunk-FCF2RHPW.mjs → chunk-UMDNWTJC.mjs} +4 -4
  73. package/dist/{chunk-FCF2RHPW.mjs.map → chunk-UMDNWTJC.mjs.map} +1 -1
  74. package/dist/chunk-UNLX2F2Y.mjs +24 -0
  75. package/dist/chunk-UNLX2F2Y.mjs.map +1 -0
  76. package/dist/index.d.mts +3 -0
  77. package/dist/index.d.ts +3 -0
  78. package/dist/index.js +57 -0
  79. package/dist/index.js.map +1 -1
  80. package/dist/index.mjs +67 -55
  81. package/dist/math/index.d.mts +1 -0
  82. package/dist/math/index.d.ts +1 -0
  83. package/dist/math/index.js +25 -0
  84. package/dist/math/index.js.map +1 -1
  85. package/dist/math/index.mjs +14 -10
  86. package/dist/math/random.d.mts +5 -5
  87. package/dist/math/random.d.ts +5 -5
  88. package/dist/math/random.js.map +1 -1
  89. package/dist/math/random.mjs +1 -1
  90. package/dist/math/randomInt.js.map +1 -1
  91. package/dist/math/randomInt.mjs +2 -2
  92. package/dist/math/range.d.mts +32 -0
  93. package/dist/math/range.d.ts +32 -0
  94. package/dist/math/range.js +48 -0
  95. package/dist/math/range.js.map +1 -0
  96. package/dist/math/range.mjs +8 -0
  97. package/dist/math/range.mjs.map +1 -0
  98. package/dist/math/round.d.mts +2 -0
  99. package/dist/math/round.d.ts +2 -0
  100. package/dist/math/round.js +3 -0
  101. package/dist/math/round.js.map +1 -1
  102. package/dist/math/round.mjs +1 -1
  103. package/dist/object/index.js.map +1 -1
  104. package/dist/object/index.mjs +7 -7
  105. package/dist/object/omitBy.d.mts +2 -2
  106. package/dist/object/omitBy.d.ts +2 -2
  107. package/dist/object/omitBy.js.map +1 -1
  108. package/dist/object/omitBy.mjs +1 -1
  109. package/dist/object/pickBy.d.mts +2 -2
  110. package/dist/object/pickBy.d.ts +2 -2
  111. package/dist/object/pickBy.js.map +1 -1
  112. package/dist/object/pickBy.mjs +1 -1
  113. package/dist/predicate/index.mjs +6 -6
  114. package/package.json +3 -1
  115. package/dist/chunk-EJGAXTF7.mjs +0 -1
  116. package/dist/chunk-SF3V7XXM.mjs.map +0 -1
  117. package/dist/chunk-T2C2WVFL.mjs.map +0 -1
  118. package/dist/chunk-UGFVAAVO.mjs.map +0 -1
  119. package/dist/chunk-V7E5DGZP.mjs.map +0 -1
  120. package/dist/chunk-VAV4XHLO.mjs +0 -1
  121. /package/dist/{chunk-EJGAXTF7.mjs.map → array/maxBy.mjs.map} +0 -0
  122. /package/dist/{chunk-VAV4XHLO.mjs.map → array/minBy.mjs.map} +0 -0
  123. /package/dist/{chunk-QWJDITYJ.mjs.map → chunk-5UT77WON.mjs.map} +0 -0
  124. /package/dist/{chunk-WXIBCOES.mjs.map → chunk-G2TTBLLJ.mjs.map} +0 -0
  125. /package/dist/{chunk-CIRFWC7Y.mjs.map → chunk-RNJM5BHX.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,46 +1,33 @@
1
1
  import "./chunk-ARZ5BDR6.mjs";
2
- import "./chunk-MAJSPFA6.mjs";
3
- import {
4
- isNil
5
- } from "./chunk-OHQAR5AU.mjs";
6
- import {
7
- isNotNil
8
- } from "./chunk-ZQNAZPSK.mjs";
9
- import {
10
- isNull
11
- } from "./chunk-AIRSKN47.mjs";
12
- import {
13
- isUndefined
14
- } from "./chunk-VH2PV426.mjs";
15
2
  import {
16
3
  delay
17
4
  } from "./chunk-AL3GJBEI.mjs";
18
- import "./chunk-VAV4XHLO.mjs";
19
- import {
20
- randomInt
21
- } from "./chunk-QWJDITYJ.mjs";
22
- import {
23
- random
24
- } from "./chunk-UGFVAAVO.mjs";
5
+ import "./chunk-T5JCRGXA.mjs";
25
6
  import {
26
- round
27
- } from "./chunk-V7E5DGZP.mjs";
7
+ omit
8
+ } from "./chunk-PLTO44KM.mjs";
28
9
  import {
29
- sum
30
- } from "./chunk-7OU22ENP.mjs";
31
- import "./chunk-T5JCRGXA.mjs";
10
+ omitBy
11
+ } from "./chunk-A67NF2C7.mjs";
32
12
  import {
33
13
  pick
34
14
  } from "./chunk-OFWKFUFZ.mjs";
35
15
  import {
36
16
  pickBy
37
- } from "./chunk-T2C2WVFL.mjs";
17
+ } from "./chunk-MQWVBKUT.mjs";
18
+ import "./chunk-MAJSPFA6.mjs";
38
19
  import {
39
- omit
40
- } from "./chunk-PLTO44KM.mjs";
20
+ isNull
21
+ } from "./chunk-AIRSKN47.mjs";
41
22
  import {
42
- omitBy
43
- } from "./chunk-SF3V7XXM.mjs";
23
+ isUndefined
24
+ } from "./chunk-VH2PV426.mjs";
25
+ import {
26
+ isNil
27
+ } from "./chunk-OHQAR5AU.mjs";
28
+ import {
29
+ isNotNil
30
+ } from "./chunk-ZQNAZPSK.mjs";
44
31
  import "./chunk-N6EM6ETS.mjs";
45
32
  import {
46
33
  debounce
@@ -58,28 +45,59 @@ import "./chunk-FZEZH22H.mjs";
58
45
  import {
59
46
  AbortError
60
47
  } from "./chunk-VP2LXY75.mjs";
48
+ import "./chunk-7LAMAYGN.mjs";
49
+ import {
50
+ sum
51
+ } from "./chunk-7OU22ENP.mjs";
61
52
  import {
62
53
  clamp
63
54
  } from "./chunk-MLCL773E.mjs";
64
- import "./chunk-EJGAXTF7.mjs";
55
+ import {
56
+ randomInt
57
+ } from "./chunk-5UT77WON.mjs";
58
+ import {
59
+ random
60
+ } from "./chunk-LCP6FOCX.mjs";
61
+ import {
62
+ range
63
+ } from "./chunk-UNLX2F2Y.mjs";
64
+ import {
65
+ round
66
+ } from "./chunk-5PMKOZ2F.mjs";
67
+ import "./chunk-NP6PDX3E.mjs";
68
+ import {
69
+ zip
70
+ } from "./chunk-IDCUZVJL.mjs";
71
+ import {
72
+ zipWith
73
+ } from "./chunk-4KYXHZ4R.mjs";
65
74
  import {
66
75
  uniqBy
67
76
  } from "./chunk-WPDDOUQT.mjs";
68
77
  import {
69
78
  xor
70
- } from "./chunk-WXIBCOES.mjs";
79
+ } from "./chunk-G2TTBLLJ.mjs";
71
80
  import {
72
81
  xorBy
73
82
  } from "./chunk-AM2EGFCU.mjs";
83
+ import {
84
+ unionBy
85
+ } from "./chunk-NRNKP6JF.mjs";
74
86
  import {
75
87
  xorWith
76
- } from "./chunk-FCF2RHPW.mjs";
88
+ } from "./chunk-UMDNWTJC.mjs";
77
89
  import {
78
- zip
79
- } from "./chunk-DD73BULA.mjs";
90
+ unionWith
91
+ } from "./chunk-642SWVKJ.mjs";
80
92
  import {
81
- zipWith
82
- } from "./chunk-T5FDOBCA.mjs";
93
+ uniqWith
94
+ } from "./chunk-2PFDLYQC.mjs";
95
+ import {
96
+ partition
97
+ } from "./chunk-5L2V7WD3.mjs";
98
+ import {
99
+ sample
100
+ } from "./chunk-DOOIIHT3.mjs";
83
101
  import {
84
102
  shuffle
85
103
  } from "./chunk-DPLJQQFX.mjs";
@@ -101,15 +119,6 @@ import {
101
119
  import {
102
120
  uniq
103
121
  } from "./chunk-XFCW7XJ4.mjs";
104
- import {
105
- unionBy
106
- } from "./chunk-NRNKP6JF.mjs";
107
- import {
108
- unionWith
109
- } from "./chunk-3KHI4I2X.mjs";
110
- import {
111
- uniqWith
112
- } from "./chunk-2PFDLYQC.mjs";
113
122
  import {
114
123
  groupBy
115
124
  } from "./chunk-LWXZFXY5.mjs";
@@ -121,25 +130,25 @@ import {
121
130
  } from "./chunk-GNSJP2AB.mjs";
122
131
  import {
123
132
  intersectionWith
124
- } from "./chunk-KLJRZJOR.mjs";
133
+ } from "./chunk-2EFS3VA3.mjs";
125
134
  import {
126
- partition
127
- } from "./chunk-5L2V7WD3.mjs";
135
+ maxBy
136
+ } from "./chunk-KZ5JY7J3.mjs";
128
137
  import {
129
- sample
130
- } from "./chunk-DOOIIHT3.mjs";
138
+ minBy
139
+ } from "./chunk-H23GUJVF.mjs";
131
140
  import {
132
141
  chunk
133
142
  } from "./chunk-E6C5EZQA.mjs";
134
143
  import {
135
144
  difference
136
- } from "./chunk-M7UI5ETO.mjs";
145
+ } from "./chunk-JPUKH67K.mjs";
137
146
  import {
138
147
  differenceBy
139
148
  } from "./chunk-LVWX5B43.mjs";
140
149
  import {
141
150
  differenceWith
142
- } from "./chunk-FQ4K36VD.mjs";
151
+ } from "./chunk-6NVQAHXP.mjs";
143
152
  import {
144
153
  drop
145
154
  } from "./chunk-ACFP3XMB.mjs";
@@ -148,10 +157,10 @@ import {
148
157
  } from "./chunk-Q75KEFW5.mjs";
149
158
  import {
150
159
  dropRightWhile
151
- } from "./chunk-CIRFWC7Y.mjs";
160
+ } from "./chunk-RNJM5BHX.mjs";
152
161
  import {
153
162
  dropWhile
154
- } from "./chunk-JFHM6EY2.mjs";
163
+ } from "./chunk-K2BAFL2T.mjs";
155
164
  import "./chunk-2MM5EJJX.mjs";
156
165
  export {
157
166
  AbortError,
@@ -174,6 +183,8 @@ export {
174
183
  isNotNil,
175
184
  isNull,
176
185
  isUndefined,
186
+ maxBy,
187
+ minBy,
177
188
  noop,
178
189
  omit,
179
190
  omitBy,
@@ -183,6 +194,7 @@ export {
183
194
  pickBy,
184
195
  random,
185
196
  randomInt,
197
+ range,
186
198
  round,
187
199
  sample,
188
200
  shuffle,
@@ -3,3 +3,4 @@ export { random } from './random.mjs';
3
3
  export { randomInt } from './randomInt.mjs';
4
4
  export { round } from './round.mjs';
5
5
  export { sum } from './sum.mjs';
6
+ export { range } from './range.mjs';
@@ -3,3 +3,4 @@ export { random } from './random.js';
3
3
  export { randomInt } from './randomInt.js';
4
4
  export { round } from './round.js';
5
5
  export { sum } from './sum.js';
6
+ export { range } from './range.js';
@@ -23,6 +23,7 @@ __export(math_exports, {
23
23
  clamp: () => clamp,
24
24
  random: () => random,
25
25
  randomInt: () => randomInt,
26
+ range: () => range,
26
27
  round: () => round,
27
28
  sum: () => sum
28
29
  });
@@ -51,6 +52,9 @@ function randomInt(minimum, maximum) {
51
52
 
52
53
  // src/math/round.ts
53
54
  function round(value, precision = 0) {
55
+ if (!Number.isInteger(precision)) {
56
+ throw new Error("Precision must be an integer.");
57
+ }
54
58
  const multiplier = Math.pow(10, precision);
55
59
  return Math.round(value * multiplier) / multiplier;
56
60
  }
@@ -63,11 +67,32 @@ function sum(nums) {
63
67
  }
64
68
  return result;
65
69
  }
70
+
71
+ // src/math/range.ts
72
+ function range(start, end, step) {
73
+ if (end == null) {
74
+ end = start;
75
+ start = 0;
76
+ }
77
+ if (step == null) {
78
+ step = 1;
79
+ }
80
+ if (!Number.isInteger(step) || step === 0) {
81
+ throw new Error(`The step value must be a non-zero integer.`);
82
+ }
83
+ const length = Math.max(Math.ceil((end - start) / step), 0);
84
+ const result = new Array(length);
85
+ for (let i = 0; i < length; i++) {
86
+ result[i] = start + i * step;
87
+ }
88
+ return result;
89
+ }
66
90
  // Annotate the CommonJS export names for ESM import in node:
67
91
  0 && (module.exports = {
68
92
  clamp,
69
93
  random,
70
94
  randomInt,
95
+ range,
71
96
  round,
72
97
  sum
73
98
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/math/index.ts","../../src/math/clamp.ts","../../src/math/random.ts","../../src/math/randomInt.ts","../../src/math/round.ts","../../src/math/sum.ts"],"sourcesContent":["export { clamp } from './clamp';\nexport { random } from './random';\nexport { randomInt } from './randomInt';\nexport { round } from './round';\nexport { sum } from './sum';\n","/**\n * Clamps a number within the inclusive lower and upper bounds.\n *\n * This function takes a number and two bounds, and returns the number clamped within the specified bounds.\n * If only one bound is provided, it returns the minimum of the value and the bound.\n *\n * @param {number} value - The number to clamp.\n * @param {number} minimum - The minimum bound to clamp the number.\n * @param {number} maximum - The maximum bound to clamp the number.\n * @returns {number} The clamped number within the specified bounds.\n *\n * @example\n * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5\n * const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15\n * const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5\n * const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15\n */\nexport function clamp(value: number, maximum: number): number;\nexport function clamp(value: number, minimum: number, maximum: number): number;\nexport function clamp(value: number, bound1: number, bound2?: number): number {\n if (bound2 == null) {\n return Math.min(value, bound1);\n }\n\n return Math.min(Math.max(value, bound1), bound2);\n}\n","/**\n * 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","import { random } from './random';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(minimum: number, maximum: number): number {\n return Math.floor(random(minimum, maximum));\n}\n","/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n *\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;AAAA;;;ACmBO,SAAS,MAAM,OAAe,QAAgB,QAAyB;AAC5E,MAAI,UAAU,MAAM;AAClB,WAAO,KAAK,IAAI,OAAO,MAAM;AAAA,EAC/B;AAEA,SAAO,KAAK,IAAI,KAAK,IAAI,OAAO,MAAM,GAAG,MAAM;AACjD;;;ACZO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ACLO,SAAS,UAAU,SAAiB,SAAyB;AAClE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAO,CAAC;AAC5C;;;ACDO,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/random.ts","../../src/math/randomInt.ts","../../src/math/round.ts","../../src/math/sum.ts","../../src/math/range.ts"],"sourcesContent":["export { clamp } from './clamp';\nexport { random } from './random';\nexport { randomInt } from './randomInt';\nexport { round } from './round';\nexport { sum } from './sum';\nexport { range } from './range';\n","/**\n * Clamps a number within the inclusive lower and upper bounds.\n *\n * This function takes a number and two bounds, and returns the number clamped within the specified bounds.\n * If only one bound is provided, it returns the minimum of the value and the bound.\n *\n * @param {number} value - The number to clamp.\n * @param {number} minimum - The minimum bound to clamp the number.\n * @param {number} maximum - The maximum bound to clamp the number.\n * @returns {number} The clamped number within the specified bounds.\n *\n * @example\n * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5\n * const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15\n * const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5\n * const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15\n */\nexport function clamp(value: number, maximum: number): number;\nexport function clamp(value: number, minimum: number, maximum: number): number;\nexport function clamp(value: number, bound1: number, bound2?: number): number {\n if (bound2 == null) {\n return Math.min(value, bound1);\n }\n\n return Math.min(Math.max(value, bound1), bound2);\n}\n","/**\n * Generate a random number within the given range.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result1 = random(0, 5); // Returns a random number between 0 and 5.\n * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown\n * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.\n */\nexport function random(minimum: number, maximum: number): number {\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n","import { random } from './random';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(minimum: number, maximum: number): number {\n return Math.floor(random(minimum, maximum));\n}\n","/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n * @throws {Error} Throws an error if `Precision` is not integer.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n * const result4 = round(1.2345, 3.1); // This will throw an error\n */\nexport function round(value: number, precision = 0): number {\n if (!Number.isInteger(precision)) {\n throw new Error('Precision must be an integer.');\n }\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n","/**\n * Calculates the sum of an array of numbers.\n *\n * This function takes an array of numbers and returns the sum of all the elements in the array.\n *\n * @param {number[]} nums - An array of numbers to be summed.\n * @returns {number} The sum of all the numbers in the array.\n *\n * @example\n * const numbers = [1, 2, 3, 4, 5];\n * const result = sum(numbers);\n * // result will be 15\n */\nexport function sum(nums: number[]): number {\n let result = 0;\n\n for (const num of nums) {\n result += num;\n }\n\n return result;\n}\n","/**\n * Returns an array of numbers from `start` to `end`, incrementing by `step`.\n *\n * If `step` is not provided, it defaults to `1` for an\n * ascending range and `-1` for a descending range.\n *\n * @param {number} start - The starting number of the range.\n * @param {number} [end] - The end number of the range.\n * @param {number} [step] - The step value for the range.\n * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.\n *\n * @example\n * // Returns [0, 1, 2, 3]\n * range(4);\n *\n * @example\n * // Returns [0, 5, 10, 15]\n * range(0, 20, 5);\n *\n * @example\n * // Returns []\n * range(0, -4, -1);\n *\n * @example\n * // Throws an error: The step value must be a non-zero integer.\n * range(1, 4, 0);\n */\nexport function range(end: number): number[];\nexport function range(start: number, end: number): number[];\nexport function range(start: number, end: number, step: number): number[];\nexport function range(start: number, end?: number, step?: number): number[] {\n if (end == null) {\n end = start;\n start = 0;\n }\n\n if (step == null) {\n step = 1;\n }\n\n if (!Number.isInteger(step) || step === 0) {\n throw new Error(`The step value must be a non-zero integer.`);\n }\n\n const length = Math.max(Math.ceil((end - start) / step), 0);\n const result = new Array(length);\n\n for (let i = 0; i < length; i++) {\n result[i] = start + i * step;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBO,SAAS,MAAM,OAAe,QAAgB,QAAyB;AAC5E,MAAI,UAAU,MAAM;AAClB,WAAO,KAAK,IAAI,OAAO,MAAM;AAAA,EAC/B;AAEA,SAAO,KAAK,IAAI,KAAK,IAAI,OAAO,MAAM,GAAG,MAAM;AACjD;;;ACZO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ACLO,SAAS,UAAU,SAAiB,SAAyB;AAClE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAO,CAAC;AAC5C;;;ACCO,SAAS,MAAM,OAAe,YAAY,GAAW;AAC1D,MAAI,CAAC,OAAO,UAAU,SAAS,GAAG;AAChC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACA,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;;;ACVO,SAAS,IAAI,MAAwB;AAC1C,MAAI,SAAS;AAEb,aAAW,OAAO,MAAM;AACtB,cAAU;AAAA,EACZ;AAEA,SAAO;AACT;;;ACSO,SAAS,MAAM,OAAe,KAAc,MAAyB;AAC1E,MAAI,OAAO,MAAM;AACf,UAAM;AACN,YAAQ;AAAA,EACV;AAEA,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,SAAS,GAAG;AACzC,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AAEA,QAAM,SAAS,KAAK,IAAI,KAAK,MAAM,MAAM,SAAS,IAAI,GAAG,CAAC;AAC1D,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,WAAO,CAAC,IAAI,QAAQ,IAAI;AAAA,EAC1B;AAEA,SAAO;AACT;","names":[]}
@@ -1,24 +1,28 @@
1
- import "../chunk-VAV4XHLO.mjs";
2
- import {
3
- randomInt
4
- } from "../chunk-QWJDITYJ.mjs";
5
- import {
6
- random
7
- } from "../chunk-UGFVAAVO.mjs";
8
- import {
9
- round
10
- } from "../chunk-V7E5DGZP.mjs";
1
+ import "../chunk-7LAMAYGN.mjs";
11
2
  import {
12
3
  sum
13
4
  } from "../chunk-7OU22ENP.mjs";
14
5
  import {
15
6
  clamp
16
7
  } from "../chunk-MLCL773E.mjs";
8
+ import {
9
+ randomInt
10
+ } from "../chunk-5UT77WON.mjs";
11
+ import {
12
+ random
13
+ } from "../chunk-LCP6FOCX.mjs";
14
+ import {
15
+ range
16
+ } from "../chunk-UNLX2F2Y.mjs";
17
+ import {
18
+ round
19
+ } from "../chunk-5PMKOZ2F.mjs";
17
20
  import "../chunk-2MM5EJJX.mjs";
18
21
  export {
19
22
  clamp,
20
23
  random,
21
24
  randomInt,
25
+ range,
22
26
  round,
23
27
  sum
24
28
  };
@@ -1,15 +1,15 @@
1
1
  /**
2
- * Generates a random floating-point number between minimum (inclusive) and maximum (exclusive).
3
- * If min is greater than maximum, the values are swapped.
2
+ * Generate a random number within the given range.
4
3
  *
5
4
  * @param {number} minimum - The lower bound (inclusive).
6
5
  * @param {number} maximum - The upper bound (exclusive).
7
- * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).
6
+ * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
8
7
  * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
9
8
  *
10
9
  * @example
11
- * const result = random(0, 5); // result will be a random floating-point number between 0 (inclusive) and 5 (exclusive)
12
- * const result2 = random(5, 0); // This will throw an error
10
+ * const result1 = random(0, 5); // Returns a random number between 0 and 5.
11
+ * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown
12
+ * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
13
13
  */
14
14
  declare function random(minimum: number, maximum: number): number;
15
15
 
@@ -1,15 +1,15 @@
1
1
  /**
2
- * Generates a random floating-point number between minimum (inclusive) and maximum (exclusive).
3
- * If min is greater than maximum, the values are swapped.
2
+ * Generate a random number within the given range.
4
3
  *
5
4
  * @param {number} minimum - The lower bound (inclusive).
6
5
  * @param {number} maximum - The upper bound (exclusive).
7
- * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).
6
+ * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
8
7
  * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
9
8
  *
10
9
  * @example
11
- * const result = random(0, 5); // result will be a random floating-point number between 0 (inclusive) and 5 (exclusive)
12
- * const result2 = random(5, 0); // This will throw an error
10
+ * const result1 = random(0, 5); // Returns a random number between 0 and 5.
11
+ * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown
12
+ * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
13
13
  */
14
14
  declare function random(minimum: number, maximum: number): number;
15
15
 
@@ -1 +1 @@
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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;","names":[]}
1
+ {"version":3,"sources":["../../src/math/random.ts"],"sourcesContent":["/**\n * Generate a random number within the given range.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result1 = random(0, 5); // Returns a random number between 0 and 5.\n * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown\n * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.\n */\nexport function random(minimum: number, maximum: number): number {\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  random
3
- } from "../chunk-UGFVAAVO.mjs";
3
+ } from "../chunk-LCP6FOCX.mjs";
4
4
  import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  random
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/math/randomInt.ts","../../src/math/random.ts"],"sourcesContent":["import { random } from './random';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(minimum: number, maximum: number): number {\n return Math.floor(random(minimum, maximum));\n}\n","/**\n * 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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ADLO,SAAS,UAAU,SAAiB,SAAyB;AAClE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAO,CAAC;AAC5C;","names":[]}
1
+ {"version":3,"sources":["../../src/math/randomInt.ts","../../src/math/random.ts"],"sourcesContent":["import { random } from './random';\n\n/**\n * Generates a random integer between minimum (inclusive) and maximum (exclusive).\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random integer between minimum (inclusive) and maximum (exclusive).\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)\n * const result2 = randomInt(5, 0); // This will throw an error\n */\nexport function randomInt(minimum: number, maximum: number): number {\n return Math.floor(random(minimum, maximum));\n}\n","/**\n * Generate a random number within the given range.\n *\n * @param {number} minimum - The lower bound (inclusive).\n * @param {number} maximum - The upper bound (exclusive).\n * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.\n * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.\n *\n * @example\n * const result1 = random(0, 5); // Returns a random number between 0 and 5.\n * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown\n * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.\n */\nexport function random(minimum: number, maximum: number): number {\n if (minimum >= maximum) {\n throw new Error('Invalid input: The maximum value must be greater than the minimum value.');\n }\n\n return Math.random() * (maximum - minimum) + minimum;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,SAAS,OAAO,SAAiB,SAAyB;AAC/D,MAAI,WAAW,SAAS;AACtB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AAEA,SAAO,KAAK,OAAO,KAAK,UAAU,WAAW;AAC/C;;;ADLO,SAAS,UAAU,SAAiB,SAAyB;AAClE,SAAO,KAAK,MAAM,OAAO,SAAS,OAAO,CAAC;AAC5C;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  randomInt
3
- } from "../chunk-QWJDITYJ.mjs";
4
- import "../chunk-UGFVAAVO.mjs";
3
+ } from "../chunk-5UT77WON.mjs";
4
+ import "../chunk-LCP6FOCX.mjs";
5
5
  import "../chunk-2MM5EJJX.mjs";
6
6
  export {
7
7
  randomInt
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Returns an array of numbers from `start` to `end`, incrementing by `step`.
3
+ *
4
+ * If `step` is not provided, it defaults to `1` for an
5
+ * ascending range and `-1` for a descending range.
6
+ *
7
+ * @param {number} start - The starting number of the range.
8
+ * @param {number} [end] - The end number of the range.
9
+ * @param {number} [step] - The step value for the range.
10
+ * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.
11
+ *
12
+ * @example
13
+ * // Returns [0, 1, 2, 3]
14
+ * range(4);
15
+ *
16
+ * @example
17
+ * // Returns [0, 5, 10, 15]
18
+ * range(0, 20, 5);
19
+ *
20
+ * @example
21
+ * // Returns []
22
+ * range(0, -4, -1);
23
+ *
24
+ * @example
25
+ * // Throws an error: The step value must be a non-zero integer.
26
+ * range(1, 4, 0);
27
+ */
28
+ declare function range(end: number): number[];
29
+ declare function range(start: number, end: number): number[];
30
+ declare function range(start: number, end: number, step: number): number[];
31
+
32
+ export { range };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Returns an array of numbers from `start` to `end`, incrementing by `step`.
3
+ *
4
+ * If `step` is not provided, it defaults to `1` for an
5
+ * ascending range and `-1` for a descending range.
6
+ *
7
+ * @param {number} start - The starting number of the range.
8
+ * @param {number} [end] - The end number of the range.
9
+ * @param {number} [step] - The step value for the range.
10
+ * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.
11
+ *
12
+ * @example
13
+ * // Returns [0, 1, 2, 3]
14
+ * range(4);
15
+ *
16
+ * @example
17
+ * // Returns [0, 5, 10, 15]
18
+ * range(0, 20, 5);
19
+ *
20
+ * @example
21
+ * // Returns []
22
+ * range(0, -4, -1);
23
+ *
24
+ * @example
25
+ * // Throws an error: The step value must be a non-zero integer.
26
+ * range(1, 4, 0);
27
+ */
28
+ declare function range(end: number): number[];
29
+ declare function range(start: number, end: number): number[];
30
+ declare function range(start: number, end: number, step: number): number[];
31
+
32
+ export { range };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/math/range.ts
21
+ var range_exports = {};
22
+ __export(range_exports, {
23
+ range: () => range
24
+ });
25
+ module.exports = __toCommonJS(range_exports);
26
+ function range(start, end, step) {
27
+ if (end == null) {
28
+ end = start;
29
+ start = 0;
30
+ }
31
+ if (step == null) {
32
+ step = 1;
33
+ }
34
+ if (!Number.isInteger(step) || step === 0) {
35
+ throw new Error(`The step value must be a non-zero integer.`);
36
+ }
37
+ const length = Math.max(Math.ceil((end - start) / step), 0);
38
+ const result = new Array(length);
39
+ for (let i = 0; i < length; i++) {
40
+ result[i] = start + i * step;
41
+ }
42
+ return result;
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ range
47
+ });
48
+ //# sourceMappingURL=range.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/math/range.ts"],"sourcesContent":["/**\n * Returns an array of numbers from `start` to `end`, incrementing by `step`.\n *\n * If `step` is not provided, it defaults to `1` for an\n * ascending range and `-1` for a descending range.\n *\n * @param {number} start - The starting number of the range.\n * @param {number} [end] - The end number of the range.\n * @param {number} [step] - The step value for the range.\n * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.\n *\n * @example\n * // Returns [0, 1, 2, 3]\n * range(4);\n *\n * @example\n * // Returns [0, 5, 10, 15]\n * range(0, 20, 5);\n *\n * @example\n * // Returns []\n * range(0, -4, -1);\n *\n * @example\n * // Throws an error: The step value must be a non-zero integer.\n * range(1, 4, 0);\n */\nexport function range(end: number): number[];\nexport function range(start: number, end: number): number[];\nexport function range(start: number, end: number, step: number): number[];\nexport function range(start: number, end?: number, step?: number): number[] {\n if (end == null) {\n end = start;\n start = 0;\n }\n\n if (step == null) {\n step = 1;\n }\n\n if (!Number.isInteger(step) || step === 0) {\n throw new Error(`The step value must be a non-zero integer.`);\n }\n\n const length = Math.max(Math.ceil((end - start) / step), 0);\n const result = new Array(length);\n\n for (let i = 0; i < length; i++) {\n result[i] = start + i * step;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BO,SAAS,MAAM,OAAe,KAAc,MAAyB;AAC1E,MAAI,OAAO,MAAM;AACf,UAAM;AACN,YAAQ;AAAA,EACV;AAEA,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,SAAS,GAAG;AACzC,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AAEA,QAAM,SAAS,KAAK,IAAI,KAAK,MAAM,MAAM,SAAS,IAAI,GAAG,CAAC;AAC1D,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,WAAO,CAAC,IAAI,QAAQ,IAAI;AAAA,EAC1B;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ range
3
+ } from "../chunk-UNLX2F2Y.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ range
7
+ };
8
+ //# sourceMappingURL=range.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -7,11 +7,13 @@
7
7
  * @param {number} value - The number to round.
8
8
  * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.
9
9
  * @returns {number} The rounded number.
10
+ * @throws {Error} Throws an error if `Precision` is not integer.
10
11
  *
11
12
  * @example
12
13
  * const result1 = round(1.2345); // result1 will be 1
13
14
  * const result2 = round(1.2345, 2); // result2 will be 1.23
14
15
  * const result3 = round(1.2345, 3); // result3 will be 1.235
16
+ * const result4 = round(1.2345, 3.1); // This will throw an error
15
17
  */
16
18
  declare function round(value: number, precision?: number): number;
17
19
 
@@ -7,11 +7,13 @@
7
7
  * @param {number} value - The number to round.
8
8
  * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.
9
9
  * @returns {number} The rounded number.
10
+ * @throws {Error} Throws an error if `Precision` is not integer.
10
11
  *
11
12
  * @example
12
13
  * const result1 = round(1.2345); // result1 will be 1
13
14
  * const result2 = round(1.2345, 2); // result2 will be 1.23
14
15
  * const result3 = round(1.2345, 3); // result3 will be 1.235
16
+ * const result4 = round(1.2345, 3.1); // This will throw an error
15
17
  */
16
18
  declare function round(value: number, precision?: number): number;
17
19
 
@@ -24,6 +24,9 @@ __export(round_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(round_exports);
26
26
  function round(value, precision = 0) {
27
+ if (!Number.isInteger(precision)) {
28
+ throw new Error("Precision must be an integer.");
29
+ }
27
30
  const multiplier = Math.pow(10, precision);
28
31
  return Math.round(value * multiplier) / multiplier;
29
32
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/math/round.ts"],"sourcesContent":["/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n */\nexport function round(value: number, precision: number = 0): number {\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeO,SAAS,MAAM,OAAe,YAAoB,GAAW;AAClE,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;","names":[]}
1
+ {"version":3,"sources":["../../src/math/round.ts"],"sourcesContent":["/**\n * Rounds a number to a specified precision.\n *\n * This function takes a number and an optional precision value, and returns the number rounded\n * to the specified number of decimal places.\n *\n * @param {number} value - The number to round.\n * @param {number} [precision=0] - The number of decimal places to round to. Defaults to 0.\n * @returns {number} The rounded number.\n * @throws {Error} Throws an error if `Precision` is not integer.\n *\n * @example\n * const result1 = round(1.2345); // result1 will be 1\n * const result2 = round(1.2345, 2); // result2 will be 1.23\n * const result3 = round(1.2345, 3); // result3 will be 1.235\n * const result4 = round(1.2345, 3.1); // This will throw an error\n */\nexport function round(value: number, precision = 0): number {\n if (!Number.isInteger(precision)) {\n throw new Error('Precision must be an integer.');\n }\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,SAAS,MAAM,OAAe,YAAY,GAAW;AAC1D,MAAI,CAAC,OAAO,UAAU,SAAS,GAAG;AAChC,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AACA,QAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,SAAO,KAAK,MAAM,QAAQ,UAAU,IAAI;AAC1C;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  round
3
- } from "../chunk-V7E5DGZP.mjs";
3
+ } from "../chunk-5PMKOZ2F.mjs";
4
4
  import "../chunk-2MM5EJJX.mjs";
5
5
  export {
6
6
  round
@@ -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"],"sourcesContent":["export { omit } from './omit';\nexport { omitBy } from './omitBy';\nexport { pick } from './pick';\nexport { pickBy } from './pickBy';\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 * @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 * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: string) => 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: string) => 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 * @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 * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: string) => 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: string) => 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACLO,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;;;AClBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,MAAM;AACtB,WAAO,GAAG,IAAI,IAAI,GAAG;AAAA,EACvB;AAEA,SAAO;AACT;;;ACLO,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;","names":[]}
1
+ {"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts"],"sourcesContent":["export { omit } from './omit';\nexport { omitBy } from './omitBy';\nexport { pick } from './pick';\nexport { pickBy } from './pickBy';\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 * @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 * @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 * @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 * @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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACLO,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;;;AClBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,MAAM;AACtB,WAAO,GAAG,IAAI,IAAI,GAAG;AAAA,EACvB;AAEA,SAAO;AACT;;;ACLO,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;","names":[]}