es-toolkit 1.49.0 → 1.50.0-dev.1975
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/CHANGELOG.md +46 -0
- package/dist/array/partition.d.mts +5 -4
- package/dist/array/partition.d.ts +5 -4
- package/dist/array/unzipWith.js +1 -1
- package/dist/array/unzipWith.mjs +1 -1
- package/dist/browser.global.js +3 -3
- package/dist/compat/_internal/ListIterateeCustom.d.mts +3 -2
- package/dist/compat/_internal/ListIterateeCustom.d.ts +3 -2
- package/dist/compat/_internal/assignValue.js +2 -3
- package/dist/compat/_internal/assignValue.mjs +2 -3
- package/dist/compat/_internal/createPadding.js +14 -0
- package/dist/compat/_internal/createPadding.mjs +13 -0
- package/dist/compat/_internal/isDeepKey.js +14 -1
- package/dist/compat/_internal/isDeepKey.mjs +14 -1
- package/dist/compat/_internal/isIterateeCall.js +2 -3
- package/dist/compat/_internal/isIterateeCall.mjs +2 -3
- package/dist/compat/_internal/regexMultiByte.js +11 -0
- package/dist/compat/_internal/regexMultiByte.mjs +11 -0
- package/dist/compat/array/every.js +5 -24
- package/dist/compat/array/every.mjs +5 -24
- package/dist/compat/array/filter.d.mts +7 -3
- package/dist/compat/array/filter.d.ts +7 -3
- package/dist/compat/array/filter.js +11 -11
- package/dist/compat/array/filter.mjs +11 -11
- package/dist/compat/array/find.d.mts +10 -6
- package/dist/compat/array/find.d.ts +10 -6
- package/dist/compat/array/find.js +1 -1
- package/dist/compat/array/find.mjs +1 -1
- package/dist/compat/array/findIndex.d.mts +0 -1
- package/dist/compat/array/findIndex.d.ts +0 -1
- package/dist/compat/array/findIndex.js +2 -1
- package/dist/compat/array/findIndex.mjs +2 -1
- package/dist/compat/array/findLast.d.mts +1 -1
- package/dist/compat/array/findLast.d.ts +1 -1
- package/dist/compat/array/findLast.js +12 -12
- package/dist/compat/array/findLast.mjs +12 -12
- package/dist/compat/array/findLastIndex.js +1 -0
- package/dist/compat/array/findLastIndex.mjs +1 -0
- package/dist/compat/array/flatMap.js +3 -2
- package/dist/compat/array/flatMap.mjs +3 -2
- package/dist/compat/array/flatMapDepth.js +2 -2
- package/dist/compat/array/flatMapDepth.mjs +2 -2
- package/dist/compat/array/flatten.d.mts +4 -5
- package/dist/compat/array/flatten.d.ts +4 -5
- package/dist/compat/array/flatten.js +14 -15
- package/dist/compat/array/flatten.mjs +14 -15
- package/dist/compat/array/flattenDeep.d.mts +1 -1
- package/dist/compat/array/flattenDeep.d.ts +1 -1
- package/dist/compat/array/flattenDeep.js +2 -2
- package/dist/compat/array/flattenDeep.mjs +2 -2
- package/dist/compat/array/flattenDepth.js +18 -2
- package/dist/compat/array/flattenDepth.mjs +18 -2
- package/dist/compat/array/groupBy.js +5 -4
- package/dist/compat/array/groupBy.mjs +4 -3
- package/dist/compat/array/includes.js +8 -3
- package/dist/compat/array/includes.mjs +8 -3
- package/dist/compat/array/intersectionBy.js +12 -5
- package/dist/compat/array/intersectionBy.mjs +12 -5
- package/dist/compat/array/intersectionWith.js +2 -3
- package/dist/compat/array/intersectionWith.mjs +2 -3
- package/dist/compat/array/invokeMap.js +3 -7
- package/dist/compat/array/invokeMap.mjs +3 -4
- package/dist/compat/array/lastIndexOf.js +3 -2
- package/dist/compat/array/lastIndexOf.mjs +3 -2
- package/dist/compat/array/nth.js +2 -2
- package/dist/compat/array/nth.mjs +2 -2
- package/dist/compat/array/pullAllWith.js +2 -3
- package/dist/compat/array/pullAllWith.mjs +2 -3
- package/dist/compat/array/size.js +2 -0
- package/dist/compat/array/size.mjs +2 -0
- package/dist/compat/array/sortedIndexOf.js +2 -3
- package/dist/compat/array/sortedIndexOf.mjs +2 -3
- package/dist/compat/array/sortedLastIndexOf.js +2 -3
- package/dist/compat/array/sortedLastIndexOf.mjs +2 -3
- package/dist/compat/compat.d.mts +4 -3
- package/dist/compat/compat.d.ts +4 -3
- package/dist/compat/compat.js +10 -11
- package/dist/compat/compat.mjs +10 -11
- package/dist/compat/index.d.mts +4 -3
- package/dist/compat/index.d.ts +4 -3
- package/dist/compat/index.js +10 -9
- package/dist/compat/index.mjs +10 -9
- package/dist/compat/math/inRange.d.mts +5 -2
- package/dist/compat/math/inRange.d.ts +5 -2
- package/dist/compat/math/inRange.js +14 -11
- package/dist/compat/math/inRange.mjs +14 -11
- package/dist/compat/math/maxBy.d.mts +1 -1
- package/dist/compat/math/maxBy.d.ts +1 -1
- package/dist/compat/math/maxBy.js +18 -4
- package/dist/compat/math/maxBy.mjs +18 -4
- package/dist/compat/math/minBy.d.mts +1 -1
- package/dist/compat/math/minBy.d.ts +1 -1
- package/dist/compat/math/minBy.js +18 -4
- package/dist/compat/math/minBy.mjs +18 -4
- package/dist/compat/object/assign.js +2 -3
- package/dist/compat/object/assign.mjs +2 -3
- package/dist/compat/object/assignIn.js +2 -3
- package/dist/compat/object/assignIn.mjs +2 -3
- package/dist/compat/object/assignInWith.js +2 -3
- package/dist/compat/object/assignInWith.mjs +2 -3
- package/dist/compat/object/assignWith.js +2 -3
- package/dist/compat/object/assignWith.mjs +2 -3
- package/dist/compat/object/create.js +1 -1
- package/dist/compat/object/create.mjs +1 -1
- package/dist/compat/object/defaults.js +2 -3
- package/dist/compat/object/defaults.mjs +2 -3
- package/dist/compat/object/has.js +1 -1
- package/dist/compat/object/has.mjs +1 -1
- package/dist/compat/object/hasIn.js +1 -1
- package/dist/compat/object/hasIn.mjs +1 -1
- package/dist/compat/object/unset.js +1 -1
- package/dist/compat/object/unset.mjs +1 -1
- package/dist/compat/object/values.js +5 -1
- package/dist/compat/object/values.mjs +5 -1
- package/dist/compat/predicate/isMatchWith.js +4 -5
- package/dist/compat/predicate/isMatchWith.mjs +4 -5
- package/dist/compat/string/camelCase.js +6 -2
- package/dist/compat/string/camelCase.mjs +6 -2
- package/dist/compat/string/kebabCase.js +2 -2
- package/dist/compat/string/kebabCase.mjs +2 -2
- package/dist/compat/string/lowerCase.js +2 -2
- package/dist/compat/string/lowerCase.mjs +2 -2
- package/dist/compat/string/pad.js +10 -3
- package/dist/compat/string/pad.mjs +10 -3
- package/dist/compat/string/padEnd.js +7 -1
- package/dist/compat/string/padEnd.mjs +7 -1
- package/dist/compat/string/padStart.js +7 -1
- package/dist/compat/string/padStart.mjs +7 -1
- package/dist/compat/string/snakeCase.js +2 -2
- package/dist/compat/string/snakeCase.mjs +2 -2
- package/dist/compat/string/startCase.js +1 -1
- package/dist/compat/string/startCase.mjs +1 -1
- package/dist/compat/string/template.d.mts +1 -1
- package/dist/compat/string/template.d.ts +1 -1
- package/dist/compat/string/templateSettings.d.mts +18 -1
- package/dist/compat/string/templateSettings.d.ts +18 -1
- package/dist/compat/string/templateSettings.js +4 -1
- package/dist/compat/string/templateSettings.mjs +5 -1
- package/dist/compat/string/truncate.js +2 -9
- package/dist/compat/string/truncate.mjs +1 -8
- package/dist/compat/string/upperCase.js +2 -2
- package/dist/compat/string/upperCase.mjs +2 -2
- package/dist/compat/util/eq.d.mts +17 -1
- package/dist/compat/util/eq.d.ts +17 -1
- package/dist/compat/util/eq.js +19 -1
- package/dist/compat/util/eq.mjs +19 -1
- package/dist/compat/util/toArray.js +2 -1
- package/dist/compat/util/toArray.mjs +2 -1
- package/dist/fp/flow.d.mts +213 -0
- package/dist/fp/flow.d.ts +213 -0
- package/dist/fp/flow.js +50 -0
- package/dist/fp/flow.mjs +50 -0
- package/dist/fp/index.d.mts +2 -1
- package/dist/fp/index.d.ts +2 -1
- package/dist/fp/index.js +3 -1
- package/dist/fp/index.mjs +3 -2
- package/dist/fp/pipe.js +8 -12
- package/dist/fp/pipe.mjs +8 -12
- package/dist/map/hasValue.js +2 -2
- package/dist/map/hasValue.mjs +2 -2
- package/dist/predicate/isEqualWith.js +2 -3
- package/dist/predicate/isEqualWith.mjs +2 -3
- package/dist/string/deburr.js +1 -1
- package/dist/string/deburr.mjs +1 -1
- package/dist/types/DeepPartial.d.mts +21 -0
- package/dist/types/DeepPartial.d.ts +21 -0
- package/dist/types/DeepReadonly.d.mts +22 -0
- package/dist/types/DeepReadonly.d.ts +22 -0
- package/dist/types/NonEmptyArray.d.mts +14 -0
- package/dist/types/NonEmptyArray.d.ts +14 -0
- package/dist/types/Simplify.d.mts +18 -0
- package/dist/types/Simplify.d.ts +18 -0
- package/dist/types/ValueOf.d.mts +14 -0
- package/dist/types/ValueOf.d.ts +14 -0
- package/dist/types/Writable.d.mts +15 -0
- package/dist/types/Writable.d.ts +15 -0
- package/dist/types/index.d.mts +7 -0
- package/dist/types/index.d.ts +7 -0
- package/package.json +23 -7
- package/types.d.ts +1 -0
- package/dist/_internal/isEqualsSameValueZero.d.mts +0 -17
- package/dist/_internal/isEqualsSameValueZero.d.ts +0 -17
- package/dist/_internal/isEqualsSameValueZero.js +0 -19
- package/dist/_internal/isEqualsSameValueZero.mjs +0 -19
|
@@ -6,9 +6,9 @@ const require_toInteger = require("../util/toInteger.js");
|
|
|
6
6
|
* Finds the last item in an object that has a specific property, where the property name is provided as a PropertyKey.
|
|
7
7
|
*
|
|
8
8
|
* @template T
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
* @param [fromIndex] - The index to start the search from, defaults to
|
|
9
|
+
* @param collection - The array or object to search through.
|
|
10
|
+
* @param [predicate=identity] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
|
|
11
|
+
* @param [fromIndex] - The index to start the search from, defaults to collection.length-1 for arrays or Object.keys(collection).length-1 for objects.
|
|
12
12
|
* @returns The last property value that has the specified property, or `undefined` if no match is found.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
@@ -17,23 +17,23 @@ const require_toInteger = require("../util/toInteger.js");
|
|
|
17
17
|
* const result = findLast(obj, 'name');
|
|
18
18
|
* console.log(result); // { id: 3, name: 'Bob' }
|
|
19
19
|
*/
|
|
20
|
-
function findLast(
|
|
21
|
-
if (!
|
|
22
|
-
const length = Array.isArray(
|
|
20
|
+
function findLast(collection, predicate = require_identity.identity, fromIndex) {
|
|
21
|
+
if (!collection) return;
|
|
22
|
+
const length = Array.isArray(collection) ? collection.length : Object.keys(collection).length;
|
|
23
23
|
fromIndex = require_toInteger.toInteger(fromIndex ?? length - 1);
|
|
24
24
|
if (fromIndex < 0) fromIndex = Math.max(length + fromIndex, 0);
|
|
25
25
|
else fromIndex = Math.min(fromIndex, length - 1);
|
|
26
|
-
const doesMatch = require_iteratee.iteratee(
|
|
27
|
-
if (!Array.isArray(
|
|
28
|
-
const keys = Object.keys(
|
|
26
|
+
const doesMatch = require_iteratee.iteratee(predicate);
|
|
27
|
+
if (!Array.isArray(collection)) {
|
|
28
|
+
const keys = Object.keys(collection);
|
|
29
29
|
for (let i = fromIndex; i >= 0; i--) {
|
|
30
30
|
const key = keys[i];
|
|
31
|
-
const value =
|
|
32
|
-
if (doesMatch(value, key,
|
|
31
|
+
const value = collection[key];
|
|
32
|
+
if (doesMatch(value, key, collection)) return value;
|
|
33
33
|
}
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
return
|
|
36
|
+
return collection.slice(0, fromIndex + 1).findLast(doesMatch);
|
|
37
37
|
}
|
|
38
38
|
//#endregion
|
|
39
39
|
exports.findLast = findLast;
|
|
@@ -6,9 +6,9 @@ import { toInteger } from "../util/toInteger.mjs";
|
|
|
6
6
|
* Finds the last item in an object that has a specific property, where the property name is provided as a PropertyKey.
|
|
7
7
|
*
|
|
8
8
|
* @template T
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
* @param [fromIndex] - The index to start the search from, defaults to
|
|
9
|
+
* @param collection - The array or object to search through.
|
|
10
|
+
* @param [predicate=identity] - The criteria to match. It can be a function, a partial object, a key-value pair, or a property name.
|
|
11
|
+
* @param [fromIndex] - The index to start the search from, defaults to collection.length-1 for arrays or Object.keys(collection).length-1 for objects.
|
|
12
12
|
* @returns The last property value that has the specified property, or `undefined` if no match is found.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
@@ -17,23 +17,23 @@ import { toInteger } from "../util/toInteger.mjs";
|
|
|
17
17
|
* const result = findLast(obj, 'name');
|
|
18
18
|
* console.log(result); // { id: 3, name: 'Bob' }
|
|
19
19
|
*/
|
|
20
|
-
function findLast(
|
|
21
|
-
if (!
|
|
22
|
-
const length = Array.isArray(
|
|
20
|
+
function findLast(collection, predicate = identity, fromIndex) {
|
|
21
|
+
if (!collection) return;
|
|
22
|
+
const length = Array.isArray(collection) ? collection.length : Object.keys(collection).length;
|
|
23
23
|
fromIndex = toInteger(fromIndex ?? length - 1);
|
|
24
24
|
if (fromIndex < 0) fromIndex = Math.max(length + fromIndex, 0);
|
|
25
25
|
else fromIndex = Math.min(fromIndex, length - 1);
|
|
26
|
-
const doesMatch = iteratee(
|
|
27
|
-
if (!Array.isArray(
|
|
28
|
-
const keys = Object.keys(
|
|
26
|
+
const doesMatch = iteratee(predicate);
|
|
27
|
+
if (!Array.isArray(collection)) {
|
|
28
|
+
const keys = Object.keys(collection);
|
|
29
29
|
for (let i = fromIndex; i >= 0; i--) {
|
|
30
30
|
const key = keys[i];
|
|
31
|
-
const value =
|
|
32
|
-
if (doesMatch(value, key,
|
|
31
|
+
const value = collection[key];
|
|
32
|
+
if (doesMatch(value, key, collection)) return value;
|
|
33
33
|
}
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
return
|
|
36
|
+
return collection.slice(0, fromIndex + 1).findLast(doesMatch);
|
|
37
37
|
}
|
|
38
38
|
//#endregion
|
|
39
39
|
export { findLast };
|
|
@@ -20,6 +20,7 @@ const require_matchesProperty = require("../predicate/matchesProperty.js");
|
|
|
20
20
|
*/
|
|
21
21
|
function findLastIndex(arr, doesMatch = require_identity.identity, fromIndex = arr ? arr.length - 1 : 0) {
|
|
22
22
|
if (!arr) return -1;
|
|
23
|
+
if (Number.isNaN(fromIndex)) fromIndex = 0;
|
|
23
24
|
if (fromIndex < 0) fromIndex = Math.max(arr.length + fromIndex, 0);
|
|
24
25
|
else fromIndex = Math.min(fromIndex, arr.length - 1);
|
|
25
26
|
const subArray = require_toArray.toArray(arr).slice(0, fromIndex + 1);
|
|
@@ -20,6 +20,7 @@ import { matchesProperty } from "../predicate/matchesProperty.mjs";
|
|
|
20
20
|
*/
|
|
21
21
|
function findLastIndex(arr, doesMatch = identity, fromIndex = arr ? arr.length - 1 : 0) {
|
|
22
22
|
if (!arr) return -1;
|
|
23
|
+
if (Number.isNaN(fromIndex)) fromIndex = 0;
|
|
23
24
|
if (fromIndex < 0) fromIndex = Math.max(arr.length + fromIndex, 0);
|
|
24
25
|
else fromIndex = Math.min(fromIndex, arr.length - 1);
|
|
25
26
|
const subArray = toArray(arr).slice(0, fromIndex + 1);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_identity = require("../../function/identity.js");
|
|
1
2
|
const require_isNil = require("../../predicate/isNil.js");
|
|
2
3
|
const require_flattenDepth = require("./flattenDepth.js");
|
|
3
4
|
const require_map = require("./map.js");
|
|
@@ -7,14 +8,14 @@ const require_map = require("./map.js");
|
|
|
7
8
|
*
|
|
8
9
|
* @template R
|
|
9
10
|
* @param collection - The collection to iterate over.
|
|
10
|
-
* @param [iteratee] - The function invoked per iteration.
|
|
11
|
+
* @param [iteratee=identity] - The function invoked per iteration.
|
|
11
12
|
* @returns Returns the new flattened array.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* flatMap([1, 2], n => [n, n * 2]);
|
|
15
16
|
* // => [1, 2, 2, 4]
|
|
16
17
|
*/
|
|
17
|
-
function flatMap(collection, iteratee) {
|
|
18
|
+
function flatMap(collection, iteratee = require_identity.identity) {
|
|
18
19
|
if (require_isNil.isNil(collection)) return [];
|
|
19
20
|
const mapped = require_isNil.isNil(iteratee) ? require_map.map(collection) : require_map.map(collection, iteratee);
|
|
20
21
|
return require_flattenDepth.flattenDepth(mapped, 1);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { identity } from "../../function/identity.mjs";
|
|
1
2
|
import { isNil } from "../../predicate/isNil.mjs";
|
|
2
3
|
import { flattenDepth } from "./flattenDepth.mjs";
|
|
3
4
|
import { map } from "./map.mjs";
|
|
@@ -7,14 +8,14 @@ import { map } from "./map.mjs";
|
|
|
7
8
|
*
|
|
8
9
|
* @template R
|
|
9
10
|
* @param collection - The collection to iterate over.
|
|
10
|
-
* @param [iteratee] - The function invoked per iteration.
|
|
11
|
+
* @param [iteratee=identity] - The function invoked per iteration.
|
|
11
12
|
* @returns Returns the new flattened array.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* flatMap([1, 2], n => [n, n * 2]);
|
|
15
16
|
* // => [1, 2, 2, 4]
|
|
16
17
|
*/
|
|
17
|
-
function flatMap(collection, iteratee) {
|
|
18
|
+
function flatMap(collection, iteratee = identity) {
|
|
18
19
|
if (isNil(collection)) return [];
|
|
19
20
|
return flattenDepth(isNil(iteratee) ? map(collection) : map(collection, iteratee), 1);
|
|
20
21
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_identity = require("../../function/identity.js");
|
|
2
2
|
const require_iteratee = require("../util/iteratee.js");
|
|
3
|
-
const
|
|
3
|
+
const require_flattenDepth = require("./flattenDepth.js");
|
|
4
4
|
const require_map = require("./map.js");
|
|
5
5
|
//#region src/compat/array/flatMapDepth.ts
|
|
6
6
|
/**
|
|
@@ -20,7 +20,7 @@ function flatMapDepth(collection, iteratee$1 = require_identity.identity, depth
|
|
|
20
20
|
if (collection == null) return [];
|
|
21
21
|
const iterateeFn = require_iteratee.iteratee(iteratee$1);
|
|
22
22
|
const mapped = require_map.map(collection, iterateeFn);
|
|
23
|
-
return
|
|
23
|
+
return require_flattenDepth.flattenDepth(mapped, depth);
|
|
24
24
|
}
|
|
25
25
|
//#endregion
|
|
26
26
|
exports.flatMapDepth = flatMapDepth;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { identity } from "../../function/identity.mjs";
|
|
2
2
|
import { iteratee } from "../util/iteratee.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { flattenDepth } from "./flattenDepth.mjs";
|
|
4
4
|
import { map } from "./map.mjs";
|
|
5
5
|
//#region src/compat/array/flatMapDepth.ts
|
|
6
6
|
/**
|
|
@@ -18,7 +18,7 @@ import { map } from "./map.mjs";
|
|
|
18
18
|
*/
|
|
19
19
|
function flatMapDepth(collection, iteratee$1 = identity, depth = 1) {
|
|
20
20
|
if (collection == null) return [];
|
|
21
|
-
return
|
|
21
|
+
return flattenDepth(map(collection, iteratee(iteratee$1)), depth);
|
|
22
22
|
}
|
|
23
23
|
//#endregion
|
|
24
24
|
export { flatMapDepth };
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
* Flattens array up to depth times.
|
|
4
4
|
*
|
|
5
5
|
* @template T
|
|
6
|
-
* @param
|
|
7
|
-
* @param depth - The maximum recursion depth.
|
|
6
|
+
* @param array - The array to flatten.
|
|
8
7
|
* @returns Returns the new flattened array.
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
|
-
* flatten([1, [2, [3, [4]], 5]]
|
|
12
|
-
* // => [1, 2, 3, [4], 5]
|
|
10
|
+
* flatten([1, [2, [3, [4]], 5]]);
|
|
11
|
+
* // => [1, 2, [3, [4]], 5]
|
|
13
12
|
*/
|
|
14
|
-
declare function flatten<T>(
|
|
13
|
+
declare function flatten<T>(array: ArrayLike<T | readonly T[]> | null | undefined): T[];
|
|
15
14
|
//#endregion
|
|
16
15
|
export { flatten };
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
* Flattens array up to depth times.
|
|
4
4
|
*
|
|
5
5
|
* @template T
|
|
6
|
-
* @param
|
|
7
|
-
* @param depth - The maximum recursion depth.
|
|
6
|
+
* @param array - The array to flatten.
|
|
8
7
|
* @returns Returns the new flattened array.
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
|
-
* flatten([1, [2, [3, [4]], 5]]
|
|
12
|
-
* // => [1, 2, 3, [4], 5]
|
|
10
|
+
* flatten([1, [2, [3, [4]], 5]]);
|
|
11
|
+
* // => [1, 2, [3, [4]], 5]
|
|
13
12
|
*/
|
|
14
|
-
declare function flatten<T>(
|
|
13
|
+
declare function flatten<T>(array: ArrayLike<T | readonly T[]> | null | undefined): T[];
|
|
15
14
|
//#endregion
|
|
16
15
|
export { flatten };
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_flattenDepth = require("./flattenDepth.js");
|
|
2
2
|
//#region src/compat/array/flatten.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return result;
|
|
3
|
+
/**
|
|
4
|
+
* Flattens array up to depth times.
|
|
5
|
+
*
|
|
6
|
+
* @template T
|
|
7
|
+
* @param array - The array to flatten.
|
|
8
|
+
* @returns Returns the new flattened array.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* flatten([1, [2, [3, [4]], 5]]);
|
|
12
|
+
* // => [1, 2, [3, [4]], 5]
|
|
13
|
+
*/
|
|
14
|
+
function flatten(array) {
|
|
15
|
+
return require_flattenDepth.flattenDepth(array, 1);
|
|
17
16
|
}
|
|
18
17
|
//#endregion
|
|
19
18
|
exports.flatten = flatten;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { flattenDepth } from "./flattenDepth.mjs";
|
|
2
2
|
//#region src/compat/array/flatten.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return result;
|
|
3
|
+
/**
|
|
4
|
+
* Flattens array up to depth times.
|
|
5
|
+
*
|
|
6
|
+
* @template T
|
|
7
|
+
* @param array - The array to flatten.
|
|
8
|
+
* @returns Returns the new flattened array.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* flatten([1, [2, [3, [4]], 5]]);
|
|
12
|
+
* // => [1, 2, [3, [4]], 5]
|
|
13
|
+
*/
|
|
14
|
+
function flatten(array) {
|
|
15
|
+
return flattenDepth(array, 1);
|
|
17
16
|
}
|
|
18
17
|
//#endregion
|
|
19
18
|
export { flatten };
|
|
@@ -12,6 +12,6 @@ import { ListOfRecursiveArraysOrValues } from "../_internal/ListOfRecursiveArray
|
|
|
12
12
|
* flattenDeep([1, [2, [3, [4]], 5]]);
|
|
13
13
|
* // => [1, 2, 3, 4, 5]
|
|
14
14
|
*/
|
|
15
|
-
declare function flattenDeep<T>(
|
|
15
|
+
declare function flattenDeep<T>(array: ListOfRecursiveArraysOrValues<T> | null | undefined): Array<T extends string ? T : T extends ArrayLike<any> ? never : T>;
|
|
16
16
|
//#endregion
|
|
17
17
|
export { flattenDeep };
|
|
@@ -12,6 +12,6 @@ import { ListOfRecursiveArraysOrValues } from "../_internal/ListOfRecursiveArray
|
|
|
12
12
|
* flattenDeep([1, [2, [3, [4]], 5]]);
|
|
13
13
|
* // => [1, 2, 3, 4, 5]
|
|
14
14
|
*/
|
|
15
|
-
declare function flattenDeep<T>(
|
|
15
|
+
declare function flattenDeep<T>(array: ListOfRecursiveArraysOrValues<T> | null | undefined): Array<T extends string ? T : T extends ArrayLike<any> ? never : T>;
|
|
16
16
|
//#endregion
|
|
17
17
|
export { flattenDeep };
|
|
@@ -11,8 +11,8 @@ const require_flattenDepth = require("./flattenDepth.js");
|
|
|
11
11
|
* flattenDeep([1, [2, [3, [4]], 5]]);
|
|
12
12
|
* // => [1, 2, 3, 4, 5]
|
|
13
13
|
*/
|
|
14
|
-
function flattenDeep(
|
|
15
|
-
return require_flattenDepth.flattenDepth(
|
|
14
|
+
function flattenDeep(array) {
|
|
15
|
+
return require_flattenDepth.flattenDepth(array, Infinity);
|
|
16
16
|
}
|
|
17
17
|
//#endregion
|
|
18
18
|
exports.flattenDeep = flattenDeep;
|
|
@@ -11,8 +11,8 @@ import { flattenDepth } from "./flattenDepth.mjs";
|
|
|
11
11
|
* flattenDeep([1, [2, [3, [4]], 5]]);
|
|
12
12
|
* // => [1, 2, 3, 4, 5]
|
|
13
13
|
*/
|
|
14
|
-
function flattenDeep(
|
|
15
|
-
return flattenDepth(
|
|
14
|
+
function flattenDeep(array) {
|
|
15
|
+
return flattenDepth(array, Infinity);
|
|
16
16
|
}
|
|
17
17
|
//#endregion
|
|
18
18
|
export { flattenDeep };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_isArray = require("../predicate/isArray.js");
|
|
2
|
+
const require_isArrayLike = require("../predicate/isArrayLike.js");
|
|
3
|
+
const require_isArguments = require("../predicate/isArguments.js");
|
|
2
4
|
//#region src/compat/array/flattenDepth.ts
|
|
3
5
|
/**
|
|
4
6
|
* Recursively flattens array up to depth times.
|
|
@@ -18,7 +20,21 @@ const require_flatten = require("./flatten.js");
|
|
|
18
20
|
* // => [1, 2, 3, [4], 5]
|
|
19
21
|
*/
|
|
20
22
|
function flattenDepth(array, depth = 1) {
|
|
21
|
-
|
|
23
|
+
if (!require_isArrayLike.isArrayLike(array)) return [];
|
|
24
|
+
const result = [];
|
|
25
|
+
const flooredDepth = Math.floor(depth);
|
|
26
|
+
const recursive = (arr, currentDepth) => {
|
|
27
|
+
for (let i = 0; i < arr.length; i++) {
|
|
28
|
+
const item = arr[i];
|
|
29
|
+
if (isFlattenable(item) && currentDepth < flooredDepth) recursive(item, currentDepth + 1);
|
|
30
|
+
else result.push(item);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
recursive(Array.from(array), 0);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
function isFlattenable(value) {
|
|
37
|
+
return require_isArray.isArray(value) || require_isArguments.isArguments(value) || Boolean(value && value[Symbol.isConcatSpreadable]);
|
|
22
38
|
}
|
|
23
39
|
//#endregion
|
|
24
40
|
exports.flattenDepth = flattenDepth;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isArray } from "../predicate/isArray.mjs";
|
|
2
|
+
import { isArrayLike } from "../predicate/isArrayLike.mjs";
|
|
3
|
+
import { isArguments } from "../predicate/isArguments.mjs";
|
|
2
4
|
//#region src/compat/array/flattenDepth.ts
|
|
3
5
|
/**
|
|
4
6
|
* Recursively flattens array up to depth times.
|
|
@@ -18,7 +20,21 @@ import { flatten } from "./flatten.mjs";
|
|
|
18
20
|
* // => [1, 2, 3, [4], 5]
|
|
19
21
|
*/
|
|
20
22
|
function flattenDepth(array, depth = 1) {
|
|
21
|
-
|
|
23
|
+
if (!isArrayLike(array)) return [];
|
|
24
|
+
const result = [];
|
|
25
|
+
const flooredDepth = Math.floor(depth);
|
|
26
|
+
const recursive = (arr, currentDepth) => {
|
|
27
|
+
for (let i = 0; i < arr.length; i++) {
|
|
28
|
+
const item = arr[i];
|
|
29
|
+
if (isFlattenable(item) && currentDepth < flooredDepth) recursive(item, currentDepth + 1);
|
|
30
|
+
else result.push(item);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
recursive(Array.from(array), 0);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
function isFlattenable(value) {
|
|
37
|
+
return isArray(value) || isArguments(value) || Boolean(value && value[Symbol.isConcatSpreadable]);
|
|
22
38
|
}
|
|
23
39
|
//#endregion
|
|
24
40
|
export { flattenDepth };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_groupBy = require("../../array/groupBy.js");
|
|
2
2
|
const require_identity = require("../../function/identity.js");
|
|
3
|
+
const require_toArray = require("../_internal/toArray.js");
|
|
3
4
|
const require_isArrayLike = require("../predicate/isArrayLike.js");
|
|
4
5
|
const require_iteratee = require("../util/iteratee.js");
|
|
5
6
|
//#region src/compat/array/groupBy.ts
|
|
@@ -13,7 +14,7 @@ const require_iteratee = require("../util/iteratee.js");
|
|
|
13
14
|
* @template T - The type of elements in the array or values in the object.
|
|
14
15
|
* @template K - The type of keys.
|
|
15
16
|
* @param source - The collection to group.
|
|
16
|
-
* @param [_getKeyFromItem] - The iteratee to transform keys.
|
|
17
|
+
* @param [_getKeyFromItem=identity] - The iteratee to transform keys.
|
|
17
18
|
* - If a function is provided, it's invoked for each element in the collection.
|
|
18
19
|
* - If a property name (string) is provided, that property of each element is used as the key.
|
|
19
20
|
* - If a property-value pair (array) is provided, elements with matching property values are used.
|
|
@@ -33,10 +34,10 @@ const require_iteratee = require("../util/iteratee.js");
|
|
|
33
34
|
* const result = groupBy(array, 'length');
|
|
34
35
|
* // => { 3: ['one', 'two'], 5: ['three'] }
|
|
35
36
|
*/
|
|
36
|
-
function groupBy(source, _getKeyFromItem) {
|
|
37
|
+
function groupBy(source, _getKeyFromItem = require_identity.identity) {
|
|
37
38
|
if (source == null) return {};
|
|
38
|
-
const items = require_isArrayLike.isArrayLike(source) ?
|
|
39
|
-
const getKeyFromItem = require_iteratee.iteratee(_getKeyFromItem
|
|
39
|
+
const items = require_isArrayLike.isArrayLike(source) ? require_toArray.toArray(source) : Object.values(source);
|
|
40
|
+
const getKeyFromItem = require_iteratee.iteratee(_getKeyFromItem);
|
|
40
41
|
return require_groupBy.groupBy(items, getKeyFromItem);
|
|
41
42
|
}
|
|
42
43
|
//#endregion
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { groupBy as groupBy$1 } from "../../array/groupBy.mjs";
|
|
2
2
|
import { identity } from "../../function/identity.mjs";
|
|
3
|
+
import { toArray } from "../_internal/toArray.mjs";
|
|
3
4
|
import { isArrayLike } from "../predicate/isArrayLike.mjs";
|
|
4
5
|
import { iteratee } from "../util/iteratee.mjs";
|
|
5
6
|
//#region src/compat/array/groupBy.ts
|
|
@@ -13,7 +14,7 @@ import { iteratee } from "../util/iteratee.mjs";
|
|
|
13
14
|
* @template T - The type of elements in the array or values in the object.
|
|
14
15
|
* @template K - The type of keys.
|
|
15
16
|
* @param source - The collection to group.
|
|
16
|
-
* @param [_getKeyFromItem] - The iteratee to transform keys.
|
|
17
|
+
* @param [_getKeyFromItem=identity] - The iteratee to transform keys.
|
|
17
18
|
* - If a function is provided, it's invoked for each element in the collection.
|
|
18
19
|
* - If a property name (string) is provided, that property of each element is used as the key.
|
|
19
20
|
* - If a property-value pair (array) is provided, elements with matching property values are used.
|
|
@@ -33,9 +34,9 @@ import { iteratee } from "../util/iteratee.mjs";
|
|
|
33
34
|
* const result = groupBy(array, 'length');
|
|
34
35
|
* // => { 3: ['one', 'two'], 5: ['three'] }
|
|
35
36
|
*/
|
|
36
|
-
function groupBy(source, _getKeyFromItem) {
|
|
37
|
+
function groupBy(source, _getKeyFromItem = identity) {
|
|
37
38
|
if (source == null) return {};
|
|
38
|
-
return groupBy$1(isArrayLike(source) ?
|
|
39
|
+
return groupBy$1(isArrayLike(source) ? toArray(source) : Object.values(source), iteratee(_getKeyFromItem));
|
|
39
40
|
}
|
|
40
41
|
//#endregion
|
|
41
42
|
export { groupBy };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
require("../
|
|
1
|
+
const require_eq = require("../util/eq.js");
|
|
2
|
+
const require_isArrayLike = require("../predicate/isArrayLike.js");
|
|
3
3
|
const require_toInteger = require("../util/toInteger.js");
|
|
4
4
|
const require_isString = require("../predicate/isString.js");
|
|
5
5
|
//#region src/compat/array/includes.ts
|
|
@@ -29,11 +29,16 @@ function includes(source, target, fromIndex, guard) {
|
|
|
29
29
|
return source.includes(target, fromIndex);
|
|
30
30
|
}
|
|
31
31
|
if (Array.isArray(source)) return source.includes(target, fromIndex);
|
|
32
|
+
if (require_isArrayLike.isArrayLike(source)) {
|
|
33
|
+
if (fromIndex < 0) fromIndex = Math.max(0, source.length + fromIndex);
|
|
34
|
+
for (let i = fromIndex; i < source.length; i++) if (require_eq.eq(source[i], target)) return true;
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
32
37
|
const keys = Object.keys(source);
|
|
33
38
|
if (fromIndex < 0) fromIndex = Math.max(0, keys.length + fromIndex);
|
|
34
39
|
for (let i = fromIndex; i < keys.length; i++) {
|
|
35
40
|
const value = Reflect.get(source, keys[i]);
|
|
36
|
-
if (
|
|
41
|
+
if (require_eq.eq(value, target)) return true;
|
|
37
42
|
}
|
|
38
43
|
return false;
|
|
39
44
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../
|
|
1
|
+
import { eq } from "../util/eq.mjs";
|
|
2
|
+
import { isArrayLike } from "../predicate/isArrayLike.mjs";
|
|
3
3
|
import { toInteger } from "../util/toInteger.mjs";
|
|
4
4
|
import { isString } from "../predicate/isString.mjs";
|
|
5
5
|
//#region src/compat/array/includes.ts
|
|
@@ -29,9 +29,14 @@ function includes(source, target, fromIndex, guard) {
|
|
|
29
29
|
return source.includes(target, fromIndex);
|
|
30
30
|
}
|
|
31
31
|
if (Array.isArray(source)) return source.includes(target, fromIndex);
|
|
32
|
+
if (isArrayLike(source)) {
|
|
33
|
+
if (fromIndex < 0) fromIndex = Math.max(0, source.length + fromIndex);
|
|
34
|
+
for (let i = fromIndex; i < source.length; i++) if (eq(source[i], target)) return true;
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
32
37
|
const keys = Object.keys(source);
|
|
33
38
|
if (fromIndex < 0) fromIndex = Math.max(0, keys.length + fromIndex);
|
|
34
|
-
for (let i = fromIndex; i < keys.length; i++) if (
|
|
39
|
+
for (let i = fromIndex; i < keys.length; i++) if (eq(Reflect.get(source, keys[i]), target)) return true;
|
|
35
40
|
return false;
|
|
36
41
|
}
|
|
37
42
|
//#endregion
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const require_intersectionBy = require("../../array/intersectionBy.js");
|
|
2
2
|
const require_last = require("../../array/last.js");
|
|
3
3
|
const require_uniq = require("../../array/uniq.js");
|
|
4
|
+
const require_uniqBy = require("../../array/uniqBy.js");
|
|
4
5
|
const require_identity = require("../../function/identity.js");
|
|
6
|
+
const require_toArray = require("../_internal/toArray.js");
|
|
5
7
|
const require_property = require("../object/property.js");
|
|
6
8
|
const require_isArrayLikeObject = require("../predicate/isArrayLikeObject.js");
|
|
7
9
|
//#region src/compat/array/intersectionBy.ts
|
|
@@ -36,17 +38,22 @@ const require_isArrayLikeObject = require("../predicate/isArrayLikeObject.js");
|
|
|
36
38
|
function intersectionBy(array, ...values) {
|
|
37
39
|
if (!require_isArrayLikeObject.isArrayLikeObject(array)) return [];
|
|
38
40
|
const lastValue = require_last.last(values);
|
|
39
|
-
if (lastValue === void 0) return Array.from(array);
|
|
40
|
-
let result = require_uniq.uniq(Array.from(array));
|
|
41
41
|
const count = require_isArrayLikeObject.isArrayLikeObject(lastValue) ? values.length : values.length - 1;
|
|
42
|
+
const iteratee = getIteratee(lastValue);
|
|
43
|
+
if (count <= 0) return require_uniqBy.uniqBy(require_toArray.toArray(array), iteratee ?? require_identity.identity);
|
|
44
|
+
let result = require_uniq.uniq(require_toArray.toArray(array));
|
|
42
45
|
for (let i = 0; i < count; ++i) {
|
|
43
46
|
const value = values[i];
|
|
44
47
|
if (!require_isArrayLikeObject.isArrayLikeObject(value)) return [];
|
|
45
|
-
if (
|
|
46
|
-
else if (typeof lastValue === "function") result = require_intersectionBy.intersectionBy(result, Array.from(value), (value) => lastValue(value));
|
|
47
|
-
else if (typeof lastValue === "string") result = require_intersectionBy.intersectionBy(result, Array.from(value), require_property.property(lastValue));
|
|
48
|
+
if (iteratee) result = require_intersectionBy.intersectionBy(result, require_toArray.toArray(value), iteratee);
|
|
48
49
|
}
|
|
49
50
|
return result;
|
|
50
51
|
}
|
|
52
|
+
function getIteratee(value) {
|
|
53
|
+
if (require_isArrayLikeObject.isArrayLikeObject(value)) return require_identity.identity;
|
|
54
|
+
if (typeof value === "function") return (item) => value(item);
|
|
55
|
+
if (typeof value === "string") return require_property.property(value);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
51
58
|
//#endregion
|
|
52
59
|
exports.intersectionBy = intersectionBy;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { intersectionBy as intersectionBy$1 } from "../../array/intersectionBy.mjs";
|
|
2
2
|
import { last } from "../../array/last.mjs";
|
|
3
3
|
import { uniq } from "../../array/uniq.mjs";
|
|
4
|
+
import { uniqBy } from "../../array/uniqBy.mjs";
|
|
4
5
|
import { identity } from "../../function/identity.mjs";
|
|
6
|
+
import { toArray } from "../_internal/toArray.mjs";
|
|
5
7
|
import { property } from "../object/property.mjs";
|
|
6
8
|
import { isArrayLikeObject } from "../predicate/isArrayLikeObject.mjs";
|
|
7
9
|
//#region src/compat/array/intersectionBy.ts
|
|
@@ -36,17 +38,22 @@ import { isArrayLikeObject } from "../predicate/isArrayLikeObject.mjs";
|
|
|
36
38
|
function intersectionBy(array, ...values) {
|
|
37
39
|
if (!isArrayLikeObject(array)) return [];
|
|
38
40
|
const lastValue = last(values);
|
|
39
|
-
if (lastValue === void 0) return Array.from(array);
|
|
40
|
-
let result = uniq(Array.from(array));
|
|
41
41
|
const count = isArrayLikeObject(lastValue) ? values.length : values.length - 1;
|
|
42
|
+
const iteratee = getIteratee(lastValue);
|
|
43
|
+
if (count <= 0) return uniqBy(toArray(array), iteratee ?? identity);
|
|
44
|
+
let result = uniq(toArray(array));
|
|
42
45
|
for (let i = 0; i < count; ++i) {
|
|
43
46
|
const value = values[i];
|
|
44
47
|
if (!isArrayLikeObject(value)) return [];
|
|
45
|
-
if (
|
|
46
|
-
else if (typeof lastValue === "function") result = intersectionBy$1(result, Array.from(value), (value) => lastValue(value));
|
|
47
|
-
else if (typeof lastValue === "string") result = intersectionBy$1(result, Array.from(value), property(lastValue));
|
|
48
|
+
if (iteratee) result = intersectionBy$1(result, toArray(value), iteratee);
|
|
48
49
|
}
|
|
49
50
|
return result;
|
|
50
51
|
}
|
|
52
|
+
function getIteratee(value) {
|
|
53
|
+
if (isArrayLikeObject(value)) return identity;
|
|
54
|
+
if (typeof value === "function") return (item) => value(item);
|
|
55
|
+
if (typeof value === "string") return property(value);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
51
58
|
//#endregion
|
|
52
59
|
export { intersectionBy };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const require_intersectionWith = require("../../array/intersectionWith.js");
|
|
2
|
-
const
|
|
3
|
-
require("../util/eq.js");
|
|
2
|
+
const require_eq = require("../util/eq.js");
|
|
4
3
|
const require_last = require("./last.js");
|
|
5
4
|
const require_uniq = require("./uniq.js");
|
|
6
5
|
//#region src/compat/array/intersectionWith.ts
|
|
@@ -21,7 +20,7 @@ const require_uniq = require("./uniq.js");
|
|
|
21
20
|
function intersectionWith(firstArr, ...otherArrs) {
|
|
22
21
|
if (firstArr == null) return [];
|
|
23
22
|
const _comparator = require_last.last(otherArrs);
|
|
24
|
-
let comparator =
|
|
23
|
+
let comparator = require_eq.eq;
|
|
25
24
|
let uniq$1 = require_uniq.uniq;
|
|
26
25
|
if (typeof _comparator === "function") {
|
|
27
26
|
comparator = _comparator;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { intersectionWith as intersectionWith$1 } from "../../array/intersectionWith.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import "../util/eq.mjs";
|
|
2
|
+
import { eq } from "../util/eq.mjs";
|
|
4
3
|
import { last } from "./last.mjs";
|
|
5
4
|
import { uniq } from "./uniq.mjs";
|
|
6
5
|
//#region src/compat/array/intersectionWith.ts
|
|
@@ -21,7 +20,7 @@ import { uniq } from "./uniq.mjs";
|
|
|
21
20
|
function intersectionWith(firstArr, ...otherArrs) {
|
|
22
21
|
if (firstArr == null) return [];
|
|
23
22
|
const _comparator = last(otherArrs);
|
|
24
|
-
let comparator =
|
|
23
|
+
let comparator = eq;
|
|
25
24
|
let uniq$1 = uniq;
|
|
26
25
|
if (typeof _comparator === "function") {
|
|
27
26
|
comparator = _comparator;
|