es-toolkit 1.20.0 → 1.21.0-dev.660

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 (126) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/_chunk/{isWeakSet-E_VMwB.js → isWeakSet-1xFSnK.js} +5 -0
  3. package/dist/_chunk/{toMerged-Bzkqyz.js → toMerged-D-sLFv.js} +10 -8
  4. package/dist/_chunk/{zipWith-CDtN9Y.js → zipWith-DEcUS4.js} +25 -12
  5. package/dist/array/compact.d.mts +4 -4
  6. package/dist/array/compact.d.ts +4 -4
  7. package/dist/array/compact.mjs +2 -1
  8. package/dist/array/countBy.mjs +2 -1
  9. package/dist/array/flatten.mjs +2 -1
  10. package/dist/array/groupBy.mjs +2 -1
  11. package/dist/array/index.js +1 -1
  12. package/dist/array/keyBy.mjs +2 -1
  13. package/dist/array/maxBy.d.mts +16 -0
  14. package/dist/array/maxBy.d.ts +16 -0
  15. package/dist/array/maxBy.mjs +2 -1
  16. package/dist/array/minBy.d.mts +16 -0
  17. package/dist/array/minBy.d.ts +16 -0
  18. package/dist/array/minBy.mjs +2 -1
  19. package/dist/array/partition.mjs +2 -1
  20. package/dist/array/takeWhile.mjs +2 -1
  21. package/dist/array/unionBy.mjs +3 -1
  22. package/dist/array/uniqBy.mjs +2 -1
  23. package/dist/array/uniqWith.mjs +2 -1
  24. package/dist/browser.global.js +1 -1
  25. package/dist/browser.global.js.map +1 -1
  26. package/dist/compat/array/castArray.d.mts +2 -2
  27. package/dist/compat/array/castArray.d.ts +2 -2
  28. package/dist/compat/array/flatten.mjs +2 -1
  29. package/dist/compat/function/curry.mjs +26 -34
  30. package/dist/compat/function/defer.d.mts +16 -0
  31. package/dist/compat/function/defer.d.ts +16 -0
  32. package/dist/compat/function/defer.mjs +8 -0
  33. package/dist/compat/index.d.mts +13 -5
  34. package/dist/compat/index.d.ts +13 -5
  35. package/dist/compat/index.js +200 -71
  36. package/dist/compat/index.mjs +14 -6
  37. package/dist/compat/math/inRange.d.mts +27 -0
  38. package/dist/compat/math/inRange.d.ts +27 -0
  39. package/dist/compat/math/inRange.mjs +28 -0
  40. package/dist/compat/math/max.mjs +2 -1
  41. package/dist/compat/math/min.mjs +2 -1
  42. package/dist/compat/math/random.d.mts +50 -0
  43. package/dist/compat/math/random.d.ts +50 -0
  44. package/dist/compat/math/random.mjs +70 -0
  45. package/dist/compat/object/cloneDeep.d.mts +49 -0
  46. package/dist/compat/object/cloneDeep.d.ts +49 -0
  47. package/dist/compat/object/pick.mjs +2 -1
  48. package/dist/compat/predicate/conformsTo.mjs +3 -1
  49. package/dist/compat/predicate/isArrayLikeObject.d.mts +15 -0
  50. package/dist/compat/predicate/isArrayLikeObject.d.ts +15 -0
  51. package/dist/compat/predicate/isArrayLikeObject.mjs +8 -0
  52. package/dist/compat/predicate/isBoolean.d.mts +3 -3
  53. package/dist/compat/predicate/isBoolean.d.ts +3 -3
  54. package/dist/compat/predicate/isBoolean.mjs +2 -10
  55. package/dist/compat/predicate/isError.d.mts +16 -0
  56. package/dist/compat/predicate/isError.d.ts +16 -0
  57. package/dist/compat/predicate/isError.mjs +7 -0
  58. package/dist/compat/predicate/isFinite.d.mts +20 -0
  59. package/dist/compat/predicate/isFinite.d.ts +20 -0
  60. package/dist/compat/predicate/isFinite.mjs +5 -0
  61. package/dist/compat/predicate/isNil.d.mts +22 -0
  62. package/dist/compat/predicate/isNil.d.ts +22 -0
  63. package/dist/compat/predicate/isNumber.mjs +1 -6
  64. package/dist/compat/predicate/isRegExp.mjs +2 -2
  65. package/dist/compat/predicate/isString.d.mts +1 -1
  66. package/dist/compat/predicate/isString.d.ts +1 -1
  67. package/dist/compat/predicate/isString.mjs +1 -9
  68. package/dist/compat/predicate/isSymbol.mjs +1 -1
  69. package/dist/compat/string/pad.d.mts +19 -0
  70. package/dist/compat/string/pad.d.ts +19 -0
  71. package/dist/compat/string/pad.mjs +8 -0
  72. package/dist/compat/string/padEnd.mjs +3 -1
  73. package/dist/compat/string/padStart.mjs +3 -1
  74. package/dist/compat/util/toFinite.d.mts +17 -0
  75. package/dist/compat/util/toFinite.d.ts +17 -0
  76. package/dist/compat/util/toFinite.mjs +15 -0
  77. package/dist/compat/util/toInteger.d.mts +17 -0
  78. package/dist/compat/util/toInteger.d.ts +17 -0
  79. package/dist/compat/util/toInteger.mjs +9 -0
  80. package/dist/compat/util/toNumber.d.mts +19 -0
  81. package/dist/compat/util/toNumber.d.ts +19 -0
  82. package/dist/compat/util/toNumber.mjs +10 -0
  83. package/dist/function/curry.d.mts +18 -19
  84. package/dist/function/curry.d.ts +18 -19
  85. package/dist/index.d.mts +2 -0
  86. package/dist/index.d.ts +2 -0
  87. package/dist/index.js +10 -8
  88. package/dist/index.mjs +2 -0
  89. package/dist/math/random.d.mts +1 -1
  90. package/dist/math/random.d.ts +1 -1
  91. package/dist/math/range.d.mts +7 -25
  92. package/dist/math/range.d.ts +7 -25
  93. package/dist/object/index.js +8 -4
  94. package/dist/object/omit.d.mts +1 -1
  95. package/dist/object/omit.d.ts +1 -1
  96. package/dist/object/omit.mjs +2 -1
  97. package/dist/object/omitBy.mjs +5 -4
  98. package/dist/object/pick.mjs +5 -2
  99. package/dist/object/pickBy.mjs +5 -4
  100. package/dist/predicate/index.d.mts +1 -0
  101. package/dist/predicate/index.d.ts +1 -0
  102. package/dist/predicate/index.js +5 -4
  103. package/dist/predicate/index.mjs +1 -0
  104. package/dist/predicate/isError.d.mts +16 -0
  105. package/dist/predicate/isError.d.ts +16 -0
  106. package/dist/predicate/isError.mjs +5 -0
  107. package/dist/promise/withTimeout.d.mts +8 -2
  108. package/dist/promise/withTimeout.d.ts +8 -2
  109. package/dist/string/_internal/getWords.mjs +1 -1
  110. package/dist/string/camelCase.d.mts +1 -0
  111. package/dist/string/camelCase.d.ts +1 -0
  112. package/dist/string/constantCase.d.mts +17 -0
  113. package/dist/string/constantCase.d.ts +17 -0
  114. package/dist/string/constantCase.mjs +8 -0
  115. package/dist/string/index.d.mts +1 -0
  116. package/dist/string/index.d.ts +1 -0
  117. package/dist/string/index.js +10 -8
  118. package/dist/string/index.mjs +1 -0
  119. package/dist/string/startCase.d.mts +1 -1
  120. package/dist/string/startCase.d.ts +1 -1
  121. package/dist/string/startCase.mjs +3 -7
  122. package/dist/string/trimStart.d.mts +1 -1
  123. package/dist/string/trimStart.d.ts +1 -1
  124. package/dist/string/upperFirst.d.mts +3 -3
  125. package/dist/string/upperFirst.d.ts +3 -3
  126. package/package.json +2 -1
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Generate a random number within 0 and 1.
3
+ *
4
+ * @returns {number} A random number between 0 (inclusive) and 1 (exclusive). The number can be an integer or a decimal.
5
+ * @throws {Error} Throws an error if `maximum` is not greater than `0`.
6
+ *
7
+ * @example
8
+ * const result = random(); // Returns a random number between 0 and 1.
9
+ */
10
+ declare function random(floating?: boolean): number;
11
+ /**
12
+ * Generate a random number within 0 and 1.
13
+ *
14
+ * @returns {number} A random number between 0 (inclusive) and 1 (exclusive). The number can be an integer or a decimal.
15
+ * @throws {Error} Throws an error if `maximum` is not greater than `0`.
16
+ *
17
+ * @example
18
+ * const result = random(); // Returns a random number between 0 and 1.
19
+ */
20
+ declare function random(min: number, index: string | number, guard: object): number;
21
+ /**
22
+ * Generate a random number within the given range.
23
+ *
24
+ * If only one argument is provided, a number between `0` and the given number is returned.
25
+ *
26
+ * @param {number} maximum - The upper bound (exclusive).
27
+ * @returns {number} A random number between 0 (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
28
+ * @throws {Error} Throws an error if `maximum` is not greater than `0`.
29
+ *
30
+ * @example
31
+ * const result1 = random(5); // Returns a random number between 0 and 5.
32
+ * const result2 = random(0); // Returns a random number between 0 and 0 (which is 0).
33
+ */
34
+ declare function random(maximum: number, floating?: boolean): number;
35
+ /**
36
+ * Generate a random number within the given range.
37
+ *
38
+ * @param {number} minimum - The lower bound (inclusive).
39
+ * @param {number} maximum - The upper bound (exclusive).
40
+ * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
41
+ * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
42
+ *
43
+ * @example
44
+ * const result1 = random(0, 5); // Returns a random number between 0 and 5.
45
+ * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown.
46
+ * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
47
+ */
48
+ declare function random(minimum: number, maximum: number, floating?: boolean): number;
49
+
50
+ export { random };
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Generate a random number within 0 and 1.
3
+ *
4
+ * @returns {number} A random number between 0 (inclusive) and 1 (exclusive). The number can be an integer or a decimal.
5
+ * @throws {Error} Throws an error if `maximum` is not greater than `0`.
6
+ *
7
+ * @example
8
+ * const result = random(); // Returns a random number between 0 and 1.
9
+ */
10
+ declare function random(floating?: boolean): number;
11
+ /**
12
+ * Generate a random number within 0 and 1.
13
+ *
14
+ * @returns {number} A random number between 0 (inclusive) and 1 (exclusive). The number can be an integer or a decimal.
15
+ * @throws {Error} Throws an error if `maximum` is not greater than `0`.
16
+ *
17
+ * @example
18
+ * const result = random(); // Returns a random number between 0 and 1.
19
+ */
20
+ declare function random(min: number, index: string | number, guard: object): number;
21
+ /**
22
+ * Generate a random number within the given range.
23
+ *
24
+ * If only one argument is provided, a number between `0` and the given number is returned.
25
+ *
26
+ * @param {number} maximum - The upper bound (exclusive).
27
+ * @returns {number} A random number between 0 (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
28
+ * @throws {Error} Throws an error if `maximum` is not greater than `0`.
29
+ *
30
+ * @example
31
+ * const result1 = random(5); // Returns a random number between 0 and 5.
32
+ * const result2 = random(0); // Returns a random number between 0 and 0 (which is 0).
33
+ */
34
+ declare function random(maximum: number, floating?: boolean): number;
35
+ /**
36
+ * Generate a random number within the given range.
37
+ *
38
+ * @param {number} minimum - The lower bound (inclusive).
39
+ * @param {number} maximum - The upper bound (exclusive).
40
+ * @returns {number} A random number between minimum (inclusive) and maximum (exclusive). The number can be an integer or a decimal.
41
+ * @throws {Error} Throws an error if `maximum` is not greater than `minimum`.
42
+ *
43
+ * @example
44
+ * const result1 = random(0, 5); // Returns a random number between 0 and 5.
45
+ * const result2 = random(5, 0); // If the minimum is greater than the maximum, an error is thrown.
46
+ * const result3 = random(5, 5); // If the minimum is equal to the maximum, an error is thrown.
47
+ */
48
+ declare function random(minimum: number, maximum: number, floating?: boolean): number;
49
+
50
+ export { random };
@@ -0,0 +1,70 @@
1
+ import { random as random$1 } from '../../math/random.mjs';
2
+ import { randomInt } from '../../math/randomInt.mjs';
3
+ import { clamp } from './clamp.mjs';
4
+
5
+ function random(...args) {
6
+ let minimum = 0;
7
+ let maximum = 1;
8
+ let floating = false;
9
+ switch (args.length) {
10
+ case 1: {
11
+ if (typeof args[0] === 'boolean') {
12
+ floating = args[0];
13
+ }
14
+ else {
15
+ maximum = args[0];
16
+ }
17
+ break;
18
+ }
19
+ case 2: {
20
+ if (typeof args[1] === 'boolean') {
21
+ maximum = args[0];
22
+ floating = args[1];
23
+ }
24
+ else {
25
+ minimum = args[0];
26
+ maximum = args[1];
27
+ }
28
+ }
29
+ case 3: {
30
+ if (typeof args[2] === 'object' && args[2] != null && args[2][args[1]] === args[0]) {
31
+ minimum = 0;
32
+ maximum = args[0];
33
+ floating = false;
34
+ }
35
+ else {
36
+ minimum = args[0];
37
+ maximum = args[1];
38
+ floating = args[2];
39
+ }
40
+ }
41
+ }
42
+ if (typeof minimum !== 'number') {
43
+ minimum = Number(minimum);
44
+ }
45
+ if (typeof maximum !== 'number') {
46
+ minimum = Number(maximum);
47
+ }
48
+ if (!minimum) {
49
+ minimum = 0;
50
+ }
51
+ if (!maximum) {
52
+ maximum = 0;
53
+ }
54
+ if (minimum > maximum) {
55
+ [minimum, maximum] = [maximum, minimum];
56
+ }
57
+ minimum = clamp(minimum, -Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
58
+ maximum = clamp(maximum, -Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
59
+ if (minimum === maximum) {
60
+ return minimum;
61
+ }
62
+ if (floating) {
63
+ return random$1(minimum, maximum + 1);
64
+ }
65
+ else {
66
+ return randomInt(minimum, maximum + 1);
67
+ }
68
+ }
69
+
70
+ export { random };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Creates a deep clone of the given object.
3
+ *
4
+ * @template T - The type of the object.
5
+ * @param {T} obj - The object to clone.
6
+ * @returns {T} - A deep clone of the given object.
7
+ *
8
+ * @example
9
+ * // Clone a primitive values
10
+ * const num = 29;
11
+ * const clonedNum = clone(num);
12
+ * console.log(clonedNum); // 29
13
+ * console.log(clonedNum === num) ; // true
14
+ *
15
+ * @example
16
+ * // Clone an array
17
+ * const arr = [1, 2, 3];
18
+ * const clonedArr = clone(arr);
19
+ * console.log(clonedArr); // [1, 2, 3]
20
+ * console.log(clonedArr === arr); // false
21
+ *
22
+ * @example
23
+ * // Clone an array with nested objects
24
+ * const arr = [1, { a: 1 }, [1, 2, 3]];
25
+ * const clonedArr = clone(arr);
26
+ * arr[1].a = 2;
27
+ * console.log(arr); // [2, { a: 2 }, [1, 2, 3]]
28
+ * console.log(clonedArr); // [1, { a: 1 }, [1, 2, 3]]
29
+ * console.log(clonedArr === arr); // false
30
+ *
31
+ * @example
32
+ * // Clone an object
33
+ * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
34
+ * const clonedObj = clone(obj);
35
+ * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
36
+ * console.log(clonedObj === obj); // false
37
+ *
38
+ * @example
39
+ * // Clone an object with nested objects
40
+ * const obj = { a: 1, b: { c: 1 } };
41
+ * const clonedObj = clone(obj);
42
+ * obj.b.c = 2;
43
+ * console.log(obj); // { a: 1, b: { c: 2 } }
44
+ * console.log(clonedObj); // { a: 1, b: { c: 1 } }
45
+ * console.log(clonedObj === obj); // false
46
+ */
47
+ declare function cloneDeep<T>(obj: T): T;
48
+
49
+ export { cloneDeep };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Creates a deep clone of the given object.
3
+ *
4
+ * @template T - The type of the object.
5
+ * @param {T} obj - The object to clone.
6
+ * @returns {T} - A deep clone of the given object.
7
+ *
8
+ * @example
9
+ * // Clone a primitive values
10
+ * const num = 29;
11
+ * const clonedNum = clone(num);
12
+ * console.log(clonedNum); // 29
13
+ * console.log(clonedNum === num) ; // true
14
+ *
15
+ * @example
16
+ * // Clone an array
17
+ * const arr = [1, 2, 3];
18
+ * const clonedArr = clone(arr);
19
+ * console.log(clonedArr); // [1, 2, 3]
20
+ * console.log(clonedArr === arr); // false
21
+ *
22
+ * @example
23
+ * // Clone an array with nested objects
24
+ * const arr = [1, { a: 1 }, [1, 2, 3]];
25
+ * const clonedArr = clone(arr);
26
+ * arr[1].a = 2;
27
+ * console.log(arr); // [2, { a: 2 }, [1, 2, 3]]
28
+ * console.log(clonedArr); // [1, { a: 1 }, [1, 2, 3]]
29
+ * console.log(clonedArr === arr); // false
30
+ *
31
+ * @example
32
+ * // Clone an object
33
+ * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
34
+ * const clonedObj = clone(obj);
35
+ * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
36
+ * console.log(clonedObj === obj); // false
37
+ *
38
+ * @example
39
+ * // Clone an object with nested objects
40
+ * const obj = { a: 1, b: { c: 1 } };
41
+ * const clonedObj = clone(obj);
42
+ * obj.b.c = 2;
43
+ * console.log(obj); // { a: 1, b: { c: 2 } }
44
+ * console.log(clonedObj); // { a: 1, b: { c: 1 } }
45
+ * console.log(clonedObj === obj); // false
46
+ */
47
+ declare function cloneDeep<T>(obj: T): T;
48
+
49
+ export { cloneDeep };
@@ -7,7 +7,8 @@ function pick(obj, ...keysArr) {
7
7
  return {};
8
8
  }
9
9
  const result = {};
10
- for (let keys of keysArr) {
10
+ for (let i = 0; i < keysArr.length; i++) {
11
+ let keys = keysArr[i];
11
12
  switch (typeof keys) {
12
13
  case 'object': {
13
14
  if (!Array.isArray(keys)) {
@@ -5,7 +5,9 @@ function conformsTo(target, source) {
5
5
  if (target == null) {
6
6
  return Object.keys(source).length === 0;
7
7
  }
8
- for (const key of Object.keys(source)) {
8
+ const keys = Object.keys(source);
9
+ for (let i = 0; i < keys.length; i++) {
10
+ const key = keys[i];
9
11
  const predicate = source[key];
10
12
  const value = target[key];
11
13
  if ((value === undefined && !(key in target)) || !predicate(value)) {
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Checks if the given value is a non-primitive, array-like object.
3
+ *
4
+ * @param {unknown} value The value to check.
5
+ * @returns {value is ArrayLike<unknown> & object} `true` if the value is a non-primitive, array-like object, `false` otherwise.
6
+ *
7
+ * @example
8
+ * isArrayLikeObject([1, 2, 3]); // true
9
+ * isArrayLikeObject({ 0: 'a', length: 1 }); // true
10
+ * isArrayLikeObject('abc'); // false
11
+ * isArrayLikeObject(()=>{}); // false
12
+ */
13
+ declare function isArrayLikeObject(value: unknown): value is ArrayLike<unknown> & object;
14
+
15
+ export { isArrayLikeObject };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Checks if the given value is a non-primitive, array-like object.
3
+ *
4
+ * @param {unknown} value The value to check.
5
+ * @returns {value is ArrayLike<unknown> & object} `true` if the value is a non-primitive, array-like object, `false` otherwise.
6
+ *
7
+ * @example
8
+ * isArrayLikeObject([1, 2, 3]); // true
9
+ * isArrayLikeObject({ 0: 'a', length: 1 }); // true
10
+ * isArrayLikeObject('abc'); // false
11
+ * isArrayLikeObject(()=>{}); // false
12
+ */
13
+ declare function isArrayLikeObject(value: unknown): value is ArrayLike<unknown> & object;
14
+
15
+ export { isArrayLikeObject };
@@ -0,0 +1,8 @@
1
+ import { isArrayLike } from './isArrayLike.mjs';
2
+ import { isObjectLike } from './isObjectLike.mjs';
3
+
4
+ function isArrayLikeObject(value) {
5
+ return isObjectLike(value) && isArrayLike(value);
6
+ }
7
+
8
+ export { isArrayLikeObject };
@@ -6,8 +6,8 @@
6
6
  *
7
7
  * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `boolean`.
8
8
  *
9
- * @param {unknown} x - The Value to test if it is boolean.
10
- * @returns {x is boolean} True if the value is boolean, false otherwise.
9
+ * @param {unknown} value - The Value to test if it is boolean.
10
+ * @returns {value is boolean} True if the value is boolean, false otherwise.
11
11
  *
12
12
  * @example
13
13
  *
@@ -20,6 +20,6 @@
20
20
  * console.log(isBoolean(value3)); // false
21
21
  *
22
22
  */
23
- declare function isBoolean(x: unknown): x is boolean;
23
+ declare function isBoolean(value?: unknown): value is boolean;
24
24
 
25
25
  export { isBoolean };
@@ -6,8 +6,8 @@
6
6
  *
7
7
  * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `boolean`.
8
8
  *
9
- * @param {unknown} x - The Value to test if it is boolean.
10
- * @returns {x is boolean} True if the value is boolean, false otherwise.
9
+ * @param {unknown} value - The Value to test if it is boolean.
10
+ * @returns {value is boolean} True if the value is boolean, false otherwise.
11
11
  *
12
12
  * @example
13
13
  *
@@ -20,6 +20,6 @@
20
20
  * console.log(isBoolean(value3)); // false
21
21
  *
22
22
  */
23
- declare function isBoolean(x: unknown): x is boolean;
23
+ declare function isBoolean(value?: unknown): value is boolean;
24
24
 
25
25
  export { isBoolean };
@@ -1,13 +1,5 @@
1
- import { getTag } from '../_internal/getTag.mjs';
2
-
3
- function isBoolean(x) {
4
- if (x === true || x === false) {
5
- return true;
6
- }
7
- if (typeof x === 'object' && x != null && getTag(x) === '[object Boolean]') {
8
- return true;
9
- }
10
- return false;
1
+ function isBoolean(value) {
2
+ return typeof value === 'boolean' || value instanceof Boolean;
11
3
  }
12
4
 
13
5
  export { isBoolean };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Checks if `value` is an Error object.
3
+ *
4
+ * @param {unknown} value The value to check.
5
+ * @returns {value is Error} Returns `true` if `value` is an Error object, `false` otherwise.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * console.log(isError(new Error())); // true
10
+ * console.log(isError('Error')); // false
11
+ * console.log(isError({ name: 'Error', message: '' })); // false
12
+ * ```
13
+ */
14
+ declare function isError(value?: unknown): value is Error;
15
+
16
+ export { isError };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Checks if `value` is an Error object.
3
+ *
4
+ * @param {unknown} value The value to check.
5
+ * @returns {value is Error} Returns `true` if `value` is an Error object, `false` otherwise.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * console.log(isError(new Error())); // true
10
+ * console.log(isError('Error')); // false
11
+ * console.log(isError({ name: 'Error', message: '' })); // false
12
+ * ```
13
+ */
14
+ declare function isError(value?: unknown): value is Error;
15
+
16
+ export { isError };
@@ -0,0 +1,7 @@
1
+ import { getTag } from '../_internal/getTag.mjs';
2
+
3
+ function isError(value) {
4
+ return getTag(value) === '[object Error]';
5
+ }
6
+
7
+ export { isError };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checks if `value` is a finite number.
3
+ *
4
+ * @param {unknown} value The value to check.
5
+ * @returns {value is number} Returns `true` if `value` is a finite number, `false` otherwise.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const value1 = 100;
10
+ * const value2 = Infinity;
11
+ * const value3 = '100';
12
+ *
13
+ * console.log(isFinite(value1)); // true
14
+ * console.log(isFinite(value2)); // false
15
+ * console.log(isFinite(value3)); // false
16
+ * ```
17
+ */
18
+ declare function isFinite(value: unknown): value is number;
19
+
20
+ export { isFinite };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checks if `value` is a finite number.
3
+ *
4
+ * @param {unknown} value The value to check.
5
+ * @returns {value is number} Returns `true` if `value` is a finite number, `false` otherwise.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const value1 = 100;
10
+ * const value2 = Infinity;
11
+ * const value3 = '100';
12
+ *
13
+ * console.log(isFinite(value1)); // true
14
+ * console.log(isFinite(value2)); // false
15
+ * console.log(isFinite(value3)); // false
16
+ * ```
17
+ */
18
+ declare function isFinite(value: unknown): value is number;
19
+
20
+ export { isFinite };
@@ -0,0 +1,5 @@
1
+ function isFinite(value) {
2
+ return Number.isFinite(value);
3
+ }
4
+
5
+ export { isFinite };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Checks if a given value is null or undefined.
3
+ *
4
+ * This function tests whether the provided value is either `null` or `undefined`.
5
+ * It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
6
+ *
7
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
8
+ *
9
+ * @param {unknown} x - The value to test for null or undefined.
10
+ * @returns {boolean} `true` if the value is null or undefined, `false` otherwise.
11
+ *
12
+ * @example
13
+ * const value1 = null;
14
+ * const value2 = undefined;
15
+ * const value3 = 42;
16
+ * const result1 = isNil(value1); // true
17
+ * const result2 = isNil(value2); // true
18
+ * const result3 = isNil(value3); // false
19
+ */
20
+ declare function isNil(x?: unknown): x is null | undefined;
21
+
22
+ export { isNil };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Checks if a given value is null or undefined.
3
+ *
4
+ * This function tests whether the provided value is either `null` or `undefined`.
5
+ * It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
6
+ *
7
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
8
+ *
9
+ * @param {unknown} x - The value to test for null or undefined.
10
+ * @returns {boolean} `true` if the value is null or undefined, `false` otherwise.
11
+ *
12
+ * @example
13
+ * const value1 = null;
14
+ * const value2 = undefined;
15
+ * const value3 = 42;
16
+ * const result1 = isNil(value1); // true
17
+ * const result2 = isNil(value2); // true
18
+ * const result3 = isNil(value3); // false
19
+ */
20
+ declare function isNil(x?: unknown): x is null | undefined;
21
+
22
+ export { isNil };
@@ -1,10 +1,5 @@
1
- import { getTag } from '../_internal/getTag.mjs';
2
-
3
1
  function isNumber(value) {
4
- if (typeof value === 'object' && value != null && getTag(value) === '[object Number]') {
5
- return true;
6
- }
7
- return typeof value === 'number';
2
+ return typeof value === 'number' || value instanceof Number;
8
3
  }
9
4
 
10
5
  export { isNumber };
@@ -1,7 +1,7 @@
1
- import { getTag } from '../_internal/getTag.mjs';
1
+ import { isRegExp as isRegExp$1 } from '../../predicate/isRegExp.mjs';
2
2
 
3
3
  function isRegExp(value) {
4
- return getTag(value) === '[object RegExp]';
4
+ return isRegExp$1(value);
5
5
  }
6
6
 
7
7
  export { isRegExp };
@@ -15,6 +15,6 @@
15
15
  * console.log(isString(value2)); // false
16
16
  * console.log(isString(value3)); // false
17
17
  */
18
- declare function isString(value: unknown): value is string;
18
+ declare function isString(value?: unknown): value is string;
19
19
 
20
20
  export { isString };
@@ -15,6 +15,6 @@
15
15
  * console.log(isString(value2)); // false
16
16
  * console.log(isString(value3)); // false
17
17
  */
18
- declare function isString(value: unknown): value is string;
18
+ declare function isString(value?: unknown): value is string;
19
19
 
20
20
  export { isString };
@@ -1,13 +1,5 @@
1
- import { getTag } from '../_internal/getTag.mjs';
2
-
3
1
  function isString(value) {
4
- if (typeof value === 'string') {
5
- return true;
6
- }
7
- if (typeof value === 'object' && value != null && getTag(value) === '[object String]') {
8
- return true;
9
- }
10
- return false;
2
+ return typeof value === 'string' || value instanceof String;
11
3
  }
12
4
 
13
5
  export { isString };
@@ -1,5 +1,5 @@
1
1
  function isSymbol(value) {
2
- return typeof value === 'symbol' || (value != null && value instanceof Symbol);
2
+ return typeof value === 'symbol' || value instanceof Symbol;
3
3
  }
4
4
 
5
5
  export { isSymbol };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.
3
+ * If the length is less than or equal to the original string's length, or if the padding character is an empty string, the original string is returned unchanged.
4
+ *
5
+ * @param {string} str - The string to pad.
6
+ * @param {number} [length] - The length of the resulting string once padded.
7
+ * @param {string} [chars] - The character(s) to use for padding.
8
+ * @returns {string} - The padded string, or the original string if padding is not required.
9
+ *
10
+ * @example
11
+ * const result1 = pad('abc', 8); // result will be ' abc '
12
+ * const result2 = pad('abc', 8, '_-'); // result will be '_-abc_-_'
13
+ * const result3 = pad('abc', 3); // result will be 'abc'
14
+ * const result4 = pad('abc', 2); // result will be 'abc'
15
+ *
16
+ */
17
+ declare function pad(str: string, length: number, chars?: string): string;
18
+
19
+ export { pad };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.
3
+ * If the length is less than or equal to the original string's length, or if the padding character is an empty string, the original string is returned unchanged.
4
+ *
5
+ * @param {string} str - The string to pad.
6
+ * @param {number} [length] - The length of the resulting string once padded.
7
+ * @param {string} [chars] - The character(s) to use for padding.
8
+ * @returns {string} - The padded string, or the original string if padding is not required.
9
+ *
10
+ * @example
11
+ * const result1 = pad('abc', 8); // result will be ' abc '
12
+ * const result2 = pad('abc', 8, '_-'); // result will be '_-abc_-_'
13
+ * const result3 = pad('abc', 3); // result will be 'abc'
14
+ * const result4 = pad('abc', 2); // result will be 'abc'
15
+ *
16
+ */
17
+ declare function pad(str: string, length: number, chars?: string): string;
18
+
19
+ export { pad };
@@ -0,0 +1,8 @@
1
+ import { pad as pad$1 } from '../../string/pad.mjs';
2
+ import { toString } from '../util/toString.mjs';
3
+
4
+ function pad(str, length, chars = ' ') {
5
+ return pad$1(toString(str), length, chars);
6
+ }
7
+
8
+ export { pad };
@@ -1,5 +1,7 @@
1
+ import { toString } from '../util/toString.mjs';
2
+
1
3
  function padEnd(str, length = 0, chars = ' ') {
2
- return str.padEnd(length, chars);
4
+ return toString(str).padEnd(length, chars);
3
5
  }
4
6
 
5
7
  export { padEnd };