es-toolkit 1.25.2 → 1.26.0-dev.826

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 (87) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/_chunk/{sumBy-BkErWJ.js → sumBy-RVppiV.js} +21 -0
  3. package/dist/_chunk/{toMerged-BLnW4M.js → toMerged-wNz52b.js} +2 -2
  4. package/dist/_chunk/{unary-CMvKXy.js → unary-CcTNuC.js} +5 -0
  5. package/dist/browser.global.js +1 -1
  6. package/dist/browser.global.js.map +1 -1
  7. package/dist/compat/array/drop.d.mts +2 -1
  8. package/dist/compat/array/drop.d.ts +2 -1
  9. package/dist/compat/array/drop.mjs +3 -1
  10. package/dist/compat/array/dropRight.d.mts +2 -1
  11. package/dist/compat/array/dropRight.d.ts +2 -1
  12. package/dist/compat/array/dropRight.mjs +3 -1
  13. package/dist/compat/array/every.d.mts +2 -2
  14. package/dist/compat/array/every.d.ts +2 -2
  15. package/dist/compat/array/every.mjs +6 -2
  16. package/dist/compat/array/filter.d.mts +3 -3
  17. package/dist/compat/array/filter.d.ts +3 -3
  18. package/dist/compat/array/filter.mjs +1 -1
  19. package/dist/compat/array/find.d.mts +6 -6
  20. package/dist/compat/array/find.d.ts +6 -6
  21. package/dist/compat/array/intersectionBy.d.mts +111 -0
  22. package/dist/compat/array/intersectionBy.d.ts +111 -0
  23. package/dist/compat/array/intersectionBy.mjs +36 -0
  24. package/dist/compat/array/orderBy.d.mts +3 -2
  25. package/dist/compat/array/orderBy.d.ts +3 -2
  26. package/dist/compat/array/orderBy.mjs +7 -3
  27. package/dist/compat/array/some.d.mts +68 -21
  28. package/dist/compat/array/some.d.ts +68 -21
  29. package/dist/compat/array/some.mjs +21 -9
  30. package/dist/compat/array/sortBy.d.mts +3 -3
  31. package/dist/compat/array/sortBy.d.ts +3 -3
  32. package/dist/compat/array/sortBy.mjs +11 -2
  33. package/dist/compat/array/take.d.mts +2 -1
  34. package/dist/compat/array/take.d.ts +2 -1
  35. package/dist/compat/array/take.mjs +3 -1
  36. package/dist/compat/array/takeRight.d.mts +2 -1
  37. package/dist/compat/array/takeRight.d.ts +2 -1
  38. package/dist/compat/array/takeRight.mjs +3 -1
  39. package/dist/compat/array/zipObjectDeep.d.mts +2 -4
  40. package/dist/compat/array/zipObjectDeep.d.ts +2 -4
  41. package/dist/compat/index.d.mts +7 -1
  42. package/dist/compat/index.d.ts +7 -1
  43. package/dist/compat/index.js +218 -70
  44. package/dist/compat/index.mjs +7 -1
  45. package/dist/compat/object/invertBy.mjs +1 -1
  46. package/dist/compat/object/mapKeys.mjs +1 -1
  47. package/dist/compat/object/mapValues.mjs +1 -1
  48. package/dist/compat/string/template.d.mts +89 -0
  49. package/dist/compat/string/template.d.ts +89 -0
  50. package/dist/compat/string/template.mjs +86 -0
  51. package/dist/compat/util/uniqueId.d.mts +25 -0
  52. package/dist/compat/util/uniqueId.d.ts +25 -0
  53. package/dist/compat/util/uniqueId.mjs +7 -0
  54. package/dist/function/identity.d.mts +22 -0
  55. package/dist/function/identity.d.ts +22 -0
  56. package/dist/function/index.d.mts +1 -0
  57. package/dist/function/index.d.ts +1 -0
  58. package/dist/function/index.js +2 -1
  59. package/dist/function/index.mjs +1 -0
  60. package/dist/index.d.mts +4 -0
  61. package/dist/index.d.ts +4 -0
  62. package/dist/index.js +8 -3
  63. package/dist/index.mjs +4 -0
  64. package/dist/math/index.d.mts +2 -0
  65. package/dist/math/index.d.ts +2 -0
  66. package/dist/math/index.js +3 -1
  67. package/dist/math/index.mjs +2 -0
  68. package/dist/math/median.d.mts +25 -0
  69. package/dist/math/median.d.ts +25 -0
  70. package/dist/math/median.mjs +15 -0
  71. package/dist/math/medianBy.d.mts +23 -0
  72. package/dist/math/medianBy.d.ts +23 -0
  73. package/dist/math/medianBy.mjs +8 -0
  74. package/dist/object/cloneDeep.mjs +2 -2
  75. package/dist/object/index.js +1 -1
  76. package/dist/object/merge.d.mts +1 -1
  77. package/dist/object/merge.d.ts +1 -1
  78. package/dist/util/index.d.mts +1 -0
  79. package/dist/util/index.d.ts +1 -0
  80. package/dist/util/index.js +12 -0
  81. package/dist/util/index.mjs +1 -0
  82. package/dist/util/invariant.d.mts +27 -0
  83. package/dist/util/invariant.d.ts +27 -0
  84. package/dist/util/invariant.mjs +8 -0
  85. package/package.json +21 -1
  86. package/util.d.ts +1 -0
  87. /package/dist/{compat/_internal → function}/identity.mjs +0 -0
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Calculates the median of an array of elements when applying
3
+ * the `getValue` function to each element.
4
+ *
5
+ * The median is the middle value of a sorted array.
6
+ * If the array has an odd number of elements, the median is the middle value.
7
+ * If the array has an even number of elements, it returns the average of the two middle values.
8
+ *
9
+ * If the array is empty, this function returns `NaN`.
10
+ *
11
+ * @template T - The type of elements in the array.
12
+ * @param {T[]} items An array to calculate the median.
13
+ * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
14
+ * @returns {number} The median of all the numbers as determined by the `getValue` function.
15
+ *
16
+ * @example
17
+ * medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }], x => x.a); // Returns: 3
18
+ * medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }], x => x.a); // Returns: 2.5
19
+ * medianBy([], x => x.a); // Returns: NaN
20
+ */
21
+ declare function medianBy<T>(items: readonly T[], getValue: (element: T) => number): number;
22
+
23
+ export { medianBy };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Calculates the median of an array of elements when applying
3
+ * the `getValue` function to each element.
4
+ *
5
+ * The median is the middle value of a sorted array.
6
+ * If the array has an odd number of elements, the median is the middle value.
7
+ * If the array has an even number of elements, it returns the average of the two middle values.
8
+ *
9
+ * If the array is empty, this function returns `NaN`.
10
+ *
11
+ * @template T - The type of elements in the array.
12
+ * @param {T[]} items An array to calculate the median.
13
+ * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
14
+ * @returns {number} The median of all the numbers as determined by the `getValue` function.
15
+ *
16
+ * @example
17
+ * medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }], x => x.a); // Returns: 3
18
+ * medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }], x => x.a); // Returns: 2.5
19
+ * medianBy([], x => x.a); // Returns: NaN
20
+ */
21
+ declare function medianBy<T>(items: readonly T[], getValue: (element: T) => number): number;
22
+
23
+ export { medianBy };
@@ -0,0 +1,8 @@
1
+ import { median } from './median.mjs';
2
+
3
+ function medianBy(items, getValue) {
4
+ const nums = items.map(x => getValue(x));
5
+ return median(nums);
6
+ }
7
+
8
+ export { medianBy };
@@ -37,7 +37,7 @@ function cloneDeepImpl(obj, stack = new Map()) {
37
37
  if (obj instanceof Map) {
38
38
  const result = new Map();
39
39
  stack.set(obj, result);
40
- for (const [key, value] of obj.entries()) {
40
+ for (const [key, value] of obj) {
41
41
  result.set(key, cloneDeepImpl(value, stack));
42
42
  }
43
43
  return result;
@@ -45,7 +45,7 @@ function cloneDeepImpl(obj, stack = new Map()) {
45
45
  if (obj instanceof Set) {
46
46
  const result = new Set();
47
47
  stack.set(obj, result);
48
- for (const value of obj.values()) {
48
+ for (const value of obj) {
49
49
  result.add(cloneDeepImpl(value, stack));
50
50
  }
51
51
  return result;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const toMerged = require('../_chunk/toMerged-BLnW4M.js');
5
+ const toMerged = require('../_chunk/toMerged-wNz52b.js');
6
6
 
7
7
  function mergeWith(target, source, merge) {
8
8
  const sourceKeys = Object.keys(source);
@@ -38,6 +38,6 @@
38
38
  * console.log(result);
39
39
  * // Output: { a: [1, 2, 3] }
40
40
  */
41
- declare function merge<T, S>(target: T, source: S): T & S;
41
+ declare function merge<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
42
42
 
43
43
  export { merge };
@@ -38,6 +38,6 @@
38
38
  * console.log(result);
39
39
  * // Output: { a: [1, 2, 3] }
40
40
  */
41
- declare function merge<T, S>(target: T, source: S): T & S;
41
+ declare function merge<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
42
42
 
43
43
  export { merge };
@@ -0,0 +1 @@
1
+ export { invariant } from './invariant.mjs';
@@ -0,0 +1 @@
1
+ export { invariant } from './invariant.js';
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ function invariant(condition, message) {
6
+ if (condition) {
7
+ return;
8
+ }
9
+ throw new Error(message);
10
+ }
11
+
12
+ exports.invariant = invariant;
@@ -0,0 +1 @@
1
+ export { invariant } from './invariant.mjs';
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Asserts that a given condition is true. If the condition is false, an error is thrown with the provided message.
3
+ *
4
+ * @param {unknown} condition - The condition to evaluate.
5
+ * @param {string} [message] - The error message to throw if the condition is false.
6
+ * @returns {void} Returns void if the condition is true.
7
+ * @throws {Error} Throws an error if the condition is false.
8
+ *
9
+ * @example
10
+ * // This call will succeed without any errors
11
+ * invariant(true, 'This should not throw');
12
+ *
13
+ * // This call will fail and throw an error with the message 'This should throw'
14
+ * invariant(false, 'This should throw');
15
+ *
16
+ * // Example of using invariant with a condition
17
+ * invariant(condition, 'Expected condition is false');
18
+ *
19
+ * // Ensure that the value is neither null nor undefined
20
+ * invariant(value !== null && value !== undefined, 'Value should not be null or undefined');
21
+ *
22
+ * // Example of using invariant to check if a number is positive
23
+ * invariant(number > 0, 'Number must be positive');
24
+ */
25
+ declare function invariant(condition: unknown, message: string): asserts condition;
26
+
27
+ export { invariant };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Asserts that a given condition is true. If the condition is false, an error is thrown with the provided message.
3
+ *
4
+ * @param {unknown} condition - The condition to evaluate.
5
+ * @param {string} [message] - The error message to throw if the condition is false.
6
+ * @returns {void} Returns void if the condition is true.
7
+ * @throws {Error} Throws an error if the condition is false.
8
+ *
9
+ * @example
10
+ * // This call will succeed without any errors
11
+ * invariant(true, 'This should not throw');
12
+ *
13
+ * // This call will fail and throw an error with the message 'This should throw'
14
+ * invariant(false, 'This should throw');
15
+ *
16
+ * // Example of using invariant with a condition
17
+ * invariant(condition, 'Expected condition is false');
18
+ *
19
+ * // Ensure that the value is neither null nor undefined
20
+ * invariant(value !== null && value !== undefined, 'Value should not be null or undefined');
21
+ *
22
+ * // Example of using invariant to check if a number is positive
23
+ * invariant(number > 0, 'Number must be positive');
24
+ */
25
+ declare function invariant(condition: unknown, message: string): asserts condition;
26
+
27
+ export { invariant };
@@ -0,0 +1,8 @@
1
+ function invariant(condition, message) {
2
+ if (condition) {
3
+ return;
4
+ }
5
+ throw new Error(message);
6
+ }
7
+
8
+ export { invariant };
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.25.2",
4
+ "version": "1.26.0-dev.826+0fd2ee83",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {
@@ -95,6 +95,16 @@
95
95
  "default": "./dist/string/index.js"
96
96
  }
97
97
  },
98
+ "./util": {
99
+ "import": {
100
+ "types": "./dist/util/index.d.mts",
101
+ "default": "./dist/util/index.mjs"
102
+ },
103
+ "require": {
104
+ "types": "./dist/util/index.d.ts",
105
+ "default": "./dist/util/index.js"
106
+ }
107
+ },
98
108
  "./compat": {
99
109
  "import": {
100
110
  "types": "./dist/compat/index.d.mts",
@@ -198,6 +208,16 @@
198
208
  "default": "./dist/string/index.js"
199
209
  }
200
210
  },
211
+ "./util": {
212
+ "import": {
213
+ "types": "./dist/util/index.d.mts",
214
+ "default": "./dist/util/index.mjs"
215
+ },
216
+ "require": {
217
+ "types": "./dist/util/index.d.ts",
218
+ "default": "./dist/util/index.js"
219
+ }
220
+ },
201
221
  "./compat": {
202
222
  "import": {
203
223
  "types": "./dist/compat/index.d.mts",
package/util.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/util';