es-toolkit 1.15.1 → 1.16.0-dev.455

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 (99) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/_chunk/{initial-CBsbzo.js → initial-y0QrPY.js} +28 -0
  3. package/dist/_chunk/{isFunction-D0hq6d.js → isFunction-aCEz9d.js} +5 -7
  4. package/dist/_chunk/{isObjectLike-BeLCsr.js → toMerged-BGwYW5.js} +25 -0
  5. package/dist/_internal/compareValues.mjs +11 -0
  6. package/dist/array/index.d.mts +1 -0
  7. package/dist/array/index.d.ts +1 -0
  8. package/dist/array/index.js +3 -11
  9. package/dist/array/index.mjs +1 -0
  10. package/dist/array/orderBy.mjs +2 -9
  11. package/dist/array/sortBy.d.mts +35 -0
  12. package/dist/array/sortBy.d.ts +35 -0
  13. package/dist/array/sortBy.mjs +19 -0
  14. package/dist/browser.global.js +1 -1
  15. package/dist/browser.global.js.map +1 -1
  16. package/dist/compat/_internal/getSymbols.mjs +1 -2
  17. package/dist/compat/_internal/toKey.mjs +13 -0
  18. package/dist/compat/array/find.d.mts +122 -0
  19. package/dist/compat/array/find.d.ts +122 -0
  20. package/dist/compat/array/find.mjs +42 -0
  21. package/dist/compat/array/findIndex.d.mts +62 -0
  22. package/dist/compat/array/findIndex.d.ts +62 -0
  23. package/dist/compat/array/findIndex.mjs +26 -0
  24. package/dist/compat/array/indexOf.d.mts +21 -0
  25. package/dist/compat/array/indexOf.d.ts +21 -0
  26. package/dist/compat/array/indexOf.mjs +20 -0
  27. package/dist/compat/function/ary.d.mts +2 -1
  28. package/dist/compat/function/ary.d.ts +2 -1
  29. package/dist/compat/function/bind.d.mts +3 -1
  30. package/dist/compat/function/bind.d.ts +3 -1
  31. package/dist/compat/function/rest.d.mts +33 -0
  32. package/dist/compat/function/rest.d.ts +33 -0
  33. package/dist/compat/function/rest.mjs +11 -0
  34. package/dist/compat/index.d.mts +13 -0
  35. package/dist/compat/index.d.ts +13 -0
  36. package/dist/compat/index.js +413 -259
  37. package/dist/compat/index.mjs +13 -0
  38. package/dist/compat/object/get.mjs +2 -4
  39. package/dist/compat/object/has.d.mts +32 -0
  40. package/dist/compat/object/has.d.ts +32 -0
  41. package/dist/compat/object/has.mjs +34 -0
  42. package/dist/compat/object/merge.d.mts +1 -0
  43. package/dist/compat/object/merge.d.ts +1 -0
  44. package/dist/compat/object/mergeWith.d.mts +6 -0
  45. package/dist/compat/object/mergeWith.d.ts +6 -0
  46. package/dist/compat/object/mergeWith.mjs +0 -3
  47. package/dist/compat/object/set.mjs +1 -5
  48. package/dist/compat/predicate/isArrayLike.mjs +1 -2
  49. package/dist/compat/predicate/isString.d.mts +20 -0
  50. package/dist/compat/predicate/isString.d.ts +20 -0
  51. package/dist/compat/predicate/isString.mjs +13 -0
  52. package/dist/compat/predicate/matchesProperty.d.mts +28 -0
  53. package/dist/compat/predicate/matchesProperty.d.ts +28 -0
  54. package/dist/compat/predicate/matchesProperty.mjs +22 -0
  55. package/dist/compat/string/padEnd.d.mts +20 -0
  56. package/dist/compat/string/padEnd.d.ts +20 -0
  57. package/dist/compat/string/padEnd.mjs +5 -0
  58. package/dist/function/ary.d.mts +1 -1
  59. package/dist/function/ary.d.ts +1 -1
  60. package/dist/function/index.d.mts +4 -0
  61. package/dist/function/index.d.ts +4 -0
  62. package/dist/function/index.js +76 -0
  63. package/dist/function/index.mjs +4 -0
  64. package/dist/function/memoize.d.mts +87 -0
  65. package/dist/function/memoize.d.ts +87 -0
  66. package/dist/function/memoize.mjs +16 -0
  67. package/dist/function/partial.d.mts +33 -0
  68. package/dist/function/partial.d.ts +33 -0
  69. package/dist/function/partial.mjs +23 -0
  70. package/dist/function/partialRight.d.mts +33 -0
  71. package/dist/function/partialRight.d.ts +33 -0
  72. package/dist/function/partialRight.mjs +25 -0
  73. package/dist/function/rest.d.mts +33 -0
  74. package/dist/function/rest.d.ts +33 -0
  75. package/dist/function/rest.mjs +12 -0
  76. package/dist/function/unary.d.mts +1 -1
  77. package/dist/function/unary.d.ts +1 -1
  78. package/dist/index.d.mts +7 -0
  79. package/dist/index.d.ts +7 -0
  80. package/dist/index.js +21 -14
  81. package/dist/index.mjs +7 -0
  82. package/dist/object/index.d.mts +1 -0
  83. package/dist/object/index.d.ts +1 -0
  84. package/dist/object/index.js +14 -32
  85. package/dist/object/index.mjs +1 -0
  86. package/dist/object/toMerged.d.mts +45 -0
  87. package/dist/object/toMerged.d.ts +45 -0
  88. package/dist/object/toMerged.mjs +8 -0
  89. package/dist/predicate/index.d.mts +1 -0
  90. package/dist/predicate/index.d.ts +1 -0
  91. package/dist/predicate/index.js +6 -1
  92. package/dist/predicate/index.mjs +1 -0
  93. package/dist/predicate/isEqual.mjs +4 -5
  94. package/dist/predicate/isString.d.mts +20 -0
  95. package/dist/predicate/isString.d.ts +20 -0
  96. package/dist/predicate/isString.mjs +5 -0
  97. package/dist/string/camelCase.mjs +2 -2
  98. package/dist/string/index.js +2 -2
  99. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -22,6 +22,7 @@ export { maxBy } from './array/maxBy.mjs';
22
22
  export { minBy } from './array/minBy.mjs';
23
23
  export { orderBy } from './array/orderBy.mjs';
24
24
  export { partition } from './array/partition.mjs';
25
+ export { sortBy } from './array/sortBy.mjs';
25
26
  export { sample } from './array/sample.mjs';
26
27
  export { sampleSize } from './array/sampleSize.mjs';
27
28
  export { shuffle } from './array/shuffle.mjs';
@@ -59,8 +60,12 @@ export { noop } from './function/noop.mjs';
59
60
  export { once } from './function/once.mjs';
60
61
  export { throttle } from './function/throttle.mjs';
61
62
  export { negate } from './function/negate.mjs';
63
+ export { memoize } from './function/memoize.mjs';
62
64
  export { ary } from './function/ary.mjs';
63
65
  export { unary } from './function/unary.mjs';
66
+ export { partial } from './function/partial.mjs';
67
+ export { partialRight } from './function/partialRight.mjs';
68
+ export { rest } from './function/rest.mjs';
64
69
  export { clamp } from './math/clamp.mjs';
65
70
  export { inRange } from './math/inRange.mjs';
66
71
  export { mean } from './math/mean.mjs';
@@ -82,6 +87,7 @@ export { mapKeys } from './object/mapKeys.mjs';
82
87
  export { mapValues } from './object/mapValues.mjs';
83
88
  export { cloneDeep } from './object/cloneDeep.mjs';
84
89
  export { merge } from './object/merge.mjs';
90
+ export { toMerged } from './object/toMerged.mjs';
85
91
  export { mergeWith } from './object/mergeWith.mjs';
86
92
  export { isEqual } from './predicate/isEqual.mjs';
87
93
  export { isNil } from './predicate/isNil.mjs';
@@ -95,6 +101,7 @@ export { isTypedArray } from './predicate/isTypedArray.mjs';
95
101
  export { isPrimitive } from './predicate/isPrimitive.mjs';
96
102
  export { isBoolean } from './predicate/isBoolean.mjs';
97
103
  export { isSymbol } from './predicate/isSymbol.mjs';
104
+ export { isString } from './predicate/isString.mjs';
98
105
  export { delay } from './promise/delay.mjs';
99
106
  export { withTimeout } from './promise/withTimeout.mjs';
100
107
  export { camelCase } from './string/camelCase.mjs';
@@ -9,4 +9,5 @@ export { mapKeys } from './mapKeys.mjs';
9
9
  export { mapValues } from './mapValues.mjs';
10
10
  export { cloneDeep } from './cloneDeep.mjs';
11
11
  export { merge } from './merge.mjs';
12
+ export { toMerged } from './toMerged.mjs';
12
13
  export { mergeWith } from './mergeWith.mjs';
@@ -9,4 +9,5 @@ export { mapKeys } from './mapKeys.js';
9
9
  export { mapValues } from './mapValues.js';
10
10
  export { cloneDeep } from './cloneDeep.js';
11
11
  export { merge } from './merge.js';
12
+ export { toMerged } from './toMerged.js';
12
13
  export { mergeWith } from './mergeWith.js';
@@ -2,26 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const isObjectLike = require('../_chunk/isObjectLike-BeLCsr.js');
6
-
7
- function merge(target, source) {
8
- const sourceKeys = Object.keys(source);
9
- for (let i = 0; i < sourceKeys.length; i++) {
10
- const key = sourceKeys[i];
11
- const sourceValue = source[key];
12
- const targetValue = target[key];
13
- if (Array.isArray(sourceValue)) {
14
- target[key] = merge(targetValue ?? [], sourceValue);
15
- }
16
- else if (isObjectLike.isObjectLike(targetValue) && isObjectLike.isObjectLike(sourceValue)) {
17
- target[key] = merge(targetValue ?? {}, sourceValue);
18
- }
19
- else if (targetValue === undefined || sourceValue !== undefined) {
20
- target[key] = sourceValue;
21
- }
22
- }
23
- return target;
24
- }
5
+ const toMerged = require('../_chunk/toMerged-BGwYW5.js');
25
6
 
26
7
  function mergeWith(target, source, merge) {
27
8
  const sourceKeys = Object.keys(source);
@@ -36,7 +17,7 @@ function mergeWith(target, source, merge) {
36
17
  else if (Array.isArray(sourceValue)) {
37
18
  target[key] = mergeWith(targetValue ?? [], sourceValue, merge);
38
19
  }
39
- else if (isObjectLike.isObjectLike(targetValue) && isObjectLike.isObjectLike(sourceValue)) {
20
+ else if (toMerged.isObjectLike(targetValue) && toMerged.isObjectLike(sourceValue)) {
40
21
  target[key] = mergeWith(targetValue ?? {}, sourceValue, merge);
41
22
  }
42
23
  else if (targetValue === undefined || sourceValue !== undefined) {
@@ -46,15 +27,16 @@ function mergeWith(target, source, merge) {
46
27
  return target;
47
28
  }
48
29
 
49
- exports.clone = isObjectLike.clone;
50
- exports.cloneDeep = isObjectLike.cloneDeep;
51
- exports.flattenObject = isObjectLike.flattenObject;
52
- exports.invert = isObjectLike.invert;
53
- exports.mapKeys = isObjectLike.mapKeys;
54
- exports.mapValues = isObjectLike.mapValues;
55
- exports.omit = isObjectLike.omit;
56
- exports.omitBy = isObjectLike.omitBy;
57
- exports.pick = isObjectLike.pick;
58
- exports.pickBy = isObjectLike.pickBy;
59
- exports.merge = merge;
30
+ exports.clone = toMerged.clone;
31
+ exports.cloneDeep = toMerged.cloneDeep;
32
+ exports.flattenObject = toMerged.flattenObject;
33
+ exports.invert = toMerged.invert;
34
+ exports.mapKeys = toMerged.mapKeys;
35
+ exports.mapValues = toMerged.mapValues;
36
+ exports.merge = toMerged.merge;
37
+ exports.omit = toMerged.omit;
38
+ exports.omitBy = toMerged.omitBy;
39
+ exports.pick = toMerged.pick;
40
+ exports.pickBy = toMerged.pickBy;
41
+ exports.toMerged = toMerged.toMerged;
60
42
  exports.mergeWith = mergeWith;
@@ -9,4 +9,5 @@ export { mapKeys } from './mapKeys.mjs';
9
9
  export { mapValues } from './mapValues.mjs';
10
10
  export { cloneDeep } from './cloneDeep.mjs';
11
11
  export { merge } from './merge.mjs';
12
+ export { toMerged } from './toMerged.mjs';
12
13
  export { mergeWith } from './mergeWith.mjs';
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Merges the properties of the source object into a deep clone of the target object.
3
+ * Unlike `merge`, This function does not modify the original target object.
4
+ *
5
+ * This function performs a deep merge, meaning nested objects and arrays are merged recursively.
6
+ *
7
+ * - If a property in the source object is an array or object and the corresponding property in the target object is also an array or object, they will be merged.
8
+ * - If a property in the source object is undefined, it will not overwrite a defined property in the target object.
9
+ *
10
+ * Note that this function does not mutate the target object.
11
+ *
12
+ * @param {T} target - The target object to be cloned and merged into. This object is not modified directly.
13
+ * @param {S} source - The source object whose properties will be merged into the cloned target object.
14
+ * @returns {T & S} A new object with properties from the source object merged into a deep clone of the target object.
15
+ *
16
+ * @template T - Type of the target object.
17
+ * @template S - Type of the source object.
18
+ *
19
+ * @example
20
+ * const target = { a: 1, b: { x: 1, y: 2 } };
21
+ * const source = { b: { y: 3, z: 4 }, c: 5 };
22
+ *
23
+ * const result = toMerged(target, source);
24
+ * console.log(result);
25
+ * // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 }
26
+ *
27
+ * @example
28
+ * const target = { a: [1, 2], b: { x: 1 } };
29
+ * const source = { a: [3], b: { y: 2 } };
30
+ *
31
+ * const result = toMerged(target, source);
32
+ * console.log(result);
33
+ * // Output: { a: [3, 2], b: { x: 1, y: 2 } }
34
+ *
35
+ * @example
36
+ * const target = { a: null };
37
+ * const source = { a: [1, 2, 3] };
38
+ *
39
+ * const result = toMerged(target, source);
40
+ * console.log(result);
41
+ * // Output: { a: [1, 2, 3] }
42
+ */
43
+ declare function toMerged<T, S>(target: T, source: S): T & S;
44
+
45
+ export { toMerged };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Merges the properties of the source object into a deep clone of the target object.
3
+ * Unlike `merge`, This function does not modify the original target object.
4
+ *
5
+ * This function performs a deep merge, meaning nested objects and arrays are merged recursively.
6
+ *
7
+ * - If a property in the source object is an array or object and the corresponding property in the target object is also an array or object, they will be merged.
8
+ * - If a property in the source object is undefined, it will not overwrite a defined property in the target object.
9
+ *
10
+ * Note that this function does not mutate the target object.
11
+ *
12
+ * @param {T} target - The target object to be cloned and merged into. This object is not modified directly.
13
+ * @param {S} source - The source object whose properties will be merged into the cloned target object.
14
+ * @returns {T & S} A new object with properties from the source object merged into a deep clone of the target object.
15
+ *
16
+ * @template T - Type of the target object.
17
+ * @template S - Type of the source object.
18
+ *
19
+ * @example
20
+ * const target = { a: 1, b: { x: 1, y: 2 } };
21
+ * const source = { b: { y: 3, z: 4 }, c: 5 };
22
+ *
23
+ * const result = toMerged(target, source);
24
+ * console.log(result);
25
+ * // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 }
26
+ *
27
+ * @example
28
+ * const target = { a: [1, 2], b: { x: 1 } };
29
+ * const source = { a: [3], b: { y: 2 } };
30
+ *
31
+ * const result = toMerged(target, source);
32
+ * console.log(result);
33
+ * // Output: { a: [3, 2], b: { x: 1, y: 2 } }
34
+ *
35
+ * @example
36
+ * const target = { a: null };
37
+ * const source = { a: [1, 2, 3] };
38
+ *
39
+ * const result = toMerged(target, source);
40
+ * console.log(result);
41
+ * // Output: { a: [1, 2, 3] }
42
+ */
43
+ declare function toMerged<T, S>(target: T, source: S): T & S;
44
+
45
+ export { toMerged };
@@ -0,0 +1,8 @@
1
+ import { cloneDeep } from './cloneDeep.mjs';
2
+ import { merge } from './merge.mjs';
3
+
4
+ function toMerged(target, source) {
5
+ return merge(cloneDeep(target), source);
6
+ }
7
+
8
+ export { toMerged };
@@ -10,3 +10,4 @@ export { isTypedArray } from './isTypedArray.mjs';
10
10
  export { isPrimitive } from './isPrimitive.mjs';
11
11
  export { isBoolean } from './isBoolean.mjs';
12
12
  export { isSymbol } from './isSymbol.mjs';
13
+ export { isString } from './isString.mjs';
@@ -10,3 +10,4 @@ export { isTypedArray } from './isTypedArray.js';
10
10
  export { isPrimitive } from './isPrimitive.js';
11
11
  export { isBoolean } from './isBoolean.js';
12
12
  export { isSymbol } from './isSymbol.js';
13
+ export { isString } from './isString.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const isFunction = require('../_chunk/isFunction-D0hq6d.js');
5
+ const isFunction = require('../_chunk/isFunction-aCEz9d.js');
6
6
  const isTypedArray = require('../_chunk/isTypedArray-BBEkFl.js');
7
7
 
8
8
  function isBoolean(x) {
@@ -13,6 +13,10 @@ function isSymbol(value) {
13
13
  return typeof value === 'symbol';
14
14
  }
15
15
 
16
+ function isString(value) {
17
+ return typeof value === 'string';
18
+ }
19
+
16
20
  exports.isEqual = isFunction.isEqual;
17
21
  exports.isFunction = isFunction.isFunction;
18
22
  exports.isLength = isFunction.isLength;
@@ -24,4 +28,5 @@ exports.isPlainObject = isTypedArray.isPlainObject;
24
28
  exports.isPrimitive = isTypedArray.isPrimitive;
25
29
  exports.isTypedArray = isTypedArray.isTypedArray;
26
30
  exports.isBoolean = isBoolean;
31
+ exports.isString = isString;
27
32
  exports.isSymbol = isSymbol;
@@ -10,3 +10,4 @@ export { isTypedArray } from './isTypedArray.mjs';
10
10
  export { isPrimitive } from './isPrimitive.mjs';
11
11
  export { isBoolean } from './isBoolean.mjs';
12
12
  export { isSymbol } from './isSymbol.mjs';
13
+ export { isString } from './isString.mjs';
@@ -47,7 +47,7 @@ function areObjectsEqual(a, b, stack) {
47
47
  case numberTag: {
48
48
  const x = a.valueOf();
49
49
  const y = b.valueOf();
50
- return x === y || Number.isNaN(x) && Number.isNaN(y);
50
+ return x === y || (Number.isNaN(x) && Number.isNaN(y));
51
51
  }
52
52
  case booleanTag:
53
53
  case dateTag:
@@ -57,7 +57,7 @@ function areObjectsEqual(a, b, stack) {
57
57
  return a.source === b.source && a.flags === b.flags;
58
58
  }
59
59
  case functionTag: {
60
- return a == b;
60
+ return a === b;
61
61
  }
62
62
  }
63
63
  stack = stack ?? new Map();
@@ -140,8 +140,7 @@ function areObjectsEqual(a, b, stack) {
140
140
  return a.name === b.name && a.message === b.message;
141
141
  }
142
142
  case objectTag: {
143
- const areEqualInstances = areObjectsEqual(a.constructor, b.constructor, stack) ||
144
- (isPlainObject(a) && isPlainObject(b));
143
+ const areEqualInstances = areObjectsEqual(a.constructor, b.constructor, stack) || (isPlainObject(a) && isPlainObject(b));
145
144
  if (!areEqualInstances) {
146
145
  return false;
147
146
  }
@@ -153,7 +152,7 @@ function areObjectsEqual(a, b, stack) {
153
152
  for (let i = 0; i < aKeys.length; i++) {
154
153
  const propKey = aKeys[i];
155
154
  const aProp = a[propKey];
156
- if (!b.hasOwnProperty(propKey)) {
155
+ if (!Object.prototype.hasOwnProperty.call(b, propKey)) {
157
156
  return false;
158
157
  }
159
158
  const bProp = b[propKey];
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checks if a given value is stirng.
3
+ *
4
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `string`.
5
+ *
6
+ * @param {unknown} value The value to check if it is string.
7
+ * @returns {value is string} Returns `true` if `value` is a stirng, else `false`.
8
+ *
9
+ * @example
10
+ * const value1 = 'abc';
11
+ * const value2 = 123;
12
+ * const value3 = true;
13
+ *
14
+ * console.log(isString(value1)); // true
15
+ * console.log(isString(value2)); // false
16
+ * console.log(isString(value3)); // false
17
+ */
18
+ declare function isString(value: unknown): value is string;
19
+
20
+ export { isString };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checks if a given value is stirng.
3
+ *
4
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `string`.
5
+ *
6
+ * @param {unknown} value The value to check if it is string.
7
+ * @returns {value is string} Returns `true` if `value` is a stirng, else `false`.
8
+ *
9
+ * @example
10
+ * const value1 = 'abc';
11
+ * const value2 = 123;
12
+ * const value3 = true;
13
+ *
14
+ * console.log(isString(value1)); // true
15
+ * console.log(isString(value2)); // false
16
+ * console.log(isString(value3)); // false
17
+ */
18
+ declare function isString(value: unknown): value is string;
19
+
20
+ export { isString };
@@ -0,0 +1,5 @@
1
+ function isString(value) {
2
+ return typeof value === 'string';
3
+ }
4
+
5
+ export { isString };
@@ -4,10 +4,10 @@ import { getWords } from './_internal/getWords.mjs';
4
4
  function camelCase(str) {
5
5
  const words = getWords(str);
6
6
  if (words.length === 0) {
7
- return "";
7
+ return '';
8
8
  }
9
9
  const [first, ...rest] = words;
10
- return `${first.toLowerCase()}${rest.map((word) => capitalize(word)).join("")}`;
10
+ return `${first.toLowerCase()}${rest.map(word => capitalize(word)).join('')}`;
11
11
  }
12
12
 
13
13
  export { camelCase };
@@ -14,10 +14,10 @@ function getWords(str) {
14
14
  function camelCase(str) {
15
15
  const words = getWords(str);
16
16
  if (words.length === 0) {
17
- return "";
17
+ return '';
18
18
  }
19
19
  const [first, ...rest] = words;
20
- return `${first.toLowerCase()}${rest.map((word) => capitalize(word)).join("")}`;
20
+ return `${first.toLowerCase()}${rest.map(word => capitalize(word)).join('')}`;
21
21
  }
22
22
 
23
23
  const snakeCase = (str) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.15.1",
4
+ "version": "1.16.0-dev.455+f08fbd1b",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {