es-toolkit 1.26.1-dev.866 → 1.26.1-dev.868
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/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/uniqBy.d.mts +60 -0
- package/dist/compat/array/uniqBy.d.ts +60 -0
- package/dist/compat/array/uniqBy.mjs +25 -0
- package/dist/compat/index.d.mts +1 -1
- package/dist/compat/index.d.ts +1 -1
- package/dist/compat/index.js +20 -4
- package/dist/compat/index.mjs +1 -1
- package/dist/compat/predicate/isEmpty.d.mts +2 -2
- package/dist/compat/predicate/isEmpty.d.ts +2 -2
- package/dist/compat/predicate/isEmpty.mjs +2 -4
- package/package.json +1 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a duplicate-free version of an array using a transform function for comparison.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {ArrayLike<T>} array - The array to inspect.
|
|
6
|
+
* @param {(value: T) => unknown} iteratee - The transform function.
|
|
7
|
+
* @returns {T[]} Returns the new duplicate-free array.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* uniqBy([2.1, 1.2, 2.3], Math.floor);
|
|
11
|
+
* // => [2.1, 1.2]
|
|
12
|
+
*/
|
|
13
|
+
declare function uniqBy<T>(array: ArrayLike<T>, iteratee: (value: T) => unknown): T[];
|
|
14
|
+
/**
|
|
15
|
+
* Creates a duplicate-free version of an array using a property name for comparison.
|
|
16
|
+
*
|
|
17
|
+
* @template T
|
|
18
|
+
* @param {ArrayLike<T>} array - The array to inspect.
|
|
19
|
+
* @param {string} path - The property path to get values from.
|
|
20
|
+
* @returns {T[]} Returns the new duplicate-free array.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const users = [
|
|
24
|
+
* { 'user': 'barney', 'age': 36 },
|
|
25
|
+
* { 'user': 'fred', 'age': 40 },
|
|
26
|
+
* { 'user': 'barney', 'age': 37 }
|
|
27
|
+
* ];
|
|
28
|
+
* uniqBy(users, 'user');
|
|
29
|
+
* // => [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }]
|
|
30
|
+
*/
|
|
31
|
+
declare function uniqBy<T>(array: ArrayLike<T>, path: string): T[];
|
|
32
|
+
/**
|
|
33
|
+
* Creates a duplicate-free version of an array using a property index for comparison.
|
|
34
|
+
*
|
|
35
|
+
* @template T
|
|
36
|
+
* @param {ArrayLike<T>} array - The array to inspect.
|
|
37
|
+
* @param {number} index - The index to get values from.
|
|
38
|
+
* @returns {T[]} Returns the new duplicate-free array.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const arrays = [[2], [3], [1], [2], [3], [1]];
|
|
42
|
+
* uniqBy(arrays, 0);
|
|
43
|
+
* // => [[2], [3], [1]]
|
|
44
|
+
*/
|
|
45
|
+
declare function uniqBy<T>(array: ArrayLike<T>, index: number): T[];
|
|
46
|
+
/**
|
|
47
|
+
* Creates a duplicate-free version of an array, combining multiple arrays and using an optional transform function.
|
|
48
|
+
*
|
|
49
|
+
* @template T
|
|
50
|
+
* @param {ArrayLike<T>} array - The array to inspect.
|
|
51
|
+
* @param {...Array<ArrayLike<T> | ((value: T) => unknown) | string>} values - Additional arrays and/or iteratee.
|
|
52
|
+
* @returns {T[]} Returns the new duplicate-free array.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* uniqBy([1, 2], [2, 3], [3, 4], Math.floor);
|
|
56
|
+
* // => [1, 2, 3, 4]
|
|
57
|
+
*/
|
|
58
|
+
declare function uniqBy<T>(array: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T> | ((value: T) => unknown) | string>): T[];
|
|
59
|
+
|
|
60
|
+
export { uniqBy };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a duplicate-free version of an array using a transform function for comparison.
|
|
3
|
+
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {ArrayLike<T>} array - The array to inspect.
|
|
6
|
+
* @param {(value: T) => unknown} iteratee - The transform function.
|
|
7
|
+
* @returns {T[]} Returns the new duplicate-free array.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* uniqBy([2.1, 1.2, 2.3], Math.floor);
|
|
11
|
+
* // => [2.1, 1.2]
|
|
12
|
+
*/
|
|
13
|
+
declare function uniqBy<T>(array: ArrayLike<T>, iteratee: (value: T) => unknown): T[];
|
|
14
|
+
/**
|
|
15
|
+
* Creates a duplicate-free version of an array using a property name for comparison.
|
|
16
|
+
*
|
|
17
|
+
* @template T
|
|
18
|
+
* @param {ArrayLike<T>} array - The array to inspect.
|
|
19
|
+
* @param {string} path - The property path to get values from.
|
|
20
|
+
* @returns {T[]} Returns the new duplicate-free array.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const users = [
|
|
24
|
+
* { 'user': 'barney', 'age': 36 },
|
|
25
|
+
* { 'user': 'fred', 'age': 40 },
|
|
26
|
+
* { 'user': 'barney', 'age': 37 }
|
|
27
|
+
* ];
|
|
28
|
+
* uniqBy(users, 'user');
|
|
29
|
+
* // => [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }]
|
|
30
|
+
*/
|
|
31
|
+
declare function uniqBy<T>(array: ArrayLike<T>, path: string): T[];
|
|
32
|
+
/**
|
|
33
|
+
* Creates a duplicate-free version of an array using a property index for comparison.
|
|
34
|
+
*
|
|
35
|
+
* @template T
|
|
36
|
+
* @param {ArrayLike<T>} array - The array to inspect.
|
|
37
|
+
* @param {number} index - The index to get values from.
|
|
38
|
+
* @returns {T[]} Returns the new duplicate-free array.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const arrays = [[2], [3], [1], [2], [3], [1]];
|
|
42
|
+
* uniqBy(arrays, 0);
|
|
43
|
+
* // => [[2], [3], [1]]
|
|
44
|
+
*/
|
|
45
|
+
declare function uniqBy<T>(array: ArrayLike<T>, index: number): T[];
|
|
46
|
+
/**
|
|
47
|
+
* Creates a duplicate-free version of an array, combining multiple arrays and using an optional transform function.
|
|
48
|
+
*
|
|
49
|
+
* @template T
|
|
50
|
+
* @param {ArrayLike<T>} array - The array to inspect.
|
|
51
|
+
* @param {...Array<ArrayLike<T> | ((value: T) => unknown) | string>} values - Additional arrays and/or iteratee.
|
|
52
|
+
* @returns {T[]} Returns the new duplicate-free array.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* uniqBy([1, 2], [2, 3], [3, 4], Math.floor);
|
|
56
|
+
* // => [1, 2, 3, 4]
|
|
57
|
+
*/
|
|
58
|
+
declare function uniqBy<T>(array: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T> | ((value: T) => unknown) | string>): T[];
|
|
59
|
+
|
|
60
|
+
export { uniqBy };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { flatten } from './flatten.mjs';
|
|
2
|
+
import { last } from './last.mjs';
|
|
3
|
+
import { uniq } from '../../array/uniq.mjs';
|
|
4
|
+
import { uniqBy as uniqBy$1 } from '../../array/uniqBy.mjs';
|
|
5
|
+
import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|
6
|
+
import { iteratee } from '../util/iteratee.mjs';
|
|
7
|
+
|
|
8
|
+
function uniqBy(arr, ...values) {
|
|
9
|
+
if (!isArrayLikeObject(arr)) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const iteratee$1 = last(values);
|
|
13
|
+
if (iteratee$1 === undefined) {
|
|
14
|
+
return Array.from(arr);
|
|
15
|
+
}
|
|
16
|
+
const validArrays = values.slice(0, -1).filter(isArrayLikeObject);
|
|
17
|
+
const flattenedArrays = flatten(validArrays);
|
|
18
|
+
const allValues = [...Array.from(arr), ...flattenedArrays];
|
|
19
|
+
if (isArrayLikeObject(iteratee$1)) {
|
|
20
|
+
return uniq(allValues);
|
|
21
|
+
}
|
|
22
|
+
return uniqBy$1(allValues, iteratee(iteratee$1));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { uniqBy };
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -21,7 +21,6 @@ export { takeWhile } from '../array/takeWhile.mjs';
|
|
|
21
21
|
export { toFilled } from '../array/toFilled.mjs';
|
|
22
22
|
export { unionBy } from '../array/unionBy.mjs';
|
|
23
23
|
export { unionWith } from '../array/unionWith.mjs';
|
|
24
|
-
export { uniqBy } from '../array/uniqBy.mjs';
|
|
25
24
|
export { uniqWith } from '../array/uniqWith.mjs';
|
|
26
25
|
export { unzipWith } from '../array/unzipWith.mjs';
|
|
27
26
|
export { xor } from '../array/xor.mjs';
|
|
@@ -114,6 +113,7 @@ export { take } from './array/take.mjs';
|
|
|
114
113
|
export { takeRight } from './array/takeRight.mjs';
|
|
115
114
|
export { union } from './array/union.mjs';
|
|
116
115
|
export { uniq } from './array/uniq.mjs';
|
|
116
|
+
export { uniqBy } from './array/uniqBy.mjs';
|
|
117
117
|
export { unzip } from './array/unzip.mjs';
|
|
118
118
|
export { without } from './array/without.mjs';
|
|
119
119
|
export { zip } from './array/zip.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ export { takeWhile } from '../array/takeWhile.js';
|
|
|
21
21
|
export { toFilled } from '../array/toFilled.js';
|
|
22
22
|
export { unionBy } from '../array/unionBy.js';
|
|
23
23
|
export { unionWith } from '../array/unionWith.js';
|
|
24
|
-
export { uniqBy } from '../array/uniqBy.js';
|
|
25
24
|
export { uniqWith } from '../array/uniqWith.js';
|
|
26
25
|
export { unzipWith } from '../array/unzipWith.js';
|
|
27
26
|
export { xor } from '../array/xor.js';
|
|
@@ -114,6 +113,7 @@ export { take } from './array/take.js';
|
|
|
114
113
|
export { takeRight } from './array/takeRight.js';
|
|
115
114
|
export { union } from './array/union.js';
|
|
116
115
|
export { uniq } from './array/uniq.js';
|
|
116
|
+
export { uniqBy } from './array/uniqBy.js';
|
|
117
117
|
export { unzip } from './array/unzip.js';
|
|
118
118
|
export { without } from './array/without.js';
|
|
119
119
|
export { zip } from './array/zip.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -1214,6 +1214,23 @@ function uniq(arr) {
|
|
|
1214
1214
|
return zipWith.uniq(Array.from(arr));
|
|
1215
1215
|
}
|
|
1216
1216
|
|
|
1217
|
+
function uniqBy(arr, ...values) {
|
|
1218
|
+
if (!isArrayLikeObject(arr)) {
|
|
1219
|
+
return [];
|
|
1220
|
+
}
|
|
1221
|
+
const iteratee$1 = last(values);
|
|
1222
|
+
if (iteratee$1 === undefined) {
|
|
1223
|
+
return Array.from(arr);
|
|
1224
|
+
}
|
|
1225
|
+
const validArrays = values.slice(0, -1).filter(isArrayLikeObject);
|
|
1226
|
+
const flattenedArrays = flatten(validArrays);
|
|
1227
|
+
const allValues = [...Array.from(arr), ...flattenedArrays];
|
|
1228
|
+
if (isArrayLikeObject(iteratee$1)) {
|
|
1229
|
+
return zipWith.uniq(allValues);
|
|
1230
|
+
}
|
|
1231
|
+
return zipWith.uniqBy(allValues, iteratee(iteratee$1));
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1217
1234
|
function unzip(array) {
|
|
1218
1235
|
if (!isArrayLikeObject(array) || !array.length) {
|
|
1219
1236
|
return [];
|
|
@@ -2172,11 +2189,10 @@ function isEmpty(value) {
|
|
|
2172
2189
|
return value.size === 0;
|
|
2173
2190
|
}
|
|
2174
2191
|
const keys = Object.keys(value);
|
|
2175
|
-
const symbols = isPlainObject$1.getSymbols(value);
|
|
2176
2192
|
if (isPrototype(value)) {
|
|
2177
|
-
return keys.filter(x => x !== 'constructor').length === 0
|
|
2193
|
+
return keys.filter(x => x !== 'constructor').length === 0;
|
|
2178
2194
|
}
|
|
2179
|
-
return keys.length === 0
|
|
2195
|
+
return keys.length === 0;
|
|
2180
2196
|
}
|
|
2181
2197
|
return true;
|
|
2182
2198
|
}
|
|
@@ -2554,7 +2570,6 @@ exports.takeWhile = zipWith.takeWhile;
|
|
|
2554
2570
|
exports.toFilled = zipWith.toFilled;
|
|
2555
2571
|
exports.unionBy = zipWith.unionBy;
|
|
2556
2572
|
exports.unionWith = zipWith.unionWith;
|
|
2557
|
-
exports.uniqBy = zipWith.uniqBy;
|
|
2558
2573
|
exports.uniqWith = zipWith.uniqWith;
|
|
2559
2574
|
exports.unzipWith = zipWith.unzipWith;
|
|
2560
2575
|
exports.xor = zipWith.xor;
|
|
@@ -2755,6 +2770,7 @@ exports.trimEnd = trimEnd;
|
|
|
2755
2770
|
exports.trimStart = trimStart;
|
|
2756
2771
|
exports.union = union;
|
|
2757
2772
|
exports.uniq = uniq;
|
|
2773
|
+
exports.uniqBy = uniqBy;
|
|
2758
2774
|
exports.uniqueId = uniqueId;
|
|
2759
2775
|
exports.unset = unset;
|
|
2760
2776
|
exports.unzip = unzip;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -21,7 +21,6 @@ export { takeWhile } from '../array/takeWhile.mjs';
|
|
|
21
21
|
export { toFilled } from '../array/toFilled.mjs';
|
|
22
22
|
export { unionBy } from '../array/unionBy.mjs';
|
|
23
23
|
export { unionWith } from '../array/unionWith.mjs';
|
|
24
|
-
export { uniqBy } from '../array/uniqBy.mjs';
|
|
25
24
|
export { uniqWith } from '../array/uniqWith.mjs';
|
|
26
25
|
export { unzipWith } from '../array/unzipWith.mjs';
|
|
27
26
|
export { xor } from '../array/xor.mjs';
|
|
@@ -116,6 +115,7 @@ export { take } from './array/take.mjs';
|
|
|
116
115
|
export { takeRight } from './array/takeRight.mjs';
|
|
117
116
|
export { union } from './array/union.mjs';
|
|
118
117
|
export { uniq } from './array/uniq.mjs';
|
|
118
|
+
export { uniqBy } from './array/uniqBy.mjs';
|
|
119
119
|
export { unzip } from './array/unzip.mjs';
|
|
120
120
|
export { without } from './array/without.mjs';
|
|
121
121
|
export { zip } from './array/zip.mjs';
|
|
@@ -43,14 +43,14 @@ declare function isEmpty(value: Set<any>): boolean;
|
|
|
43
43
|
/**
|
|
44
44
|
* Checks if a given array is empty.
|
|
45
45
|
*
|
|
46
|
-
* @param {
|
|
46
|
+
* @param {any[]} value - The array to check.
|
|
47
47
|
* @returns {boolean} `true` if the array is empty, `false` otherwise.
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
50
50
|
* isEmpty([]); // true
|
|
51
51
|
* isEmpty([1, 2, 3]); // false
|
|
52
52
|
*/
|
|
53
|
-
declare function isEmpty(value:
|
|
53
|
+
declare function isEmpty(value: any[]): value is [];
|
|
54
54
|
/**
|
|
55
55
|
* Checks if a given object is empty.
|
|
56
56
|
*
|
|
@@ -43,14 +43,14 @@ declare function isEmpty(value: Set<any>): boolean;
|
|
|
43
43
|
/**
|
|
44
44
|
* Checks if a given array is empty.
|
|
45
45
|
*
|
|
46
|
-
* @param {
|
|
46
|
+
* @param {any[]} value - The array to check.
|
|
47
47
|
* @returns {boolean} `true` if the array is empty, `false` otherwise.
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
50
50
|
* isEmpty([]); // true
|
|
51
51
|
* isEmpty([1, 2, 3]); // false
|
|
52
52
|
*/
|
|
53
|
-
declare function isEmpty(value:
|
|
53
|
+
declare function isEmpty(value: any[]): value is [];
|
|
54
54
|
/**
|
|
55
55
|
* Checks if a given object is empty.
|
|
56
56
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isArguments } from './isArguments.mjs';
|
|
2
2
|
import { isArrayLike } from './isArrayLike.mjs';
|
|
3
3
|
import { isTypedArray } from './isTypedArray.mjs';
|
|
4
|
-
import { getSymbols } from '../_internal/getSymbols.mjs';
|
|
5
4
|
import { isPrototype } from '../_internal/isPrototype.mjs';
|
|
6
5
|
|
|
7
6
|
function isEmpty(value) {
|
|
@@ -23,11 +22,10 @@ function isEmpty(value) {
|
|
|
23
22
|
return value.size === 0;
|
|
24
23
|
}
|
|
25
24
|
const keys = Object.keys(value);
|
|
26
|
-
const symbols = getSymbols(value);
|
|
27
25
|
if (isPrototype(value)) {
|
|
28
|
-
return keys.filter(x => x !== 'constructor').length === 0
|
|
26
|
+
return keys.filter(x => x !== 'constructor').length === 0;
|
|
29
27
|
}
|
|
30
|
-
return keys.length === 0
|
|
28
|
+
return keys.length === 0;
|
|
31
29
|
}
|
|
32
30
|
return true;
|
|
33
31
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
3
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
4
|
-
"version": "1.26.1-dev.
|
|
4
|
+
"version": "1.26.1-dev.868+b4cd2551",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|