es-toolkit 1.25.2 → 1.26.0-dev.828

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/_chunk/{sumBy-BkErWJ.js → sumBy-RVppiV.js} +21 -0
  3. package/dist/_chunk/{toMerged-BLnW4M.js → toMerged-wNz52b.js} +2 -2
  4. package/dist/_chunk/{unary-CMvKXy.js → unary-CcTNuC.js} +5 -0
  5. package/dist/browser.global.js +1 -1
  6. package/dist/browser.global.js.map +1 -1
  7. package/dist/compat/array/drop.d.mts +2 -1
  8. package/dist/compat/array/drop.d.ts +2 -1
  9. package/dist/compat/array/drop.mjs +3 -1
  10. package/dist/compat/array/dropRight.d.mts +2 -1
  11. package/dist/compat/array/dropRight.d.ts +2 -1
  12. package/dist/compat/array/dropRight.mjs +3 -1
  13. package/dist/compat/array/every.d.mts +2 -2
  14. package/dist/compat/array/every.d.ts +2 -2
  15. package/dist/compat/array/every.mjs +6 -2
  16. package/dist/compat/array/filter.d.mts +3 -3
  17. package/dist/compat/array/filter.d.ts +3 -3
  18. package/dist/compat/array/filter.mjs +1 -1
  19. package/dist/compat/array/find.d.mts +6 -6
  20. package/dist/compat/array/find.d.ts +6 -6
  21. package/dist/compat/array/intersectionBy.d.mts +111 -0
  22. package/dist/compat/array/intersectionBy.d.ts +111 -0
  23. package/dist/compat/array/intersectionBy.mjs +36 -0
  24. package/dist/compat/array/orderBy.d.mts +3 -2
  25. package/dist/compat/array/orderBy.d.ts +3 -2
  26. package/dist/compat/array/orderBy.mjs +7 -3
  27. package/dist/compat/array/some.d.mts +68 -21
  28. package/dist/compat/array/some.d.ts +68 -21
  29. package/dist/compat/array/some.mjs +21 -9
  30. package/dist/compat/array/sortBy.d.mts +3 -3
  31. package/dist/compat/array/sortBy.d.ts +3 -3
  32. package/dist/compat/array/sortBy.mjs +11 -2
  33. package/dist/compat/array/take.d.mts +2 -1
  34. package/dist/compat/array/take.d.ts +2 -1
  35. package/dist/compat/array/take.mjs +3 -1
  36. package/dist/compat/array/takeRight.d.mts +2 -1
  37. package/dist/compat/array/takeRight.d.ts +2 -1
  38. package/dist/compat/array/takeRight.mjs +3 -1
  39. package/dist/compat/array/zipObjectDeep.d.mts +2 -4
  40. package/dist/compat/array/zipObjectDeep.d.ts +2 -4
  41. package/dist/compat/index.d.mts +7 -1
  42. package/dist/compat/index.d.ts +7 -1
  43. package/dist/compat/index.js +218 -70
  44. package/dist/compat/index.mjs +7 -1
  45. package/dist/compat/object/invertBy.mjs +1 -1
  46. package/dist/compat/object/mapKeys.mjs +1 -1
  47. package/dist/compat/object/mapValues.mjs +1 -1
  48. package/dist/compat/string/template.d.mts +89 -0
  49. package/dist/compat/string/template.d.ts +89 -0
  50. package/dist/compat/string/template.mjs +86 -0
  51. package/dist/compat/util/uniqueId.d.mts +25 -0
  52. package/dist/compat/util/uniqueId.d.ts +25 -0
  53. package/dist/compat/util/uniqueId.mjs +7 -0
  54. package/dist/function/identity.d.mts +22 -0
  55. package/dist/function/identity.d.ts +22 -0
  56. package/dist/function/index.d.mts +1 -0
  57. package/dist/function/index.d.ts +1 -0
  58. package/dist/function/index.js +2 -1
  59. package/dist/function/index.mjs +1 -0
  60. package/dist/index.d.mts +4 -0
  61. package/dist/index.d.ts +4 -0
  62. package/dist/index.js +8 -3
  63. package/dist/index.mjs +4 -0
  64. package/dist/math/index.d.mts +2 -0
  65. package/dist/math/index.d.ts +2 -0
  66. package/dist/math/index.js +3 -1
  67. package/dist/math/index.mjs +2 -0
  68. package/dist/math/median.d.mts +25 -0
  69. package/dist/math/median.d.ts +25 -0
  70. package/dist/math/median.mjs +15 -0
  71. package/dist/math/medianBy.d.mts +23 -0
  72. package/dist/math/medianBy.d.ts +23 -0
  73. package/dist/math/medianBy.mjs +8 -0
  74. package/dist/object/cloneDeep.mjs +2 -2
  75. package/dist/object/index.js +1 -1
  76. package/dist/object/merge.d.mts +1 -1
  77. package/dist/object/merge.d.ts +1 -1
  78. package/dist/util/index.d.mts +1 -0
  79. package/dist/util/index.d.ts +1 -0
  80. package/dist/util/index.js +12 -0
  81. package/dist/util/index.mjs +1 -0
  82. package/dist/util/invariant.d.mts +27 -0
  83. package/dist/util/invariant.d.ts +27 -0
  84. package/dist/util/invariant.mjs +8 -0
  85. package/package.json +21 -1
  86. package/util.d.ts +1 -0
  87. /package/dist/{compat/_internal → function}/identity.mjs +0 -0
@@ -1,30 +1,33 @@
1
1
  /**
2
2
  * Checks if there is an element in an array that is truthy.
3
3
  *
4
- * @param {T[]} arr The array to iterate over.
4
+ * @template T
5
+ * @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
5
6
  * @returns {boolean} Returns `true` if any element is truthy, else `false`.
6
7
  *
7
8
  * @example
8
9
  * some([1, 2, 3, 4]);
9
10
  * // => true
10
11
  */
11
- declare function some<T>(arr: readonly T[]): boolean;
12
+ declare function some<T>(arr: ArrayLike<T> | null | undefined): boolean;
12
13
  /**
13
14
  * Checks if there is an element in an array that matches the given predicate function.
14
15
  *
15
- * @param {T[]} arr The array to iterate over.
16
- * @param {(item: T, index: number, arr: any) => unknown} predicate The function invoked per iteration.
16
+ * @template T
17
+ * @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
18
+ * @param {(item: T, index: number, arr: readonly T[]) => unknown} predicate The function invoked per iteration.
17
19
  * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
18
20
  *
19
21
  * @example
20
22
  * some([1, 2, 3, 4], n => n % 2 === 0);
21
23
  * // => true
22
24
  */
23
- declare function some<T>(arr: readonly T[], predicate: (item: T, index: number, arr: any) => unknown): boolean;
25
+ declare function some<T>(arr: ArrayLike<T> | null | undefined, predicate: (item: T, index: number, arr: readonly T[]) => unknown): boolean;
24
26
  /**
25
27
  * Checks if there is an element in an array that matches the given key-value pair.
26
28
  *
27
- * @param {T[]} arr The array to iterate over.
29
+ * @template T
30
+ * @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
28
31
  * @param {[keyof T, unknown]} predicate The key-value pair to match.
29
32
  * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
30
33
  *
@@ -32,11 +35,12 @@ declare function some<T>(arr: readonly T[], predicate: (item: T, index: number,
32
35
  * some([{ a: 1 }, { a: 2 }, { a: 3 }], ['a', 2]);
33
36
  * // => true
34
37
  */
35
- declare function some<T>(arr: readonly T[], predicate: [keyof T, unknown]): boolean;
38
+ declare function some<T>(arr: ArrayLike<T> | null | undefined, predicate: [keyof T, unknown]): boolean;
36
39
  /**
37
40
  * Checks if there is an element in an array that has a truthy value for the given property name.
38
41
  *
39
- * @param {T[]} arr The array to iterate over.
42
+ * @template T
43
+ * @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
40
44
  * @param {string} propertyToCheck The property name to check.
41
45
  * @returns {boolean} Returns `true` if any element has a truthy value for the property, else `false`.
42
46
  *
@@ -44,11 +48,12 @@ declare function some<T>(arr: readonly T[], predicate: [keyof T, unknown]): bool
44
48
  * some([{ a: 1 }, { a: 2 }, { a: 3 }], 'a');
45
49
  * // => true
46
50
  */
47
- declare function some<T>(arr: readonly T[], propertyToCheck: string): boolean;
51
+ declare function some<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: string): boolean;
48
52
  /**
49
53
  * Checks if there is an element in an array that matches the given partial object.
50
54
  *
51
- * @param {T[]} arr The array to iterate over.
55
+ * @template T
56
+ * @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
52
57
  * @param {Partial<T>} doesMatch The partial object to match.
53
58
  * @returns {boolean} Returns `true` if any element matches the partial object, else `false`.
54
59
  *
@@ -56,30 +61,72 @@ declare function some<T>(arr: readonly T[], propertyToCheck: string): boolean;
56
61
  * some([{ a: 1 }, { a: 2 }, { a: 3 }], { a: 2 });
57
62
  * // => true
58
63
  */
59
- declare function some<T>(arr: readonly T[], doesMatch: Partial<T>): boolean;
64
+ declare function some<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T>): boolean;
60
65
  /**
61
- * Checks if there is an element in an array that matches the given predicate.
66
+ * Checks if there is an element in an object that matches the given predicate function.
62
67
  *
63
- * Iteration is stopped once there is an element that matches `predicate`.
68
+ * @template T
69
+ * @param {T | null | undefined} object The object to iterate over.
70
+ * @returns {boolean} Returns `true` if any element is truthy, else `false`.
64
71
  *
65
- * @param {T[]} arr The array to iterate over.
66
- * @param {((item: T, index: number, arr: any) => unknown) | Partial<T> | [keyof T, unknown] | string} [predicate=identity] The function invoked per iteration.
67
- * If a property name or an object is provided it will be used to create a predicate function.
72
+ * @example
73
+ * some({ a: 1, b: 2, c: 3 });
74
+ * // => true
75
+ */
76
+ declare function some<T extends Record<string, unknown>>(object: T | null | undefined): boolean;
77
+ /**
78
+ * Checks if there is an element in an object that matches the given predicate function.
79
+ *
80
+ * @template T
81
+ * @param {T | null | undefined} object The object to iterate over.
82
+ * @param {(value: T[keyof T], key: keyof T, object: T) => unknown} doesMatch A function that takes an value, its key, and the object, and returns a truthy value if the item matches the criteria.
68
83
  * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
69
84
  *
70
85
  * @example
71
- * some([1, 2, 3, 4], n => n % 2 === 0);
86
+ * some({ a: 1, b: 2, c: 3 }, n => n % 2 === 0);
72
87
  * // => true
88
+ */
89
+ declare function some<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown): boolean;
90
+ /**
91
+ * Checks if there is an element in an object that matches the given partial value.
73
92
  *
74
- * some([{ a: 1 }, { a: 2 }, { a: 3 }], { a: 2 });
93
+ * @template T
94
+ * @param {T | null | undefined} object The object to iterate over.
95
+ * @param {Partial<T[keyof T]>} doesMatch A partial value to match against the values of the object.
96
+ * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
97
+ *
98
+ * @example
99
+ * some({ a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } }, { name: 'Bob' });
75
100
  * // => true
101
+ */
102
+ declare function some<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]>): boolean;
103
+ /**
104
+ * Checks if there is an element in an object that matches a property with a specific value.
76
105
  *
77
- * some([{ a: 1 }, { a: 2 }, { a: 3 }], ['a', 2]);
106
+ * @template T
107
+ * @param {T | null | undefined} object The object to iterate over.
108
+ * @param {[keyof T, unknown]} doesMatchProperty An array where the first element is the property key and the second element is the value to match.
109
+ * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
110
+ *
111
+ * @example
112
+ * const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
113
+ * const result = some(obj, ['name', 'Alice']);
78
114
  * // => true
115
+ */
116
+ declare function some<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown]): boolean;
117
+ /**
118
+ * Checks if there is an element in an object that has a specific property, where the property name is provided as a string.
79
119
  *
80
- * some([{ a: 1 }, { a: 2 }, { a: 3 }], 'a');
120
+ * @template T
121
+ * @param {T | null | undefined} object The object to iterate over.
122
+ * @param {string} propertyToCheck The property name to check.
123
+ * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
124
+ *
125
+ * @example
126
+ * const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
127
+ * const result = some(obj, 'name');
81
128
  * // => true
82
129
  */
83
- declare function some<T>(arr: readonly T[] | null | undefined, predicate?: ((item: T, index: number, arr: any) => unknown) | Partial<T> | [keyof T, unknown] | string, guard?: unknown): boolean;
130
+ declare function some<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: string): boolean;
84
131
 
85
132
  export { some };
@@ -1,30 +1,33 @@
1
1
  /**
2
2
  * Checks if there is an element in an array that is truthy.
3
3
  *
4
- * @param {T[]} arr The array to iterate over.
4
+ * @template T
5
+ * @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
5
6
  * @returns {boolean} Returns `true` if any element is truthy, else `false`.
6
7
  *
7
8
  * @example
8
9
  * some([1, 2, 3, 4]);
9
10
  * // => true
10
11
  */
11
- declare function some<T>(arr: readonly T[]): boolean;
12
+ declare function some<T>(arr: ArrayLike<T> | null | undefined): boolean;
12
13
  /**
13
14
  * Checks if there is an element in an array that matches the given predicate function.
14
15
  *
15
- * @param {T[]} arr The array to iterate over.
16
- * @param {(item: T, index: number, arr: any) => unknown} predicate The function invoked per iteration.
16
+ * @template T
17
+ * @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
18
+ * @param {(item: T, index: number, arr: readonly T[]) => unknown} predicate The function invoked per iteration.
17
19
  * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
18
20
  *
19
21
  * @example
20
22
  * some([1, 2, 3, 4], n => n % 2 === 0);
21
23
  * // => true
22
24
  */
23
- declare function some<T>(arr: readonly T[], predicate: (item: T, index: number, arr: any) => unknown): boolean;
25
+ declare function some<T>(arr: ArrayLike<T> | null | undefined, predicate: (item: T, index: number, arr: readonly T[]) => unknown): boolean;
24
26
  /**
25
27
  * Checks if there is an element in an array that matches the given key-value pair.
26
28
  *
27
- * @param {T[]} arr The array to iterate over.
29
+ * @template T
30
+ * @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
28
31
  * @param {[keyof T, unknown]} predicate The key-value pair to match.
29
32
  * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
30
33
  *
@@ -32,11 +35,12 @@ declare function some<T>(arr: readonly T[], predicate: (item: T, index: number,
32
35
  * some([{ a: 1 }, { a: 2 }, { a: 3 }], ['a', 2]);
33
36
  * // => true
34
37
  */
35
- declare function some<T>(arr: readonly T[], predicate: [keyof T, unknown]): boolean;
38
+ declare function some<T>(arr: ArrayLike<T> | null | undefined, predicate: [keyof T, unknown]): boolean;
36
39
  /**
37
40
  * Checks if there is an element in an array that has a truthy value for the given property name.
38
41
  *
39
- * @param {T[]} arr The array to iterate over.
42
+ * @template T
43
+ * @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
40
44
  * @param {string} propertyToCheck The property name to check.
41
45
  * @returns {boolean} Returns `true` if any element has a truthy value for the property, else `false`.
42
46
  *
@@ -44,11 +48,12 @@ declare function some<T>(arr: readonly T[], predicate: [keyof T, unknown]): bool
44
48
  * some([{ a: 1 }, { a: 2 }, { a: 3 }], 'a');
45
49
  * // => true
46
50
  */
47
- declare function some<T>(arr: readonly T[], propertyToCheck: string): boolean;
51
+ declare function some<T>(arr: ArrayLike<T> | null | undefined, propertyToCheck: string): boolean;
48
52
  /**
49
53
  * Checks if there is an element in an array that matches the given partial object.
50
54
  *
51
- * @param {T[]} arr The array to iterate over.
55
+ * @template T
56
+ * @param {ArrayLike<T> | null | undefined} arr The array to iterate over.
52
57
  * @param {Partial<T>} doesMatch The partial object to match.
53
58
  * @returns {boolean} Returns `true` if any element matches the partial object, else `false`.
54
59
  *
@@ -56,30 +61,72 @@ declare function some<T>(arr: readonly T[], propertyToCheck: string): boolean;
56
61
  * some([{ a: 1 }, { a: 2 }, { a: 3 }], { a: 2 });
57
62
  * // => true
58
63
  */
59
- declare function some<T>(arr: readonly T[], doesMatch: Partial<T>): boolean;
64
+ declare function some<T>(arr: ArrayLike<T> | null | undefined, doesMatch: Partial<T>): boolean;
60
65
  /**
61
- * Checks if there is an element in an array that matches the given predicate.
66
+ * Checks if there is an element in an object that matches the given predicate function.
62
67
  *
63
- * Iteration is stopped once there is an element that matches `predicate`.
68
+ * @template T
69
+ * @param {T | null | undefined} object The object to iterate over.
70
+ * @returns {boolean} Returns `true` if any element is truthy, else `false`.
64
71
  *
65
- * @param {T[]} arr The array to iterate over.
66
- * @param {((item: T, index: number, arr: any) => unknown) | Partial<T> | [keyof T, unknown] | string} [predicate=identity] The function invoked per iteration.
67
- * If a property name or an object is provided it will be used to create a predicate function.
72
+ * @example
73
+ * some({ a: 1, b: 2, c: 3 });
74
+ * // => true
75
+ */
76
+ declare function some<T extends Record<string, unknown>>(object: T | null | undefined): boolean;
77
+ /**
78
+ * Checks if there is an element in an object that matches the given predicate function.
79
+ *
80
+ * @template T
81
+ * @param {T | null | undefined} object The object to iterate over.
82
+ * @param {(value: T[keyof T], key: keyof T, object: T) => unknown} doesMatch A function that takes an value, its key, and the object, and returns a truthy value if the item matches the criteria.
68
83
  * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
69
84
  *
70
85
  * @example
71
- * some([1, 2, 3, 4], n => n % 2 === 0);
86
+ * some({ a: 1, b: 2, c: 3 }, n => n % 2 === 0);
72
87
  * // => true
88
+ */
89
+ declare function some<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: (value: T[keyof T], key: keyof T, object: T) => unknown): boolean;
90
+ /**
91
+ * Checks if there is an element in an object that matches the given partial value.
73
92
  *
74
- * some([{ a: 1 }, { a: 2 }, { a: 3 }], { a: 2 });
93
+ * @template T
94
+ * @param {T | null | undefined} object The object to iterate over.
95
+ * @param {Partial<T[keyof T]>} doesMatch A partial value to match against the values of the object.
96
+ * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
97
+ *
98
+ * @example
99
+ * some({ a: { id: 1, name: 'Alice' }, b: { id: 2, name: 'Bob' } }, { name: 'Bob' });
75
100
  * // => true
101
+ */
102
+ declare function some<T extends Record<string, unknown>>(object: T | null | undefined, doesMatch: Partial<T[keyof T]>): boolean;
103
+ /**
104
+ * Checks if there is an element in an object that matches a property with a specific value.
76
105
  *
77
- * some([{ a: 1 }, { a: 2 }, { a: 3 }], ['a', 2]);
106
+ * @template T
107
+ * @param {T | null | undefined} object The object to iterate over.
108
+ * @param {[keyof T, unknown]} doesMatchProperty An array where the first element is the property key and the second element is the value to match.
109
+ * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
110
+ *
111
+ * @example
112
+ * const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
113
+ * const result = some(obj, ['name', 'Alice']);
78
114
  * // => true
115
+ */
116
+ declare function some<T extends Record<string, unknown>>(object: T | null | undefined, doesMatchProperty: [keyof T[keyof T], unknown]): boolean;
117
+ /**
118
+ * Checks if there is an element in an object that has a specific property, where the property name is provided as a string.
79
119
  *
80
- * some([{ a: 1 }, { a: 2 }, { a: 3 }], 'a');
120
+ * @template T
121
+ * @param {T | null | undefined} object The object to iterate over.
122
+ * @param {string} propertyToCheck The property name to check.
123
+ * @returns {boolean} Returns `true` if any element passes the predicate check, else `false`.
124
+ *
125
+ * @example
126
+ * const obj = { alice: { id: 1, name: 'Alice' }, bob: { id: 2, name: 'Bob' } };
127
+ * const result = some(obj, 'name');
81
128
  * // => true
82
129
  */
83
- declare function some<T>(arr: readonly T[] | null | undefined, predicate?: ((item: T, index: number, arr: any) => unknown) | Partial<T> | [keyof T, unknown] | string, guard?: unknown): boolean;
130
+ declare function some<T extends Record<string, unknown>>(object: T | null | undefined, propertyToCheck: string): boolean;
84
131
 
85
132
  export { some };
@@ -1,34 +1,46 @@
1
- import { identity } from '../_internal/identity.mjs';
1
+ import { identity } from '../../function/identity.mjs';
2
2
  import { property } from '../object/property.mjs';
3
3
  import { matches } from '../predicate/matches.mjs';
4
4
  import { matchesProperty } from '../predicate/matchesProperty.mjs';
5
5
 
6
- function some(arr, predicate, guard) {
6
+ function some(source, predicate, guard) {
7
+ if (!source) {
8
+ return false;
9
+ }
7
10
  if (guard != null) {
8
11
  predicate = undefined;
9
12
  }
10
13
  if (!predicate) {
11
14
  predicate = identity;
12
15
  }
13
- if (!Array.isArray(arr)) {
14
- return false;
15
- }
16
+ const values = Array.isArray(source) ? source : Object.values(source);
16
17
  switch (typeof predicate) {
17
18
  case 'function': {
18
- return arr.some(predicate);
19
+ if (!Array.isArray(source)) {
20
+ const keys = Object.keys(source);
21
+ for (let i = 0; i < keys.length; i++) {
22
+ const key = keys[i];
23
+ const value = source[key];
24
+ if (predicate(value, key, source)) {
25
+ return true;
26
+ }
27
+ }
28
+ return false;
29
+ }
30
+ return values.some(predicate);
19
31
  }
20
32
  case 'object': {
21
33
  if (Array.isArray(predicate) && predicate.length === 2) {
22
34
  const key = predicate[0];
23
35
  const value = predicate[1];
24
- return arr.some(matchesProperty(key, value));
36
+ return values.some(matchesProperty(key, value));
25
37
  }
26
38
  else {
27
- return arr.some(matches(predicate));
39
+ return values.some(matches(predicate));
28
40
  }
29
41
  }
30
42
  case 'string': {
31
- return arr.some(property(predicate));
43
+ return values.some(property(predicate));
32
44
  }
33
45
  }
34
46
  }
@@ -8,8 +8,8 @@ import { Criterion } from './orderBy.mjs';
8
8
  * If values for a key are equal, it moves to the next key to determine the order.
9
9
  *
10
10
  * @template T - The type of elements in the array.
11
- * @param { T[] | object | null | undefined} collection - The array of objects to be sorted.
12
- * @param {Criterion<T> | Array<Criterion<T>>} criteria - An array of criteria (property names or property paths or custom key functions) to sort by.
11
+ * @param {ArrayLike<T> | object | null | undefined} collection - The array of objects to be sorted.
12
+ * @param {Array<Array<Criterion<T> | Criterion<T>>>} criteria - An array of criteria (property names or property paths or custom key functions) to sort by.
13
13
  * @returns {T[]} - The ascending sorted array.
14
14
  *
15
15
  * @example
@@ -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: readonly T[] | object | number | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>): T[];
32
+ declare function sortBy<T = any>(collection: ArrayLike<T> | object | null | undefined, ...criteria: Array<Criterion<T> | Array<Criterion<T>>>): T[];
33
33
 
34
34
  export { sortBy };
@@ -8,8 +8,8 @@ import { Criterion } from './orderBy.js';
8
8
  * If values for a key are equal, it moves to the next key to determine the order.
9
9
  *
10
10
  * @template T - The type of elements in the array.
11
- * @param { T[] | object | null | undefined} collection - The array of objects to be sorted.
12
- * @param {Criterion<T> | Array<Criterion<T>>} criteria - An array of criteria (property names or property paths or custom key functions) to sort by.
11
+ * @param {ArrayLike<T> | object | null | undefined} collection - The array of objects to be sorted.
12
+ * @param {Array<Array<Criterion<T> | Criterion<T>>>} criteria - An array of criteria (property names or property paths or custom key functions) to sort by.
13
13
  * @returns {T[]} - The ascending sorted array.
14
14
  *
15
15
  * @example
@@ -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: readonly T[] | object | number | null | undefined, criteria?: Criterion<T> | Array<Criterion<T>>): T[];
32
+ declare function sortBy<T = any>(collection: ArrayLike<T> | object | null | undefined, ...criteria: Array<Criterion<T> | Array<Criterion<T>>>): T[];
33
33
 
34
34
  export { sortBy };
@@ -1,7 +1,16 @@
1
1
  import { orderBy } from './orderBy.mjs';
2
+ import { flatten } from '../../array/flatten.mjs';
3
+ import { isIterateeCall } from '../_internal/isIterateeCall.mjs';
2
4
 
3
- function sortBy(collection, criteria) {
4
- return orderBy(collection, criteria, ['asc']);
5
+ function sortBy(collection, ...criteria) {
6
+ const length = criteria.length;
7
+ if (length > 1 && isIterateeCall(collection, criteria[0], criteria[1])) {
8
+ criteria = [];
9
+ }
10
+ else if (length > 2 && isIterateeCall(criteria[0], criteria[1], criteria[2])) {
11
+ criteria = [criteria[0]];
12
+ }
13
+ return orderBy(collection, flatten(criteria), ['asc']);
5
14
  }
6
15
 
7
16
  export { sortBy };
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @param {ArrayLike<T> | null | undefined} arr - The array to take elements from.
8
8
  * @param {number} [count=1] - The number of elements to take.
9
+ * @param {unknown} [guard] - Enables use as an iteratee for methods like `_.map`.
9
10
  * @returns {T[]} A new array containing the first `count` elements from `arr`.
10
11
  *
11
12
  * @example
@@ -20,6 +21,6 @@
20
21
  * // Returns [1, 2, 3]
21
22
  * take([1, 2, 3], 5);
22
23
  */
23
- declare function take<T>(arr: ArrayLike<T> | null | undefined, count?: number): T[];
24
+ declare function take<T>(arr: ArrayLike<T> | null | undefined, count?: number, guard?: unknown): T[];
24
25
 
25
26
  export { take };
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @param {ArrayLike<T> | null | undefined} arr - The array to take elements from.
8
8
  * @param {number} [count=1] - The number of elements to take.
9
+ * @param {unknown} [guard] - Enables use as an iteratee for methods like `_.map`.
9
10
  * @returns {T[]} A new array containing the first `count` elements from `arr`.
10
11
  *
11
12
  * @example
@@ -20,6 +21,6 @@
20
21
  * // Returns [1, 2, 3]
21
22
  * take([1, 2, 3], 5);
22
23
  */
23
- declare function take<T>(arr: ArrayLike<T> | null | undefined, count?: number): T[];
24
+ declare function take<T>(arr: ArrayLike<T> | null | undefined, count?: number, guard?: unknown): T[];
24
25
 
25
26
  export { take };
@@ -1,7 +1,9 @@
1
1
  import { take as take$1 } from '../../array/take.mjs';
2
2
  import { isArrayLike } from '../predicate/isArrayLike.mjs';
3
+ import { toInteger } from '../util/toInteger.mjs';
3
4
 
4
- function take(arr, count = 1) {
5
+ function take(arr, count = 1, guard) {
6
+ count = guard ? 1 : toInteger(count);
5
7
  if (count < 1 || !isArrayLike(arr)) {
6
8
  return [];
7
9
  }
@@ -5,6 +5,7 @@
5
5
  * @template T - The type of elements in the array.
6
6
  * @param {ArrayLike<T> | null | undefined} arr - The array to take elements from.
7
7
  * @param {number} [count=1] - The number of elements to take.
8
+ * @param {unknown} [guard] - Enables use as an iteratee for methods like `_.map`.
8
9
  * @returns {T[]} A new array containing the last `count` elements from `arr`.
9
10
  *
10
11
  * @example
@@ -19,6 +20,6 @@
19
20
  * // Returns [1, 2, 3]
20
21
  * takeRight([1, 2, 3], 5);
21
22
  */
22
- declare function takeRight<T>(arr: ArrayLike<T> | null | undefined, count?: number): T[];
23
+ declare function takeRight<T>(arr: ArrayLike<T> | null | undefined, count?: number, guard?: unknown): T[];
23
24
 
24
25
  export { takeRight };
@@ -5,6 +5,7 @@
5
5
  * @template T - The type of elements in the array.
6
6
  * @param {ArrayLike<T> | null | undefined} arr - The array to take elements from.
7
7
  * @param {number} [count=1] - The number of elements to take.
8
+ * @param {unknown} [guard] - Enables use as an iteratee for methods like `_.map`.
8
9
  * @returns {T[]} A new array containing the last `count` elements from `arr`.
9
10
  *
10
11
  * @example
@@ -19,6 +20,6 @@
19
20
  * // Returns [1, 2, 3]
20
21
  * takeRight([1, 2, 3], 5);
21
22
  */
22
- declare function takeRight<T>(arr: ArrayLike<T> | null | undefined, count?: number): T[];
23
+ declare function takeRight<T>(arr: ArrayLike<T> | null | undefined, count?: number, guard?: unknown): T[];
23
24
 
24
25
  export { takeRight };
@@ -1,7 +1,9 @@
1
1
  import { takeRight as takeRight$1 } from '../../array/takeRight.mjs';
2
2
  import { isArrayLike } from '../predicate/isArrayLike.mjs';
3
+ import { toInteger } from '../util/toInteger.mjs';
3
4
 
4
- function takeRight(arr, count = 1) {
5
+ function takeRight(arr, count = 1, guard) {
6
+ count = guard ? 1 : toInteger(count);
5
7
  if (count <= 0 || !isArrayLike(arr)) {
6
8
  return [];
7
9
  }
@@ -11,7 +11,7 @@
11
11
  * @template V - The type of values corresponding to the property paths.
12
12
  * @param {ArrayLike<P | P[]>} keys - An array of property paths, each path can be a dot-separated string or an array of property names.
13
13
  * @param {ArrayLike<V>} values - An array of values corresponding to the property paths.
14
- * @returns {{ [K in P]: V }} A new object composed of the given property paths and values.
14
+ * @returns {Record<P, V>} A new object composed of the given property paths and values.
15
15
  *
16
16
  * @example
17
17
  * const paths = ['a.b.c', 'd.e.f'];
@@ -31,8 +31,6 @@
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: ArrayLike<P | P[]>, values: ArrayLike<V>): {
35
- [K in P]: V;
36
- };
34
+ declare function zipObjectDeep<P extends PropertyKey, V>(keys: ArrayLike<P | P[]>, values: ArrayLike<V>): Record<P, V>;
37
35
 
38
36
  export { zipObjectDeep };
@@ -11,7 +11,7 @@
11
11
  * @template V - The type of values corresponding to the property paths.
12
12
  * @param {ArrayLike<P | P[]>} keys - An array of property paths, each path can be a dot-separated string or an array of property names.
13
13
  * @param {ArrayLike<V>} values - An array of values corresponding to the property paths.
14
- * @returns {{ [K in P]: V }} A new object composed of the given property paths and values.
14
+ * @returns {Record<P, V>} A new object composed of the given property paths and values.
15
15
  *
16
16
  * @example
17
17
  * const paths = ['a.b.c', 'd.e.f'];
@@ -31,8 +31,6 @@
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: ArrayLike<P | P[]>, values: ArrayLike<V>): {
35
- [K in P]: V;
36
- };
34
+ declare function zipObjectDeep<P extends PropertyKey, V>(keys: ArrayLike<P | P[]>, values: ArrayLike<V>): Record<P, V>;
37
35
 
38
36
  export { zipObjectDeep };
@@ -7,7 +7,6 @@ export { flatMapDeep } from '../array/flatMapDeep.mjs';
7
7
  export { forEachRight } from '../array/forEachRight.mjs';
8
8
  export { groupBy } from '../array/groupBy.mjs';
9
9
  export { initial } from '../array/initial.mjs';
10
- export { intersectionBy } from '../array/intersectionBy.mjs';
11
10
  export { intersectionWith } from '../array/intersectionWith.mjs';
12
11
  export { isSubset } from '../array/isSubset.mjs';
13
12
  export { keyBy } from '../array/keyBy.mjs';
@@ -36,6 +35,7 @@ export { zipWith } from '../array/zipWith.mjs';
36
35
  export { AbortError } from '../error/AbortError.mjs';
37
36
  export { TimeoutError } from '../error/TimeoutError.mjs';
38
37
  export { after } from '../function/after.mjs';
38
+ export { identity } from '../function/identity.mjs';
39
39
  export { MemoizeCache, memoize } from '../function/memoize.mjs';
40
40
  export { negate } from '../function/negate.mjs';
41
41
  export { noop } from '../function/noop.mjs';
@@ -45,6 +45,8 @@ export { partialRight } from '../function/partialRight.mjs';
45
45
  export { unary } from '../function/unary.mjs';
46
46
  export { mean } from '../math/mean.mjs';
47
47
  export { meanBy } from '../math/meanBy.mjs';
48
+ export { median } from '../math/median.mjs';
49
+ export { medianBy } from '../math/medianBy.mjs';
48
50
  export { randomInt } from '../math/randomInt.mjs';
49
51
  export { range } from '../math/range.mjs';
50
52
  export { rangeRight } from '../math/rangeRight.mjs';
@@ -77,6 +79,7 @@ export { lowerFirst } from '../string/lowerFirst.mjs';
77
79
  export { pascalCase } from '../string/pascalCase.mjs';
78
80
  export { unescape } from '../string/unescape.mjs';
79
81
  export { upperFirst } from '../string/upperFirst.mjs';
82
+ export { invariant } from '../util/invariant.mjs';
80
83
  export { castArray } from './array/castArray.mjs';
81
84
  export { chunk } from './array/chunk.mjs';
82
85
  export { compact } from './array/compact.mjs';
@@ -99,6 +102,7 @@ export { head as first, head } from './array/head.mjs';
99
102
  export { includes } from './array/includes.mjs';
100
103
  export { indexOf } from './array/indexOf.mjs';
101
104
  export { intersection } from './array/intersection.mjs';
105
+ export { intersectionBy } from './array/intersectionBy.mjs';
102
106
  export { join } from './array/join.mjs';
103
107
  export { last } from './array/last.mjs';
104
108
  export { orderBy } from './array/orderBy.mjs';
@@ -198,6 +202,7 @@ export { snakeCase } from './string/snakeCase.mjs';
198
202
  export { startCase } from './string/startCase.mjs';
199
203
  export { startsWith } from './string/startsWith.mjs';
200
204
  export { upperCase } from './string/upperCase.mjs';
205
+ export { template, templateSettings } from './string/template.mjs';
201
206
  export { trim } from './string/trim.mjs';
202
207
  export { trimEnd } from './string/trimEnd.mjs';
203
208
  export { trimStart } from './string/trimStart.mjs';
@@ -212,3 +217,4 @@ export { toNumber } from './util/toNumber.mjs';
212
217
  export { toPath } from './util/toPath.mjs';
213
218
  export { toSafeInteger } from './util/toSafeInteger.mjs';
214
219
  export { toString } from './util/toString.mjs';
220
+ export { uniqueId } from './util/uniqueId.mjs';