es-toolkit 1.18.0 → 1.19.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 +11 -0
- package/dist/_chunk/{rest-CXt9w3.js → curry-BmwJrK.js} +21 -0
- package/dist/_chunk/{isWeakSet-CogETi.js → isWeakSet-E_VMwB.js} +9 -3
- package/dist/_chunk/range-BXlMmn.js +68 -0
- package/dist/_chunk/{toMerged-DN1PPP.js → toMerged-Bzkqyz.js} +28 -46
- package/dist/_chunk/{zipWith-CYaH1Y.js → zipWith-B-5AMf.js} +1 -1
- package/dist/array/forEachRight.d.mts +23 -0
- package/dist/array/forEachRight.d.ts +23 -0
- package/dist/array/groupBy.mjs +1 -1
- package/dist/array/index.js +1 -1
- package/dist/array/orderBy.d.mts +1 -1
- package/dist/array/orderBy.d.ts +1 -1
- package/dist/array/sortBy.d.mts +1 -1
- package/dist/array/sortBy.d.ts +1 -1
- package/dist/array/unzip.d.mts +1 -1
- package/dist/array/unzip.d.ts +1 -1
- package/dist/array/zipObject.d.mts +1 -1
- package/dist/array/zipObject.d.ts +1 -1
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/decimalAdjust.mjs +19 -0
- package/dist/compat/_internal/isDeepKey.mjs +1 -3
- package/dist/compat/_internal/normalizeForCase.mjs +5 -4
- package/dist/compat/_internal/toKey.mjs +2 -7
- package/dist/compat/array/flatten.d.mts +1 -1
- package/dist/compat/array/flatten.d.ts +1 -1
- package/dist/compat/array/flattenDepth.d.mts +1 -1
- package/dist/compat/array/flattenDepth.d.ts +1 -1
- package/dist/compat/array/indexOf.d.mts +1 -1
- package/dist/compat/array/indexOf.d.ts +1 -1
- package/dist/compat/array/orderBy.d.mts +1 -1
- package/dist/compat/array/orderBy.d.ts +1 -1
- package/dist/compat/array/orderBy.mjs +1 -1
- package/dist/compat/array/size.d.mts +1 -1
- package/dist/compat/array/size.d.ts +1 -1
- package/dist/compat/array/sortBy.d.mts +1 -1
- package/dist/compat/array/sortBy.d.ts +1 -1
- package/dist/compat/array/zipObjectDeep.d.mts +1 -1
- package/dist/compat/array/zipObjectDeep.d.ts +1 -1
- package/dist/compat/index.d.mts +20 -7
- package/dist/compat/index.d.ts +20 -7
- package/dist/compat/index.js +459 -137
- package/dist/compat/index.mjs +20 -7
- package/dist/compat/math/ceil.d.mts +15 -0
- package/dist/compat/math/ceil.d.ts +15 -0
- package/dist/compat/math/ceil.mjs +7 -0
- package/dist/compat/math/floor.d.mts +15 -0
- package/dist/compat/math/floor.d.ts +15 -0
- package/dist/compat/math/floor.mjs +7 -0
- package/dist/compat/math/round.d.mts +15 -0
- package/dist/compat/math/round.d.ts +15 -0
- package/dist/compat/math/round.mjs +7 -0
- package/dist/compat/object/fromPairs.d.mts +2 -2
- package/dist/compat/object/fromPairs.d.ts +2 -2
- package/dist/compat/object/get.d.mts +12 -12
- package/dist/compat/object/get.d.ts +12 -12
- package/dist/compat/object/get.mjs +54 -17
- package/dist/compat/object/has.mjs +1 -1
- package/dist/compat/object/mergeWith.mjs +14 -2
- package/dist/compat/object/omit.d.mts +34 -0
- package/dist/compat/object/omit.d.ts +34 -0
- package/dist/compat/object/omit.mjs +33 -0
- package/dist/compat/object/pick.d.mts +47 -0
- package/dist/compat/object/pick.d.ts +47 -0
- package/dist/compat/object/pick.mjs +38 -0
- package/dist/compat/object/set.mjs +1 -1
- package/dist/compat/object/unset.d.mts +20 -0
- package/dist/compat/object/unset.d.ts +20 -0
- package/dist/compat/object/unset.mjs +68 -0
- package/dist/compat/predicate/isInteger.d.mts +17 -0
- package/dist/compat/predicate/isInteger.d.ts +17 -0
- package/dist/compat/predicate/isInteger.mjs +5 -0
- package/dist/compat/predicate/isMatch.mjs +44 -4
- package/dist/compat/predicate/isNil.mjs +5 -0
- package/dist/compat/predicate/isObject.d.mts +4 -4
- package/dist/compat/predicate/isObject.d.ts +4 -4
- package/dist/compat/predicate/isSafeInteger.d.mts +20 -0
- package/dist/compat/predicate/isSafeInteger.d.ts +20 -0
- package/dist/compat/predicate/isSafeInteger.mjs +5 -0
- package/dist/compat/predicate/matchesProperty.mjs +12 -1
- package/dist/compat/string/kebabCase.d.mts +17 -0
- package/dist/compat/string/kebabCase.d.ts +17 -0
- package/dist/compat/string/kebabCase.mjs +9 -0
- package/dist/compat/string/lowerCase.d.mts +17 -0
- package/dist/compat/string/lowerCase.d.ts +17 -0
- package/dist/compat/string/lowerCase.mjs +8 -0
- package/dist/compat/string/snakeCase.d.mts +17 -0
- package/dist/compat/string/snakeCase.d.ts +17 -0
- package/dist/compat/string/snakeCase.mjs +8 -0
- package/dist/compat/string/startCase.d.mts +16 -0
- package/dist/compat/string/startCase.d.ts +16 -0
- package/dist/compat/string/startCase.mjs +8 -0
- package/dist/compat/string/trim.d.mts +16 -0
- package/dist/compat/string/trim.d.ts +16 -0
- package/dist/compat/string/trim.mjs +25 -0
- package/dist/compat/string/trimEnd.d.mts +17 -0
- package/dist/compat/string/trimEnd.d.ts +17 -0
- package/dist/compat/string/trimEnd.mjs +25 -0
- package/dist/compat/string/trimStart.d.mts +17 -0
- package/dist/compat/string/trimStart.d.ts +17 -0
- package/dist/compat/string/trimStart.mjs +25 -0
- package/dist/compat/util/toPath.d.mts +20 -0
- package/dist/compat/util/toPath.d.ts +20 -0
- package/dist/compat/util/toPath.mjs +37 -0
- package/dist/compat/util/toString.d.mts +19 -0
- package/dist/compat/util/toString.d.ts +19 -0
- package/dist/compat/util/toString.mjs +15 -0
- package/dist/function/curry.d.mts +127 -0
- package/dist/function/curry.d.ts +127 -0
- package/dist/function/curry.mjs +21 -0
- package/dist/function/index.d.mts +1 -0
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.js +15 -14
- package/dist/function/index.mjs +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +40 -33
- package/dist/index.mjs +6 -0
- package/dist/math/index.js +8 -66
- package/dist/object/clone.mjs +28 -25
- package/dist/object/index.js +19 -3
- package/dist/object/pick.d.mts +1 -1
- package/dist/object/pick.d.ts +1 -1
- package/dist/predicate/index.d.mts +1 -0
- package/dist/predicate/index.d.ts +1 -0
- package/dist/predicate/index.js +6 -5
- package/dist/predicate/index.mjs +1 -0
- package/dist/predicate/isDate.d.mts +16 -0
- package/dist/predicate/isDate.d.ts +16 -0
- package/dist/predicate/isDate.mjs +5 -0
- package/dist/predicate/isNotNil.mjs +1 -1
- package/dist/string/capitalize.d.mts +1 -0
- package/dist/string/capitalize.d.ts +1 -0
- package/dist/string/index.d.mts +4 -0
- package/dist/string/index.d.ts +4 -0
- package/dist/string/index.js +65 -0
- package/dist/string/index.mjs +4 -0
- package/dist/string/startCase.d.mts +1 -1
- package/dist/string/startCase.d.ts +1 -1
- package/dist/string/trim.d.mts +15 -0
- package/dist/string/trim.d.ts +15 -0
- package/dist/string/trim.mjs +11 -0
- package/dist/string/trimEnd.d.mts +16 -0
- package/dist/string/trimEnd.d.ts +16 -0
- package/dist/string/trimEnd.mjs +22 -0
- package/dist/string/trimStart.d.mts +16 -0
- package/dist/string/trimStart.d.ts +16 -0
- package/dist/string/trimStart.mjs +22 -0
- package/dist/string/upperCase.d.mts +17 -0
- package/dist/string/upperCase.d.ts +17 -0
- package/dist/string/upperCase.mjs +15 -0
- package/package.json +1 -1
- package/dist/compat/_internal/isArrayMatch.mjs +0 -24
- package/dist/compat/_internal/isMapMatch.mjs +0 -18
- package/dist/compat/_internal/isSetMatch.mjs +0 -13
- package/dist/compat/_internal/toPath.mjs +0 -40
- package/dist/_chunk/{isTypedArray-Dsrnb1.js → isPlainObject-BIekvL.js} +8 -8
package/dist/compat/index.mjs
CHANGED
|
@@ -60,19 +60,17 @@ export { memoize } from '../function/memoize.mjs';
|
|
|
60
60
|
export { unary } from '../function/unary.mjs';
|
|
61
61
|
export { partial } from '../function/partial.mjs';
|
|
62
62
|
export { partialRight } from '../function/partialRight.mjs';
|
|
63
|
+
export { curry } from '../function/curry.mjs';
|
|
63
64
|
export { clamp } from '../math/clamp.mjs';
|
|
64
65
|
export { inRange } from '../math/inRange.mjs';
|
|
65
66
|
export { mean } from '../math/mean.mjs';
|
|
66
67
|
export { meanBy } from '../math/meanBy.mjs';
|
|
67
68
|
export { random } from '../math/random.mjs';
|
|
68
69
|
export { randomInt } from '../math/randomInt.mjs';
|
|
69
|
-
export { round } from '../math/round.mjs';
|
|
70
70
|
export { sum } from '../math/sum.mjs';
|
|
71
71
|
export { sumBy } from '../math/sumBy.mjs';
|
|
72
72
|
export { range } from '../math/range.mjs';
|
|
73
|
-
export { omit } from '../object/omit.mjs';
|
|
74
73
|
export { omitBy } from '../object/omitBy.mjs';
|
|
75
|
-
export { pick } from '../object/pick.mjs';
|
|
76
74
|
export { pickBy } from '../object/pickBy.mjs';
|
|
77
75
|
export { invert } from '../object/invert.mjs';
|
|
78
76
|
export { clone } from '../object/clone.mjs';
|
|
@@ -80,6 +78,7 @@ export { flattenObject } from '../object/flattenObject.mjs';
|
|
|
80
78
|
export { cloneDeep } from '../object/cloneDeep.mjs';
|
|
81
79
|
export { isObjectLike } from './predicate/isObjectLike.mjs';
|
|
82
80
|
export { toMerged } from '../object/toMerged.mjs';
|
|
81
|
+
export { isDate } from '../predicate/isDate.mjs';
|
|
83
82
|
export { isEqual } from '../predicate/isEqual.mjs';
|
|
84
83
|
export { isNil } from '../predicate/isNil.mjs';
|
|
85
84
|
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
@@ -92,10 +91,7 @@ export { delay } from '../promise/delay.mjs';
|
|
|
92
91
|
export { withTimeout } from '../promise/withTimeout.mjs';
|
|
93
92
|
export { timeout } from '../promise/timeout.mjs';
|
|
94
93
|
export { capitalize } from '../string/capitalize.mjs';
|
|
95
|
-
export {
|
|
96
|
-
export { kebabCase } from '../string/kebabCase.mjs';
|
|
97
|
-
export { lowerCase } from '../string/lowerCase.mjs';
|
|
98
|
-
export { startCase } from '../string/startCase.mjs';
|
|
94
|
+
export { upperCase } from '../string/upperCase.mjs';
|
|
99
95
|
export { pascalCase } from '../string/pascalCase.mjs';
|
|
100
96
|
export { upperFirst } from '../string/upperFirst.mjs';
|
|
101
97
|
export { lowerFirst } from '../string/lowerFirst.mjs';
|
|
@@ -131,6 +127,8 @@ export { attempt } from './function/attempt.mjs';
|
|
|
131
127
|
export { rearg } from './function/rearg.mjs';
|
|
132
128
|
export { get } from './object/get.mjs';
|
|
133
129
|
export { set } from './object/set.mjs';
|
|
130
|
+
export { pick } from './object/pick.mjs';
|
|
131
|
+
export { omit } from './object/omit.mjs';
|
|
134
132
|
export { has } from './object/has.mjs';
|
|
135
133
|
export { property } from './object/property.mjs';
|
|
136
134
|
export { mapKeys } from './object/mapKeys.mjs';
|
|
@@ -138,6 +136,7 @@ export { mapValues } from './object/mapValues.mjs';
|
|
|
138
136
|
export { merge } from './object/merge.mjs';
|
|
139
137
|
export { mergeWith } from './object/mergeWith.mjs';
|
|
140
138
|
export { fromPairs } from './object/fromPairs.mjs';
|
|
139
|
+
export { unset } from './object/unset.mjs';
|
|
141
140
|
export { isPlainObject } from './predicate/isPlainObject.mjs';
|
|
142
141
|
export { isArray } from './predicate/isArray.mjs';
|
|
143
142
|
export { isArguments } from './predicate/isArguments.mjs';
|
|
@@ -155,12 +154,26 @@ export { isWeakMap } from './predicate/isWeakMap.mjs';
|
|
|
155
154
|
export { isWeakSet } from './predicate/isWeakSet.mjs';
|
|
156
155
|
export { conforms } from './predicate/conforms.mjs';
|
|
157
156
|
export { conformsTo } from './predicate/conformsTo.mjs';
|
|
157
|
+
export { isInteger } from './predicate/isInteger.mjs';
|
|
158
|
+
export { isSafeInteger } from './predicate/isSafeInteger.mjs';
|
|
158
159
|
export { camelCase } from './string/camelCase.mjs';
|
|
160
|
+
export { kebabCase } from './string/kebabCase.mjs';
|
|
161
|
+
export { snakeCase } from './string/snakeCase.mjs';
|
|
162
|
+
export { startCase } from './string/startCase.mjs';
|
|
163
|
+
export { lowerCase } from './string/lowerCase.mjs';
|
|
159
164
|
export { startsWith } from './string/startsWith.mjs';
|
|
160
165
|
export { endsWith } from './string/endsWith.mjs';
|
|
161
166
|
export { padStart } from './string/padStart.mjs';
|
|
162
167
|
export { padEnd } from './string/padEnd.mjs';
|
|
163
168
|
export { repeat } from './string/repeat.mjs';
|
|
169
|
+
export { trim } from './string/trim.mjs';
|
|
170
|
+
export { trimStart } from './string/trimStart.mjs';
|
|
171
|
+
export { trimEnd } from './string/trimEnd.mjs';
|
|
164
172
|
export { max } from './math/max.mjs';
|
|
165
173
|
export { min } from './math/min.mjs';
|
|
174
|
+
export { ceil } from './math/ceil.mjs';
|
|
175
|
+
export { floor } from './math/floor.mjs';
|
|
176
|
+
export { round } from './math/round.mjs';
|
|
166
177
|
export { parseInt } from './math/parseInt.mjs';
|
|
178
|
+
export { toPath } from './util/toPath.mjs';
|
|
179
|
+
export { toString } from './util/toString.mjs';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes number rounded up to precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number | string} number The number to round up.
|
|
5
|
+
* @param {number | string} precision The precision to round up to.
|
|
6
|
+
* @returns {number} Returns the rounded up number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ceil(4.006); // => 5
|
|
10
|
+
* ceil(6.004, 2); // => 6.01
|
|
11
|
+
* ceil(6040, -2); // => 6100
|
|
12
|
+
*/
|
|
13
|
+
declare function ceil(number: number | string, precision?: number | string): number;
|
|
14
|
+
|
|
15
|
+
export { ceil };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes number rounded up to precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number | string} number The number to round up.
|
|
5
|
+
* @param {number | string} precision The precision to round up to.
|
|
6
|
+
* @returns {number} Returns the rounded up number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ceil(4.006); // => 5
|
|
10
|
+
* ceil(6.004, 2); // => 6.01
|
|
11
|
+
* ceil(6040, -2); // => 6100
|
|
12
|
+
*/
|
|
13
|
+
declare function ceil(number: number | string, precision?: number | string): number;
|
|
14
|
+
|
|
15
|
+
export { ceil };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes number rounded down to precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number | string} number The number to round down.
|
|
5
|
+
* @param {number | string} precision The precision to round down to.
|
|
6
|
+
* @returns {number} Returns the rounded down number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* floor(4.006); // => 4
|
|
10
|
+
* floor(0.046, 2); // => 0.04
|
|
11
|
+
* floor(4060, -2); // => 4000
|
|
12
|
+
*/
|
|
13
|
+
declare function floor(number: number | string, precision?: number | string): number;
|
|
14
|
+
|
|
15
|
+
export { floor };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes number rounded down to precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number | string} number The number to round down.
|
|
5
|
+
* @param {number | string} precision The precision to round down to.
|
|
6
|
+
* @returns {number} Returns the rounded down number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* floor(4.006); // => 4
|
|
10
|
+
* floor(0.046, 2); // => 0.04
|
|
11
|
+
* floor(4060, -2); // => 4000
|
|
12
|
+
*/
|
|
13
|
+
declare function floor(number: number | string, precision?: number | string): number;
|
|
14
|
+
|
|
15
|
+
export { floor };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes number rounded to precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number | string} number The number to round.
|
|
5
|
+
* @param {number | string} precision The precision to round to.
|
|
6
|
+
* @returns {number} Returns the rounded number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* round(4.006); // => 4
|
|
10
|
+
* round(4.006, 2); // => 4.01
|
|
11
|
+
* round(4060, -2); // => 4100
|
|
12
|
+
*/
|
|
13
|
+
declare function round(number: number | string, precision?: number | string): number;
|
|
14
|
+
|
|
15
|
+
export { round };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes number rounded to precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number | string} number The number to round.
|
|
5
|
+
* @param {number | string} precision The precision to round to.
|
|
6
|
+
* @returns {number} Returns the rounded number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* round(4.006); // => 4
|
|
10
|
+
* round(4.006, 2); // => 4.01
|
|
11
|
+
* round(4060, -2); // => 4100
|
|
12
|
+
*/
|
|
13
|
+
declare function round(number: number | string, precision?: number | string): number;
|
|
14
|
+
|
|
15
|
+
export { round };
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* const result = fromPairs(pairs);
|
|
10
10
|
* // result will be: { a: 1, b: 2 }
|
|
11
11
|
*/
|
|
12
|
-
declare function fromPairs(pairs: any[]): Record<string, any>;
|
|
12
|
+
declare function fromPairs(pairs: readonly any[]): Record<string, any>;
|
|
13
13
|
/**
|
|
14
14
|
* Converts an array of key-value pairs into an object.
|
|
15
15
|
*
|
|
@@ -24,6 +24,6 @@ declare function fromPairs(pairs: any[]): Record<string, any>;
|
|
|
24
24
|
* const result = fromPairs(pairs);
|
|
25
25
|
* // result will be: { a: 1, b: 2 }
|
|
26
26
|
*/
|
|
27
|
-
declare function fromPairs<T extends PropertyKey, U>(pairs:
|
|
27
|
+
declare function fromPairs<T extends PropertyKey, U>(pairs: ReadonlyArray<[T, U]> | Map<T, U>): Record<T, U>;
|
|
28
28
|
|
|
29
29
|
export { fromPairs };
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* const result = fromPairs(pairs);
|
|
10
10
|
* // result will be: { a: 1, b: 2 }
|
|
11
11
|
*/
|
|
12
|
-
declare function fromPairs(pairs: any[]): Record<string, any>;
|
|
12
|
+
declare function fromPairs(pairs: readonly any[]): Record<string, any>;
|
|
13
13
|
/**
|
|
14
14
|
* Converts an array of key-value pairs into an object.
|
|
15
15
|
*
|
|
@@ -24,6 +24,6 @@ declare function fromPairs(pairs: any[]): Record<string, any>;
|
|
|
24
24
|
* const result = fromPairs(pairs);
|
|
25
25
|
* // result will be: { a: 1, b: 2 }
|
|
26
26
|
*/
|
|
27
|
-
declare function fromPairs<T extends PropertyKey, U>(pairs:
|
|
27
|
+
declare function fromPairs<T extends PropertyKey, U>(pairs: ReadonlyArray<[T, U]> | Map<T, U>): Record<T, U>;
|
|
28
28
|
|
|
29
29
|
export { fromPairs };
|
|
@@ -11,7 +11,7 @@ import { Get } from './get.types.mjs';
|
|
|
11
11
|
* @param {K | [K]} path - The path of the property to get.
|
|
12
12
|
* @returns {T[K]} - Returns the resolved value.
|
|
13
13
|
*/
|
|
14
|
-
declare function get<T extends object, K extends keyof T>(object: T, path: K | [K]): T[K];
|
|
14
|
+
declare function get<T extends object, K extends keyof T>(object: T, path: K | readonly [K]): T[K];
|
|
15
15
|
/**
|
|
16
16
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
17
17
|
*
|
|
@@ -22,7 +22,7 @@ declare function get<T extends object, K extends keyof T>(object: T, path: K | [
|
|
|
22
22
|
* @param {K | [K]} path - The path of the property to get.
|
|
23
23
|
* @returns {T[K] | undefined} - Returns the resolved value.
|
|
24
24
|
*/
|
|
25
|
-
declare function get<T extends object, K extends keyof T>(object: T | null | undefined, path: K | [K]): T[K] | undefined;
|
|
25
|
+
declare function get<T extends object, K extends keyof T>(object: T | null | undefined, path: K | readonly [K]): T[K] | undefined;
|
|
26
26
|
/**
|
|
27
27
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
28
28
|
*
|
|
@@ -35,7 +35,7 @@ declare function get<T extends object, K extends keyof T>(object: T | null | und
|
|
|
35
35
|
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
36
36
|
* @returns {Exclude<T[K], undefined> | D} - Returns the resolved value.
|
|
37
37
|
*/
|
|
38
|
-
declare function get<T extends object, K extends keyof T, D>(object: T | null | undefined, path: K | [K], defaultValue: D): Exclude<T[K], undefined> | D;
|
|
38
|
+
declare function get<T extends object, K extends keyof T, D>(object: T | null | undefined, path: K | readonly [K], defaultValue: D): Exclude<T[K], undefined> | D;
|
|
39
39
|
/**
|
|
40
40
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
41
41
|
*
|
|
@@ -47,7 +47,7 @@ declare function get<T extends object, K extends keyof T, D>(object: T | null |
|
|
|
47
47
|
* @param {[K1, K2]} path - The path of the property to get.
|
|
48
48
|
* @returns {T[K1][K2]} - Returns the resolved value.
|
|
49
49
|
*/
|
|
50
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T, path: [K1, K2]): T[K1][K2];
|
|
50
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T, path: readonly [K1, K2]): T[K1][K2];
|
|
51
51
|
/**
|
|
52
52
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
53
53
|
*
|
|
@@ -59,7 +59,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
59
59
|
* @param {[K1, K2]} path - The path of the property to get.
|
|
60
60
|
* @returns {T[K1][K2] | undefined} - Returns the resolved value.
|
|
61
61
|
*/
|
|
62
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T | null | undefined, path: [K1, K2]): T[K1][K2] | undefined;
|
|
62
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T | null | undefined, path: readonly [K1, K2]): T[K1][K2] | undefined;
|
|
63
63
|
/**
|
|
64
64
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
65
65
|
*
|
|
@@ -73,7 +73,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
73
73
|
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
74
74
|
* @returns {Exclude<T[K1][K2], undefined> | D} - Returns the resolved value.
|
|
75
75
|
*/
|
|
76
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], D>(object: T | null | undefined, path: [K1, K2], defaultValue: D): Exclude<T[K1][K2], undefined> | D;
|
|
76
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], D>(object: T | null | undefined, path: readonly [K1, K2], defaultValue: D): Exclude<T[K1][K2], undefined> | D;
|
|
77
77
|
/**
|
|
78
78
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
79
79
|
*
|
|
@@ -86,7 +86,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
86
86
|
* @param {[K1, K2, K3]} path - The path of the property to get.
|
|
87
87
|
* @returns {T[K1][K2][K3]} - Returns the resolved value.
|
|
88
88
|
*/
|
|
89
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T, path: [K1, K2, K3]): T[K1][K2][K3];
|
|
89
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T, path: readonly [K1, K2, K3]): T[K1][K2][K3];
|
|
90
90
|
/**
|
|
91
91
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
92
92
|
*
|
|
@@ -99,7 +99,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
99
99
|
* @param {[K1, K2, K3]} path - The path of the property to get.
|
|
100
100
|
* @returns {T[K1][K2][K3] | undefined} - Returns the resolved value.
|
|
101
101
|
*/
|
|
102
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T | null | undefined, path: [K1, K2, K3]): T[K1][K2][K3] | undefined;
|
|
102
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T | null | undefined, path: readonly [K1, K2, K3]): T[K1][K2][K3] | undefined;
|
|
103
103
|
/**
|
|
104
104
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
105
105
|
*
|
|
@@ -114,7 +114,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
114
114
|
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
115
115
|
* @returns {Exclude<T[K1][K2][K3], undefined> | D} - Returns the resolved value.
|
|
116
116
|
*/
|
|
117
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], D>(object: T | null | undefined, path: [K1, K2, K3], defaultValue: D): Exclude<T[K1][K2][K3], undefined> | D;
|
|
117
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], D>(object: T | null | undefined, path: readonly [K1, K2, K3], defaultValue: D): Exclude<T[K1][K2][K3], undefined> | D;
|
|
118
118
|
/**
|
|
119
119
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
120
120
|
*
|
|
@@ -128,7 +128,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
128
128
|
* @param {[K1, K2, K3, K4]} path - The path of the property to get.
|
|
129
129
|
* @returns {T[K1][K2][K3][K4]} - Returns the resolved value.
|
|
130
130
|
*/
|
|
131
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T, path: [K1, K2, K3, K4]): T[K1][K2][K3][K4];
|
|
131
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4];
|
|
132
132
|
/**
|
|
133
133
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
134
134
|
*
|
|
@@ -142,7 +142,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
142
142
|
* @param {[K1, K2, K3, K4]} path - The path of the property to get.
|
|
143
143
|
* @returns {T[K1][K2][K3][K4] | undefined} - Returns the resolved value.
|
|
144
144
|
*/
|
|
145
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T | null | undefined, path: [K1, K2, K3, K4]): T[K1][K2][K3][K4] | undefined;
|
|
145
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T | null | undefined, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4] | undefined;
|
|
146
146
|
/**
|
|
147
147
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
148
148
|
*
|
|
@@ -158,7 +158,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
158
158
|
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
159
159
|
* @returns {Exclude<T[K1][K2][K3][K4], undefined> | D} - Returns the resolved value.
|
|
160
160
|
*/
|
|
161
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], D>(object: T | null | undefined, path: [K1, K2, K3, K4], defaultValue: D): Exclude<T[K1][K2][K3][K4], undefined> | D;
|
|
161
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], D>(object: T | null | undefined, path: readonly [K1, K2, K3, K4], defaultValue: D): Exclude<T[K1][K2][K3][K4], undefined> | D;
|
|
162
162
|
/**
|
|
163
163
|
* Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.
|
|
164
164
|
*
|
|
@@ -11,7 +11,7 @@ import { Get } from './get.types.js';
|
|
|
11
11
|
* @param {K | [K]} path - The path of the property to get.
|
|
12
12
|
* @returns {T[K]} - Returns the resolved value.
|
|
13
13
|
*/
|
|
14
|
-
declare function get<T extends object, K extends keyof T>(object: T, path: K | [K]): T[K];
|
|
14
|
+
declare function get<T extends object, K extends keyof T>(object: T, path: K | readonly [K]): T[K];
|
|
15
15
|
/**
|
|
16
16
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
17
17
|
*
|
|
@@ -22,7 +22,7 @@ declare function get<T extends object, K extends keyof T>(object: T, path: K | [
|
|
|
22
22
|
* @param {K | [K]} path - The path of the property to get.
|
|
23
23
|
* @returns {T[K] | undefined} - Returns the resolved value.
|
|
24
24
|
*/
|
|
25
|
-
declare function get<T extends object, K extends keyof T>(object: T | null | undefined, path: K | [K]): T[K] | undefined;
|
|
25
|
+
declare function get<T extends object, K extends keyof T>(object: T | null | undefined, path: K | readonly [K]): T[K] | undefined;
|
|
26
26
|
/**
|
|
27
27
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
28
28
|
*
|
|
@@ -35,7 +35,7 @@ declare function get<T extends object, K extends keyof T>(object: T | null | und
|
|
|
35
35
|
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
36
36
|
* @returns {Exclude<T[K], undefined> | D} - Returns the resolved value.
|
|
37
37
|
*/
|
|
38
|
-
declare function get<T extends object, K extends keyof T, D>(object: T | null | undefined, path: K | [K], defaultValue: D): Exclude<T[K], undefined> | D;
|
|
38
|
+
declare function get<T extends object, K extends keyof T, D>(object: T | null | undefined, path: K | readonly [K], defaultValue: D): Exclude<T[K], undefined> | D;
|
|
39
39
|
/**
|
|
40
40
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
41
41
|
*
|
|
@@ -47,7 +47,7 @@ declare function get<T extends object, K extends keyof T, D>(object: T | null |
|
|
|
47
47
|
* @param {[K1, K2]} path - The path of the property to get.
|
|
48
48
|
* @returns {T[K1][K2]} - Returns the resolved value.
|
|
49
49
|
*/
|
|
50
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T, path: [K1, K2]): T[K1][K2];
|
|
50
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T, path: readonly [K1, K2]): T[K1][K2];
|
|
51
51
|
/**
|
|
52
52
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
53
53
|
*
|
|
@@ -59,7 +59,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
59
59
|
* @param {[K1, K2]} path - The path of the property to get.
|
|
60
60
|
* @returns {T[K1][K2] | undefined} - Returns the resolved value.
|
|
61
61
|
*/
|
|
62
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T | null | undefined, path: [K1, K2]): T[K1][K2] | undefined;
|
|
62
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T | null | undefined, path: readonly [K1, K2]): T[K1][K2] | undefined;
|
|
63
63
|
/**
|
|
64
64
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
65
65
|
*
|
|
@@ -73,7 +73,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
73
73
|
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
74
74
|
* @returns {Exclude<T[K1][K2], undefined> | D} - Returns the resolved value.
|
|
75
75
|
*/
|
|
76
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], D>(object: T | null | undefined, path: [K1, K2], defaultValue: D): Exclude<T[K1][K2], undefined> | D;
|
|
76
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], D>(object: T | null | undefined, path: readonly [K1, K2], defaultValue: D): Exclude<T[K1][K2], undefined> | D;
|
|
77
77
|
/**
|
|
78
78
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
79
79
|
*
|
|
@@ -86,7 +86,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
86
86
|
* @param {[K1, K2, K3]} path - The path of the property to get.
|
|
87
87
|
* @returns {T[K1][K2][K3]} - Returns the resolved value.
|
|
88
88
|
*/
|
|
89
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T, path: [K1, K2, K3]): T[K1][K2][K3];
|
|
89
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T, path: readonly [K1, K2, K3]): T[K1][K2][K3];
|
|
90
90
|
/**
|
|
91
91
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
92
92
|
*
|
|
@@ -99,7 +99,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
99
99
|
* @param {[K1, K2, K3]} path - The path of the property to get.
|
|
100
100
|
* @returns {T[K1][K2][K3] | undefined} - Returns the resolved value.
|
|
101
101
|
*/
|
|
102
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T | null | undefined, path: [K1, K2, K3]): T[K1][K2][K3] | undefined;
|
|
102
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T | null | undefined, path: readonly [K1, K2, K3]): T[K1][K2][K3] | undefined;
|
|
103
103
|
/**
|
|
104
104
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
105
105
|
*
|
|
@@ -114,7 +114,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
114
114
|
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
115
115
|
* @returns {Exclude<T[K1][K2][K3], undefined> | D} - Returns the resolved value.
|
|
116
116
|
*/
|
|
117
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], D>(object: T | null | undefined, path: [K1, K2, K3], defaultValue: D): Exclude<T[K1][K2][K3], undefined> | D;
|
|
117
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], D>(object: T | null | undefined, path: readonly [K1, K2, K3], defaultValue: D): Exclude<T[K1][K2][K3], undefined> | D;
|
|
118
118
|
/**
|
|
119
119
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
120
120
|
*
|
|
@@ -128,7 +128,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
128
128
|
* @param {[K1, K2, K3, K4]} path - The path of the property to get.
|
|
129
129
|
* @returns {T[K1][K2][K3][K4]} - Returns the resolved value.
|
|
130
130
|
*/
|
|
131
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T, path: [K1, K2, K3, K4]): T[K1][K2][K3][K4];
|
|
131
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4];
|
|
132
132
|
/**
|
|
133
133
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
134
134
|
*
|
|
@@ -142,7 +142,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
142
142
|
* @param {[K1, K2, K3, K4]} path - The path of the property to get.
|
|
143
143
|
* @returns {T[K1][K2][K3][K4] | undefined} - Returns the resolved value.
|
|
144
144
|
*/
|
|
145
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T | null | undefined, path: [K1, K2, K3, K4]): T[K1][K2][K3][K4] | undefined;
|
|
145
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T | null | undefined, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4] | undefined;
|
|
146
146
|
/**
|
|
147
147
|
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
148
148
|
*
|
|
@@ -158,7 +158,7 @@ declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1
|
|
|
158
158
|
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
159
159
|
* @returns {Exclude<T[K1][K2][K3][K4], undefined> | D} - Returns the resolved value.
|
|
160
160
|
*/
|
|
161
|
-
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], D>(object: T | null | undefined, path: [K1, K2, K3, K4], defaultValue: D): Exclude<T[K1][K2][K3][K4], undefined> | D;
|
|
161
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], D>(object: T | null | undefined, path: readonly [K1, K2, K3, K4], defaultValue: D): Exclude<T[K1][K2][K3][K4], undefined> | D;
|
|
162
162
|
/**
|
|
163
163
|
* Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.
|
|
164
164
|
*
|
|
@@ -1,31 +1,68 @@
|
|
|
1
1
|
import { isDeepKey } from '../_internal/isDeepKey.mjs';
|
|
2
2
|
import { toKey } from '../_internal/toKey.mjs';
|
|
3
|
-
import { toPath } from '../
|
|
3
|
+
import { toPath } from '../util/toPath.mjs';
|
|
4
4
|
|
|
5
5
|
function get(object, path, defaultValue) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
resolvedPath = path;
|
|
9
|
-
}
|
|
10
|
-
else if (typeof path === 'string' && isDeepKey(path) && object?.[path] == null) {
|
|
11
|
-
resolvedPath = toPath(path);
|
|
6
|
+
if (object == null) {
|
|
7
|
+
return defaultValue;
|
|
12
8
|
}
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
switch (typeof path) {
|
|
10
|
+
case 'string': {
|
|
11
|
+
const result = object[path];
|
|
12
|
+
if (result === undefined) {
|
|
13
|
+
if (isDeepKey(path)) {
|
|
14
|
+
return get(object, toPath(path), defaultValue);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return defaultValue;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
case 'number':
|
|
23
|
+
case 'symbol': {
|
|
24
|
+
if (typeof path === 'number') {
|
|
25
|
+
path = toKey(path);
|
|
26
|
+
}
|
|
27
|
+
const result = object[path];
|
|
28
|
+
if (result === undefined) {
|
|
29
|
+
return defaultValue;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
default: {
|
|
34
|
+
if (Array.isArray(path)) {
|
|
35
|
+
return getWithPath(object, path, defaultValue);
|
|
36
|
+
}
|
|
37
|
+
if (Object.is(path?.valueOf(), -0)) {
|
|
38
|
+
path = '-0';
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
path = String(path);
|
|
42
|
+
}
|
|
43
|
+
const result = object[path];
|
|
44
|
+
if (result === undefined) {
|
|
45
|
+
return defaultValue;
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
15
49
|
}
|
|
16
|
-
|
|
50
|
+
}
|
|
51
|
+
function getWithPath(object, path, defaultValue) {
|
|
52
|
+
if (path.length === 0) {
|
|
17
53
|
return defaultValue;
|
|
18
54
|
}
|
|
19
55
|
let current = object;
|
|
20
|
-
let index;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
56
|
+
for (let index = 0; index < path.length; index++) {
|
|
57
|
+
if (current == null) {
|
|
58
|
+
return defaultValue;
|
|
59
|
+
}
|
|
60
|
+
current = current[path[index]];
|
|
24
61
|
}
|
|
25
|
-
if (current ===
|
|
26
|
-
return
|
|
62
|
+
if (current === undefined) {
|
|
63
|
+
return defaultValue;
|
|
27
64
|
}
|
|
28
|
-
return current
|
|
65
|
+
return current;
|
|
29
66
|
}
|
|
30
67
|
|
|
31
68
|
export { get };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDeepKey } from '../_internal/isDeepKey.mjs';
|
|
2
2
|
import { isIndex } from '../_internal/isIndex.mjs';
|
|
3
|
-
import { toPath } from '../
|
|
3
|
+
import { toPath } from '../util/toPath.mjs';
|
|
4
4
|
import { isArguments } from '../predicate/isArguments.mjs';
|
|
5
5
|
|
|
6
6
|
function has(object, path) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { clone } from '../../object/clone.mjs';
|
|
2
|
+
import { getSymbols } from '../_internal/getSymbols.mjs';
|
|
2
3
|
import { isArguments } from '../predicate/isArguments.mjs';
|
|
3
4
|
import { isObjectLike } from '../predicate/isObjectLike.mjs';
|
|
4
5
|
import { isPlainObject } from '../predicate/isPlainObject.mjs';
|
|
@@ -29,7 +30,7 @@ function mergeWithDeep(target, source, merge, stack) {
|
|
|
29
30
|
source[i] = source[i] ?? undefined;
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
const sourceKeys = Object.keys(source);
|
|
33
|
+
const sourceKeys = [...Object.keys(source), ...getSymbols(source)];
|
|
33
34
|
for (let i = 0; i < sourceKeys.length; i++) {
|
|
34
35
|
const key = sourceKeys[i];
|
|
35
36
|
let sourceValue = source[key];
|
|
@@ -44,7 +45,18 @@ function mergeWithDeep(target, source, merge, stack) {
|
|
|
44
45
|
sourceValue = cloneDeep(sourceValue);
|
|
45
46
|
}
|
|
46
47
|
if (Array.isArray(sourceValue)) {
|
|
47
|
-
|
|
48
|
+
if (typeof targetValue === 'object') {
|
|
49
|
+
const cloned = [];
|
|
50
|
+
const targetKeys = Reflect.ownKeys(targetValue);
|
|
51
|
+
for (let i = 0; i < targetKeys.length; i++) {
|
|
52
|
+
const targetKey = targetKeys[i];
|
|
53
|
+
cloned[targetKey] = targetValue[targetKey];
|
|
54
|
+
}
|
|
55
|
+
targetValue = cloned;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
targetValue = [];
|
|
59
|
+
}
|
|
48
60
|
}
|
|
49
61
|
const merged = merge(targetValue, sourceValue, key, target, source, stack);
|
|
50
62
|
if (merged != null) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object with specified keys omitted.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
5
|
+
* excludes the properties corresponding to the specified keys.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of object.
|
|
8
|
+
* @template K - The type of keys in object.
|
|
9
|
+
* @param {T} obj - The object to omit keys from.
|
|
10
|
+
* @param {K[]} keys - An array of keys to be omitted from the object.
|
|
11
|
+
* @returns {Omit<T, K>} A new object with the specified keys omitted.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
15
|
+
* const result = omit(obj, ['b', 'c']);
|
|
16
|
+
* // result will be { a: 1 }
|
|
17
|
+
*/
|
|
18
|
+
declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new object with specified keys omitted.
|
|
21
|
+
*
|
|
22
|
+
* This function takes an object and a variable number of keys, and returns a new object that
|
|
23
|
+
* excludes the properties corresponding to the specified keys.
|
|
24
|
+
*
|
|
25
|
+
* Deep keys can be specified for keys.
|
|
26
|
+
*
|
|
27
|
+
* @template T - The type of object.
|
|
28
|
+
* @param {T} obj - The object to omit keys from.
|
|
29
|
+
* @param {...(PropertyKey | PropertyKey[] | PropertyKey[][]} keys - A variable number of keys to be omitted from the object.
|
|
30
|
+
* @returns {Partial<T>} A new object with the specified keys omitted.
|
|
31
|
+
*/
|
|
32
|
+
declare function omit<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | ReadonlyArray<readonly PropertyKey[]>>): Partial<T>;
|
|
33
|
+
|
|
34
|
+
export { omit };
|