es-toolkit 1.15.1 → 1.16.0
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.
- package/CHANGELOG.md +6 -0
- package/dist/_chunk/{initial-CBsbzo.js → initial-y0QrPY.js} +28 -0
- package/dist/_chunk/{isFunction-D0hq6d.js → isFunction-aCEz9d.js} +5 -7
- package/dist/_chunk/{isObjectLike-BeLCsr.js → toMerged-BGwYW5.js} +25 -0
- package/dist/_internal/compareValues.mjs +11 -0
- package/dist/array/index.d.mts +1 -0
- package/dist/array/index.d.ts +1 -0
- package/dist/array/index.js +3 -11
- package/dist/array/index.mjs +1 -0
- package/dist/array/orderBy.mjs +2 -9
- package/dist/array/sortBy.d.mts +35 -0
- package/dist/array/sortBy.d.ts +35 -0
- package/dist/array/sortBy.mjs +19 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/getSymbols.mjs +1 -2
- package/dist/compat/_internal/toKey.mjs +13 -0
- package/dist/compat/array/find.d.mts +122 -0
- package/dist/compat/array/find.d.ts +122 -0
- package/dist/compat/array/find.mjs +42 -0
- package/dist/compat/array/findIndex.d.mts +62 -0
- package/dist/compat/array/findIndex.d.ts +62 -0
- package/dist/compat/array/findIndex.mjs +26 -0
- package/dist/compat/array/indexOf.d.mts +21 -0
- package/dist/compat/array/indexOf.d.ts +21 -0
- package/dist/compat/array/indexOf.mjs +20 -0
- package/dist/compat/function/ary.d.mts +2 -1
- package/dist/compat/function/ary.d.ts +2 -1
- package/dist/compat/function/bind.d.mts +3 -1
- package/dist/compat/function/bind.d.ts +3 -1
- package/dist/compat/function/rest.d.mts +33 -0
- package/dist/compat/function/rest.d.ts +33 -0
- package/dist/compat/function/rest.mjs +11 -0
- package/dist/compat/index.d.mts +13 -0
- package/dist/compat/index.d.ts +13 -0
- package/dist/compat/index.js +413 -259
- package/dist/compat/index.mjs +13 -0
- package/dist/compat/object/get.mjs +2 -4
- package/dist/compat/object/has.d.mts +32 -0
- package/dist/compat/object/has.d.ts +32 -0
- package/dist/compat/object/has.mjs +34 -0
- package/dist/compat/object/merge.d.mts +1 -0
- package/dist/compat/object/merge.d.ts +1 -0
- package/dist/compat/object/mergeWith.d.mts +6 -0
- package/dist/compat/object/mergeWith.d.ts +6 -0
- package/dist/compat/object/mergeWith.mjs +0 -3
- package/dist/compat/object/set.mjs +1 -5
- package/dist/compat/predicate/isArrayLike.mjs +1 -2
- package/dist/compat/predicate/isString.d.mts +20 -0
- package/dist/compat/predicate/isString.d.ts +20 -0
- package/dist/compat/predicate/isString.mjs +13 -0
- package/dist/compat/predicate/matchesProperty.d.mts +28 -0
- package/dist/compat/predicate/matchesProperty.d.ts +28 -0
- package/dist/compat/predicate/matchesProperty.mjs +22 -0
- package/dist/compat/string/padEnd.d.mts +20 -0
- package/dist/compat/string/padEnd.d.ts +20 -0
- package/dist/compat/string/padEnd.mjs +5 -0
- package/dist/function/ary.d.mts +1 -1
- package/dist/function/ary.d.ts +1 -1
- package/dist/function/index.d.mts +4 -0
- package/dist/function/index.d.ts +4 -0
- package/dist/function/index.js +76 -0
- package/dist/function/index.mjs +4 -0
- package/dist/function/memoize.d.mts +87 -0
- package/dist/function/memoize.d.ts +87 -0
- package/dist/function/memoize.mjs +16 -0
- package/dist/function/partial.d.mts +33 -0
- package/dist/function/partial.d.ts +33 -0
- package/dist/function/partial.mjs +23 -0
- package/dist/function/partialRight.d.mts +33 -0
- package/dist/function/partialRight.d.ts +33 -0
- package/dist/function/partialRight.mjs +25 -0
- package/dist/function/rest.d.mts +33 -0
- package/dist/function/rest.d.ts +33 -0
- package/dist/function/rest.mjs +12 -0
- package/dist/function/unary.d.mts +1 -1
- package/dist/function/unary.d.ts +1 -1
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +21 -14
- package/dist/index.mjs +7 -0
- package/dist/object/index.d.mts +1 -0
- package/dist/object/index.d.ts +1 -0
- package/dist/object/index.js +14 -32
- package/dist/object/index.mjs +1 -0
- package/dist/object/toMerged.d.mts +45 -0
- package/dist/object/toMerged.d.ts +45 -0
- package/dist/object/toMerged.mjs +8 -0
- package/dist/predicate/index.d.mts +1 -0
- package/dist/predicate/index.d.ts +1 -0
- package/dist/predicate/index.js +6 -1
- package/dist/predicate/index.mjs +1 -0
- package/dist/predicate/isEqual.mjs +4 -5
- package/dist/predicate/isString.d.mts +20 -0
- package/dist/predicate/isString.d.ts +20 -0
- package/dist/predicate/isString.mjs +5 -0
- package/dist/string/camelCase.mjs +2 -2
- package/dist/string/index.js +2 -2
- package/package.json +1 -1
package/dist/compat/index.mjs
CHANGED
|
@@ -16,6 +16,7 @@ export { keyBy } from '../array/keyBy.mjs';
|
|
|
16
16
|
export { maxBy } from '../array/maxBy.mjs';
|
|
17
17
|
export { minBy } from '../array/minBy.mjs';
|
|
18
18
|
export { partition } from '../array/partition.mjs';
|
|
19
|
+
export { sortBy } from '../array/sortBy.mjs';
|
|
19
20
|
export { sample } from '../array/sample.mjs';
|
|
20
21
|
export { sampleSize } from '../array/sampleSize.mjs';
|
|
21
22
|
export { shuffle } from '../array/shuffle.mjs';
|
|
@@ -53,7 +54,10 @@ export { noop } from '../function/noop.mjs';
|
|
|
53
54
|
export { once } from '../function/once.mjs';
|
|
54
55
|
export { throttle } from '../function/throttle.mjs';
|
|
55
56
|
export { negate } from '../function/negate.mjs';
|
|
57
|
+
export { memoize } from '../function/memoize.mjs';
|
|
56
58
|
export { unary } from '../function/unary.mjs';
|
|
59
|
+
export { partial } from '../function/partial.mjs';
|
|
60
|
+
export { partialRight } from '../function/partialRight.mjs';
|
|
57
61
|
export { clamp } from '../math/clamp.mjs';
|
|
58
62
|
export { inRange } from '../math/inRange.mjs';
|
|
59
63
|
export { mean } from '../math/mean.mjs';
|
|
@@ -73,6 +77,7 @@ export { clone } from '../object/clone.mjs';
|
|
|
73
77
|
export { flattenObject } from '../object/flattenObject.mjs';
|
|
74
78
|
export { cloneDeep } from '../object/cloneDeep.mjs';
|
|
75
79
|
export { isObjectLike } from './predicate/isObjectLike.mjs';
|
|
80
|
+
export { toMerged } from '../object/toMerged.mjs';
|
|
76
81
|
export { isEqual } from '../predicate/isEqual.mjs';
|
|
77
82
|
export { isNil } from '../predicate/isNil.mjs';
|
|
78
83
|
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
@@ -94,16 +99,21 @@ export { chunk } from './array/chunk.mjs';
|
|
|
94
99
|
export { concat } from './array/concat.mjs';
|
|
95
100
|
export { difference } from './array/difference.mjs';
|
|
96
101
|
export { fill } from './array/fill.mjs';
|
|
102
|
+
export { find } from './array/find.mjs';
|
|
103
|
+
export { findIndex } from './array/findIndex.mjs';
|
|
97
104
|
export { flatten } from './array/flatten.mjs';
|
|
98
105
|
export { flattenDeep } from './array/flattenDeep.mjs';
|
|
99
106
|
export { flattenDepth } from './array/flattenDepth.mjs';
|
|
100
107
|
export { orderBy } from './array/orderBy.mjs';
|
|
101
108
|
export { size } from './array/size.mjs';
|
|
102
109
|
export { zipObjectDeep } from './array/zipObjectDeep.mjs';
|
|
110
|
+
export { indexOf } from './array/indexOf.mjs';
|
|
103
111
|
export { ary } from './function/ary.mjs';
|
|
104
112
|
export { bind } from './function/bind.mjs';
|
|
113
|
+
export { rest } from './function/rest.mjs';
|
|
105
114
|
export { get } from './object/get.mjs';
|
|
106
115
|
export { set } from './object/set.mjs';
|
|
116
|
+
export { has } from './object/has.mjs';
|
|
107
117
|
export { property } from './object/property.mjs';
|
|
108
118
|
export { mapKeys } from './object/mapKeys.mjs';
|
|
109
119
|
export { mapValues } from './object/mapValues.mjs';
|
|
@@ -117,9 +127,12 @@ export { isSymbol } from './predicate/isSymbol.mjs';
|
|
|
117
127
|
export { isBoolean } from './predicate/isBoolean.mjs';
|
|
118
128
|
export { isTypedArray } from './predicate/isTypedArray.mjs';
|
|
119
129
|
export { isMatch } from './predicate/isMatch.mjs';
|
|
130
|
+
export { isString } from './predicate/isString.mjs';
|
|
120
131
|
export { matches } from './predicate/matches.mjs';
|
|
132
|
+
export { matchesProperty } from './predicate/matchesProperty.mjs';
|
|
121
133
|
export { startsWith } from './string/startsWith.mjs';
|
|
122
134
|
export { endsWith } from './string/endsWith.mjs';
|
|
123
135
|
export { padStart } from './string/padStart.mjs';
|
|
136
|
+
export { padEnd } from './string/padEnd.mjs';
|
|
124
137
|
export { max } from './math/max.mjs';
|
|
125
138
|
export { min } from './math/min.mjs';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isDeepKey } from '../_internal/isDeepKey.mjs';
|
|
2
|
+
import { toKey } from '../_internal/toKey.mjs';
|
|
2
3
|
import { toPath } from '../_internal/toPath.mjs';
|
|
3
4
|
|
|
4
5
|
function get(object, path, defaultValue) {
|
|
@@ -18,10 +19,7 @@ function get(object, path, defaultValue) {
|
|
|
18
19
|
let current = object;
|
|
19
20
|
let index;
|
|
20
21
|
for (index = 0; index < resolvedPath.length && current != null; index++) {
|
|
21
|
-
|
|
22
|
-
if (Object.is(key.valueOf(), -0)) {
|
|
23
|
-
key = '-0';
|
|
24
|
-
}
|
|
22
|
+
const key = toKey(resolvedPath[index]);
|
|
25
23
|
current = current[key];
|
|
26
24
|
}
|
|
27
25
|
if (current === null && index === resolvedPath.length) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given path exists within an object.
|
|
3
|
+
*
|
|
4
|
+
* You can provide the path as a single property key, an array of property keys,
|
|
5
|
+
* or a string representing a deep path.
|
|
6
|
+
*
|
|
7
|
+
* If the path is an index and the object is an array or an arguments object, the function will verify
|
|
8
|
+
* if the index is valid and within the bounds of the array or arguments object, even if the array or
|
|
9
|
+
* arguments object is sparse (i.e., not all indexes are defined).
|
|
10
|
+
*
|
|
11
|
+
* @param {object} object - The object to query.
|
|
12
|
+
* @param {PropertyKey | PropertyKey[]} path - The path to check. This can be a single property key,
|
|
13
|
+
* an array of property keys, or a string representing a deep path.
|
|
14
|
+
* @returns {boolean} Returns `true` if the path exists in the object, `false` otherwise.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* const obj = { a: { b: { c: 3 } } };
|
|
19
|
+
*
|
|
20
|
+
* has(obj, 'a'); // true
|
|
21
|
+
* has(obj, ['a', 'b']); // true
|
|
22
|
+
* has(obj, ['a', 'b', 'c']); // true
|
|
23
|
+
* has(obj, 'a.b.c'); // true
|
|
24
|
+
* has(obj, 'a.b.d'); // false
|
|
25
|
+
* has(obj, ['a', 'b', 'c', 'd']); // false
|
|
26
|
+
* has([], 0); // false
|
|
27
|
+
* has([1, 2, 3], 2); // true
|
|
28
|
+
* has([1, 2, 3], 5); // false
|
|
29
|
+
*/
|
|
30
|
+
declare function has(object: unknown, path: PropertyKey | readonly PropertyKey[]): boolean;
|
|
31
|
+
|
|
32
|
+
export { has };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given path exists within an object.
|
|
3
|
+
*
|
|
4
|
+
* You can provide the path as a single property key, an array of property keys,
|
|
5
|
+
* or a string representing a deep path.
|
|
6
|
+
*
|
|
7
|
+
* If the path is an index and the object is an array or an arguments object, the function will verify
|
|
8
|
+
* if the index is valid and within the bounds of the array or arguments object, even if the array or
|
|
9
|
+
* arguments object is sparse (i.e., not all indexes are defined).
|
|
10
|
+
*
|
|
11
|
+
* @param {object} object - The object to query.
|
|
12
|
+
* @param {PropertyKey | PropertyKey[]} path - The path to check. This can be a single property key,
|
|
13
|
+
* an array of property keys, or a string representing a deep path.
|
|
14
|
+
* @returns {boolean} Returns `true` if the path exists in the object, `false` otherwise.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* const obj = { a: { b: { c: 3 } } };
|
|
19
|
+
*
|
|
20
|
+
* has(obj, 'a'); // true
|
|
21
|
+
* has(obj, ['a', 'b']); // true
|
|
22
|
+
* has(obj, ['a', 'b', 'c']); // true
|
|
23
|
+
* has(obj, 'a.b.c'); // true
|
|
24
|
+
* has(obj, 'a.b.d'); // false
|
|
25
|
+
* has(obj, ['a', 'b', 'c', 'd']); // false
|
|
26
|
+
* has([], 0); // false
|
|
27
|
+
* has([1, 2, 3], 2); // true
|
|
28
|
+
* has([1, 2, 3], 5); // false
|
|
29
|
+
*/
|
|
30
|
+
declare function has(object: unknown, path: PropertyKey | readonly PropertyKey[]): boolean;
|
|
31
|
+
|
|
32
|
+
export { has };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isDeepKey } from '../_internal/isDeepKey.mjs';
|
|
2
|
+
import { isIndex } from '../_internal/isIndex.mjs';
|
|
3
|
+
import { toPath } from '../_internal/toPath.mjs';
|
|
4
|
+
import { isArguments } from '../predicate/isArguments.mjs';
|
|
5
|
+
|
|
6
|
+
function has(object, path) {
|
|
7
|
+
let resolvedPath;
|
|
8
|
+
if (Array.isArray(path)) {
|
|
9
|
+
resolvedPath = path;
|
|
10
|
+
}
|
|
11
|
+
else if (typeof path === 'string' && isDeepKey(path) && object?.[path] == null) {
|
|
12
|
+
resolvedPath = toPath(path);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
resolvedPath = [path];
|
|
16
|
+
}
|
|
17
|
+
if (resolvedPath.length === 0) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
let current = object;
|
|
21
|
+
for (let i = 0; i < resolvedPath.length; i++) {
|
|
22
|
+
const key = resolvedPath[i];
|
|
23
|
+
if (current == null || !Object.prototype.hasOwnProperty.call(current, key)) {
|
|
24
|
+
const isSparseIndex = (Array.isArray(current) || isArguments(current)) && isIndex(key) && key < current.length;
|
|
25
|
+
if (!isSparseIndex) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
current = current[key];
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { has };
|
|
@@ -184,6 +184,7 @@ declare function merge<O, S1, S2, S3, S4>(object: O, source1: S1, source2: S2, s
|
|
|
184
184
|
* The function can handle multiple source objects and will merge them all into the target object.
|
|
185
185
|
*
|
|
186
186
|
* @param {any} any - The target object into which the source object properties will be merged. This object is modified in place.
|
|
187
|
+
* @param object
|
|
187
188
|
* @param {any[]} sources - The source objects whose properties will be merged into the target object.
|
|
188
189
|
* @returns {any} The updated target object with properties from the source object(s) merged in.
|
|
189
190
|
*
|
|
@@ -184,6 +184,7 @@ declare function merge<O, S1, S2, S3, S4>(object: O, source1: S1, source2: S2, s
|
|
|
184
184
|
* The function can handle multiple source objects and will merge them all into the target object.
|
|
185
185
|
*
|
|
186
186
|
* @param {any} any - The target object into which the source object properties will be merged. This object is modified in place.
|
|
187
|
+
* @param object
|
|
187
188
|
* @param {any[]} sources - The source objects whose properties will be merged into the target object.
|
|
188
189
|
* @returns {any} The updated target object with properties from the source object(s) merged in.
|
|
189
190
|
*
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
*
|
|
21
21
|
* @param {T} target - The target object into which the source object properties will be merged. This object is modified in place.
|
|
22
22
|
* @param {S} source - The first source object whose properties will be merged into the target object.
|
|
23
|
+
* @param merge
|
|
23
24
|
* @returns {T & S} The updated target object with properties from the source object(s) merged in.
|
|
24
25
|
*
|
|
25
26
|
* @template T - Type of the target object.
|
|
@@ -71,6 +72,7 @@ declare function mergeWith<T, S>(target: T, source: S, merge: (targetValue: any,
|
|
|
71
72
|
* @param {O} object - The target object into which the source object properties will be merged. This object is modified in place.
|
|
72
73
|
* @param {S1} source1 - The first source object to be merged into the target object.
|
|
73
74
|
* @param {S2} source2 - The second source object to be merged into the target object.
|
|
75
|
+
* @param merge
|
|
74
76
|
* @returns {O & S1 & S2} The updated target object with properties from the source objects merged in.
|
|
75
77
|
*
|
|
76
78
|
* @template O - Type of the target object.
|
|
@@ -124,6 +126,7 @@ declare function mergeWith<O, S1, S2>(object: O, source1: S1, source2: S2, merge
|
|
|
124
126
|
* @param {S1} source1 - The first source object whose properties will be merged into the target object.
|
|
125
127
|
* @param {S2} source2 - The second source object whose properties will be merged into the target object.
|
|
126
128
|
* @param {S3} source3 - The third source object whose properties will be merged into the target object.
|
|
129
|
+
* @param merge
|
|
127
130
|
* @returns {O & S1 & S2 & S3} The updated target object with properties from the source object(s) merged in.
|
|
128
131
|
*
|
|
129
132
|
* @template O - Type of the target object.
|
|
@@ -179,6 +182,7 @@ declare function mergeWith<O, S1, S2, S3>(object: O, source1: S1, source2: S2, s
|
|
|
179
182
|
* @param {S2} source2 - The second source object whose properties will be merged into the target object.
|
|
180
183
|
* @param {S3} source3 - The third source object whose properties will be merged into the target object.
|
|
181
184
|
* @param {S4} source4 - The fourth source object whose properties will be merged into the target object.
|
|
185
|
+
* @param merge
|
|
182
186
|
* @returns {O & S1 & S2 & S3 & S4} The updated target object with properties from the source object(s) merged in.
|
|
183
187
|
*
|
|
184
188
|
* @template O - Type of the target object.
|
|
@@ -232,6 +236,8 @@ declare function mergeWith<O, S1, S2, S3, S4>(object: O, source1: S1, source2: S
|
|
|
232
236
|
*
|
|
233
237
|
* @param {any} any - The target object into which the source object properties will be merged. This object is modified in place.
|
|
234
238
|
* @param {any[]} sources - The source objects whose properties will be merged into the target object.
|
|
239
|
+
* @param object
|
|
240
|
+
* @param {...any} otherArgs
|
|
235
241
|
* @returns {any} The updated target object with properties from the source object(s) merged in.
|
|
236
242
|
*
|
|
237
243
|
* @example
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
*
|
|
21
21
|
* @param {T} target - The target object into which the source object properties will be merged. This object is modified in place.
|
|
22
22
|
* @param {S} source - The first source object whose properties will be merged into the target object.
|
|
23
|
+
* @param merge
|
|
23
24
|
* @returns {T & S} The updated target object with properties from the source object(s) merged in.
|
|
24
25
|
*
|
|
25
26
|
* @template T - Type of the target object.
|
|
@@ -71,6 +72,7 @@ declare function mergeWith<T, S>(target: T, source: S, merge: (targetValue: any,
|
|
|
71
72
|
* @param {O} object - The target object into which the source object properties will be merged. This object is modified in place.
|
|
72
73
|
* @param {S1} source1 - The first source object to be merged into the target object.
|
|
73
74
|
* @param {S2} source2 - The second source object to be merged into the target object.
|
|
75
|
+
* @param merge
|
|
74
76
|
* @returns {O & S1 & S2} The updated target object with properties from the source objects merged in.
|
|
75
77
|
*
|
|
76
78
|
* @template O - Type of the target object.
|
|
@@ -124,6 +126,7 @@ declare function mergeWith<O, S1, S2>(object: O, source1: S1, source2: S2, merge
|
|
|
124
126
|
* @param {S1} source1 - The first source object whose properties will be merged into the target object.
|
|
125
127
|
* @param {S2} source2 - The second source object whose properties will be merged into the target object.
|
|
126
128
|
* @param {S3} source3 - The third source object whose properties will be merged into the target object.
|
|
129
|
+
* @param merge
|
|
127
130
|
* @returns {O & S1 & S2 & S3} The updated target object with properties from the source object(s) merged in.
|
|
128
131
|
*
|
|
129
132
|
* @template O - Type of the target object.
|
|
@@ -179,6 +182,7 @@ declare function mergeWith<O, S1, S2, S3>(object: O, source1: S1, source2: S2, s
|
|
|
179
182
|
* @param {S2} source2 - The second source object whose properties will be merged into the target object.
|
|
180
183
|
* @param {S3} source3 - The third source object whose properties will be merged into the target object.
|
|
181
184
|
* @param {S4} source4 - The fourth source object whose properties will be merged into the target object.
|
|
185
|
+
* @param merge
|
|
182
186
|
* @returns {O & S1 & S2 & S3 & S4} The updated target object with properties from the source object(s) merged in.
|
|
183
187
|
*
|
|
184
188
|
* @template O - Type of the target object.
|
|
@@ -232,6 +236,8 @@ declare function mergeWith<O, S1, S2, S3, S4>(object: O, source1: S1, source2: S
|
|
|
232
236
|
*
|
|
233
237
|
* @param {any} any - The target object into which the source object properties will be merged. This object is modified in place.
|
|
234
238
|
* @param {any[]} sources - The source objects whose properties will be merged into the target object.
|
|
239
|
+
* @param object
|
|
240
|
+
* @param {...any} otherArgs
|
|
235
241
|
* @returns {any} The updated target object with properties from the source object(s) merged in.
|
|
236
242
|
*
|
|
237
243
|
* @example
|
|
@@ -56,9 +56,6 @@ function mergeWithDeep(target, source, merge, stack) {
|
|
|
56
56
|
else if (isObjectLike(targetValue) && isObjectLike(sourceValue)) {
|
|
57
57
|
target[key] = mergeWithDeep(targetValue, sourceValue, merge, stack);
|
|
58
58
|
}
|
|
59
|
-
else if (targetValue == null && Array.isArray(sourceValue)) {
|
|
60
|
-
target[key] = mergeWithDeep([], sourceValue, merge, stack);
|
|
61
|
-
}
|
|
62
59
|
else if (targetValue == null && isPlainObject(sourceValue)) {
|
|
63
60
|
target[key] = mergeWithDeep({}, sourceValue, merge, stack);
|
|
64
61
|
}
|
|
@@ -2,11 +2,7 @@ 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)
|
|
6
|
-
? path
|
|
7
|
-
: typeof path === 'string'
|
|
8
|
-
? toPath(path)
|
|
9
|
-
: [path];
|
|
5
|
+
const resolvedPath = Array.isArray(path) ? path : typeof path === 'string' ? toPath(path) : [path];
|
|
10
6
|
let current = obj;
|
|
11
7
|
for (let i = 0; i < resolvedPath.length - 1; i++) {
|
|
12
8
|
const key = resolvedPath[i];
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { isLength } from '../../predicate/isLength.mjs';
|
|
2
2
|
|
|
3
3
|
function isArrayLike(value) {
|
|
4
|
-
return value != null && typeof value !==
|
|
5
|
-
isLength(value.length);
|
|
4
|
+
return value != null && typeof value !== 'function' && isLength(value.length);
|
|
6
5
|
}
|
|
7
6
|
|
|
8
7
|
export { isArrayLike };
|
|
@@ -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,13 @@
|
|
|
1
|
+
import { getTag } from '../_internal/getTag.mjs';
|
|
2
|
+
|
|
3
|
+
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;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { isString };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that checks if a given target object matches a specific property value.
|
|
3
|
+
*
|
|
4
|
+
* The returned function takes a target object and determines if the property at the
|
|
5
|
+
* specified path within the target object is equal to the given value.
|
|
6
|
+
*
|
|
7
|
+
* @param {PropertyKey | PropertyKey[]} property - The property path to check within the target object.
|
|
8
|
+
* This can be a single property key or an array of property keys.
|
|
9
|
+
* @param {unknown} source - The value to compare against the property value in the target object.
|
|
10
|
+
*
|
|
11
|
+
* @returns {(target: unknown) => boolean} - A function that takes a target object and returns
|
|
12
|
+
* `true` if the property value at the given path in the target object matches the provided value,
|
|
13
|
+
* otherwise returns `false`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Using a single property key
|
|
17
|
+
* const checkName = matchesProperty('name', 'Alice');
|
|
18
|
+
* console.log(checkName({ name: 'Alice' })); // true
|
|
19
|
+
* console.log(checkName({ name: 'Bob' })); // false
|
|
20
|
+
*
|
|
21
|
+
* // Using an array of property keys
|
|
22
|
+
* const checkNested = matchesProperty(['address', 'city'], 'New York');
|
|
23
|
+
* console.log(checkNested({ address: { city: 'New York' } })); // true
|
|
24
|
+
* console.log(checkNested({ address: { city: 'Los Angeles' } })); // false
|
|
25
|
+
*/
|
|
26
|
+
declare function matchesProperty(property: PropertyKey | readonly PropertyKey[], source: unknown): (target?: unknown) => boolean;
|
|
27
|
+
|
|
28
|
+
export { matchesProperty };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that checks if a given target object matches a specific property value.
|
|
3
|
+
*
|
|
4
|
+
* The returned function takes a target object and determines if the property at the
|
|
5
|
+
* specified path within the target object is equal to the given value.
|
|
6
|
+
*
|
|
7
|
+
* @param {PropertyKey | PropertyKey[]} property - The property path to check within the target object.
|
|
8
|
+
* This can be a single property key or an array of property keys.
|
|
9
|
+
* @param {unknown} source - The value to compare against the property value in the target object.
|
|
10
|
+
*
|
|
11
|
+
* @returns {(target: unknown) => boolean} - A function that takes a target object and returns
|
|
12
|
+
* `true` if the property value at the given path in the target object matches the provided value,
|
|
13
|
+
* otherwise returns `false`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Using a single property key
|
|
17
|
+
* const checkName = matchesProperty('name', 'Alice');
|
|
18
|
+
* console.log(checkName({ name: 'Alice' })); // true
|
|
19
|
+
* console.log(checkName({ name: 'Bob' })); // false
|
|
20
|
+
*
|
|
21
|
+
* // Using an array of property keys
|
|
22
|
+
* const checkNested = matchesProperty(['address', 'city'], 'New York');
|
|
23
|
+
* console.log(checkNested({ address: { city: 'New York' } })); // true
|
|
24
|
+
* console.log(checkNested({ address: { city: 'Los Angeles' } })); // false
|
|
25
|
+
*/
|
|
26
|
+
declare function matchesProperty(property: PropertyKey | readonly PropertyKey[], source: unknown): (target?: unknown) => boolean;
|
|
27
|
+
|
|
28
|
+
export { matchesProperty };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { toKey } from '../_internal/toKey.mjs';
|
|
2
|
+
import { cloneDeep } from '../object/cloneDeep.mjs';
|
|
3
|
+
import { get } from '../object/get.mjs';
|
|
4
|
+
import { has } from '../object/has.mjs';
|
|
5
|
+
import { isMatch } from './isMatch.mjs';
|
|
6
|
+
|
|
7
|
+
function matchesProperty(property, source) {
|
|
8
|
+
property = Array.isArray(property) ? property : toKey(property);
|
|
9
|
+
source = cloneDeep(source);
|
|
10
|
+
return function (target) {
|
|
11
|
+
const result = get(target, property);
|
|
12
|
+
if (result === undefined) {
|
|
13
|
+
return has(target, property);
|
|
14
|
+
}
|
|
15
|
+
if (source === undefined) {
|
|
16
|
+
return result === undefined;
|
|
17
|
+
}
|
|
18
|
+
return isMatch(result, source);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { matchesProperty };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pads the end of a string with a given character until it reaches the specified length.
|
|
3
|
+
*
|
|
4
|
+
* If the length is less than or equal to the original string's length, or if the padding character is an empty string,
|
|
5
|
+
* the original string is returned unchanged.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} str - The string to pad.
|
|
8
|
+
* @param {number} [length] - The length of the resulting string once padded.
|
|
9
|
+
* @param {string} [chars] - The character(s) to use for padding.
|
|
10
|
+
* @returns {string} - The padded string, or the original string if padding is not required.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const result1 = padEnd('abc', 6); // result will be 'abc '
|
|
14
|
+
* const result2 = padEnd('abc', 6, '_-'); // result will be 'abc_-_'
|
|
15
|
+
* const result3 = padEnd('abc', 3); // result will be 'abc'
|
|
16
|
+
* const result4 = padEnd('abc', 2); // result will be 'abc'
|
|
17
|
+
*/
|
|
18
|
+
declare function padEnd(str: string, length?: number, chars?: string): string;
|
|
19
|
+
|
|
20
|
+
export { padEnd };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pads the end of a string with a given character until it reaches the specified length.
|
|
3
|
+
*
|
|
4
|
+
* If the length is less than or equal to the original string's length, or if the padding character is an empty string,
|
|
5
|
+
* the original string is returned unchanged.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} str - The string to pad.
|
|
8
|
+
* @param {number} [length] - The length of the resulting string once padded.
|
|
9
|
+
* @param {string} [chars] - The character(s) to use for padding.
|
|
10
|
+
* @returns {string} - The padded string, or the original string if padding is not required.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const result1 = padEnd('abc', 6); // result will be 'abc '
|
|
14
|
+
* const result2 = padEnd('abc', 6, '_-'); // result will be 'abc_-_'
|
|
15
|
+
* const result3 = padEnd('abc', 3); // result will be 'abc'
|
|
16
|
+
* const result4 = padEnd('abc', 2); // result will be 'abc'
|
|
17
|
+
*/
|
|
18
|
+
declare function padEnd(str: string, length?: number, chars?: string): string;
|
|
19
|
+
|
|
20
|
+
export { padEnd };
|
package/dist/function/ary.d.mts
CHANGED
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
* @param {any} guard - Enables use as an iteratee for methods like `map`.
|
|
8
8
|
* @returns {(...args: any[]) => ReturnType<F>} Returns the new capped function.
|
|
9
9
|
*/
|
|
10
|
-
declare function ary<F extends (...args: any[]) => any>(func: F, n: number): (
|
|
10
|
+
declare function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: any[]) => ReturnType<F>;
|
|
11
11
|
|
|
12
12
|
export { ary };
|
package/dist/function/ary.d.ts
CHANGED
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
* @param {any} guard - Enables use as an iteratee for methods like `map`.
|
|
8
8
|
* @returns {(...args: any[]) => ReturnType<F>} Returns the new capped function.
|
|
9
9
|
*/
|
|
10
|
-
declare function ary<F extends (...args: any[]) => any>(func: F, n: number): (
|
|
10
|
+
declare function ary<F extends (...args: any[]) => any>(func: F, n: number): (...args: any[]) => ReturnType<F>;
|
|
11
11
|
|
|
12
12
|
export { ary };
|
|
@@ -5,5 +5,9 @@ export { noop } from './noop.mjs';
|
|
|
5
5
|
export { once } from './once.mjs';
|
|
6
6
|
export { throttle } from './throttle.mjs';
|
|
7
7
|
export { negate } from './negate.mjs';
|
|
8
|
+
export { MemoizeCache, memoize } from './memoize.mjs';
|
|
8
9
|
export { ary } from './ary.mjs';
|
|
9
10
|
export { unary } from './unary.mjs';
|
|
11
|
+
export { partial } from './partial.mjs';
|
|
12
|
+
export { partialRight } from './partialRight.mjs';
|
|
13
|
+
export { rest } from './rest.mjs';
|
package/dist/function/index.d.ts
CHANGED
|
@@ -5,5 +5,9 @@ export { noop } from './noop.js';
|
|
|
5
5
|
export { once } from './once.js';
|
|
6
6
|
export { throttle } from './throttle.js';
|
|
7
7
|
export { negate } from './negate.js';
|
|
8
|
+
export { MemoizeCache, memoize } from './memoize.js';
|
|
8
9
|
export { ary } from './ary.js';
|
|
9
10
|
export { unary } from './unary.js';
|
|
11
|
+
export { partial } from './partial.js';
|
|
12
|
+
export { partialRight } from './partialRight.js';
|
|
13
|
+
export { rest } from './rest.js';
|
package/dist/function/index.js
CHANGED
|
@@ -87,6 +87,21 @@ function negate(func) {
|
|
|
87
87
|
return ((...args) => !func(...args));
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
function memoize(fn, options = {}) {
|
|
91
|
+
const { cache = new Map(), getCacheKey } = options;
|
|
92
|
+
const memoizedFn = function (arg) {
|
|
93
|
+
const key = getCacheKey ? getCacheKey(arg) : arg;
|
|
94
|
+
if (cache.has(key)) {
|
|
95
|
+
return cache.get(key);
|
|
96
|
+
}
|
|
97
|
+
const result = fn.call(this, arg);
|
|
98
|
+
cache.set(key, result);
|
|
99
|
+
return result;
|
|
100
|
+
};
|
|
101
|
+
memoizedFn.cache = cache;
|
|
102
|
+
return memoizedFn;
|
|
103
|
+
}
|
|
104
|
+
|
|
90
105
|
function ary(func, n) {
|
|
91
106
|
return function (...args) {
|
|
92
107
|
return func.apply(this, args.slice(0, n));
|
|
@@ -97,12 +112,73 @@ function unary(func) {
|
|
|
97
112
|
return ary(func, 1);
|
|
98
113
|
}
|
|
99
114
|
|
|
115
|
+
function partial(func, ...partialArgs) {
|
|
116
|
+
return function (...providedArgs) {
|
|
117
|
+
const args = [];
|
|
118
|
+
let startIndex = 0;
|
|
119
|
+
for (let i = 0; i < partialArgs.length; i++) {
|
|
120
|
+
const arg = partialArgs[i];
|
|
121
|
+
if (arg === partial.placeholder) {
|
|
122
|
+
args.push(providedArgs[startIndex++]);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
args.push(arg);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (let i = startIndex; i < providedArgs.length; i++) {
|
|
129
|
+
args.push(providedArgs[i]);
|
|
130
|
+
}
|
|
131
|
+
return func.apply(this, args);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const partialPlaceholder = Symbol('partial.placeholder');
|
|
135
|
+
partial.placeholder = partialPlaceholder;
|
|
136
|
+
|
|
137
|
+
function partialRight(func, ...partialArgs) {
|
|
138
|
+
return function (...providedArgs) {
|
|
139
|
+
const placeholderLength = partialArgs.filter(arg => arg === partialRightPlaceholder).length;
|
|
140
|
+
const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
|
|
141
|
+
const args = [];
|
|
142
|
+
let providedIndex = 0;
|
|
143
|
+
for (let i = 0; i < rangeLength; i++) {
|
|
144
|
+
args.push(providedArgs[providedIndex++]);
|
|
145
|
+
}
|
|
146
|
+
for (let i = 0; i < partialArgs.length; i++) {
|
|
147
|
+
const arg = partialArgs[i];
|
|
148
|
+
if (arg === partialRight.placeholder) {
|
|
149
|
+
args.push(providedArgs[providedIndex++]);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
args.push(arg);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return func.apply(this, args);
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const partialRightPlaceholder = Symbol('partialRight.placeholder');
|
|
159
|
+
partialRight.placeholder = partialRightPlaceholder;
|
|
160
|
+
|
|
161
|
+
function rest(func, startIndex = func.length - 1) {
|
|
162
|
+
return function (...args) {
|
|
163
|
+
const rest = args.slice(startIndex);
|
|
164
|
+
const params = args.slice(0, startIndex);
|
|
165
|
+
while (params.length < startIndex) {
|
|
166
|
+
params.push(undefined);
|
|
167
|
+
}
|
|
168
|
+
return func.apply(this, [...params, rest]);
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
100
172
|
exports.after = after;
|
|
101
173
|
exports.ary = ary;
|
|
102
174
|
exports.before = before;
|
|
103
175
|
exports.debounce = debounce;
|
|
176
|
+
exports.memoize = memoize;
|
|
104
177
|
exports.negate = negate;
|
|
105
178
|
exports.noop = noop;
|
|
106
179
|
exports.once = once;
|
|
180
|
+
exports.partial = partial;
|
|
181
|
+
exports.partialRight = partialRight;
|
|
182
|
+
exports.rest = rest;
|
|
107
183
|
exports.throttle = throttle;
|
|
108
184
|
exports.unary = unary;
|
package/dist/function/index.mjs
CHANGED
|
@@ -5,5 +5,9 @@ export { noop } from './noop.mjs';
|
|
|
5
5
|
export { once } from './once.mjs';
|
|
6
6
|
export { throttle } from './throttle.mjs';
|
|
7
7
|
export { negate } from './negate.mjs';
|
|
8
|
+
export { memoize } from './memoize.mjs';
|
|
8
9
|
export { ary } from './ary.mjs';
|
|
9
10
|
export { unary } from './unary.mjs';
|
|
11
|
+
export { partial } from './partial.mjs';
|
|
12
|
+
export { partialRight } from './partialRight.mjs';
|
|
13
|
+
export { rest } from './rest.mjs';
|