es-toolkit 1.24.0 → 1.25.0-dev.786
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 +12 -0
- package/dist/_chunk/isPlainObject-octpoD.js +32 -0
- package/dist/_chunk/{isWeakSet-Bd6nry.js → isWeakSet-BuFfzX.js} +11 -8
- package/dist/_chunk/{toMerged-DDLv0D.js → toMerged-B5ZVux.js} +3 -6
- package/dist/_chunk/{unary-BZ5Ixo.js → unary-CMvKXy.js} +2 -2
- package/dist/_chunk/{zipWith-wpjySR.js → zipWith-Dkv3D1.js} +7 -1
- package/dist/array/at.mjs +1 -1
- package/dist/array/index.js +2 -7
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/MAX_SAFE_INTEGER.mjs +3 -0
- package/dist/compat/array/chunk.d.mts +2 -3
- package/dist/compat/array/chunk.d.ts +2 -3
- package/dist/compat/array/chunk.mjs +3 -2
- package/dist/compat/array/compact.d.mts +16 -0
- package/dist/compat/array/compact.d.ts +16 -0
- package/dist/compat/array/compact.mjs +11 -0
- package/dist/compat/array/drop.d.mts +2 -2
- package/dist/compat/array/drop.d.ts +2 -2
- package/dist/compat/array/drop.mjs +5 -3
- package/dist/compat/array/dropRight.d.mts +19 -0
- package/dist/compat/array/dropRight.d.ts +19 -0
- package/dist/compat/array/dropRight.mjs +11 -0
- package/dist/compat/array/dropRightWhile.d.mts +8 -8
- package/dist/compat/array/dropRightWhile.d.ts +8 -8
- package/dist/compat/array/dropRightWhile.mjs +7 -0
- package/dist/compat/array/dropWhile.d.mts +8 -8
- package/dist/compat/array/dropWhile.d.ts +8 -8
- package/dist/compat/array/dropWhile.mjs +7 -0
- package/dist/compat/array/head.d.mts +18 -0
- package/dist/compat/array/head.d.ts +18 -0
- package/dist/compat/array/head.mjs +11 -0
- package/dist/compat/array/intersection.d.mts +20 -0
- package/dist/compat/array/intersection.d.ts +20 -0
- package/dist/compat/array/intersection.mjs +23 -0
- package/dist/compat/array/last.d.mts +25 -0
- package/dist/compat/array/last.d.ts +25 -0
- package/dist/compat/array/last.mjs +11 -0
- package/dist/compat/array/sample.d.mts +80 -0
- package/dist/compat/array/sample.d.ts +80 -0
- package/dist/compat/array/sample.mjs +14 -0
- package/dist/compat/array/tail.d.mts +27 -0
- package/dist/compat/array/tail.d.ts +27 -0
- package/dist/compat/array/tail.mjs +11 -0
- package/dist/compat/array/take.d.mts +3 -3
- package/dist/compat/array/take.d.ts +3 -3
- package/dist/compat/array/take.mjs +4 -3
- package/dist/compat/array/takeRight.d.mts +24 -0
- package/dist/compat/array/takeRight.d.ts +24 -0
- package/dist/compat/array/takeRight.mjs +11 -0
- package/dist/compat/array/uniq.d.mts +18 -0
- package/dist/compat/array/uniq.d.ts +18 -0
- package/dist/compat/array/uniq.mjs +11 -0
- package/dist/compat/array/without.d.mts +23 -0
- package/dist/compat/array/without.d.ts +23 -0
- package/dist/compat/array/without.mjs +11 -0
- package/dist/compat/index.d.mts +13 -11
- package/dist/compat/index.d.ts +13 -11
- package/dist/compat/index.js +143 -30
- package/dist/compat/index.mjs +13 -11
- package/dist/compat/object/pick.mjs +4 -0
- package/dist/compat/string/escape.d.mts +16 -0
- package/dist/compat/string/escape.d.ts +16 -0
- package/dist/compat/string/escape.mjs +8 -0
- package/dist/compat/util/toSafeInteger.d.mts +20 -0
- package/dist/compat/util/toSafeInteger.d.ts +20 -0
- package/dist/compat/util/toSafeInteger.mjs +12 -0
- package/dist/function/after.d.mts +2 -2
- package/dist/function/after.d.ts +2 -2
- package/dist/function/after.mjs +2 -2
- package/dist/function/index.js +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -6
- package/dist/index.mjs +1 -0
- package/dist/object/cloneDeep.mjs +3 -5
- package/dist/object/index.js +1 -1
- package/dist/predicate/index.d.mts +1 -0
- package/dist/predicate/index.d.ts +1 -0
- package/dist/predicate/index.js +3 -2
- package/dist/predicate/index.mjs +1 -0
- package/dist/predicate/isFile.d.mts +21 -0
- package/dist/predicate/isFile.d.ts +21 -0
- package/dist/predicate/isFile.mjs +10 -0
- package/dist/predicate/isPlainObject.d.mts +34 -5
- package/dist/predicate/isPlainObject.d.ts +34 -5
- package/dist/predicate/isPlainObject.mjs +7 -13
- package/package.json +1 -1
- package/dist/_chunk/isPlainObject-DgrsU7.js +0 -33
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
* the final sub-array will contain the remaining elements.
|
|
7
7
|
*
|
|
8
8
|
* @template T The type of elements in the array.
|
|
9
|
-
* @param {T
|
|
9
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array to be chunked into smaller arrays.
|
|
10
10
|
* @param {number} size - The size of each smaller array. Must be a positive integer.
|
|
11
11
|
* @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.
|
|
12
|
-
* @throws {Error} Throws an error if `size` is not a positive integer.
|
|
13
12
|
*
|
|
14
13
|
* @example
|
|
15
14
|
* // Splits an array of numbers into sub-arrays of length 2
|
|
@@ -21,6 +20,6 @@
|
|
|
21
20
|
* chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
|
|
22
21
|
* // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
|
|
23
22
|
*/
|
|
24
|
-
declare function chunk<T>(arr:
|
|
23
|
+
declare function chunk<T>(arr: ArrayLike<T> | null | undefined, size?: number): T[][];
|
|
25
24
|
|
|
26
25
|
export { chunk };
|
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
* the final sub-array will contain the remaining elements.
|
|
7
7
|
*
|
|
8
8
|
* @template T The type of elements in the array.
|
|
9
|
-
* @param {T
|
|
9
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array to be chunked into smaller arrays.
|
|
10
10
|
* @param {number} size - The size of each smaller array. Must be a positive integer.
|
|
11
11
|
* @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.
|
|
12
|
-
* @throws {Error} Throws an error if `size` is not a positive integer.
|
|
13
12
|
*
|
|
14
13
|
* @example
|
|
15
14
|
* // Splits an array of numbers into sub-arrays of length 2
|
|
@@ -21,6 +20,6 @@
|
|
|
21
20
|
* chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
|
|
22
21
|
* // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
|
|
23
22
|
*/
|
|
24
|
-
declare function chunk<T>(arr:
|
|
23
|
+
declare function chunk<T>(arr: ArrayLike<T> | null | undefined, size?: number): T[][];
|
|
25
24
|
|
|
26
25
|
export { chunk };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { chunk as chunk$1 } from '../../array/chunk.mjs';
|
|
2
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
2
3
|
|
|
3
4
|
function chunk(arr, size = 1) {
|
|
4
5
|
size = Math.max(Math.floor(size), 0);
|
|
5
|
-
if (size === 0) {
|
|
6
|
+
if (size === 0 || !isArrayLike(arr)) {
|
|
6
7
|
return [];
|
|
7
8
|
}
|
|
8
|
-
return chunk$1(arr, size);
|
|
9
|
+
return chunk$1(Array.from(arr), size);
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export { chunk };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type Falsey = false | null | 0 | 0n | '' | undefined;
|
|
2
|
+
type NotFalsey<T> = Exclude<T, Falsey>;
|
|
3
|
+
/**
|
|
4
|
+
* Removes falsey values (false, null, 0, 0n, '', undefined, NaN) from an array.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of elements in the array.
|
|
7
|
+
* @param {ArrayLike<T | Falsey> | null | undefined} arr - The input array to remove falsey values.
|
|
8
|
+
* @returns {Array<Exclude<T, false | null | 0 | 0n | '' | undefined>>} - A new array with all falsey values removed.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* compact([0, 0n, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
|
|
12
|
+
* Returns: [1, 2, 3, 4, 5]
|
|
13
|
+
*/
|
|
14
|
+
declare function compact<T>(arr: ArrayLike<T | Falsey> | null | undefined): Array<NotFalsey<T>>;
|
|
15
|
+
|
|
16
|
+
export { compact };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type Falsey = false | null | 0 | 0n | '' | undefined;
|
|
2
|
+
type NotFalsey<T> = Exclude<T, Falsey>;
|
|
3
|
+
/**
|
|
4
|
+
* Removes falsey values (false, null, 0, 0n, '', undefined, NaN) from an array.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of elements in the array.
|
|
7
|
+
* @param {ArrayLike<T | Falsey> | null | undefined} arr - The input array to remove falsey values.
|
|
8
|
+
* @returns {Array<Exclude<T, false | null | 0 | 0n | '' | undefined>>} - A new array with all falsey values removed.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* compact([0, 0n, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]);
|
|
12
|
+
* Returns: [1, 2, 3, 4, 5]
|
|
13
|
+
*/
|
|
14
|
+
declare function compact<T>(arr: ArrayLike<T | Falsey> | null | undefined): Array<NotFalsey<T>>;
|
|
15
|
+
|
|
16
|
+
export { compact };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { compact as compact$1 } from '../../array/compact.mjs';
|
|
2
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
|
+
|
|
4
|
+
function compact(arr) {
|
|
5
|
+
if (!isArrayLike(arr)) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
return compact$1(Array.from(arr));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { compact };
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* of elements removed from the start.
|
|
6
6
|
*
|
|
7
7
|
* @template T - The type of elements in the array.
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {ArrayLike<T> | null | undefined} collection - The array from which to drop elements.
|
|
9
9
|
* @param {number} itemsCount - The number of elements to drop from the beginning of the array.
|
|
10
10
|
* @returns {T[]} A new array with the specified number of elements removed from the start.
|
|
11
11
|
*
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
* const result = drop(array, 2);
|
|
15
15
|
* result will be [3, 4, 5] since the first two elements are dropped.
|
|
16
16
|
*/
|
|
17
|
-
declare function drop<T>(collection:
|
|
17
|
+
declare function drop<T>(collection: ArrayLike<T> | null | undefined, itemsCount: number): T[];
|
|
18
18
|
|
|
19
19
|
export { drop };
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* of elements removed from the start.
|
|
6
6
|
*
|
|
7
7
|
* @template T - The type of elements in the array.
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {ArrayLike<T> | null | undefined} collection - The array from which to drop elements.
|
|
9
9
|
* @param {number} itemsCount - The number of elements to drop from the beginning of the array.
|
|
10
10
|
* @returns {T[]} A new array with the specified number of elements removed from the start.
|
|
11
11
|
*
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
* const result = drop(array, 2);
|
|
15
15
|
* result will be [3, 4, 5] since the first two elements are dropped.
|
|
16
16
|
*/
|
|
17
|
-
declare function drop<T>(collection:
|
|
17
|
+
declare function drop<T>(collection: ArrayLike<T> | null | undefined, itemsCount: number): T[];
|
|
18
18
|
|
|
19
19
|
export { drop };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { drop as drop$1 } from '../../array/drop.mjs';
|
|
2
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
|
+
|
|
1
4
|
function drop(collection, itemsCount) {
|
|
2
|
-
if (collection
|
|
5
|
+
if (!isArrayLike(collection)) {
|
|
3
6
|
return [];
|
|
4
7
|
}
|
|
5
|
-
|
|
6
|
-
return collection.slice(itemsCount);
|
|
8
|
+
return drop$1(Array.from(collection), itemsCount);
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export { drop };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes a specified number of elements from the end of an array and returns the rest.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and a number, and returns a new array with the specified number
|
|
5
|
+
* of elements removed from the end.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements in the array.
|
|
8
|
+
* @param {ArrayLike<T> | null | undefined} collection - The array from which to drop elements.
|
|
9
|
+
* @param {number} itemsCount - The number of elements to drop from the end of the array.
|
|
10
|
+
* @returns {T[]} A new array with the specified number of elements removed from the end.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const array = [1, 2, 3, 4, 5];
|
|
14
|
+
* const result = dropRight(array, 2);
|
|
15
|
+
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
16
|
+
*/
|
|
17
|
+
declare function dropRight<T>(collection: ArrayLike<T> | null | undefined, itemsCount: number): T[];
|
|
18
|
+
|
|
19
|
+
export { dropRight };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes a specified number of elements from the end of an array and returns the rest.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and a number, and returns a new array with the specified number
|
|
5
|
+
* of elements removed from the end.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements in the array.
|
|
8
|
+
* @param {ArrayLike<T> | null | undefined} collection - The array from which to drop elements.
|
|
9
|
+
* @param {number} itemsCount - The number of elements to drop from the end of the array.
|
|
10
|
+
* @returns {T[]} A new array with the specified number of elements removed from the end.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const array = [1, 2, 3, 4, 5];
|
|
14
|
+
* const result = dropRight(array, 2);
|
|
15
|
+
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
16
|
+
*/
|
|
17
|
+
declare function dropRight<T>(collection: ArrayLike<T> | null | undefined, itemsCount: number): T[];
|
|
18
|
+
|
|
19
|
+
export { dropRight };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { dropRight as dropRight$1 } from '../../array/dropRight.mjs';
|
|
2
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
|
+
|
|
4
|
+
function dropRight(collection, itemsCount) {
|
|
5
|
+
if (!isArrayLike(collection)) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
return dropRight$1(Array.from(collection), itemsCount);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { dropRight };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Drops elements from the end of an array while the predicate function returns truthy.
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of elements in the array.
|
|
5
|
-
* @param {T
|
|
5
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
6
6
|
* @param {(item: T, index: number, arr: T[]) => unknown} canContinueDropping - A predicate function that determines
|
|
7
7
|
* whether to continue dropping elements. The function is called with each element, index, and array, and dropping
|
|
8
8
|
* continues as long as it returns true.
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
* const result = dropRightWhile(array, x => x < 3);
|
|
14
14
|
* result will be [5, 4, 3] since elements less than 3 are dropped.
|
|
15
15
|
*/
|
|
16
|
-
declare function dropRightWhile<T>(arr:
|
|
16
|
+
declare function dropRightWhile<T>(arr: ArrayLike<T> | null | undefined, canContinueDropping: (item: T, index: number, arr: readonly T[]) => unknown): T[];
|
|
17
17
|
/**
|
|
18
18
|
* Drops elements from the end of an array while the specified object properties match.
|
|
19
19
|
*
|
|
20
20
|
* @template T - The type of elements in the array.
|
|
21
|
-
* @param {T
|
|
21
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
22
22
|
* @param {Partial<T>} objectToDrop - An object specifying the properties to match for dropping elements.
|
|
23
23
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
24
24
|
*
|
|
@@ -27,12 +27,12 @@ declare function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item
|
|
|
27
27
|
* const result = dropRightWhile(array, { a: 3 });
|
|
28
28
|
* result will be [{ a: 1 }, { a: 2 }] since the last object matches the properties of the provided object.
|
|
29
29
|
*/
|
|
30
|
-
declare function dropRightWhile<T>(arr:
|
|
30
|
+
declare function dropRightWhile<T>(arr: ArrayLike<T> | null | undefined, objectToDrop: Partial<T>): T[];
|
|
31
31
|
/**
|
|
32
32
|
* Drops elements from the end of an array while the specified property matches a given value.
|
|
33
33
|
*
|
|
34
34
|
* @template T - The type of elements in the array.
|
|
35
|
-
* @param {T
|
|
35
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
36
36
|
* @param {[keyof T, unknown]} propertyToDrop - A tuple containing the property key and the value to match for dropping elements.
|
|
37
37
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
38
38
|
*
|
|
@@ -41,12 +41,12 @@ declare function dropRightWhile<T>(arr: readonly T[], objectToDrop: Partial<T>):
|
|
|
41
41
|
* const result = dropRightWhile(array, ['id', 3]);
|
|
42
42
|
* result will be [{ id: 1 }, { id: 2 }] since the last object has the id property matching the value 3.
|
|
43
43
|
*/
|
|
44
|
-
declare function dropRightWhile<T>(arr:
|
|
44
|
+
declare function dropRightWhile<T>(arr: ArrayLike<T> | null | undefined, propertyToDrop: [keyof T, unknown]): T[];
|
|
45
45
|
/**
|
|
46
46
|
* Drops elements from the end of an array while the specified property name matches.
|
|
47
47
|
*
|
|
48
48
|
* @template T - The type of elements in the array.
|
|
49
|
-
* @param {T
|
|
49
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
50
50
|
* @param {string} propertyToDrop - The name of the property to match for dropping elements.
|
|
51
51
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
52
52
|
*
|
|
@@ -55,6 +55,6 @@ declare function dropRightWhile<T>(arr: readonly T[], propertyToDrop: [keyof T,
|
|
|
55
55
|
* const result = dropRightWhile(array, 'isActive');
|
|
56
56
|
* result will be [{ isActive: false }] since it drops elements until it finds one with a falsy isActive property.
|
|
57
57
|
*/
|
|
58
|
-
declare function dropRightWhile<T>(arr:
|
|
58
|
+
declare function dropRightWhile<T>(arr: ArrayLike<T> | null | undefined, propertyToDrop: string): T[];
|
|
59
59
|
|
|
60
60
|
export { dropRightWhile };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Drops elements from the end of an array while the predicate function returns truthy.
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of elements in the array.
|
|
5
|
-
* @param {T
|
|
5
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
6
6
|
* @param {(item: T, index: number, arr: T[]) => unknown} canContinueDropping - A predicate function that determines
|
|
7
7
|
* whether to continue dropping elements. The function is called with each element, index, and array, and dropping
|
|
8
8
|
* continues as long as it returns true.
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
* const result = dropRightWhile(array, x => x < 3);
|
|
14
14
|
* result will be [5, 4, 3] since elements less than 3 are dropped.
|
|
15
15
|
*/
|
|
16
|
-
declare function dropRightWhile<T>(arr:
|
|
16
|
+
declare function dropRightWhile<T>(arr: ArrayLike<T> | null | undefined, canContinueDropping: (item: T, index: number, arr: readonly T[]) => unknown): T[];
|
|
17
17
|
/**
|
|
18
18
|
* Drops elements from the end of an array while the specified object properties match.
|
|
19
19
|
*
|
|
20
20
|
* @template T - The type of elements in the array.
|
|
21
|
-
* @param {T
|
|
21
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
22
22
|
* @param {Partial<T>} objectToDrop - An object specifying the properties to match for dropping elements.
|
|
23
23
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
24
24
|
*
|
|
@@ -27,12 +27,12 @@ declare function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item
|
|
|
27
27
|
* const result = dropRightWhile(array, { a: 3 });
|
|
28
28
|
* result will be [{ a: 1 }, { a: 2 }] since the last object matches the properties of the provided object.
|
|
29
29
|
*/
|
|
30
|
-
declare function dropRightWhile<T>(arr:
|
|
30
|
+
declare function dropRightWhile<T>(arr: ArrayLike<T> | null | undefined, objectToDrop: Partial<T>): T[];
|
|
31
31
|
/**
|
|
32
32
|
* Drops elements from the end of an array while the specified property matches a given value.
|
|
33
33
|
*
|
|
34
34
|
* @template T - The type of elements in the array.
|
|
35
|
-
* @param {T
|
|
35
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
36
36
|
* @param {[keyof T, unknown]} propertyToDrop - A tuple containing the property key and the value to match for dropping elements.
|
|
37
37
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
38
38
|
*
|
|
@@ -41,12 +41,12 @@ declare function dropRightWhile<T>(arr: readonly T[], objectToDrop: Partial<T>):
|
|
|
41
41
|
* const result = dropRightWhile(array, ['id', 3]);
|
|
42
42
|
* result will be [{ id: 1 }, { id: 2 }] since the last object has the id property matching the value 3.
|
|
43
43
|
*/
|
|
44
|
-
declare function dropRightWhile<T>(arr:
|
|
44
|
+
declare function dropRightWhile<T>(arr: ArrayLike<T> | null | undefined, propertyToDrop: [keyof T, unknown]): T[];
|
|
45
45
|
/**
|
|
46
46
|
* Drops elements from the end of an array while the specified property name matches.
|
|
47
47
|
*
|
|
48
48
|
* @template T - The type of elements in the array.
|
|
49
|
-
* @param {T
|
|
49
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
50
50
|
* @param {string} propertyToDrop - The name of the property to match for dropping elements.
|
|
51
51
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
52
52
|
*
|
|
@@ -55,6 +55,6 @@ declare function dropRightWhile<T>(arr: readonly T[], propertyToDrop: [keyof T,
|
|
|
55
55
|
* const result = dropRightWhile(array, 'isActive');
|
|
56
56
|
* result will be [{ isActive: false }] since it drops elements until it finds one with a falsy isActive property.
|
|
57
57
|
*/
|
|
58
|
-
declare function dropRightWhile<T>(arr:
|
|
58
|
+
declare function dropRightWhile<T>(arr: ArrayLike<T> | null | undefined, propertyToDrop: string): T[];
|
|
59
59
|
|
|
60
60
|
export { dropRightWhile };
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { dropRightWhile as dropRightWhile$1 } from '../../array/dropRightWhile.mjs';
|
|
2
2
|
import { property } from '../object/property.mjs';
|
|
3
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
import { matches } from '../predicate/matches.mjs';
|
|
4
5
|
import { matchesProperty } from '../predicate/matchesProperty.mjs';
|
|
5
6
|
|
|
6
7
|
function dropRightWhile(arr, predicate) {
|
|
8
|
+
if (!isArrayLike(arr)) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
return dropRightWhileImpl(Array.from(arr), predicate);
|
|
12
|
+
}
|
|
13
|
+
function dropRightWhileImpl(arr, predicate) {
|
|
7
14
|
switch (typeof predicate) {
|
|
8
15
|
case 'function': {
|
|
9
16
|
return dropRightWhile$1(arr, (item, index, arr) => Boolean(predicate(item, index, arr)));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Drops elements from the beginning of an array while the predicate function returns truthy.
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of elements in the array.
|
|
5
|
-
* @param {T
|
|
5
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
6
6
|
* @param {(item: T, index: number, arr: T[]) => unknown} canContinueDropping - A predicate function that determines
|
|
7
7
|
* whether to continue dropping elements. The function is called with each element, index, and array, and dropping
|
|
8
8
|
* continues as long as it returns true.
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
* const result = dropWhile(array, x => x < 3);
|
|
14
14
|
* result will be [3, 4, 5] since elements less than 3 are dropped.
|
|
15
15
|
*/
|
|
16
|
-
declare function dropWhile<T>(arr:
|
|
16
|
+
declare function dropWhile<T>(arr: ArrayLike<T> | null | undefined, canContinueDropping: (item: T, index: number, arr: readonly T[]) => unknown): T[];
|
|
17
17
|
/**
|
|
18
18
|
* Drops elements from the beginning of an array while the specified object properties match.
|
|
19
19
|
*
|
|
20
20
|
* @template T - The type of elements in the array.
|
|
21
|
-
* @param {T
|
|
21
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
22
22
|
* @param {Partial<T>} objectToDrop - An object specifying the properties to match for dropping elements.
|
|
23
23
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
24
24
|
*
|
|
@@ -27,12 +27,12 @@ declare function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T,
|
|
|
27
27
|
* const result = dropWhile(array, { a: 1 });
|
|
28
28
|
* result will be [{ a: 2 }, { a: 3 }] since the first object matches the properties of the provided object.
|
|
29
29
|
*/
|
|
30
|
-
declare function dropWhile<T>(arr:
|
|
30
|
+
declare function dropWhile<T>(arr: ArrayLike<T> | null | undefined, objectToDrop: Partial<T>): T[];
|
|
31
31
|
/**
|
|
32
32
|
* Drops elements from the beginning of an array while the specified property matches a given value.
|
|
33
33
|
*
|
|
34
34
|
* @template T - The type of elements in the array.
|
|
35
|
-
* @param {T
|
|
35
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
36
36
|
* @param {[keyof T, unknown]} propertyToDrop - A tuple containing the property key and the value to match for dropping elements.
|
|
37
37
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
38
38
|
*
|
|
@@ -41,12 +41,12 @@ declare function dropWhile<T>(arr: readonly T[], objectToDrop: Partial<T>): T[];
|
|
|
41
41
|
* const result = dropWhile(array, ['id', 1]);
|
|
42
42
|
* result will be [{ id: 2 }, { id: 3 }] since the first object has the id property matching the value 1.
|
|
43
43
|
*/
|
|
44
|
-
declare function dropWhile<T>(arr:
|
|
44
|
+
declare function dropWhile<T>(arr: ArrayLike<T> | null | undefined, propertyToDrop: [keyof T, unknown]): T[];
|
|
45
45
|
/**
|
|
46
46
|
* Drops elements from the beginning of an array while the specified property name matches.
|
|
47
47
|
*
|
|
48
48
|
* @template T - The type of elements in the array.
|
|
49
|
-
* @param {T
|
|
49
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
50
50
|
* @param {string} propertyToDrop - The name of the property to match for dropping elements.
|
|
51
51
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
52
52
|
*
|
|
@@ -55,6 +55,6 @@ declare function dropWhile<T>(arr: readonly T[], propertyToDrop: [keyof T, unkno
|
|
|
55
55
|
* const result = dropWhile(array, 'isActive');
|
|
56
56
|
* result will be [{ isActive: false }] since it drops elements until it finds one with a falsy isActive property.
|
|
57
57
|
*/
|
|
58
|
-
declare function dropWhile<T>(arr:
|
|
58
|
+
declare function dropWhile<T>(arr: ArrayLike<T> | null | undefined, propertyToDrop: string): T[];
|
|
59
59
|
|
|
60
60
|
export { dropWhile };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Drops elements from the beginning of an array while the predicate function returns truthy.
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of elements in the array.
|
|
5
|
-
* @param {T
|
|
5
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
6
6
|
* @param {(item: T, index: number, arr: T[]) => unknown} canContinueDropping - A predicate function that determines
|
|
7
7
|
* whether to continue dropping elements. The function is called with each element, index, and array, and dropping
|
|
8
8
|
* continues as long as it returns true.
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
* const result = dropWhile(array, x => x < 3);
|
|
14
14
|
* result will be [3, 4, 5] since elements less than 3 are dropped.
|
|
15
15
|
*/
|
|
16
|
-
declare function dropWhile<T>(arr:
|
|
16
|
+
declare function dropWhile<T>(arr: ArrayLike<T> | null | undefined, canContinueDropping: (item: T, index: number, arr: readonly T[]) => unknown): T[];
|
|
17
17
|
/**
|
|
18
18
|
* Drops elements from the beginning of an array while the specified object properties match.
|
|
19
19
|
*
|
|
20
20
|
* @template T - The type of elements in the array.
|
|
21
|
-
* @param {T
|
|
21
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
22
22
|
* @param {Partial<T>} objectToDrop - An object specifying the properties to match for dropping elements.
|
|
23
23
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
24
24
|
*
|
|
@@ -27,12 +27,12 @@ declare function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T,
|
|
|
27
27
|
* const result = dropWhile(array, { a: 1 });
|
|
28
28
|
* result will be [{ a: 2 }, { a: 3 }] since the first object matches the properties of the provided object.
|
|
29
29
|
*/
|
|
30
|
-
declare function dropWhile<T>(arr:
|
|
30
|
+
declare function dropWhile<T>(arr: ArrayLike<T> | null | undefined, objectToDrop: Partial<T>): T[];
|
|
31
31
|
/**
|
|
32
32
|
* Drops elements from the beginning of an array while the specified property matches a given value.
|
|
33
33
|
*
|
|
34
34
|
* @template T - The type of elements in the array.
|
|
35
|
-
* @param {T
|
|
35
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
36
36
|
* @param {[keyof T, unknown]} propertyToDrop - A tuple containing the property key and the value to match for dropping elements.
|
|
37
37
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
38
38
|
*
|
|
@@ -41,12 +41,12 @@ declare function dropWhile<T>(arr: readonly T[], objectToDrop: Partial<T>): T[];
|
|
|
41
41
|
* const result = dropWhile(array, ['id', 1]);
|
|
42
42
|
* result will be [{ id: 2 }, { id: 3 }] since the first object has the id property matching the value 1.
|
|
43
43
|
*/
|
|
44
|
-
declare function dropWhile<T>(arr:
|
|
44
|
+
declare function dropWhile<T>(arr: ArrayLike<T> | null | undefined, propertyToDrop: [keyof T, unknown]): T[];
|
|
45
45
|
/**
|
|
46
46
|
* Drops elements from the beginning of an array while the specified property name matches.
|
|
47
47
|
*
|
|
48
48
|
* @template T - The type of elements in the array.
|
|
49
|
-
* @param {T
|
|
49
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to drop elements.
|
|
50
50
|
* @param {string} propertyToDrop - The name of the property to match for dropping elements.
|
|
51
51
|
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
52
52
|
*
|
|
@@ -55,6 +55,6 @@ declare function dropWhile<T>(arr: readonly T[], propertyToDrop: [keyof T, unkno
|
|
|
55
55
|
* const result = dropWhile(array, 'isActive');
|
|
56
56
|
* result will be [{ isActive: false }] since it drops elements until it finds one with a falsy isActive property.
|
|
57
57
|
*/
|
|
58
|
-
declare function dropWhile<T>(arr:
|
|
58
|
+
declare function dropWhile<T>(arr: ArrayLike<T> | null | undefined, propertyToDrop: string): T[];
|
|
59
59
|
|
|
60
60
|
export { dropWhile };
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { dropWhile as dropWhile$1 } from '../../array/dropWhile.mjs';
|
|
2
2
|
import { property } from '../object/property.mjs';
|
|
3
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
3
4
|
import { matches } from '../predicate/matches.mjs';
|
|
4
5
|
import { matchesProperty } from '../predicate/matchesProperty.mjs';
|
|
5
6
|
|
|
6
7
|
function dropWhile(arr, predicate) {
|
|
8
|
+
if (!isArrayLike(arr)) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
return dropWhileImpl(Array.from(arr), predicate);
|
|
12
|
+
}
|
|
13
|
+
function dropWhileImpl(arr, predicate) {
|
|
7
14
|
switch (typeof predicate) {
|
|
8
15
|
case 'function': {
|
|
9
16
|
return dropWhile$1(arr, (item, index, arr) => Boolean(predicate(item, index, arr)));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the first element of an array or `undefined` if the array is empty.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and returns the first element of the array.
|
|
5
|
+
* If the array is empty, the function returns `undefined`.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements in the array.
|
|
8
|
+
* @param {ArrayLike<T> | undefined | null} arr - The array from which to get the first element.
|
|
9
|
+
* @returns {T | undefined} The first element of the array, or `undefined` if the array is empty.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const emptyArr: number[] = [];
|
|
13
|
+
* const noElement = head(emptyArr);
|
|
14
|
+
* // noElement will be undefined
|
|
15
|
+
*/
|
|
16
|
+
declare function head<T>(arr: ArrayLike<T> | undefined | null): T | undefined;
|
|
17
|
+
|
|
18
|
+
export { head };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the first element of an array or `undefined` if the array is empty.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and returns the first element of the array.
|
|
5
|
+
* If the array is empty, the function returns `undefined`.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements in the array.
|
|
8
|
+
* @param {ArrayLike<T> | undefined | null} arr - The array from which to get the first element.
|
|
9
|
+
* @returns {T | undefined} The first element of the array, or `undefined` if the array is empty.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const emptyArr: number[] = [];
|
|
13
|
+
* const noElement = head(emptyArr);
|
|
14
|
+
* // noElement will be undefined
|
|
15
|
+
*/
|
|
16
|
+
declare function head<T>(arr: ArrayLike<T> | undefined | null): T | undefined;
|
|
17
|
+
|
|
18
|
+
export { head };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the intersection of multiple arrays.
|
|
3
|
+
*
|
|
4
|
+
* This function takes multiple arrays and returns a new array containing the elements that are
|
|
5
|
+
* present in all provided arrays. It effectively filters out any elements that are not found
|
|
6
|
+
* in every array.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the arrays.
|
|
9
|
+
* @param {...(ArrayLike<T> | null | undefined)} arrays - The arrays to compare.
|
|
10
|
+
* @returns {T[]} A new array containing the elements that are present in all arrays.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const array1 = [1, 2, 3, 4, 5];
|
|
14
|
+
* const array2 = [3, 4, 5, 6, 7];
|
|
15
|
+
* const result = intersection(array1, array2);
|
|
16
|
+
* // result will be [3, 4, 5] since these elements are in both arrays.
|
|
17
|
+
*/
|
|
18
|
+
declare function intersection<T>(...arrays: Array<ArrayLike<T> | null | undefined>): T[];
|
|
19
|
+
|
|
20
|
+
export { intersection };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the intersection of multiple arrays.
|
|
3
|
+
*
|
|
4
|
+
* This function takes multiple arrays and returns a new array containing the elements that are
|
|
5
|
+
* present in all provided arrays. It effectively filters out any elements that are not found
|
|
6
|
+
* in every array.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type of elements in the arrays.
|
|
9
|
+
* @param {...(ArrayLike<T> | null | undefined)} arrays - The arrays to compare.
|
|
10
|
+
* @returns {T[]} A new array containing the elements that are present in all arrays.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const array1 = [1, 2, 3, 4, 5];
|
|
14
|
+
* const array2 = [3, 4, 5, 6, 7];
|
|
15
|
+
* const result = intersection(array1, array2);
|
|
16
|
+
* // result will be [3, 4, 5] since these elements are in both arrays.
|
|
17
|
+
*/
|
|
18
|
+
declare function intersection<T>(...arrays: Array<ArrayLike<T> | null | undefined>): T[];
|
|
19
|
+
|
|
20
|
+
export { intersection };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { intersection as intersection$1 } from '../../array/intersection.mjs';
|
|
2
|
+
import { uniq } from '../../array/uniq.mjs';
|
|
3
|
+
import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|
4
|
+
|
|
5
|
+
function intersection(...arrays) {
|
|
6
|
+
if (arrays.length === 0) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
if (!isArrayLikeObject(arrays[0])) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
let result = uniq(Array.from(arrays[0]));
|
|
13
|
+
for (let i = 1; i < arrays.length; i++) {
|
|
14
|
+
const array = arrays[i];
|
|
15
|
+
if (!isArrayLikeObject(array)) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
result = intersection$1(result, Array.from(array));
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { intersection };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the last element of an array.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array and returns the last element of the array.
|
|
5
|
+
* If the array is empty, the function returns `undefined`.
|
|
6
|
+
*
|
|
7
|
+
* Unlike some implementations, this function is optimized for performance
|
|
8
|
+
* by directly accessing the last index of the array.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of elements in the array.
|
|
11
|
+
* @param {ArrayLike<T> | null | undefined} arr - The array from which to get the last element.
|
|
12
|
+
* @returns {T | undefined} The last element of the array, or `undefined` if the array is empty.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const arr = [1, 2, 3];
|
|
16
|
+
* const lastElement = last(arr);
|
|
17
|
+
* // lastElement will be 3
|
|
18
|
+
*
|
|
19
|
+
* const emptyArr: number[] = [];
|
|
20
|
+
* const noElement = last(emptyArr);
|
|
21
|
+
* // noElement will be undefined
|
|
22
|
+
*/
|
|
23
|
+
declare function last<T>(array: ArrayLike<T> | null | undefined): T | undefined;
|
|
24
|
+
|
|
25
|
+
export { last };
|