es-toolkit 1.18.0-dev.593 → 1.18.0-dev.595

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 (42) hide show
  1. package/dist/_chunk/{isWeakSet-Dob5v4.js → isWeakSet-Cg7dfc.js} +1 -0
  2. package/dist/array/forEachRight.d.mts +23 -0
  3. package/dist/array/forEachRight.d.ts +23 -0
  4. package/dist/array/orderBy.d.mts +1 -1
  5. package/dist/array/orderBy.d.ts +1 -1
  6. package/dist/array/sortBy.d.mts +1 -1
  7. package/dist/array/sortBy.d.ts +1 -1
  8. package/dist/array/unzip.d.mts +1 -1
  9. package/dist/array/unzip.d.ts +1 -1
  10. package/dist/array/zipObject.d.mts +1 -1
  11. package/dist/array/zipObject.d.ts +1 -1
  12. package/dist/browser.global.js +1 -1
  13. package/dist/browser.global.js.map +1 -1
  14. package/dist/compat/array/flatten.d.mts +1 -1
  15. package/dist/compat/array/flatten.d.ts +1 -1
  16. package/dist/compat/array/flattenDepth.d.mts +1 -1
  17. package/dist/compat/array/flattenDepth.d.ts +1 -1
  18. package/dist/compat/array/orderBy.d.mts +1 -1
  19. package/dist/compat/array/orderBy.d.ts +1 -1
  20. package/dist/compat/array/size.d.mts +1 -1
  21. package/dist/compat/array/size.d.ts +1 -1
  22. package/dist/compat/array/sortBy.d.mts +1 -1
  23. package/dist/compat/array/sortBy.d.ts +1 -1
  24. package/dist/compat/array/zipObjectDeep.d.mts +1 -1
  25. package/dist/compat/array/zipObjectDeep.d.ts +1 -1
  26. package/dist/compat/index.js +57 -49
  27. package/dist/compat/object/fromPairs.d.mts +2 -2
  28. package/dist/compat/object/fromPairs.d.ts +2 -2
  29. package/dist/compat/object/get.d.mts +12 -12
  30. package/dist/compat/object/get.d.ts +12 -12
  31. package/dist/compat/object/mergeWith.mjs +14 -2
  32. package/dist/compat/object/pick.d.mts +2 -2
  33. package/dist/compat/object/pick.d.ts +2 -2
  34. package/dist/compat/predicate/isMatch.mjs +44 -4
  35. package/dist/index.js +1 -1
  36. package/dist/object/pick.d.mts +1 -1
  37. package/dist/object/pick.d.ts +1 -1
  38. package/dist/predicate/index.js +1 -1
  39. package/package.json +1 -1
  40. package/dist/compat/_internal/isArrayMatch.mjs +0 -24
  41. package/dist/compat/_internal/isMapMatch.mjs +0 -18
  42. package/dist/compat/_internal/isSetMatch.mjs +0 -13
@@ -14,6 +14,6 @@
14
14
  * const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);
15
15
  * // Returns: [1, 2, 3, 4, 5, 6]
16
16
  */
17
- declare function flatten<T, D extends number = 1>(value: T[] | object, depth?: D): Array<FlatArray<T[], D>> | [];
17
+ declare function flatten<T, D extends number = 1>(value: readonly T[] | object, depth?: D): Array<FlatArray<T[], D>> | [];
18
18
 
19
19
  export { flatten };
@@ -14,6 +14,6 @@
14
14
  * const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);
15
15
  * // Returns: [1, 2, 3, 4, 5, 6]
16
16
  */
17
- declare function flatten<T, D extends number = 1>(value: T[] | object, depth?: D): Array<FlatArray<T[], D>> | [];
17
+ declare function flatten<T, D extends number = 1>(value: readonly T[] | object, depth?: D): Array<FlatArray<T[], D>> | [];
18
18
 
19
19
  export { flatten };
@@ -14,6 +14,6 @@
14
14
  * const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);
15
15
  * // Returns: [1, 2, 3, 4, 5, 6]
16
16
  */
17
- declare function flattenDepth<T, D extends number = 1>(value: T[] | object, depth?: D): Array<FlatArray<T[], D>> | [];
17
+ declare function flattenDepth<T, D extends number = 1>(value: readonly T[] | object, depth?: D): Array<FlatArray<T[], D>> | [];
18
18
 
19
19
  export { flattenDepth };
@@ -14,6 +14,6 @@
14
14
  * const arr = flatten([1, [2, 3], [4, [5, 6]]], 2);
15
15
  * // Returns: [1, 2, 3, 4, 5, 6]
16
16
  */
17
- declare function flattenDepth<T, D extends number = 1>(value: T[] | object, depth?: D): Array<FlatArray<T[], D>> | [];
17
+ declare function flattenDepth<T, D extends number = 1>(value: readonly T[] | object, depth?: D): Array<FlatArray<T[], D>> | [];
18
18
 
19
19
  export { flattenDepth };
@@ -29,6 +29,6 @@ type Criterion<T> = ((item: T) => unknown) | PropertyKey | PropertyKey[] | null
29
29
  * // { user: 'fred', age: 40 },
30
30
  * // ]
31
31
  */
32
- declare function orderBy<T>(collection: T[] | object | number | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>, orders?: unknown | unknown[]): T[];
32
+ declare function orderBy<T>(collection: readonly T[] | object | number | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>, orders?: unknown | unknown[]): T[];
33
33
 
34
34
  export { type Criterion, orderBy };
@@ -29,6 +29,6 @@ type Criterion<T> = ((item: T) => unknown) | PropertyKey | PropertyKey[] | null
29
29
  * // { user: 'fred', age: 40 },
30
30
  * // ]
31
31
  */
32
- declare function orderBy<T>(collection: T[] | object | number | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>, orders?: unknown | unknown[]): T[];
32
+ declare function orderBy<T>(collection: readonly T[] | object | number | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>, orders?: unknown | unknown[]): T[];
33
33
 
34
34
  export { type Criterion, orderBy };
@@ -34,6 +34,6 @@
34
34
  * const emptyObjSize = size(emptyObj);
35
35
  * // emptyObjSize will be 0
36
36
  */
37
- declare function size<T>(target: T[] | object | string | Map<unknown, T> | Set<T> | null | undefined): number;
37
+ declare function size<T>(target: readonly T[] | object | string | Map<unknown, T> | Set<T> | null | undefined): number;
38
38
 
39
39
  export { size };
@@ -34,6 +34,6 @@
34
34
  * const emptyObjSize = size(emptyObj);
35
35
  * // emptyObjSize will be 0
36
36
  */
37
- declare function size<T>(target: T[] | object | string | Map<unknown, T> | Set<T> | null | undefined): number;
37
+ declare function size<T>(target: readonly T[] | object | string | Map<unknown, T> | Set<T> | null | undefined): number;
38
38
 
39
39
  export { size };
@@ -29,6 +29,6 @@ import { Criterion } from './orderBy.mjs';
29
29
  * // { user: 'fred', age: 48 },
30
30
  * // ]
31
31
  */
32
- declare function sortBy<T>(collection: T[] | object | number | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>): T[];
32
+ declare function sortBy<T>(collection: readonly T[] | object | number | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>): T[];
33
33
 
34
34
  export { sortBy };
@@ -29,6 +29,6 @@ import { Criterion } from './orderBy.js';
29
29
  * // { user: 'fred', age: 48 },
30
30
  * // ]
31
31
  */
32
- declare function sortBy<T>(collection: T[] | object | number | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>): T[];
32
+ declare function sortBy<T>(collection: readonly T[] | object | number | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>): T[];
33
33
 
34
34
  export { sortBy };
@@ -31,7 +31,7 @@
31
31
  * const result = zipObjectDeep(paths, values);
32
32
  * // result will be { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
33
33
  */
34
- declare function zipObjectDeep<P extends PropertyKey, V>(keys: P[] | P[][], values: V[]): {
34
+ declare function zipObjectDeep<P extends PropertyKey, V>(keys: readonly P[] | readonly P[][], values: readonly V[]): {
35
35
  [K in P]: V;
36
36
  };
37
37
 
@@ -31,7 +31,7 @@
31
31
  * const result = zipObjectDeep(paths, values);
32
32
  * // result will be { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
33
33
  */
34
- declare function zipObjectDeep<P extends PropertyKey, V>(keys: P[] | P[][], values: V[]): {
34
+ declare function zipObjectDeep<P extends PropertyKey, V>(keys: readonly P[] | readonly P[][], values: readonly V[]): {
35
35
  [K in P]: V;
36
36
  };
37
37
 
@@ -8,7 +8,7 @@ const curry = require('../_chunk/curry-BmwJrK.js');
8
8
  const range = require('../_chunk/range-BXlMmn.js');
9
9
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
10
10
  const toMerged = require('../_chunk/toMerged-LBvzaK.js');
11
- const isWeakSet$1 = require('../_chunk/isWeakSet-Dob5v4.js');
11
+ const isWeakSet$1 = require('../_chunk/isWeakSet-Cg7dfc.js');
12
12
  const isPlainObject$1 = require('../_chunk/isPlainObject-BIekvL.js');
13
13
  const string_index = require('../string/index.js');
14
14
 
@@ -148,52 +148,6 @@ function property(path) {
148
148
  };
149
149
  }
150
150
 
151
- function isArrayMatch(target, source) {
152
- if (source.length === 0) {
153
- return true;
154
- }
155
- if (!Array.isArray(target)) {
156
- return false;
157
- }
158
- const countedIndex = new Set();
159
- for (let i = 0; i < source.length; i++) {
160
- const sourceItem = source[i];
161
- const index = target.findIndex((targetItem, index) => {
162
- return isMatch(targetItem, sourceItem) && !countedIndex.has(index);
163
- });
164
- if (index === -1) {
165
- return false;
166
- }
167
- countedIndex.add(index);
168
- }
169
- return true;
170
- }
171
-
172
- function isMapMatch(target, source) {
173
- if (source.size === 0) {
174
- return true;
175
- }
176
- if (!(target instanceof Map)) {
177
- return false;
178
- }
179
- for (const [key, value] of source.entries()) {
180
- if (!isMatch(target.get(key), value)) {
181
- return false;
182
- }
183
- }
184
- return true;
185
- }
186
-
187
- function isSetMatch(target, source) {
188
- if (source.size === 0) {
189
- return true;
190
- }
191
- if (!(target instanceof Set)) {
192
- return false;
193
- }
194
- return isArrayMatch([...target], [...source]);
195
- }
196
-
197
151
  function isMatch(target, source) {
198
152
  if (source === target) {
199
153
  return true;
@@ -244,6 +198,49 @@ function isMatch(target, source) {
244
198
  }
245
199
  }
246
200
  }
201
+ function isMapMatch(target, source) {
202
+ if (source.size === 0) {
203
+ return true;
204
+ }
205
+ if (!(target instanceof Map)) {
206
+ return false;
207
+ }
208
+ for (const [key, value] of source.entries()) {
209
+ if (!isMatch(target.get(key), value)) {
210
+ return false;
211
+ }
212
+ }
213
+ return true;
214
+ }
215
+ function isArrayMatch(target, source) {
216
+ if (source.length === 0) {
217
+ return true;
218
+ }
219
+ if (!Array.isArray(target)) {
220
+ return false;
221
+ }
222
+ const countedIndex = new Set();
223
+ for (let i = 0; i < source.length; i++) {
224
+ const sourceItem = source[i];
225
+ const index = target.findIndex((targetItem, index) => {
226
+ return isMatch(targetItem, sourceItem) && !countedIndex.has(index);
227
+ });
228
+ if (index === -1) {
229
+ return false;
230
+ }
231
+ countedIndex.add(index);
232
+ }
233
+ return true;
234
+ }
235
+ function isSetMatch(target, source) {
236
+ if (source.size === 0) {
237
+ return true;
238
+ }
239
+ if (!(target instanceof Set)) {
240
+ return false;
241
+ }
242
+ return isArrayMatch([...target], [...source]);
243
+ }
247
244
 
248
245
  function matches(source) {
249
246
  source = toMerged.cloneDeep(source);
@@ -905,7 +902,7 @@ function mergeWithDeep(target, source, merge, stack) {
905
902
  source[i] = source[i] ?? undefined;
906
903
  }
907
904
  }
908
- const sourceKeys = Object.keys(source);
905
+ const sourceKeys = [...Object.keys(source), ...isWeakSet$1.getSymbols(source)];
909
906
  for (let i = 0; i < sourceKeys.length; i++) {
910
907
  const key = sourceKeys[i];
911
908
  let sourceValue = source[key];
@@ -920,7 +917,18 @@ function mergeWithDeep(target, source, merge, stack) {
920
917
  sourceValue = cloneDeep(sourceValue);
921
918
  }
922
919
  if (Array.isArray(sourceValue)) {
923
- targetValue = typeof targetValue === 'object' ? Array.from(targetValue ?? []) : [];
920
+ if (typeof targetValue === 'object') {
921
+ const cloned = [];
922
+ const targetKeys = Reflect.ownKeys(targetValue);
923
+ for (let i = 0; i < targetKeys.length; i++) {
924
+ const targetKey = targetKeys[i];
925
+ cloned[targetKey] = targetValue[targetKey];
926
+ }
927
+ targetValue = cloned;
928
+ }
929
+ else {
930
+ targetValue = [];
931
+ }
924
932
  }
925
933
  const merged = merge(targetValue, sourceValue, key, target, source, stack);
926
934
  if (merged != null) {
@@ -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: Array<[T, U]> | Map<T, U>): Record<T, U>;
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: Array<[T, U]> | Map<T, U>): Record<T, U>;
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,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
- targetValue = typeof targetValue === 'object' ? Array.from(targetValue ?? []) : [];
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) {
@@ -15,7 +15,7 @@
15
15
  * const result = pick(obj, ['a', 'c']);
16
16
  * // result will be { a: 1, c: 3 }
17
17
  */
18
- declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
18
+ declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;
19
19
  /**
20
20
  * Creates a new object composed of the picked object properties.
21
21
  *
@@ -41,6 +41,6 @@ declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T,
41
41
  * const result = pick(obj, 'a.b');
42
42
  * // result will be { 'a.b': 1 }
43
43
  */
44
- declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | PropertyKey[] | PropertyKey[][]>): Partial<T>;
44
+ declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | readonly (readonly PropertyKey[])[]>): Partial<T>;
45
45
 
46
46
  export { pick };
@@ -15,7 +15,7 @@
15
15
  * const result = pick(obj, ['a', 'c']);
16
16
  * // result will be { a: 1, c: 3 }
17
17
  */
18
- declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
18
+ declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;
19
19
  /**
20
20
  * Creates a new object composed of the picked object properties.
21
21
  *
@@ -41,6 +41,6 @@ declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T,
41
41
  * const result = pick(obj, 'a.b');
42
42
  * // result will be { 'a.b': 1 }
43
43
  */
44
- declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | PropertyKey[] | PropertyKey[][]>): Partial<T>;
44
+ declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | readonly (readonly PropertyKey[])[]>): Partial<T>;
45
45
 
46
46
  export { pick };
@@ -1,7 +1,4 @@
1
1
  import { isPrimitive } from '../../predicate/isPrimitive.mjs';
2
- import { isArrayMatch } from '../_internal/isArrayMatch.mjs';
3
- import { isMapMatch } from '../_internal/isMapMatch.mjs';
4
- import { isSetMatch } from '../_internal/isSetMatch.mjs';
5
2
 
6
3
  function isMatch(target, source) {
7
4
  if (source === target) {
@@ -53,5 +50,48 @@ function isMatch(target, source) {
53
50
  }
54
51
  }
55
52
  }
53
+ function isMapMatch(target, source) {
54
+ if (source.size === 0) {
55
+ return true;
56
+ }
57
+ if (!(target instanceof Map)) {
58
+ return false;
59
+ }
60
+ for (const [key, value] of source.entries()) {
61
+ if (!isMatch(target.get(key), value)) {
62
+ return false;
63
+ }
64
+ }
65
+ return true;
66
+ }
67
+ function isArrayMatch(target, source) {
68
+ if (source.length === 0) {
69
+ return true;
70
+ }
71
+ if (!Array.isArray(target)) {
72
+ return false;
73
+ }
74
+ const countedIndex = new Set();
75
+ for (let i = 0; i < source.length; i++) {
76
+ const sourceItem = source[i];
77
+ const index = target.findIndex((targetItem, index) => {
78
+ return isMatch(targetItem, sourceItem) && !countedIndex.has(index);
79
+ });
80
+ if (index === -1) {
81
+ return false;
82
+ }
83
+ countedIndex.add(index);
84
+ }
85
+ return true;
86
+ }
87
+ function isSetMatch(target, source) {
88
+ if (source.size === 0) {
89
+ return true;
90
+ }
91
+ if (!(target instanceof Set)) {
92
+ return false;
93
+ }
94
+ return isArrayMatch([...target], [...source]);
95
+ }
56
96
 
57
- export { isMatch };
97
+ export { isArrayMatch, isMapMatch, isMatch, isSetMatch };
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ const randomInt = require('./_chunk/randomInt-CF7bZK.js');
12
12
  const math_index = require('./math/index.js');
13
13
  const toMerged = require('./_chunk/toMerged-LBvzaK.js');
14
14
  const object_index = require('./object/index.js');
15
- const isWeakSet = require('./_chunk/isWeakSet-Dob5v4.js');
15
+ const isWeakSet = require('./_chunk/isWeakSet-Cg7dfc.js');
16
16
  const isPlainObject = require('./_chunk/isPlainObject-BIekvL.js');
17
17
  const predicate_index = require('./predicate/index.js');
18
18
  const string_index = require('./string/index.js');
@@ -15,6 +15,6 @@
15
15
  * const result = pick(obj, ['a', 'c']);
16
16
  * // result will be { a: 1, c: 3 }
17
17
  */
18
- declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
18
+ declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;
19
19
 
20
20
  export { pick };