es-toolkit 1.37.2 → 1.38.0-dev.1285

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 (76) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/_chunk/{snakeCase-BwvoPi.js → snakeCase-6cG1f4.js} +0 -1
  3. package/dist/_chunk/{unary-DzPndU.js → unary-BVQ0iC.js} +0 -16
  4. package/dist/_chunk/{upperFirst-C7IztG.js → upperFirst-Cx78bs.js} +1 -1
  5. package/dist/_chunk/{zip-CIqPLd.js → zip-Cyyp17.js} +10 -4
  6. package/dist/array/at.d.mts +1 -1
  7. package/dist/array/at.d.ts +1 -1
  8. package/dist/array/index.js +1 -1
  9. package/dist/array/maxBy.d.mts +2 -1
  10. package/dist/array/maxBy.d.ts +2 -1
  11. package/dist/array/maxBy.mjs +5 -2
  12. package/dist/array/minBy.d.mts +2 -1
  13. package/dist/array/minBy.d.ts +2 -1
  14. package/dist/array/minBy.mjs +5 -2
  15. package/dist/array/zip.d.mts +20 -0
  16. package/dist/array/zip.d.ts +20 -0
  17. package/dist/browser.global.js +1 -1
  18. package/dist/browser.global.js.map +1 -1
  19. package/dist/compat/array/every.mjs +25 -16
  20. package/dist/compat/array/filter.mjs +9 -3
  21. package/dist/compat/array/invokeMap.d.mts +43 -0
  22. package/dist/compat/array/invokeMap.d.ts +43 -0
  23. package/dist/compat/array/invokeMap.mjs +36 -0
  24. package/dist/compat/array/some.mjs +36 -4
  25. package/dist/compat/array/sortedLastIndexOf.d.mts +35 -0
  26. package/dist/compat/array/sortedLastIndexOf.d.ts +35 -0
  27. package/dist/compat/array/sortedLastIndexOf.mjs +15 -0
  28. package/dist/compat/compat.d.mts +8 -2
  29. package/dist/compat/compat.d.ts +8 -2
  30. package/dist/compat/compat.mjs +8 -2
  31. package/dist/compat/function/memoize.d.mts +138 -0
  32. package/dist/compat/function/memoize.d.ts +138 -0
  33. package/dist/compat/function/memoize.mjs +21 -0
  34. package/dist/compat/index.d.mts +8 -2
  35. package/dist/compat/index.d.ts +8 -2
  36. package/dist/compat/index.js +425 -48
  37. package/dist/compat/index.mjs +8 -2
  38. package/dist/compat/math/max.d.mts +7 -5
  39. package/dist/compat/math/max.d.ts +7 -5
  40. package/dist/compat/math/max.mjs +12 -8
  41. package/dist/compat/math/min.d.mts +6 -5
  42. package/dist/compat/math/min.d.ts +6 -5
  43. package/dist/compat/math/min.mjs +12 -8
  44. package/dist/compat/object/clone.d.mts +31 -0
  45. package/dist/compat/object/clone.d.ts +31 -0
  46. package/dist/compat/object/clone.mjs +160 -0
  47. package/dist/compat/object/cloneWith.d.mts +48 -0
  48. package/dist/compat/object/cloneWith.d.ts +48 -0
  49. package/dist/compat/object/cloneWith.mjs +14 -0
  50. package/dist/compat/object/findKey.d.mts +1 -1
  51. package/dist/compat/object/findKey.d.ts +1 -1
  52. package/dist/compat/object/setWith.d.mts +25 -0
  53. package/dist/compat/object/setWith.d.ts +25 -0
  54. package/dist/compat/object/setWith.mjs +14 -0
  55. package/dist/compat/predicate/isNative.d.mts +18 -0
  56. package/dist/compat/predicate/isNative.d.ts +18 -0
  57. package/dist/compat/predicate/isNative.mjs +17 -0
  58. package/dist/compat/string/words.mjs +23 -3
  59. package/dist/compat/util/bindAll.d.mts +28 -0
  60. package/dist/compat/util/bindAll.d.ts +28 -0
  61. package/dist/compat/util/bindAll.mjs +43 -0
  62. package/dist/function/index.js +17 -2
  63. package/dist/index.d.mts +1 -1
  64. package/dist/index.d.ts +1 -1
  65. package/dist/index.js +6 -5
  66. package/dist/index.mjs +1 -1
  67. package/dist/object/index.js +1 -1
  68. package/dist/string/index.js +2 -2
  69. package/dist/util/index.d.mts +1 -1
  70. package/dist/util/index.d.ts +1 -1
  71. package/dist/util/index.js +5 -1
  72. package/dist/util/index.mjs +1 -1
  73. package/dist/util/invariant.d.mts +21 -8
  74. package/dist/util/invariant.d.ts +21 -8
  75. package/dist/util/invariant.mjs +4 -1
  76. package/package.json +2 -2
@@ -0,0 +1,138 @@
1
+ interface MemoizeCache {
2
+ /**
3
+ * Optional internal data structure for the cache implementation.
4
+ * This is primarily used for testing and internal operations.
5
+ */
6
+ __data__?: any;
7
+ /**
8
+ * Removes the value associated with the specified key from the cache.
9
+ *
10
+ * @param key - The key of the value to remove
11
+ * @returns `true` if an element was removed, `false` if the key wasn't found
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * cache.set('user', { id: 123, name: 'John' });
16
+ * cache.delete('user'); // Returns true
17
+ * cache.delete('unknown'); // Returns false
18
+ * ```
19
+ */
20
+ delete(key: any): boolean;
21
+ /**
22
+ * Retrieves the value associated with the specified key from the cache.
23
+ *
24
+ * @param key - The key of the value to retrieve
25
+ * @returns The cached value or undefined if not found
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * cache.set('user', { id: 123, name: 'John' });
30
+ * cache.get('user'); // Returns { id: 123, name: 'John' }
31
+ * cache.get('unknown'); // Returns undefined
32
+ * ```
33
+ */
34
+ get(key: any): any;
35
+ /**
36
+ * Checks if the cache contains a value for the specified key.
37
+ *
38
+ * @param key - The key to check for existence
39
+ * @returns `true` if the key exists in the cache, otherwise `false`
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * cache.set('user', { id: 123, name: 'John' });
44
+ * cache.has('user'); // Returns true
45
+ * cache.has('unknown'); // Returns false
46
+ * ```
47
+ */
48
+ has(key: any): boolean;
49
+ /**
50
+ * Stores a value in the cache with the specified key.
51
+ * If the key already exists, its value is updated.
52
+ *
53
+ * @param key - The key to associate with the value
54
+ * @param value - The value to store in the cache
55
+ * @returns The cache instance for method chaining
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * cache.set('user', { id: 123, name: 'John' })
60
+ * .set('settings', { theme: 'dark' });
61
+ * ```
62
+ */
63
+ set(key: any, value: any): this;
64
+ /**
65
+ * Removes all key-value pairs from the cache.
66
+ * This method is optional as some cache implementations may be immutable.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * cache.set('user', { id: 123, name: 'John' });
71
+ * cache.set('settings', { theme: 'dark' });
72
+ * cache.clear(); // Cache is now empty
73
+ * ```
74
+ */
75
+ clear?(): void;
76
+ }
77
+ /**
78
+ * Interface for the constructor of cache implementations.
79
+ * This allows for creating new cache instances with optional initial entries.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // Use a custom cache constructor with memoize
84
+ * memoize.Cache = CustomCache;
85
+ *
86
+ * // Create a cache with initial entries
87
+ * const cache = new CustomCache([
88
+ * ['key1', 'value1'],
89
+ * ['key2', 'value2']
90
+ * ]);
91
+ * ```
92
+ */
93
+ interface MemoizeCacheConstructor {
94
+ /**
95
+ * Creates a new cache instance.
96
+ *
97
+ * @param entries - Optional array of key-value pairs to initialize the cache with
98
+ * @returns A new cache instance
99
+ */
100
+ new (entries?: Array<[any, any]>): MemoizeCache;
101
+ }
102
+ /**
103
+ * Represents a function that has been memoized.
104
+ * A memoized function maintains the same signature as the original function
105
+ * but adds a cache property to store previously computed results.
106
+ *
107
+ * @template T - The type of the original function being memoized
108
+ */
109
+ interface MemoizedFunction<T extends (...args: any) => any> {
110
+ /**
111
+ * Calls the function with the provided arguments, using cached results when available
112
+ *
113
+ * @param {...Parameters<T>} args - The arguments to pass to the original function
114
+ * @returns {ReturnType<T>} The result of the function call, either from cache or freshly computed
115
+ */
116
+ (...args: Parameters<T>): ReturnType<T>;
117
+ /**
118
+ * The cache storing previously computed results
119
+ */
120
+ cache: MemoizeCache;
121
+ }
122
+ /**
123
+ * Creates a function that memoizes the result of func. If resolver is provided it determines the cache key for
124
+ * storing the result based on the arguments provided to the memoized function. By default, the first argument
125
+ * provided to the memoized function is coerced to a string and used as the cache key. The func is invoked with
126
+ * the this binding of the memoized function.
127
+ *
128
+ * @template T - The type of the original function being memoized
129
+ * @param {T} func The function to have its output memoized.
130
+ * @param {Function} [resolver] The function to resolve the cache key.
131
+ * @return {MemoizedFunction<T>} Returns the new memoizing function.
132
+ */
133
+ declare function memoize<T extends (...args: any) => any>(func: T, resolver?: (...args: Parameters<T>) => any): MemoizedFunction<T>;
134
+ declare namespace memoize {
135
+ var Cache: MemoizeCacheConstructor;
136
+ }
137
+
138
+ export { memoize };
@@ -0,0 +1,138 @@
1
+ interface MemoizeCache {
2
+ /**
3
+ * Optional internal data structure for the cache implementation.
4
+ * This is primarily used for testing and internal operations.
5
+ */
6
+ __data__?: any;
7
+ /**
8
+ * Removes the value associated with the specified key from the cache.
9
+ *
10
+ * @param key - The key of the value to remove
11
+ * @returns `true` if an element was removed, `false` if the key wasn't found
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * cache.set('user', { id: 123, name: 'John' });
16
+ * cache.delete('user'); // Returns true
17
+ * cache.delete('unknown'); // Returns false
18
+ * ```
19
+ */
20
+ delete(key: any): boolean;
21
+ /**
22
+ * Retrieves the value associated with the specified key from the cache.
23
+ *
24
+ * @param key - The key of the value to retrieve
25
+ * @returns The cached value or undefined if not found
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * cache.set('user', { id: 123, name: 'John' });
30
+ * cache.get('user'); // Returns { id: 123, name: 'John' }
31
+ * cache.get('unknown'); // Returns undefined
32
+ * ```
33
+ */
34
+ get(key: any): any;
35
+ /**
36
+ * Checks if the cache contains a value for the specified key.
37
+ *
38
+ * @param key - The key to check for existence
39
+ * @returns `true` if the key exists in the cache, otherwise `false`
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * cache.set('user', { id: 123, name: 'John' });
44
+ * cache.has('user'); // Returns true
45
+ * cache.has('unknown'); // Returns false
46
+ * ```
47
+ */
48
+ has(key: any): boolean;
49
+ /**
50
+ * Stores a value in the cache with the specified key.
51
+ * If the key already exists, its value is updated.
52
+ *
53
+ * @param key - The key to associate with the value
54
+ * @param value - The value to store in the cache
55
+ * @returns The cache instance for method chaining
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * cache.set('user', { id: 123, name: 'John' })
60
+ * .set('settings', { theme: 'dark' });
61
+ * ```
62
+ */
63
+ set(key: any, value: any): this;
64
+ /**
65
+ * Removes all key-value pairs from the cache.
66
+ * This method is optional as some cache implementations may be immutable.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * cache.set('user', { id: 123, name: 'John' });
71
+ * cache.set('settings', { theme: 'dark' });
72
+ * cache.clear(); // Cache is now empty
73
+ * ```
74
+ */
75
+ clear?(): void;
76
+ }
77
+ /**
78
+ * Interface for the constructor of cache implementations.
79
+ * This allows for creating new cache instances with optional initial entries.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // Use a custom cache constructor with memoize
84
+ * memoize.Cache = CustomCache;
85
+ *
86
+ * // Create a cache with initial entries
87
+ * const cache = new CustomCache([
88
+ * ['key1', 'value1'],
89
+ * ['key2', 'value2']
90
+ * ]);
91
+ * ```
92
+ */
93
+ interface MemoizeCacheConstructor {
94
+ /**
95
+ * Creates a new cache instance.
96
+ *
97
+ * @param entries - Optional array of key-value pairs to initialize the cache with
98
+ * @returns A new cache instance
99
+ */
100
+ new (entries?: Array<[any, any]>): MemoizeCache;
101
+ }
102
+ /**
103
+ * Represents a function that has been memoized.
104
+ * A memoized function maintains the same signature as the original function
105
+ * but adds a cache property to store previously computed results.
106
+ *
107
+ * @template T - The type of the original function being memoized
108
+ */
109
+ interface MemoizedFunction<T extends (...args: any) => any> {
110
+ /**
111
+ * Calls the function with the provided arguments, using cached results when available
112
+ *
113
+ * @param {...Parameters<T>} args - The arguments to pass to the original function
114
+ * @returns {ReturnType<T>} The result of the function call, either from cache or freshly computed
115
+ */
116
+ (...args: Parameters<T>): ReturnType<T>;
117
+ /**
118
+ * The cache storing previously computed results
119
+ */
120
+ cache: MemoizeCache;
121
+ }
122
+ /**
123
+ * Creates a function that memoizes the result of func. If resolver is provided it determines the cache key for
124
+ * storing the result based on the arguments provided to the memoized function. By default, the first argument
125
+ * provided to the memoized function is coerced to a string and used as the cache key. The func is invoked with
126
+ * the this binding of the memoized function.
127
+ *
128
+ * @template T - The type of the original function being memoized
129
+ * @param {T} func The function to have its output memoized.
130
+ * @param {Function} [resolver] The function to resolve the cache key.
131
+ * @return {MemoizedFunction<T>} Returns the new memoizing function.
132
+ */
133
+ declare function memoize<T extends (...args: any) => any>(func: T, resolver?: (...args: Parameters<T>) => any): MemoizedFunction<T>;
134
+ declare namespace memoize {
135
+ var Cache: MemoizeCacheConstructor;
136
+ }
137
+
138
+ export { memoize };
@@ -0,0 +1,21 @@
1
+ function memoize(func, resolver) {
2
+ if (typeof func !== 'function' || (resolver != null && typeof resolver !== 'function')) {
3
+ throw new TypeError('Expected a function');
4
+ }
5
+ const memoized = function (...args) {
6
+ const key = resolver ? resolver.apply(this, args) : args[0];
7
+ const cache = memoized.cache;
8
+ if (cache.has(key)) {
9
+ return cache.get(key);
10
+ }
11
+ const result = func.apply(this, args);
12
+ memoized.cache = cache.set(key, result) || cache;
13
+ return result;
14
+ };
15
+ const CacheConstructor = memoize.Cache || Map;
16
+ memoized.cache = new CacheConstructor();
17
+ return memoized;
18
+ }
19
+ memoize.Cache = Map;
20
+
21
+ export { memoize };
@@ -30,6 +30,7 @@ export { initial } from './array/initial.mjs';
30
30
  export { intersection } from './array/intersection.mjs';
31
31
  export { intersectionBy } from './array/intersectionBy.mjs';
32
32
  export { intersectionWith } from './array/intersectionWith.mjs';
33
+ export { invokeMap } from './array/invokeMap.mjs';
33
34
  export { join } from './array/join.mjs';
34
35
  export { keyBy } from './array/keyBy.mjs';
35
36
  export { last } from './array/last.mjs';
@@ -60,6 +61,7 @@ export { sortedIndexBy } from './array/sortedIndexBy.mjs';
60
61
  export { sortedIndexOf } from './array/sortedIndexOf.mjs';
61
62
  export { sortedLastIndex } from './array/sortedLastIndex.mjs';
62
63
  export { sortedLastIndexBy } from './array/sortedLastIndexBy.mjs';
64
+ export { sortedLastIndexOf } from './array/sortedLastIndexOf.mjs';
63
65
  export { tail } from './array/tail.mjs';
64
66
  export { take } from './array/take.mjs';
65
67
  export { takeRight } from './array/takeRight.mjs';
@@ -95,7 +97,7 @@ export { delay } from './function/delay.mjs';
95
97
  export { flip } from './function/flip.mjs';
96
98
  export { flow } from './function/flow.mjs';
97
99
  export { flowRight } from './function/flowRight.mjs';
98
- export { memoize } from '../function/memoize.mjs';
100
+ export { memoize } from './function/memoize.mjs';
99
101
  export { negate } from './function/negate.mjs';
100
102
  export { nthArg } from './function/nthArg.mjs';
101
103
  export { once } from '../function/once.mjs';
@@ -133,9 +135,10 @@ export { assignIn, assignIn as extend } from './object/assignIn.mjs';
133
135
  export { assignInWith, assignInWith as extendWith } from './object/assignInWith.mjs';
134
136
  export { assignWith } from './object/assignWith.mjs';
135
137
  export { at } from './object/at.mjs';
136
- export { clone } from '../object/clone.mjs';
138
+ export { clone } from './object/clone.mjs';
137
139
  export { cloneDeep } from './object/cloneDeep.mjs';
138
140
  export { cloneDeepWith } from './object/cloneDeepWith.mjs';
141
+ export { cloneWith } from './object/cloneWith.mjs';
139
142
  export { create } from './object/create.mjs';
140
143
  export { defaults } from './object/defaults.mjs';
141
144
  export { findKey } from './object/findKey.mjs';
@@ -155,6 +158,7 @@ export { invertBy } from './object/invertBy.mjs';
155
158
  export { isEqual } from '../predicate/isEqual.mjs';
156
159
  export { isFunction } from '../predicate/isFunction.mjs';
157
160
  export { isLength } from '../predicate/isLength.mjs';
161
+ export { isNative } from './predicate/isNative.mjs';
158
162
  export { isNull } from '../predicate/isNull.mjs';
159
163
  export { isUndefined } from '../predicate/isUndefined.mjs';
160
164
  export { keys } from './object/keys.mjs';
@@ -172,6 +176,7 @@ export { property } from './object/property.mjs';
172
176
  export { propertyOf } from './object/propertyOf.mjs';
173
177
  export { result } from './object/result.mjs';
174
178
  export { set } from './object/set.mjs';
179
+ export { setWith } from './object/setWith.mjs';
175
180
  export { toDefaulted } from './object/toDefaulted.mjs';
176
181
  export { toPairs } from './object/toPairs.mjs';
177
182
  export { toPairsIn } from './object/toPairsIn.mjs';
@@ -181,6 +186,7 @@ export { update } from './object/update.mjs';
181
186
  export { updateWith } from './object/updateWith.mjs';
182
187
  export { values } from './object/values.mjs';
183
188
  export { valuesIn } from './object/valuesIn.mjs';
189
+ export { bindAll } from './util/bindAll.mjs';
184
190
  export { capitalize } from '../string/capitalize.mjs';
185
191
  export { conforms } from './predicate/conforms.mjs';
186
192
  export { conformsTo } from './predicate/conformsTo.mjs';
@@ -30,6 +30,7 @@ export { initial } from './array/initial.js';
30
30
  export { intersection } from './array/intersection.js';
31
31
  export { intersectionBy } from './array/intersectionBy.js';
32
32
  export { intersectionWith } from './array/intersectionWith.js';
33
+ export { invokeMap } from './array/invokeMap.js';
33
34
  export { join } from './array/join.js';
34
35
  export { keyBy } from './array/keyBy.js';
35
36
  export { last } from './array/last.js';
@@ -60,6 +61,7 @@ export { sortedIndexBy } from './array/sortedIndexBy.js';
60
61
  export { sortedIndexOf } from './array/sortedIndexOf.js';
61
62
  export { sortedLastIndex } from './array/sortedLastIndex.js';
62
63
  export { sortedLastIndexBy } from './array/sortedLastIndexBy.js';
64
+ export { sortedLastIndexOf } from './array/sortedLastIndexOf.js';
63
65
  export { tail } from './array/tail.js';
64
66
  export { take } from './array/take.js';
65
67
  export { takeRight } from './array/takeRight.js';
@@ -95,7 +97,7 @@ export { delay } from './function/delay.js';
95
97
  export { flip } from './function/flip.js';
96
98
  export { flow } from './function/flow.js';
97
99
  export { flowRight } from './function/flowRight.js';
98
- export { memoize } from '../function/memoize.js';
100
+ export { memoize } from './function/memoize.js';
99
101
  export { negate } from './function/negate.js';
100
102
  export { nthArg } from './function/nthArg.js';
101
103
  export { once } from '../function/once.js';
@@ -133,9 +135,10 @@ export { assignIn, assignIn as extend } from './object/assignIn.js';
133
135
  export { assignInWith, assignInWith as extendWith } from './object/assignInWith.js';
134
136
  export { assignWith } from './object/assignWith.js';
135
137
  export { at } from './object/at.js';
136
- export { clone } from '../object/clone.js';
138
+ export { clone } from './object/clone.js';
137
139
  export { cloneDeep } from './object/cloneDeep.js';
138
140
  export { cloneDeepWith } from './object/cloneDeepWith.js';
141
+ export { cloneWith } from './object/cloneWith.js';
139
142
  export { create } from './object/create.js';
140
143
  export { defaults } from './object/defaults.js';
141
144
  export { findKey } from './object/findKey.js';
@@ -155,6 +158,7 @@ export { invertBy } from './object/invertBy.js';
155
158
  export { isEqual } from '../predicate/isEqual.js';
156
159
  export { isFunction } from '../predicate/isFunction.js';
157
160
  export { isLength } from '../predicate/isLength.js';
161
+ export { isNative } from './predicate/isNative.js';
158
162
  export { isNull } from '../predicate/isNull.js';
159
163
  export { isUndefined } from '../predicate/isUndefined.js';
160
164
  export { keys } from './object/keys.js';
@@ -172,6 +176,7 @@ export { property } from './object/property.js';
172
176
  export { propertyOf } from './object/propertyOf.js';
173
177
  export { result } from './object/result.js';
174
178
  export { set } from './object/set.js';
179
+ export { setWith } from './object/setWith.js';
175
180
  export { toDefaulted } from './object/toDefaulted.js';
176
181
  export { toPairs } from './object/toPairs.js';
177
182
  export { toPairsIn } from './object/toPairsIn.js';
@@ -181,6 +186,7 @@ export { update } from './object/update.js';
181
186
  export { updateWith } from './object/updateWith.js';
182
187
  export { values } from './object/values.js';
183
188
  export { valuesIn } from './object/valuesIn.js';
189
+ export { bindAll } from './util/bindAll.js';
184
190
  export { capitalize } from '../string/capitalize.js';
185
191
  export { conforms } from './predicate/conforms.js';
186
192
  export { conformsTo } from './predicate/conformsTo.js';