es-toolkit 1.26.1-dev.863 → 1.26.1-dev.864
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/toArray.mjs +5 -0
- package/dist/compat/array/chunk.mjs +2 -1
- package/dist/compat/array/difference.mjs +2 -1
- package/dist/compat/array/drop.mjs +2 -1
- package/dist/compat/array/dropRight.mjs +2 -1
- package/dist/compat/array/dropWhile.mjs +2 -1
- package/dist/compat/array/findLastIndex.mjs +2 -1
- package/dist/compat/array/head.mjs +2 -1
- package/dist/compat/array/last.mjs +2 -1
- package/dist/compat/array/sample.mjs +2 -1
- package/dist/compat/array/tail.mjs +2 -1
- package/dist/compat/array/take.mjs +2 -1
- package/dist/compat/array/takeRight.mjs +2 -1
- package/dist/compat/index.js +16 -12
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chunk as chunk$1 } from '../../array/chunk.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
|
|
4
5
|
function chunk(arr, size = 1) {
|
|
@@ -6,7 +7,7 @@ function chunk(arr, size = 1) {
|
|
|
6
7
|
if (size === 0 || !isArrayLike(arr)) {
|
|
7
8
|
return [];
|
|
8
9
|
}
|
|
9
|
-
return chunk$1(
|
|
10
|
+
return chunk$1(toArray(arr), size);
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export { chunk };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { difference as difference$1 } from '../../array/difference.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|
3
4
|
|
|
4
5
|
function difference(arr, ...values) {
|
|
5
6
|
if (!isArrayLikeObject(arr)) {
|
|
6
7
|
return [];
|
|
7
8
|
}
|
|
8
|
-
const arr1 =
|
|
9
|
+
const arr1 = toArray(arr);
|
|
9
10
|
const arr2 = [];
|
|
10
11
|
for (let i = 0; i < values.length; i++) {
|
|
11
12
|
const value = values[i];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { drop as drop$1 } from '../../array/drop.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
import { toInteger } from '../util/toInteger.mjs';
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ function drop(collection, itemsCount = 1, guard) {
|
|
|
7
8
|
return [];
|
|
8
9
|
}
|
|
9
10
|
itemsCount = guard ? 1 : toInteger(itemsCount);
|
|
10
|
-
return drop$1(
|
|
11
|
+
return drop$1(toArray(collection), itemsCount);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export { drop };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { dropRight as dropRight$1 } from '../../array/dropRight.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
import { toInteger } from '../util/toInteger.mjs';
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ function dropRight(collection, itemsCount = 1, guard) {
|
|
|
7
8
|
return [];
|
|
8
9
|
}
|
|
9
10
|
itemsCount = guard ? 1 : toInteger(itemsCount);
|
|
10
|
-
return dropRight$1(
|
|
11
|
+
return dropRight$1(toArray(collection), itemsCount);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export { dropRight };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { dropWhile as dropWhile$1 } from '../../array/dropWhile.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { property } from '../object/property.mjs';
|
|
3
4
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
4
5
|
import { matches } from '../predicate/matches.mjs';
|
|
@@ -8,7 +9,7 @@ function dropWhile(arr, predicate) {
|
|
|
8
9
|
if (!isArrayLike(arr)) {
|
|
9
10
|
return [];
|
|
10
11
|
}
|
|
11
|
-
return dropWhileImpl(
|
|
12
|
+
return dropWhileImpl(toArray(arr), predicate);
|
|
12
13
|
}
|
|
13
14
|
function dropWhileImpl(arr, predicate) {
|
|
14
15
|
switch (typeof predicate) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
1
2
|
import { property } from '../object/property.mjs';
|
|
2
3
|
import { matches } from '../predicate/matches.mjs';
|
|
3
4
|
import { matchesProperty } from '../predicate/matchesProperty.mjs';
|
|
@@ -12,7 +13,7 @@ function findLastIndex(arr, doesMatch, fromIndex = arr ? arr.length - 1 : 0) {
|
|
|
12
13
|
else {
|
|
13
14
|
fromIndex = Math.min(fromIndex, arr.length - 1);
|
|
14
15
|
}
|
|
15
|
-
const subArray =
|
|
16
|
+
const subArray = toArray(arr).slice(0, fromIndex + 1);
|
|
16
17
|
switch (typeof doesMatch) {
|
|
17
18
|
case 'function': {
|
|
18
19
|
return subArray.findLastIndex(doesMatch);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { head as head$1 } from '../../array/head.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
|
|
4
5
|
function head(arr) {
|
|
5
6
|
if (!isArrayLike(arr)) {
|
|
6
7
|
return undefined;
|
|
7
8
|
}
|
|
8
|
-
return head$1(
|
|
9
|
+
return head$1(toArray(arr));
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export { head };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { last as last$1 } from '../../array/last.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
|
|
4
5
|
function last(array) {
|
|
5
6
|
if (!isArrayLike(array)) {
|
|
6
7
|
return undefined;
|
|
7
8
|
}
|
|
8
|
-
return last$1(
|
|
9
|
+
return last$1(toArray(array));
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export { last };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { sample as sample$1 } from '../../array/sample.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
|
|
4
5
|
function sample(collection) {
|
|
@@ -6,7 +7,7 @@ function sample(collection) {
|
|
|
6
7
|
return undefined;
|
|
7
8
|
}
|
|
8
9
|
if (isArrayLike(collection)) {
|
|
9
|
-
return sample$1(
|
|
10
|
+
return sample$1(toArray(collection));
|
|
10
11
|
}
|
|
11
12
|
return sample$1(Object.values(collection));
|
|
12
13
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { tail as tail$1 } from '../../array/tail.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
|
|
4
5
|
function tail(arr) {
|
|
5
6
|
if (!isArrayLike(arr)) {
|
|
6
7
|
return [];
|
|
7
8
|
}
|
|
8
|
-
return tail$1(
|
|
9
|
+
return tail$1(toArray(arr));
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export { tail };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { take as take$1 } from '../../array/take.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
import { toInteger } from '../util/toInteger.mjs';
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ function take(arr, count = 1, guard) {
|
|
|
7
8
|
if (count < 1 || !isArrayLike(arr)) {
|
|
8
9
|
return [];
|
|
9
10
|
}
|
|
10
|
-
return take$1(
|
|
11
|
+
return take$1(toArray(arr), count);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export { take };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { takeRight as takeRight$1 } from '../../array/takeRight.mjs';
|
|
2
|
+
import { toArray } from '../_internal/toArray.mjs';
|
|
2
3
|
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
import { toInteger } from '../util/toInteger.mjs';
|
|
4
5
|
|
|
@@ -7,7 +8,7 @@ function takeRight(arr, count = 1, guard) {
|
|
|
7
8
|
if (count <= 0 || !isArrayLike(arr)) {
|
|
8
9
|
return [];
|
|
9
10
|
}
|
|
10
|
-
return takeRight$1(
|
|
11
|
+
return takeRight$1(toArray(arr), count);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export { takeRight };
|
package/dist/compat/index.js
CHANGED
|
@@ -21,6 +21,10 @@ function castArray(value) {
|
|
|
21
21
|
return Array.isArray(value) ? value : [value];
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function toArray(value) {
|
|
25
|
+
return Array.isArray(value) ? value : Array.from(value);
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
function isArrayLike(value) {
|
|
25
29
|
return value != null && typeof value !== 'function' && isWeakSet$1.isLength(value.length);
|
|
26
30
|
}
|
|
@@ -30,7 +34,7 @@ function chunk(arr, size = 1) {
|
|
|
30
34
|
if (size === 0 || !isArrayLike(arr)) {
|
|
31
35
|
return [];
|
|
32
36
|
}
|
|
33
|
-
return zipWith.chunk(
|
|
37
|
+
return zipWith.chunk(toArray(arr), size);
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
function compact(arr) {
|
|
@@ -52,7 +56,7 @@ function difference(arr, ...values) {
|
|
|
52
56
|
if (!isArrayLikeObject(arr)) {
|
|
53
57
|
return [];
|
|
54
58
|
}
|
|
55
|
-
const arr1 =
|
|
59
|
+
const arr1 = toArray(arr);
|
|
56
60
|
const arr2 = [];
|
|
57
61
|
for (let i = 0; i < values.length; i++) {
|
|
58
62
|
const value = values[i];
|
|
@@ -96,7 +100,7 @@ function last(array) {
|
|
|
96
100
|
if (!isArrayLike(array)) {
|
|
97
101
|
return undefined;
|
|
98
102
|
}
|
|
99
|
-
return zipWith.last(
|
|
103
|
+
return zipWith.last(toArray(array));
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
function isDeepKey(key) {
|
|
@@ -530,7 +534,7 @@ function drop(collection, itemsCount = 1, guard) {
|
|
|
530
534
|
return [];
|
|
531
535
|
}
|
|
532
536
|
itemsCount = guard ? 1 : toInteger(itemsCount);
|
|
533
|
-
return zipWith.drop(
|
|
537
|
+
return zipWith.drop(toArray(collection), itemsCount);
|
|
534
538
|
}
|
|
535
539
|
|
|
536
540
|
function dropRight(collection, itemsCount = 1, guard) {
|
|
@@ -538,7 +542,7 @@ function dropRight(collection, itemsCount = 1, guard) {
|
|
|
538
542
|
return [];
|
|
539
543
|
}
|
|
540
544
|
itemsCount = guard ? 1 : toInteger(itemsCount);
|
|
541
|
-
return zipWith.dropRight(
|
|
545
|
+
return zipWith.dropRight(toArray(collection), itemsCount);
|
|
542
546
|
}
|
|
543
547
|
|
|
544
548
|
function dropRightWhile(arr, predicate) {
|
|
@@ -572,7 +576,7 @@ function dropWhile(arr, predicate) {
|
|
|
572
576
|
if (!isArrayLike(arr)) {
|
|
573
577
|
return [];
|
|
574
578
|
}
|
|
575
|
-
return dropWhileImpl(
|
|
579
|
+
return dropWhileImpl(toArray(arr), predicate);
|
|
576
580
|
}
|
|
577
581
|
function dropWhileImpl(arr, predicate) {
|
|
578
582
|
switch (typeof predicate) {
|
|
@@ -787,7 +791,7 @@ function findLastIndex(arr, doesMatch, fromIndex = arr ? arr.length - 1 : 0) {
|
|
|
787
791
|
else {
|
|
788
792
|
fromIndex = Math.min(fromIndex, arr.length - 1);
|
|
789
793
|
}
|
|
790
|
-
const subArray =
|
|
794
|
+
const subArray = toArray(arr).slice(0, fromIndex + 1);
|
|
791
795
|
switch (typeof doesMatch) {
|
|
792
796
|
case 'function': {
|
|
793
797
|
return subArray.findLastIndex(doesMatch);
|
|
@@ -836,7 +840,7 @@ function head(arr) {
|
|
|
836
840
|
if (!isArrayLike(arr)) {
|
|
837
841
|
return undefined;
|
|
838
842
|
}
|
|
839
|
-
return zipWith.head(
|
|
843
|
+
return zipWith.head(toArray(arr));
|
|
840
844
|
}
|
|
841
845
|
|
|
842
846
|
function includes(source, target, fromIndex, guard) {
|
|
@@ -1072,7 +1076,7 @@ function sample(collection) {
|
|
|
1072
1076
|
return undefined;
|
|
1073
1077
|
}
|
|
1074
1078
|
if (isArrayLike(collection)) {
|
|
1075
|
-
return zipWith.sample(
|
|
1079
|
+
return zipWith.sample(toArray(collection));
|
|
1076
1080
|
}
|
|
1077
1081
|
return zipWith.sample(Object.values(collection));
|
|
1078
1082
|
}
|
|
@@ -1178,7 +1182,7 @@ function tail(arr) {
|
|
|
1178
1182
|
if (!isArrayLike(arr)) {
|
|
1179
1183
|
return [];
|
|
1180
1184
|
}
|
|
1181
|
-
return zipWith.tail(
|
|
1185
|
+
return zipWith.tail(toArray(arr));
|
|
1182
1186
|
}
|
|
1183
1187
|
|
|
1184
1188
|
function take(arr, count = 1, guard) {
|
|
@@ -1186,7 +1190,7 @@ function take(arr, count = 1, guard) {
|
|
|
1186
1190
|
if (count < 1 || !isArrayLike(arr)) {
|
|
1187
1191
|
return [];
|
|
1188
1192
|
}
|
|
1189
|
-
return zipWith.take(
|
|
1193
|
+
return zipWith.take(toArray(arr), count);
|
|
1190
1194
|
}
|
|
1191
1195
|
|
|
1192
1196
|
function takeRight(arr, count = 1, guard) {
|
|
@@ -1194,7 +1198,7 @@ function takeRight(arr, count = 1, guard) {
|
|
|
1194
1198
|
if (count <= 0 || !isArrayLike(arr)) {
|
|
1195
1199
|
return [];
|
|
1196
1200
|
}
|
|
1197
|
-
return zipWith.takeRight(
|
|
1201
|
+
return zipWith.takeRight(toArray(arr), count);
|
|
1198
1202
|
}
|
|
1199
1203
|
|
|
1200
1204
|
function uniq(arr) {
|
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.864+a0f61e4b",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|