es-toolkit 1.26.1-dev.867 → 1.26.1-dev.869
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/_internal/flattenArrayLike.mjs +17 -0
- package/dist/compat/array/differenceBy.mjs +6 -5
- package/dist/compat/index.js +50 -36
- 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,17 @@
|
|
|
1
|
+
import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|
2
|
+
|
|
3
|
+
function flattenArrayLike(values) {
|
|
4
|
+
const result = [];
|
|
5
|
+
for (let i = 0; i < values.length; i++) {
|
|
6
|
+
const arrayLike = values[i];
|
|
7
|
+
if (!isArrayLikeObject(arrayLike)) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
for (let j = 0; j < arrayLike.length; j++) {
|
|
11
|
+
result.push(arrayLike[j]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { flattenArrayLike };
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { flatten } from './flatten.mjs';
|
|
2
1
|
import { last } from './last.mjs';
|
|
3
2
|
import { difference } from '../../array/difference.mjs';
|
|
4
3
|
import { differenceBy as differenceBy$1 } from '../../array/differenceBy.mjs';
|
|
4
|
+
import { flattenArrayLike } from '../_internal/flattenArrayLike.mjs';
|
|
5
5
|
import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|
6
6
|
import { iteratee } from '../util/iteratee.mjs';
|
|
7
7
|
|
|
8
|
-
function differenceBy(arr, ...
|
|
8
|
+
function differenceBy(arr, ..._values) {
|
|
9
9
|
if (!isArrayLikeObject(arr)) {
|
|
10
10
|
return [];
|
|
11
11
|
}
|
|
12
|
-
const iteratee$1 = last(
|
|
12
|
+
const iteratee$1 = last(_values);
|
|
13
|
+
const values = flattenArrayLike(_values);
|
|
13
14
|
if (isArrayLikeObject(iteratee$1)) {
|
|
14
|
-
return difference(Array.from(arr),
|
|
15
|
+
return difference(Array.from(arr), values);
|
|
15
16
|
}
|
|
16
|
-
return differenceBy$1(Array.from(arr),
|
|
17
|
+
return differenceBy$1(Array.from(arr), values, iteratee(iteratee$1));
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export { differenceBy };
|
package/dist/compat/index.js
CHANGED
|
@@ -67,35 +67,6 @@ function difference(arr, ...values) {
|
|
|
67
67
|
return zipWith.difference(arr1, arr2);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
function flatten(value, depth = 1) {
|
|
71
|
-
const result = [];
|
|
72
|
-
const flooredDepth = Math.floor(depth);
|
|
73
|
-
if (!isArrayLike(value)) {
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
const recursive = (arr, currentDepth) => {
|
|
77
|
-
for (let i = 0; i < arr.length; i++) {
|
|
78
|
-
const item = arr[i];
|
|
79
|
-
if (currentDepth < flooredDepth &&
|
|
80
|
-
(Array.isArray(item) ||
|
|
81
|
-
Boolean(item?.[Symbol.isConcatSpreadable]) ||
|
|
82
|
-
(item !== null && typeof item === 'object' && Object.prototype.toString.call(item) === '[object Arguments]'))) {
|
|
83
|
-
if (Array.isArray(item)) {
|
|
84
|
-
recursive(item, currentDepth + 1);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
recursive(Array.from(item), currentDepth + 1);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
result.push(item);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
recursive(Array.from(value), 0);
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
70
|
function last(array) {
|
|
100
71
|
if (!isArrayLike(array)) {
|
|
101
72
|
return undefined;
|
|
@@ -103,6 +74,20 @@ function last(array) {
|
|
|
103
74
|
return zipWith.last(toArray(array));
|
|
104
75
|
}
|
|
105
76
|
|
|
77
|
+
function flattenArrayLike(values) {
|
|
78
|
+
const result = [];
|
|
79
|
+
for (let i = 0; i < values.length; i++) {
|
|
80
|
+
const arrayLike = values[i];
|
|
81
|
+
if (!isArrayLikeObject(arrayLike)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
for (let j = 0; j < arrayLike.length; j++) {
|
|
85
|
+
result.push(arrayLike[j]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
|
|
106
91
|
function isDeepKey(key) {
|
|
107
92
|
switch (typeof key) {
|
|
108
93
|
case 'number':
|
|
@@ -489,15 +474,16 @@ function iteratee(value) {
|
|
|
489
474
|
}
|
|
490
475
|
}
|
|
491
476
|
|
|
492
|
-
function differenceBy(arr, ...
|
|
477
|
+
function differenceBy(arr, ..._values) {
|
|
493
478
|
if (!isArrayLikeObject(arr)) {
|
|
494
479
|
return [];
|
|
495
480
|
}
|
|
496
|
-
const iteratee$1 = last(
|
|
481
|
+
const iteratee$1 = last(_values);
|
|
482
|
+
const values = flattenArrayLike(_values);
|
|
497
483
|
if (isArrayLikeObject(iteratee$1)) {
|
|
498
|
-
return zipWith.difference(Array.from(arr),
|
|
484
|
+
return zipWith.difference(Array.from(arr), values);
|
|
499
485
|
}
|
|
500
|
-
return zipWith.differenceBy(Array.from(arr),
|
|
486
|
+
return zipWith.differenceBy(Array.from(arr), values, iteratee(iteratee$1));
|
|
501
487
|
}
|
|
502
488
|
|
|
503
489
|
function isSymbol(value) {
|
|
@@ -812,6 +798,35 @@ function findLastIndex(arr, doesMatch, fromIndex = arr ? arr.length - 1 : 0) {
|
|
|
812
798
|
}
|
|
813
799
|
}
|
|
814
800
|
|
|
801
|
+
function flatten(value, depth = 1) {
|
|
802
|
+
const result = [];
|
|
803
|
+
const flooredDepth = Math.floor(depth);
|
|
804
|
+
if (!isArrayLike(value)) {
|
|
805
|
+
return result;
|
|
806
|
+
}
|
|
807
|
+
const recursive = (arr, currentDepth) => {
|
|
808
|
+
for (let i = 0; i < arr.length; i++) {
|
|
809
|
+
const item = arr[i];
|
|
810
|
+
if (currentDepth < flooredDepth &&
|
|
811
|
+
(Array.isArray(item) ||
|
|
812
|
+
Boolean(item?.[Symbol.isConcatSpreadable]) ||
|
|
813
|
+
(item !== null && typeof item === 'object' && Object.prototype.toString.call(item) === '[object Arguments]'))) {
|
|
814
|
+
if (Array.isArray(item)) {
|
|
815
|
+
recursive(item, currentDepth + 1);
|
|
816
|
+
}
|
|
817
|
+
else {
|
|
818
|
+
recursive(Array.from(item), currentDepth + 1);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
result.push(item);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
recursive(Array.from(value), 0);
|
|
827
|
+
return result;
|
|
828
|
+
}
|
|
829
|
+
|
|
815
830
|
function flattenDeep(value) {
|
|
816
831
|
return flatten(value, Infinity);
|
|
817
832
|
}
|
|
@@ -2189,11 +2204,10 @@ function isEmpty(value) {
|
|
|
2189
2204
|
return value.size === 0;
|
|
2190
2205
|
}
|
|
2191
2206
|
const keys = Object.keys(value);
|
|
2192
|
-
const symbols = isPlainObject$1.getSymbols(value);
|
|
2193
2207
|
if (isPrototype(value)) {
|
|
2194
|
-
return keys.filter(x => x !== 'constructor').length === 0
|
|
2208
|
+
return keys.filter(x => x !== 'constructor').length === 0;
|
|
2195
2209
|
}
|
|
2196
|
-
return keys.length === 0
|
|
2210
|
+
return keys.length === 0;
|
|
2197
2211
|
}
|
|
2198
2212
|
return true;
|
|
2199
2213
|
}
|
|
@@ -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.869+0feabb4c",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|