es-toolkit 1.17.0-dev.533 → 1.17.0-dev.536

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 (112) hide show
  1. package/dist/_chunk/{initial-crEecP.js → initial-CMlK06.js} +5 -5
  2. package/dist/_chunk/{randomInt-CF7bZK.js → randomInt-DJFj2K.js} +1 -1
  3. package/dist/_chunk/{rest-Bzm2XK.js → rest-CXB7TJ.js} +6 -6
  4. package/dist/array/fill.d.mts +55 -2
  5. package/dist/array/fill.d.ts +55 -2
  6. package/dist/array/head.d.mts +14 -3
  7. package/dist/array/head.d.ts +14 -3
  8. package/dist/array/index.js +1 -1
  9. package/dist/array/join.d.mts +3 -7
  10. package/dist/array/join.d.ts +3 -7
  11. package/dist/array/join.mjs +1 -1
  12. package/dist/array/last.d.mts +23 -1
  13. package/dist/array/last.d.ts +23 -1
  14. package/dist/array/maxBy.d.mts +13 -1
  15. package/dist/array/maxBy.d.ts +13 -1
  16. package/dist/array/minBy.d.mts +13 -1
  17. package/dist/array/minBy.d.ts +13 -1
  18. package/dist/array/toFilled.d.mts +59 -2
  19. package/dist/array/toFilled.d.ts +59 -2
  20. package/dist/array/zip.d.mts +65 -7
  21. package/dist/array/zip.d.ts +65 -7
  22. package/dist/array/zip.mjs +1 -1
  23. package/dist/array/zipObject.d.mts +2 -4
  24. package/dist/array/zipObject.d.ts +2 -4
  25. package/dist/array/zipWith.d.mts +39 -6
  26. package/dist/array/zipWith.d.ts +39 -6
  27. package/dist/array/zipWith.mjs +2 -2
  28. package/dist/browser.global.js +1 -1
  29. package/dist/browser.global.js.map +1 -1
  30. package/dist/compat/array/difference.d.mts +22 -0
  31. package/dist/compat/array/difference.d.ts +22 -0
  32. package/dist/compat/array/fill.d.mts +55 -2
  33. package/dist/compat/array/fill.d.ts +55 -2
  34. package/dist/compat/array/find.mjs +3 -3
  35. package/dist/compat/array/findIndex.mjs +3 -3
  36. package/dist/compat/index.js +43 -34
  37. package/dist/compat/math/max.d.mts +16 -5
  38. package/dist/compat/math/max.d.ts +16 -5
  39. package/dist/compat/math/min.d.mts +16 -4
  40. package/dist/compat/math/min.d.ts +16 -4
  41. package/dist/compat/object/get.mjs +1 -1
  42. package/dist/compat/object/has.mjs +3 -2
  43. package/dist/compat/object/mapKeys.mjs +7 -6
  44. package/dist/compat/object/mapValues.mjs +7 -6
  45. package/dist/compat/object/mergeWith.mjs +5 -3
  46. package/dist/compat/object/set.mjs +5 -1
  47. package/dist/compat/predicate/isMatch.mjs +2 -2
  48. package/dist/compat/string/endsWith.d.mts +1 -1
  49. package/dist/compat/string/endsWith.d.ts +1 -1
  50. package/dist/compat/string/endsWith.mjs +2 -2
  51. package/dist/compat/string/repeat.d.mts +1 -1
  52. package/dist/compat/string/repeat.d.ts +1 -1
  53. package/dist/compat/string/startsWith.d.mts +1 -1
  54. package/dist/compat/string/startsWith.d.ts +1 -1
  55. package/dist/compat/string/startsWith.mjs +2 -2
  56. package/dist/function/after.d.mts +1 -1
  57. package/dist/function/after.d.ts +1 -1
  58. package/dist/function/after.mjs +2 -2
  59. package/dist/function/before.d.mts +1 -1
  60. package/dist/function/before.d.ts +1 -1
  61. package/dist/function/before.mjs +3 -3
  62. package/dist/function/debounce.d.mts +1 -1
  63. package/dist/function/debounce.d.ts +1 -1
  64. package/dist/function/debounce.mjs +1 -1
  65. package/dist/function/index.js +1 -1
  66. package/dist/function/memoize.d.mts +37 -1
  67. package/dist/function/memoize.d.ts +37 -1
  68. package/dist/index.js +3 -3
  69. package/dist/math/clamp.d.mts +14 -3
  70. package/dist/math/clamp.d.ts +14 -3
  71. package/dist/math/index.js +1 -1
  72. package/dist/math/random.d.mts +13 -2
  73. package/dist/math/random.d.ts +13 -2
  74. package/dist/math/random.mjs +1 -1
  75. package/dist/math/randomInt.d.mts +11 -3
  76. package/dist/math/randomInt.d.ts +11 -3
  77. package/dist/math/range.d.mts +25 -0
  78. package/dist/math/range.d.ts +25 -0
  79. package/dist/object/invert.d.mts +2 -4
  80. package/dist/object/invert.d.ts +2 -4
  81. package/dist/predicate/index.js +1 -1
  82. package/dist/predicate/isRegExp.d.mts +8 -1
  83. package/dist/predicate/isRegExp.d.ts +8 -1
  84. package/dist/predicate/isSymbol.d.mts +15 -0
  85. package/dist/predicate/isSymbol.d.ts +15 -0
  86. package/dist/predicate/isSymbol.mjs +1 -1
  87. package/dist/string/capitalize.d.mts +1 -1
  88. package/dist/string/capitalize.d.ts +1 -1
  89. package/dist/string/capitalize.mjs +4 -3
  90. package/dist/string/escapeRegExp.d.mts +5 -0
  91. package/dist/string/escapeRegExp.d.ts +5 -0
  92. package/dist/string/escapeRegExp.mjs +1 -1
  93. package/dist/string/index.js +21 -20
  94. package/dist/string/kebabCase.d.mts +1 -1
  95. package/dist/string/kebabCase.d.ts +1 -1
  96. package/dist/string/kebabCase.mjs +3 -3
  97. package/dist/string/lowerCase.d.mts +1 -1
  98. package/dist/string/lowerCase.d.ts +1 -1
  99. package/dist/string/lowerCase.mjs +3 -3
  100. package/dist/string/lowerFirst.d.mts +1 -1
  101. package/dist/string/lowerFirst.d.ts +1 -1
  102. package/dist/string/lowerFirst.mjs +2 -2
  103. package/dist/string/pascalCase.d.mts +1 -1
  104. package/dist/string/pascalCase.d.ts +1 -1
  105. package/dist/string/pascalCase.mjs +3 -3
  106. package/dist/string/snakeCase.d.mts +1 -1
  107. package/dist/string/snakeCase.d.ts +1 -1
  108. package/dist/string/snakeCase.mjs +3 -3
  109. package/dist/string/upperFirst.d.mts +1 -1
  110. package/dist/string/upperFirst.d.ts +1 -1
  111. package/dist/string/upperFirst.mjs +2 -2
  112. package/package.json +2 -1
@@ -16,7 +16,7 @@ function mergeWith(object, ...otherArgs) {
16
16
  return result;
17
17
  }
18
18
  function mergeWithDeep(target, source, merge, stack) {
19
- if (source == null || typeof source !== 'object') {
19
+ if (source == null || typeof source !== "object") {
20
20
  return target;
21
21
  }
22
22
  if (stack.has(source)) {
@@ -40,11 +40,13 @@ function mergeWithDeep(target, source, merge, stack) {
40
40
  if (isArguments(targetValue)) {
41
41
  targetValue = { ...targetValue };
42
42
  }
43
- if (typeof Buffer !== 'undefined' && Buffer.isBuffer(sourceValue)) {
43
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(sourceValue)) {
44
44
  sourceValue = cloneDeep(sourceValue);
45
45
  }
46
46
  if (Array.isArray(sourceValue)) {
47
- targetValue = typeof targetValue === 'object' ? Array.from(targetValue ?? []) : [];
47
+ targetValue = typeof targetValue === "object"
48
+ ? Array.from(targetValue ?? [])
49
+ : [];
48
50
  }
49
51
  const merged = merge(targetValue, sourceValue, key, target, source, stack);
50
52
  if (merged != null) {
@@ -2,7 +2,11 @@ import { isIndex } from '../_internal/isIndex.mjs';
2
2
  import { toPath } from '../_internal/toPath.mjs';
3
3
 
4
4
  function set(obj, path, value) {
5
- const resolvedPath = Array.isArray(path) ? path : typeof path === 'string' ? toPath(path) : [path];
5
+ const resolvedPath = Array.isArray(path)
6
+ ? path
7
+ : typeof path === "string"
8
+ ? toPath(path)
9
+ : [path];
6
10
  let current = obj;
7
11
  for (let i = 0; i < resolvedPath.length - 1; i++) {
8
12
  const key = resolvedPath[i];
@@ -8,7 +8,7 @@ function isMatch(target, source) {
8
8
  return true;
9
9
  }
10
10
  switch (typeof source) {
11
- case 'object': {
11
+ case "object": {
12
12
  if (source == null) {
13
13
  return true;
14
14
  }
@@ -42,7 +42,7 @@ function isMatch(target, source) {
42
42
  }
43
43
  return true;
44
44
  }
45
- case 'function': {
45
+ case "function": {
46
46
  if (Object.keys(source).length > 0) {
47
47
  return isMatch(target, { ...source });
48
48
  }
@@ -15,6 +15,6 @@
15
15
  * const isPrefix = endsWith('fooBar', 'foo', 3) // returns true
16
16
  * const isPrefix = endsWith('fooBar', 'abc', 5) // returns false
17
17
  */
18
- declare const endsWith: (str: string, target: string, position?: number) => boolean;
18
+ declare function endsWith(str: string, target: string, position?: number): boolean;
19
19
 
20
20
  export { endsWith };
@@ -15,6 +15,6 @@
15
15
  * const isPrefix = endsWith('fooBar', 'foo', 3) // returns true
16
16
  * const isPrefix = endsWith('fooBar', 'abc', 5) // returns false
17
17
  */
18
- declare const endsWith: (str: string, target: string, position?: number) => boolean;
18
+ declare function endsWith(str: string, target: string, position?: number): boolean;
19
19
 
20
20
  export { endsWith };
@@ -1,5 +1,5 @@
1
- const endsWith = (str, target, position = str.length) => {
1
+ function endsWith(str, target, position = str.length) {
2
2
  return str.endsWith(target, position);
3
- };
3
+ }
4
4
 
5
5
  export { endsWith };
@@ -5,7 +5,7 @@
5
5
  * the original string is returned unchanged.
6
6
  *
7
7
  * @param {string} str - The string to repeat.
8
- * @param n {number} - The number of times to repeat the string.
8
+ * @param {number} n - The number of times to repeat the string.
9
9
  * @returns {string} - The repeated string, or an empty string if n is less than 1.
10
10
  */
11
11
  declare function repeat(str: string, n: number): string;
@@ -5,7 +5,7 @@
5
5
  * the original string is returned unchanged.
6
6
  *
7
7
  * @param {string} str - The string to repeat.
8
- * @param n {number} - The number of times to repeat the string.
8
+ * @param {number} n - The number of times to repeat the string.
9
9
  * @returns {string} - The repeated string, or an empty string if n is less than 1.
10
10
  */
11
11
  declare function repeat(str: string, n: number): string;
@@ -15,6 +15,6 @@
15
15
  * const isPrefix = startsWith('fooBar', 'Bar', 2) // returns true
16
16
  * const isPrefix = startsWith('fooBar', 'Bar', 5) // returns false
17
17
  */
18
- declare const startsWith: (str: string, target: string, position?: number) => boolean;
18
+ declare function startsWith(str: string, target: string, position?: number): boolean;
19
19
 
20
20
  export { startsWith };
@@ -15,6 +15,6 @@
15
15
  * const isPrefix = startsWith('fooBar', 'Bar', 2) // returns true
16
16
  * const isPrefix = startsWith('fooBar', 'Bar', 5) // returns false
17
17
  */
18
- declare const startsWith: (str: string, target: string, position?: number) => boolean;
18
+ declare function startsWith(str: string, target: string, position?: number): boolean;
19
19
 
20
20
  export { startsWith };
@@ -1,5 +1,5 @@
1
- const startsWith = (str, target, position = 0) => {
1
+ function startsWith(str, target, position = 0) {
2
2
  return str.startsWith(target, position);
3
- };
3
+ }
4
4
 
5
5
  export { startsWith };
@@ -26,6 +26,6 @@
26
26
  * // Will log 'called'.
27
27
  * afterFn()
28
28
  */
29
- declare const after: <F extends (...args: any[]) => any>(n: number, func: F) => F;
29
+ declare function after<F extends (...args: any[]) => any>(n: number, func: F): F;
30
30
 
31
31
  export { after };
@@ -26,6 +26,6 @@
26
26
  * // Will log 'called'.
27
27
  * afterFn()
28
28
  */
29
- declare const after: <F extends (...args: any[]) => any>(n: number, func: F) => F;
29
+ declare function after<F extends (...args: any[]) => any>(n: number, func: F): F;
30
30
 
31
31
  export { after };
@@ -1,4 +1,4 @@
1
- const after = (n, func) => {
1
+ function after(n, func) {
2
2
  if (!Number.isInteger(n) || n < 0) {
3
3
  throw new Error(`n must be a non-negative integer.`);
4
4
  }
@@ -9,6 +9,6 @@ const after = (n, func) => {
9
9
  }
10
10
  return undefined;
11
11
  });
12
- };
12
+ }
13
13
 
14
14
  export { after };
@@ -26,6 +26,6 @@
26
26
  * // Will not log anything.
27
27
  * beforeFn();
28
28
  */
29
- declare const before: <F extends (...args: any[]) => any>(n: number, func: F) => F;
29
+ declare function before<F extends (...args: any[]) => any>(n: number, func: F): F;
30
30
 
31
31
  export { before };
@@ -26,6 +26,6 @@
26
26
  * // Will not log anything.
27
27
  * beforeFn();
28
28
  */
29
- declare const before: <F extends (...args: any[]) => any>(n: number, func: F) => F;
29
+ declare function before<F extends (...args: any[]) => any>(n: number, func: F): F;
30
30
 
31
31
  export { before };
@@ -1,6 +1,6 @@
1
- const before = (n, func) => {
1
+ function before(n, func) {
2
2
  if (!Number.isInteger(n) || n < 0) {
3
- throw new Error('n must be a non-negative integer.');
3
+ throw new Error("n must be a non-negative integer.");
4
4
  }
5
5
  let counter = 0;
6
6
  return ((...args) => {
@@ -9,6 +9,6 @@ const before = (n, func) => {
9
9
  }
10
10
  return undefined;
11
11
  });
12
- };
12
+ }
13
13
 
14
14
  export { before };
@@ -11,7 +11,7 @@ interface DebounceOptions {
11
11
  * @param {number} debounceMs - The number of milliseconds to delay.
12
12
  * @param {DebounceOptions} options - The options object
13
13
  * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.
14
- * @returns {((...args: Parameters<F>) => void) & { cancel: () => void }} A new debounced function with a `cancel` method.
14
+ * @returns A new debounced function with a `cancel` method.
15
15
  *
16
16
  * @example
17
17
  * const debouncedFunction = debounce(() => {
@@ -11,7 +11,7 @@ interface DebounceOptions {
11
11
  * @param {number} debounceMs - The number of milliseconds to delay.
12
12
  * @param {DebounceOptions} options - The options object
13
13
  * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.
14
- * @returns {((...args: Parameters<F>) => void) & { cancel: () => void }} A new debounced function with a `cancel` method.
14
+ * @returns A new debounced function with a `cancel` method.
15
15
  *
16
16
  * @example
17
17
  * const debouncedFunction = debounce(() => {
@@ -21,7 +21,7 @@ function debounce(func, debounceMs, { signal } = {}) {
21
21
  timeoutId = null;
22
22
  }
23
23
  };
24
- signal?.addEventListener('abort', onAbort, { once: true });
24
+ signal?.addEventListener("abort", onAbort, { once: true });
25
25
  return debounced;
26
26
  }
27
27
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const rest = require('../_chunk/rest-Bzm2XK.js');
5
+ const rest = require('../_chunk/rest-CXB7TJ.js');
6
6
 
7
7
  function spread(func) {
8
8
  return function (argsArr) {
@@ -16,7 +16,7 @@
16
16
  * @param {MemoizeCache<any, V>} [options.cache] - The cache object used to store results. Defaults to a new `Map`.
17
17
  * @param {(args: A) => unknown} [options.getCacheKey] - An optional function to generate a unique cache key for each argument.
18
18
  *
19
- * @returns {F & { cache: MemoizeCache<any, ReturnType<F>> }} - The memoized function with an additional `cache` property that exposes the internal cache.
19
+ * @returns The memoized function with an additional `cache` property that exposes the internal cache.
20
20
  *
21
21
  * @example
22
22
  * // Example using the default cache
@@ -76,12 +76,48 @@ declare function memoize<F extends (...args: any) => any>(fn: F, options?: {
76
76
  }): F & {
77
77
  cache: MemoizeCache<any, ReturnType<F>>;
78
78
  };
79
+ /**
80
+ * Represents a cache for memoization, allowing storage and retrieval of computed values.
81
+ *
82
+ * @template K - The type of keys used to store values in the cache.
83
+ * @template V - The type of values stored in the cache.
84
+ */
79
85
  interface MemoizeCache<K, V> {
86
+ /**
87
+ * Stores a value in the cache with the specified key.
88
+ *
89
+ * @param key - The key to associate with the value.
90
+ * @param value - The value to store in the cache.
91
+ */
80
92
  set(key: K, value: V): void;
93
+ /**
94
+ * Retrieves a value from the cache by its key.
95
+ *
96
+ * @param key - The key of the value to retrieve.
97
+ * @returns The value associated with the key, or undefined if the key does not exist.
98
+ */
81
99
  get(key: K): V | undefined;
100
+ /**
101
+ * Checks if a value exists in the cache for the specified key.
102
+ *
103
+ * @param key - The key to check for existence in the cache.
104
+ * @returns True if the cache contains the key, false otherwise.
105
+ */
82
106
  has(key: K): boolean;
107
+ /**
108
+ * Deletes a value from the cache by its key.
109
+ *
110
+ * @param key - The key of the value to delete.
111
+ * @returns True if the value was successfully deleted, false otherwise.
112
+ */
83
113
  delete(key: K): boolean | void;
114
+ /**
115
+ * Clears all values from the cache.
116
+ */
84
117
  clear(): void;
118
+ /**
119
+ * The number of entries in the cache.
120
+ */
85
121
  size: number;
86
122
  }
87
123
 
@@ -16,7 +16,7 @@
16
16
  * @param {MemoizeCache<any, V>} [options.cache] - The cache object used to store results. Defaults to a new `Map`.
17
17
  * @param {(args: A) => unknown} [options.getCacheKey] - An optional function to generate a unique cache key for each argument.
18
18
  *
19
- * @returns {F & { cache: MemoizeCache<any, ReturnType<F>> }} - The memoized function with an additional `cache` property that exposes the internal cache.
19
+ * @returns The memoized function with an additional `cache` property that exposes the internal cache.
20
20
  *
21
21
  * @example
22
22
  * // Example using the default cache
@@ -76,12 +76,48 @@ declare function memoize<F extends (...args: any) => any>(fn: F, options?: {
76
76
  }): F & {
77
77
  cache: MemoizeCache<any, ReturnType<F>>;
78
78
  };
79
+ /**
80
+ * Represents a cache for memoization, allowing storage and retrieval of computed values.
81
+ *
82
+ * @template K - The type of keys used to store values in the cache.
83
+ * @template V - The type of values stored in the cache.
84
+ */
79
85
  interface MemoizeCache<K, V> {
86
+ /**
87
+ * Stores a value in the cache with the specified key.
88
+ *
89
+ * @param key - The key to associate with the value.
90
+ * @param value - The value to store in the cache.
91
+ */
80
92
  set(key: K, value: V): void;
93
+ /**
94
+ * Retrieves a value from the cache by its key.
95
+ *
96
+ * @param key - The key of the value to retrieve.
97
+ * @returns The value associated with the key, or undefined if the key does not exist.
98
+ */
81
99
  get(key: K): V | undefined;
100
+ /**
101
+ * Checks if a value exists in the cache for the specified key.
102
+ *
103
+ * @param key - The key to check for existence in the cache.
104
+ * @returns True if the cache contains the key, false otherwise.
105
+ */
82
106
  has(key: K): boolean;
107
+ /**
108
+ * Deletes a value from the cache by its key.
109
+ *
110
+ * @param key - The key of the value to delete.
111
+ * @returns True if the value was successfully deleted, false otherwise.
112
+ */
83
113
  delete(key: K): boolean | void;
114
+ /**
115
+ * Clears all values from the cache.
116
+ */
84
117
  clear(): void;
118
+ /**
119
+ * The number of entries in the cache.
120
+ */
85
121
  size: number;
86
122
  }
87
123
 
package/dist/index.js CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const initial = require('./_chunk/initial-crEecP.js');
5
+ const initial = require('./_chunk/initial-CMlK06.js');
6
6
  const array_index = require('./array/index.js');
7
7
  const promise_index = require('./_chunk/index-BGZDR9.js');
8
- const rest = require('./_chunk/rest-Bzm2XK.js');
8
+ const rest = require('./_chunk/rest-CXB7TJ.js');
9
9
  const function_index = require('./function/index.js');
10
10
  const math_index = require('./math/index.js');
11
- const randomInt = require('./_chunk/randomInt-CF7bZK.js');
11
+ const randomInt = require('./_chunk/randomInt-DJFj2K.js');
12
12
  const toMerged = require('./_chunk/toMerged-DN1PPP.js');
13
13
  const object_index = require('./object/index.js');
14
14
  const isWeakSet = require('./_chunk/isWeakSet-CogETi.js');
@@ -1,8 +1,21 @@
1
+ /**
2
+ * Clamps a number within the inclusive upper bound.
3
+ *
4
+ * This function takes a number and a maximum bound, and returns the number clamped within the specified upper bound.
5
+ * If only one bound is provided, it returns the minimum of the value and the bound.
6
+ *
7
+ * @param {number} value - The number to clamp.
8
+ * @param {number} maximum - The maximum bound to clamp the number.
9
+ * @returns {number} The clamped number within the specified upper bound.
10
+ *
11
+ * @example
12
+ * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5
13
+ */
14
+ declare function clamp(value: number, maximum: number): number;
1
15
  /**
2
16
  * Clamps a number within the inclusive lower and upper bounds.
3
17
  *
4
18
  * This function takes a number and two bounds, and returns the number clamped within the specified bounds.
5
- * If only one bound is provided, it returns the minimum of the value and the bound.
6
19
  *
7
20
  * @param {number} value - The number to clamp.
8
21
  * @param {number} minimum - The minimum bound to clamp the number.
@@ -10,12 +23,10 @@
10
23
  * @returns {number} The clamped number within the specified bounds.
11
24
  *
12
25
  * @example
13
- * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5
14
26
  * const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15
15
27
  * const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5
16
28
  * const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15
17
29
  */
18
- declare function clamp(value: number, maximum: number): number;
19
30
  declare function clamp(value: number, minimum: number, maximum: number): number;
20
31
 
21
32
  export { clamp };
@@ -1,8 +1,21 @@
1
+ /**
2
+ * Clamps a number within the inclusive upper bound.
3
+ *
4
+ * This function takes a number and a maximum bound, and returns the number clamped within the specified upper bound.
5
+ * If only one bound is provided, it returns the minimum of the value and the bound.
6
+ *
7
+ * @param {number} value - The number to clamp.
8
+ * @param {number} maximum - The maximum bound to clamp the number.
9
+ * @returns {number} The clamped number within the specified upper bound.
10
+ *
11
+ * @example
12
+ * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5
13
+ */
14
+ declare function clamp(value: number, maximum: number): number;
1
15
  /**
2
16
  * Clamps a number within the inclusive lower and upper bounds.
3
17
  *
4
18
  * This function takes a number and two bounds, and returns the number clamped within the specified bounds.
5
- * If only one bound is provided, it returns the minimum of the value and the bound.
6
19
  *
7
20
  * @param {number} value - The number to clamp.
8
21
  * @param {number} minimum - The minimum bound to clamp the number.
@@ -10,12 +23,10 @@
10
23
  * @returns {number} The clamped number within the specified bounds.
11
24
  *
12
25
  * @example
13
- * const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5
14
26
  * const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15
15
27
  * const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5
16
28
  * const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15
17
29
  */
18
- declare function clamp(value: number, maximum: number): number;
19
30
  declare function clamp(value: number, minimum: number, maximum: number): number;
20
31
 
21
32
  export { clamp };
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const randomInt = require('../_chunk/randomInt-CF7bZK.js');
5
+ const randomInt = require('../_chunk/randomInt-DJFj2K.js');
6
6
 
7
7
  function clamp(value, bound1, bound2) {
8
8
  if (bound2 == null) {
@@ -3,6 +3,18 @@
3
3
  *
4
4
  * If only one argument is provided, a number between `0` and the given number is returned.
5
5
  *
6
+ * @param {number} maximum - The upper bound (exclusive).
7
+ * @returns {number} A random number between 0 (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
8
+ * @throws {Error} Throws an error if `maximum` is not greater than `0`.
9
+ *
10
+ * @example
11
+ * const result1 = random(5); // Returns a random number between 0 and 5.
12
+ * const result2 = random(0); // Returns a random number between 0 and 0 (which is 0).
13
+ */
14
+ declare function random(maximum: number): number;
15
+ /**
16
+ * Generate a random number within the given range.
17
+ *
6
18
  * @param {number} minimum - The lower bound (inclusive).
7
19
  * @param {number} maximum - The upper bound (exclusive).
8
20
  * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
@@ -10,10 +22,9 @@
10
22
  *
11
23
  * @example
12
24
  * const result1 = random(0, 5); // Returns a random number between 0 and 5.
13
- * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown
25
+ * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown.
14
26
  * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
15
27
  */
16
- declare function random(maximum: number): number;
17
28
  declare function random(minimum: number, maximum: number): number;
18
29
 
19
30
  export { random };
@@ -3,6 +3,18 @@
3
3
  *
4
4
  * If only one argument is provided, a number between `0` and the given number is returned.
5
5
  *
6
+ * @param {number} maximum - The upper bound (exclusive).
7
+ * @returns {number} A random number between 0 (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
8
+ * @throws {Error} Throws an error if `maximum` is not greater than `0`.
9
+ *
10
+ * @example
11
+ * const result1 = random(5); // Returns a random number between 0 and 5.
12
+ * const result2 = random(0); // Returns a random number between 0 and 0 (which is 0).
13
+ */
14
+ declare function random(maximum: number): number;
15
+ /**
16
+ * Generate a random number within the given range.
17
+ *
6
18
  * @param {number} minimum - The lower bound (inclusive).
7
19
  * @param {number} maximum - The upper bound (exclusive).
8
20
  * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
@@ -10,10 +22,9 @@
10
22
  *
11
23
  * @example
12
24
  * const result1 = random(0, 5); // Returns a random number between 0 and 5.
13
- * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown
25
+ * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown.
14
26
  * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
15
27
  */
16
- declare function random(maximum: number): number;
17
28
  declare function random(minimum: number, maximum: number): number;
18
29
 
19
30
  export { random };
@@ -4,7 +4,7 @@ function random(minimum, maximum) {
4
4
  minimum = 0;
5
5
  }
6
6
  if (minimum >= maximum) {
7
- throw new Error('Invalid input: The maximum value must be greater than the minimum value.');
7
+ throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
8
8
  }
9
9
  return Math.random() * (maximum - minimum) + minimum;
10
10
  }
@@ -1,7 +1,16 @@
1
1
  /**
2
- * Generates a random integer between minimum (inclusive) and maximum (exclusive).
2
+ * Generates a random integer between 0 (inclusive) and the given maximum (exclusive).
3
3
  *
4
- * If only one argument is provided, a number between `0` and the given number is returned.
4
+ * @param {number} maximum - The upper bound (exclusive).
5
+ * @returns {number} A random integer between 0 (inclusive) and maximum (exclusive).
6
+ * @throws {Error} Throws an error if `maximum` is not greater than `0`.
7
+ *
8
+ * @example
9
+ * const result = randomInt(5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)
10
+ */
11
+ declare function randomInt(maximum: number): number;
12
+ /**
13
+ * Generates a random integer between minimum (inclusive) and maximum (exclusive).
5
14
  *
6
15
  * @param {number} minimum - The lower bound (inclusive).
7
16
  * @param {number} maximum - The upper bound (exclusive).
@@ -12,7 +21,6 @@
12
21
  * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)
13
22
  * const result2 = randomInt(5, 0); // This will throw an error
14
23
  */
15
- declare function randomInt(maximum: number): number;
16
24
  declare function randomInt(minimum: number, maximum: number): number;
17
25
 
18
26
  export { randomInt };
@@ -1,7 +1,16 @@
1
1
  /**
2
- * Generates a random integer between minimum (inclusive) and maximum (exclusive).
2
+ * Generates a random integer between 0 (inclusive) and the given maximum (exclusive).
3
3
  *
4
- * If only one argument is provided, a number between `0` and the given number is returned.
4
+ * @param {number} maximum - The upper bound (exclusive).
5
+ * @returns {number} A random integer between 0 (inclusive) and maximum (exclusive).
6
+ * @throws {Error} Throws an error if `maximum` is not greater than `0`.
7
+ *
8
+ * @example
9
+ * const result = randomInt(5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)
10
+ */
11
+ declare function randomInt(maximum: number): number;
12
+ /**
13
+ * Generates a random integer between minimum (inclusive) and maximum (exclusive).
5
14
  *
6
15
  * @param {number} minimum - The lower bound (inclusive).
7
16
  * @param {number} maximum - The upper bound (exclusive).
@@ -12,7 +21,6 @@
12
21
  * const result = randomInt(0, 5); // result will be a random integer between 0 (inclusive) and 5 (exclusive)
13
22
  * const result2 = randomInt(5, 0); // This will throw an error
14
23
  */
15
- declare function randomInt(maximum: number): number;
16
24
  declare function randomInt(minimum: number, maximum: number): number;
17
25
 
18
26
  export { randomInt };
@@ -25,7 +25,32 @@
25
25
  * range(1, 4, 0);
26
26
  */
27
27
  declare function range(end: number): number[];
28
+ /**
29
+ * Returns an array of numbers from `start` to `end`, incrementing by `step`.
30
+ *
31
+ * If `step` is not provided, it defaults to `1`.
32
+ *
33
+ * @param {number} start - The starting number of the range (inclusive).
34
+ * @param {number} end - The end number of the range (exclusive).
35
+ * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.
36
+ *
37
+ * @example
38
+ * // Returns [1, 2, 3]
39
+ * range(1, 4);
40
+ */
28
41
  declare function range(start: number, end: number): number[];
42
+ /**
43
+ * Returns an array of numbers from `start` to `end`, incrementing by `step`.
44
+ *
45
+ * @param {number} start - The starting number of the range (inclusive).
46
+ * @param {number} end - The end number of the range (exclusive).
47
+ * @param {number} step - The step value for the range.
48
+ * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.
49
+ *
50
+ * @example
51
+ * // Returns [0, 5, 10, 15]
52
+ * range(0, 20, 5);
53
+ */
29
54
  declare function range(start: number, end: number, step: number): number[];
30
55
 
31
56
  export { range };
@@ -25,7 +25,32 @@
25
25
  * range(1, 4, 0);
26
26
  */
27
27
  declare function range(end: number): number[];
28
+ /**
29
+ * Returns an array of numbers from `start` to `end`, incrementing by `step`.
30
+ *
31
+ * If `step` is not provided, it defaults to `1`.
32
+ *
33
+ * @param {number} start - The starting number of the range (inclusive).
34
+ * @param {number} end - The end number of the range (exclusive).
35
+ * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.
36
+ *
37
+ * @example
38
+ * // Returns [1, 2, 3]
39
+ * range(1, 4);
40
+ */
28
41
  declare function range(start: number, end: number): number[];
42
+ /**
43
+ * Returns an array of numbers from `start` to `end`, incrementing by `step`.
44
+ *
45
+ * @param {number} start - The starting number of the range (inclusive).
46
+ * @param {number} end - The end number of the range (exclusive).
47
+ * @param {number} step - The step value for the range.
48
+ * @returns {number[]} An array of numbers from `start` to `end` with the specified `step`.
49
+ *
50
+ * @example
51
+ * // Returns [0, 5, 10, 15]
52
+ * range(0, 20, 5);
53
+ */
29
54
  declare function range(start: number, end: number, step: number): number[];
30
55
 
31
56
  export { range };