es-toolkit 1.17.0-dev.533 → 1.17.0-dev.535
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/_chunk/{initial-crEecP.js → initial-CMlK06.js} +5 -5
- package/dist/_chunk/{randomInt-CF7bZK.js → randomInt-DJFj2K.js} +1 -1
- package/dist/_chunk/{rest-Bzm2XK.js → rest-CXB7TJ.js} +6 -6
- package/dist/array/fill.d.mts +55 -2
- package/dist/array/fill.d.ts +55 -2
- package/dist/array/head.d.mts +14 -3
- package/dist/array/head.d.ts +14 -3
- package/dist/array/index.js +1 -1
- package/dist/array/join.d.mts +3 -7
- package/dist/array/join.d.ts +3 -7
- package/dist/array/join.mjs +1 -1
- package/dist/array/last.d.mts +23 -1
- package/dist/array/last.d.ts +23 -1
- package/dist/array/maxBy.d.mts +13 -1
- package/dist/array/maxBy.d.ts +13 -1
- package/dist/array/minBy.d.mts +13 -1
- package/dist/array/minBy.d.ts +13 -1
- package/dist/array/toFilled.d.mts +59 -2
- package/dist/array/toFilled.d.ts +59 -2
- package/dist/array/zip.d.mts +65 -7
- package/dist/array/zip.d.ts +65 -7
- package/dist/array/zip.mjs +1 -1
- package/dist/array/zipObject.d.mts +2 -4
- package/dist/array/zipObject.d.ts +2 -4
- package/dist/array/zipWith.d.mts +39 -6
- package/dist/array/zipWith.d.ts +39 -6
- package/dist/array/zipWith.mjs +2 -2
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/difference.d.mts +22 -0
- package/dist/compat/array/difference.d.ts +22 -0
- package/dist/compat/array/fill.d.mts +55 -2
- package/dist/compat/array/fill.d.ts +55 -2
- package/dist/compat/array/find.mjs +3 -3
- package/dist/compat/array/findIndex.mjs +3 -3
- package/dist/compat/index.js +43 -34
- package/dist/compat/math/max.d.mts +16 -5
- package/dist/compat/math/max.d.ts +16 -5
- package/dist/compat/math/min.d.mts +16 -4
- package/dist/compat/math/min.d.ts +16 -4
- package/dist/compat/object/get.mjs +1 -1
- package/dist/compat/object/has.mjs +3 -2
- package/dist/compat/object/mapKeys.mjs +7 -6
- package/dist/compat/object/mapValues.mjs +7 -6
- package/dist/compat/object/mergeWith.mjs +5 -3
- package/dist/compat/object/set.mjs +5 -1
- package/dist/compat/predicate/isMatch.mjs +2 -2
- package/dist/compat/string/endsWith.d.mts +1 -1
- package/dist/compat/string/endsWith.d.ts +1 -1
- package/dist/compat/string/endsWith.mjs +2 -2
- package/dist/compat/string/repeat.d.mts +1 -1
- package/dist/compat/string/repeat.d.ts +1 -1
- package/dist/compat/string/startsWith.d.mts +1 -1
- package/dist/compat/string/startsWith.d.ts +1 -1
- package/dist/compat/string/startsWith.mjs +2 -2
- package/dist/function/after.d.mts +1 -1
- package/dist/function/after.d.ts +1 -1
- package/dist/function/after.mjs +2 -2
- package/dist/function/before.d.mts +1 -1
- package/dist/function/before.d.ts +1 -1
- package/dist/function/before.mjs +3 -3
- package/dist/function/debounce.d.mts +1 -1
- package/dist/function/debounce.d.ts +1 -1
- package/dist/function/debounce.mjs +1 -1
- package/dist/function/index.js +1 -1
- package/dist/function/memoize.d.mts +37 -1
- package/dist/function/memoize.d.ts +37 -1
- package/dist/index.js +3 -3
- package/dist/math/clamp.d.mts +14 -3
- package/dist/math/clamp.d.ts +14 -3
- package/dist/math/index.js +1 -1
- package/dist/math/random.d.mts +13 -2
- package/dist/math/random.d.ts +13 -2
- package/dist/math/random.mjs +1 -1
- package/dist/math/randomInt.d.mts +11 -3
- package/dist/math/randomInt.d.ts +11 -3
- package/dist/math/range.d.mts +25 -0
- package/dist/math/range.d.ts +25 -0
- package/dist/object/invert.d.mts +2 -4
- package/dist/object/invert.d.ts +2 -4
- package/dist/predicate/index.js +1 -1
- package/dist/predicate/isRegExp.d.mts +8 -1
- package/dist/predicate/isRegExp.d.ts +8 -1
- package/dist/predicate/isSymbol.d.mts +15 -0
- package/dist/predicate/isSymbol.d.ts +15 -0
- package/dist/predicate/isSymbol.mjs +1 -1
- package/dist/string/capitalize.d.mts +1 -1
- package/dist/string/capitalize.d.ts +1 -1
- package/dist/string/capitalize.mjs +4 -3
- package/dist/string/escapeRegExp.d.mts +5 -0
- package/dist/string/escapeRegExp.d.ts +5 -0
- package/dist/string/escapeRegExp.mjs +1 -1
- package/dist/string/index.js +21 -20
- package/dist/string/kebabCase.d.mts +1 -1
- package/dist/string/kebabCase.d.ts +1 -1
- package/dist/string/kebabCase.mjs +3 -3
- package/dist/string/lowerCase.d.mts +1 -1
- package/dist/string/lowerCase.d.ts +1 -1
- package/dist/string/lowerCase.mjs +3 -3
- package/dist/string/lowerFirst.d.mts +1 -1
- package/dist/string/lowerFirst.d.ts +1 -1
- package/dist/string/lowerFirst.mjs +2 -2
- package/dist/string/pascalCase.d.mts +1 -1
- package/dist/string/pascalCase.d.ts +1 -1
- package/dist/string/pascalCase.mjs +3 -3
- package/dist/string/snakeCase.d.mts +1 -1
- package/dist/string/snakeCase.d.ts +1 -1
- package/dist/string/snakeCase.mjs +3 -3
- package/dist/string/upperFirst.d.mts +1 -1
- package/dist/string/upperFirst.d.ts +1 -1
- package/dist/string/upperFirst.mjs +2 -2
- package/package.json +2 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const randomInt = require('./randomInt-
|
|
3
|
+
const randomInt = require('./randomInt-DJFj2K.js');
|
|
4
4
|
|
|
5
5
|
function at(arr, indices) {
|
|
6
6
|
const result = [];
|
|
@@ -172,7 +172,7 @@ function intersectionWith(firstArr, secondArr, areItemsEqual) {
|
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
function join(array, separator =
|
|
175
|
+
function join(array, separator = ",") {
|
|
176
176
|
return array.join(separator);
|
|
177
177
|
}
|
|
178
178
|
|
|
@@ -389,7 +389,7 @@ function xorWith(arr1, arr2, areElementsEqual) {
|
|
|
389
389
|
|
|
390
390
|
function zip(...arrs) {
|
|
391
391
|
const result = [];
|
|
392
|
-
const maxIndex = Math.max(...arrs.map(x => x.length));
|
|
392
|
+
const maxIndex = Math.max(...arrs.map((x) => x.length));
|
|
393
393
|
for (let i = 0; i < maxIndex; i++) {
|
|
394
394
|
const element = [];
|
|
395
395
|
for (const arr of arrs) {
|
|
@@ -412,9 +412,9 @@ function zipWith(arr1, ...rest) {
|
|
|
412
412
|
const arrs = [arr1, ...rest.slice(0, -1)];
|
|
413
413
|
const combine = rest[rest.length - 1];
|
|
414
414
|
const result = [];
|
|
415
|
-
const maxIndex = Math.max(...arrs.map(arr => arr.length));
|
|
415
|
+
const maxIndex = Math.max(...arrs.map((arr) => arr.length));
|
|
416
416
|
for (let i = 0; i < maxIndex; i++) {
|
|
417
|
-
const elements = arrs.map(arr => arr[i]);
|
|
417
|
+
const elements = arrs.map((arr) => arr[i]);
|
|
418
418
|
result.push(combine(...elements));
|
|
419
419
|
}
|
|
420
420
|
return result;
|
|
@@ -6,7 +6,7 @@ function random(minimum, maximum) {
|
|
|
6
6
|
minimum = 0;
|
|
7
7
|
}
|
|
8
8
|
if (minimum >= maximum) {
|
|
9
|
-
throw new Error(
|
|
9
|
+
throw new Error("Invalid input: The maximum value must be greater than the minimum value.");
|
|
10
10
|
}
|
|
11
11
|
return Math.random() * (maximum - minimum) + minimum;
|
|
12
12
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
function before(n, func) {
|
|
4
4
|
if (!Number.isInteger(n) || n < 0) {
|
|
5
|
-
throw new Error(
|
|
5
|
+
throw new Error("n must be a non-negative integer.");
|
|
6
6
|
}
|
|
7
7
|
let counter = 0;
|
|
8
8
|
return ((...args) => {
|
|
@@ -11,9 +11,9 @@ const before = (n, func) => {
|
|
|
11
11
|
}
|
|
12
12
|
return undefined;
|
|
13
13
|
});
|
|
14
|
-
}
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
function after(n, func) {
|
|
17
17
|
if (!Number.isInteger(n) || n < 0) {
|
|
18
18
|
throw new Error(`n must be a non-negative integer.`);
|
|
19
19
|
}
|
|
@@ -24,7 +24,7 @@ const after = (n, func) => {
|
|
|
24
24
|
}
|
|
25
25
|
return undefined;
|
|
26
26
|
});
|
|
27
|
-
}
|
|
27
|
+
}
|
|
28
28
|
|
|
29
29
|
function debounce(func, debounceMs, { signal } = {}) {
|
|
30
30
|
let timeoutId = null;
|
|
@@ -49,7 +49,7 @@ function debounce(func, debounceMs, { signal } = {}) {
|
|
|
49
49
|
timeoutId = null;
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
-
signal?.addEventListener(
|
|
52
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
53
53
|
return debounced;
|
|
54
54
|
}
|
|
55
55
|
|
package/dist/array/fill.d.mts
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fills the whole array with a specified value.
|
|
3
|
+
*
|
|
4
|
+
* This function mutates the original array and replaces its elements with the provided value, starting from the specified
|
|
5
|
+
* start index up to the end index (non-inclusive). If the start or end indices are not provided, it defaults to filling the
|
|
6
|
+
* entire array.
|
|
7
|
+
*
|
|
8
|
+
* @template T, U
|
|
9
|
+
* @param {Array<T | U>} array - The array to fill.
|
|
10
|
+
* @param {U} value - The value to fill the array with.
|
|
11
|
+
* @returns {Array<T | U>} The array with the filled values.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const array = [1, 2, 3];
|
|
15
|
+
* const result = fill(array, 'a');
|
|
16
|
+
* // => ['a', 'a', 'a']
|
|
17
|
+
*
|
|
18
|
+
* const result = fill(Array(3), 2);
|
|
19
|
+
* // => [2, 2, 2]
|
|
20
|
+
*
|
|
21
|
+
* const result = fill([4, 6, 8, 10], '*', 1, 3);
|
|
22
|
+
* // => [4, '*', '*', 10]
|
|
23
|
+
*
|
|
24
|
+
* const result = fill(array, '*', -2, -1);
|
|
25
|
+
* // => [1, '*', 3]
|
|
26
|
+
*/
|
|
27
|
+
declare function fill<T>(array: unknown[], value: T): T[];
|
|
28
|
+
/**
|
|
29
|
+
* Fills elements of an array with a specified value from the start position up to the end of the array.
|
|
30
|
+
*
|
|
31
|
+
* This function mutates the original array and replaces its elements with the provided value, starting from the specified
|
|
32
|
+
* start index up to the end index (non-inclusive). If the start or end indices are not provided, it defaults to filling the
|
|
33
|
+
* entire array.
|
|
34
|
+
*
|
|
35
|
+
* @template T, U
|
|
36
|
+
* @param {Array<T | U>} array - The array to fill.
|
|
37
|
+
* @param {U} value - The value to fill the array with.
|
|
38
|
+
* @param {number} [start=0] - The start position. Defaults to 0.
|
|
39
|
+
* @returns {Array<T | U>} The array with the filled values.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const array = [1, 2, 3];
|
|
43
|
+
* const result = fill(array, 'a');
|
|
44
|
+
* // => ['a', 'a', 'a']
|
|
45
|
+
*
|
|
46
|
+
* const result = fill(Array(3), 2);
|
|
47
|
+
* // => [2, 2, 2]
|
|
48
|
+
*
|
|
49
|
+
* const result = fill([4, 6, 8, 10], '*', 1, 3);
|
|
50
|
+
* // => [4, '*', '*', 10]
|
|
51
|
+
*
|
|
52
|
+
* const result = fill(array, '*', -2, -1);
|
|
53
|
+
* // => [1, '*', 3]
|
|
54
|
+
*/
|
|
55
|
+
declare function fill<T, U>(array: Array<T | U>, value: U, start: number): Array<T | U>;
|
|
1
56
|
/**
|
|
2
57
|
* Fills elements of an array with a specified value from the start position up to, but not including, the end position.
|
|
3
58
|
*
|
|
@@ -26,8 +81,6 @@
|
|
|
26
81
|
* const result = fill(array, '*', -2, -1);
|
|
27
82
|
* // => [1, '*', 3]
|
|
28
83
|
*/
|
|
29
|
-
declare function fill<T>(array: unknown[], value: T): T[];
|
|
30
|
-
declare function fill<T, U>(array: Array<T | U>, value: U, start: number): Array<T | U>;
|
|
31
84
|
declare function fill<T, U>(array: Array<T | U>, value: U, start: number, end: number): Array<T | U>;
|
|
32
85
|
|
|
33
86
|
export { fill };
|
package/dist/array/fill.d.ts
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fills the whole array with a specified value.
|
|
3
|
+
*
|
|
4
|
+
* This function mutates the original array and replaces its elements with the provided value, starting from the specified
|
|
5
|
+
* start index up to the end index (non-inclusive). If the start or end indices are not provided, it defaults to filling the
|
|
6
|
+
* entire array.
|
|
7
|
+
*
|
|
8
|
+
* @template T, U
|
|
9
|
+
* @param {Array<T | U>} array - The array to fill.
|
|
10
|
+
* @param {U} value - The value to fill the array with.
|
|
11
|
+
* @returns {Array<T | U>} The array with the filled values.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const array = [1, 2, 3];
|
|
15
|
+
* const result = fill(array, 'a');
|
|
16
|
+
* // => ['a', 'a', 'a']
|
|
17
|
+
*
|
|
18
|
+
* const result = fill(Array(3), 2);
|
|
19
|
+
* // => [2, 2, 2]
|
|
20
|
+
*
|
|
21
|
+
* const result = fill([4, 6, 8, 10], '*', 1, 3);
|
|
22
|
+
* // => [4, '*', '*', 10]
|
|
23
|
+
*
|
|
24
|
+
* const result = fill(array, '*', -2, -1);
|
|
25
|
+
* // => [1, '*', 3]
|
|
26
|
+
*/
|
|
27
|
+
declare function fill<T>(array: unknown[], value: T): T[];
|
|
28
|
+
/**
|
|
29
|
+
* Fills elements of an array with a specified value from the start position up to the end of the array.
|
|
30
|
+
*
|
|
31
|
+
* This function mutates the original array and replaces its elements with the provided value, starting from the specified
|
|
32
|
+
* start index up to the end index (non-inclusive). If the start or end indices are not provided, it defaults to filling the
|
|
33
|
+
* entire array.
|
|
34
|
+
*
|
|
35
|
+
* @template T, U
|
|
36
|
+
* @param {Array<T | U>} array - The array to fill.
|
|
37
|
+
* @param {U} value - The value to fill the array with.
|
|
38
|
+
* @param {number} [start=0] - The start position. Defaults to 0.
|
|
39
|
+
* @returns {Array<T | U>} The array with the filled values.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const array = [1, 2, 3];
|
|
43
|
+
* const result = fill(array, 'a');
|
|
44
|
+
* // => ['a', 'a', 'a']
|
|
45
|
+
*
|
|
46
|
+
* const result = fill(Array(3), 2);
|
|
47
|
+
* // => [2, 2, 2]
|
|
48
|
+
*
|
|
49
|
+
* const result = fill([4, 6, 8, 10], '*', 1, 3);
|
|
50
|
+
* // => [4, '*', '*', 10]
|
|
51
|
+
*
|
|
52
|
+
* const result = fill(array, '*', -2, -1);
|
|
53
|
+
* // => [1, '*', 3]
|
|
54
|
+
*/
|
|
55
|
+
declare function fill<T, U>(array: Array<T | U>, value: U, start: number): Array<T | U>;
|
|
1
56
|
/**
|
|
2
57
|
* Fills elements of an array with a specified value from the start position up to, but not including, the end position.
|
|
3
58
|
*
|
|
@@ -26,8 +81,6 @@
|
|
|
26
81
|
* const result = fill(array, '*', -2, -1);
|
|
27
82
|
* // => [1, '*', 3]
|
|
28
83
|
*/
|
|
29
|
-
declare function fill<T>(array: unknown[], value: T): T[];
|
|
30
|
-
declare function fill<T, U>(array: Array<T | U>, value: U, start: number): Array<T | U>;
|
|
31
84
|
declare function fill<T, U>(array: Array<T | U>, value: U, start: number, end: number): Array<T | U>;
|
|
32
85
|
|
|
33
86
|
export { fill };
|
package/dist/array/head.d.mts
CHANGED
|
@@ -5,19 +5,30 @@
|
|
|
5
5
|
* If the array is empty, the function returns `undefined`.
|
|
6
6
|
*
|
|
7
7
|
* @template T - The type of elements in the array.
|
|
8
|
-
* @param {T[]} arr -
|
|
9
|
-
* @returns {T
|
|
8
|
+
* @param {[T, ...T[]]} arr - A non-empty array from which to get the first element.
|
|
9
|
+
* @returns {T} The first element of the array.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* const arr = [1, 2, 3];
|
|
13
13
|
* const firstElement = head(arr);
|
|
14
14
|
* // firstElement will be 1
|
|
15
|
+
*/
|
|
16
|
+
declare function head<T>(arr: readonly [T, ...T[]]): T;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the first element of an array or `undefined` if the array is empty.
|
|
19
|
+
*
|
|
20
|
+
* This function takes an array and returns the first element of the array.
|
|
21
|
+
* If the array is empty, the function returns `undefined`.
|
|
15
22
|
*
|
|
23
|
+
* @template T - The type of elements in the array.
|
|
24
|
+
* @param {T[]} arr - The array from which to get the first element.
|
|
25
|
+
* @returns {T | undefined} The first element of the array, or `undefined` if the array is empty.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
16
28
|
* const emptyArr: number[] = [];
|
|
17
29
|
* const noElement = head(emptyArr);
|
|
18
30
|
* // noElement will be undefined
|
|
19
31
|
*/
|
|
20
|
-
declare function head<T>(arr: readonly [T, ...T[]]): T;
|
|
21
32
|
declare function head<T>(arr: readonly T[]): T | undefined;
|
|
22
33
|
|
|
23
34
|
export { head };
|
package/dist/array/head.d.ts
CHANGED
|
@@ -5,19 +5,30 @@
|
|
|
5
5
|
* If the array is empty, the function returns `undefined`.
|
|
6
6
|
*
|
|
7
7
|
* @template T - The type of elements in the array.
|
|
8
|
-
* @param {T[]} arr -
|
|
9
|
-
* @returns {T
|
|
8
|
+
* @param {[T, ...T[]]} arr - A non-empty array from which to get the first element.
|
|
9
|
+
* @returns {T} The first element of the array.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* const arr = [1, 2, 3];
|
|
13
13
|
* const firstElement = head(arr);
|
|
14
14
|
* // firstElement will be 1
|
|
15
|
+
*/
|
|
16
|
+
declare function head<T>(arr: readonly [T, ...T[]]): T;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the first element of an array or `undefined` if the array is empty.
|
|
19
|
+
*
|
|
20
|
+
* This function takes an array and returns the first element of the array.
|
|
21
|
+
* If the array is empty, the function returns `undefined`.
|
|
15
22
|
*
|
|
23
|
+
* @template T - The type of elements in the array.
|
|
24
|
+
* @param {T[]} arr - The array from which to get the first element.
|
|
25
|
+
* @returns {T | undefined} The first element of the array, or `undefined` if the array is empty.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
16
28
|
* const emptyArr: number[] = [];
|
|
17
29
|
* const noElement = head(emptyArr);
|
|
18
30
|
* // noElement will be undefined
|
|
19
31
|
*/
|
|
20
|
-
declare function head<T>(arr: readonly [T, ...T[]]): T;
|
|
21
32
|
declare function head<T>(arr: readonly T[]): T | undefined;
|
|
22
33
|
|
|
23
34
|
export { head };
|
package/dist/array/index.js
CHANGED
package/dist/array/join.d.mts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Join elements of an array into a string.
|
|
2
|
+
* Joins elements of an array into a string.
|
|
4
3
|
*
|
|
5
4
|
* @template T - The type of elements in the array.
|
|
6
|
-
* @param {
|
|
5
|
+
* @param {T[]} array - The array to join.
|
|
7
6
|
* @param {string} separator - The separator used to join the elements, default is common separator `,`.
|
|
8
7
|
* @returns {string} - Returns a string containing all elements of the array joined by the specified separator.
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
|
-
*
|
|
12
|
-
* const arr = ["a","b","c"];
|
|
10
|
+
* const arr = ["a", "b", "c"];
|
|
13
11
|
* const result = join(arr, "~");
|
|
14
12
|
* console.log(result); // Output: "a~b~c"
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
13
|
*/
|
|
18
14
|
declare function join<T>(array: readonly T[], separator?: string): string;
|
|
19
15
|
|
package/dist/array/join.d.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Join elements of an array into a string.
|
|
2
|
+
* Joins elements of an array into a string.
|
|
4
3
|
*
|
|
5
4
|
* @template T - The type of elements in the array.
|
|
6
|
-
* @param {
|
|
5
|
+
* @param {T[]} array - The array to join.
|
|
7
6
|
* @param {string} separator - The separator used to join the elements, default is common separator `,`.
|
|
8
7
|
* @returns {string} - Returns a string containing all elements of the array joined by the specified separator.
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
|
-
*
|
|
12
|
-
* const arr = ["a","b","c"];
|
|
10
|
+
* const arr = ["a", "b", "c"];
|
|
13
11
|
* const result = join(arr, "~");
|
|
14
12
|
* console.log(result); // Output: "a~b~c"
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
13
|
*/
|
|
18
14
|
declare function join<T>(array: readonly T[], separator?: string): string;
|
|
19
15
|
|
package/dist/array/join.mjs
CHANGED
package/dist/array/last.d.mts
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
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 {[...T[], T]} arr - The array from which to get the last element.
|
|
12
|
+
* @returns {T} 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>(arr: readonly [...T[], T]): T;
|
|
1
24
|
/**
|
|
2
25
|
* Returns the last element of an array.
|
|
3
26
|
*
|
|
@@ -20,7 +43,6 @@
|
|
|
20
43
|
* const noElement = last(emptyArr);
|
|
21
44
|
* // noElement will be undefined
|
|
22
45
|
*/
|
|
23
|
-
declare function last<T>(arr: readonly [...T[], T]): T;
|
|
24
46
|
declare function last<T>(arr: readonly T[]): T | undefined;
|
|
25
47
|
|
|
26
48
|
export { last };
|
package/dist/array/last.d.ts
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
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 {[...T[], T]} arr - The array from which to get the last element.
|
|
12
|
+
* @returns {T} 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>(arr: readonly [...T[], T]): T;
|
|
1
24
|
/**
|
|
2
25
|
* Returns the last element of an array.
|
|
3
26
|
*
|
|
@@ -20,7 +43,6 @@
|
|
|
20
43
|
* const noElement = last(emptyArr);
|
|
21
44
|
* // noElement will be undefined
|
|
22
45
|
*/
|
|
23
|
-
declare function last<T>(arr: readonly [...T[], T]): T;
|
|
24
46
|
declare function last<T>(arr: readonly T[]): T | undefined;
|
|
25
47
|
|
|
26
48
|
export { last };
|
package/dist/array/maxBy.d.mts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the element in an array that has the maximum value when applying
|
|
3
|
+
* the `getValue` function to each element.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of elements in the array.
|
|
6
|
+
* @param {[T, ...T[]]} items The nonempty array of elements to search.
|
|
7
|
+
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
8
|
+
* @returns {T} The element with the maximum value as determined by the `getValue` function.
|
|
9
|
+
* @example
|
|
10
|
+
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
|
|
11
|
+
* maxBy([], x => x.a); // Returns: undefined
|
|
12
|
+
*/
|
|
13
|
+
declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
|
|
1
14
|
/**
|
|
2
15
|
* Finds the element in an array that has the maximum value when applying
|
|
3
16
|
* the `getValue` function to each element.
|
|
@@ -10,7 +23,6 @@
|
|
|
10
23
|
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
|
|
11
24
|
* maxBy([], x => x.a); // Returns: undefined
|
|
12
25
|
*/
|
|
13
|
-
declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
|
|
14
26
|
declare function maxBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
|
|
15
27
|
|
|
16
28
|
export { maxBy };
|
package/dist/array/maxBy.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the element in an array that has the maximum value when applying
|
|
3
|
+
* the `getValue` function to each element.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of elements in the array.
|
|
6
|
+
* @param {[T, ...T[]]} items The nonempty array of elements to search.
|
|
7
|
+
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
8
|
+
* @returns {T} The element with the maximum value as determined by the `getValue` function.
|
|
9
|
+
* @example
|
|
10
|
+
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
|
|
11
|
+
* maxBy([], x => x.a); // Returns: undefined
|
|
12
|
+
*/
|
|
13
|
+
declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
|
|
1
14
|
/**
|
|
2
15
|
* Finds the element in an array that has the maximum value when applying
|
|
3
16
|
* the `getValue` function to each element.
|
|
@@ -10,7 +23,6 @@
|
|
|
10
23
|
* maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 }
|
|
11
24
|
* maxBy([], x => x.a); // Returns: undefined
|
|
12
25
|
*/
|
|
13
|
-
declare function maxBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
|
|
14
26
|
declare function maxBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
|
|
15
27
|
|
|
16
28
|
export { maxBy };
|
package/dist/array/minBy.d.mts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the element in an array that has the minimum value when applying
|
|
3
|
+
* the `getValue` function to each element.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of elements in the array.
|
|
6
|
+
* @param {[T, ...T[]]} items The nonempty array of elements to search.
|
|
7
|
+
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
8
|
+
* @returns {T} The element with the minimum value as determined by the `getValue` function.
|
|
9
|
+
* @example
|
|
10
|
+
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
|
|
11
|
+
* minBy([], x => x.a); // Returns: undefined
|
|
12
|
+
*/
|
|
13
|
+
declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
|
|
1
14
|
/**
|
|
2
15
|
* Finds the element in an array that has the minimum value when applying
|
|
3
16
|
* the `getValue` function to each element.
|
|
@@ -10,7 +23,6 @@
|
|
|
10
23
|
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
|
|
11
24
|
* minBy([], x => x.a); // Returns: undefined
|
|
12
25
|
*/
|
|
13
|
-
declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
|
|
14
26
|
declare function minBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
|
|
15
27
|
|
|
16
28
|
export { minBy };
|
package/dist/array/minBy.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the element in an array that has the minimum value when applying
|
|
3
|
+
* the `getValue` function to each element.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of elements in the array.
|
|
6
|
+
* @param {[T, ...T[]]} items The nonempty array of elements to search.
|
|
7
|
+
* @param {(element: T) => number} getValue A function that selects a numeric value from each element.
|
|
8
|
+
* @returns {T} The element with the minimum value as determined by the `getValue` function.
|
|
9
|
+
* @example
|
|
10
|
+
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
|
|
11
|
+
* minBy([], x => x.a); // Returns: undefined
|
|
12
|
+
*/
|
|
13
|
+
declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
|
|
1
14
|
/**
|
|
2
15
|
* Finds the element in an array that has the minimum value when applying
|
|
3
16
|
* the `getValue` function to each element.
|
|
@@ -10,7 +23,6 @@
|
|
|
10
23
|
* minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 }
|
|
11
24
|
* minBy([], x => x.a); // Returns: undefined
|
|
12
25
|
*/
|
|
13
|
-
declare function minBy<T>(items: readonly [T, ...T[]], getValue: (element: T) => number): T;
|
|
14
26
|
declare function minBy<T>(items: readonly T[], getValue: (element: T) => number): T | undefined;
|
|
15
27
|
|
|
16
28
|
export { minBy };
|
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
* @template U - The type of the value to fill the new array with.
|
|
7
7
|
* @param {Array<T>} arr - The array to base the new array on.
|
|
8
8
|
* @param {U} value - The value to fill the new array with.
|
|
9
|
-
* @param {number} [start=0] - The start position. Defaults to 0.
|
|
10
|
-
* @param {number} [end=arr.length] - The end position. Defaults to the array's length.
|
|
11
9
|
* @returns {Array<T | U>} The new array with the filled values.
|
|
12
10
|
*
|
|
13
11
|
* @example
|
|
@@ -29,7 +27,66 @@
|
|
|
29
27
|
* console.log(array); // [1, 2, 3, 4, 5]
|
|
30
28
|
*/
|
|
31
29
|
declare function toFilled<T, U>(arr: readonly T[], value: U): Array<T | U>;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new array filled with the specified value from the start position up to, but not including, the end position.
|
|
32
|
+
* This function does not mutate the original array.
|
|
33
|
+
*
|
|
34
|
+
* @template T - The type of elements in the original array.
|
|
35
|
+
* @template U - The type of the value to fill the new array with.
|
|
36
|
+
* @param {Array<T>} arr - The array to base the new array on.
|
|
37
|
+
* @param {U} value - The value to fill the new array with.
|
|
38
|
+
* @param {number} [start=0] - The start position. Defaults to 0.
|
|
39
|
+
* @returns {Array<T | U>} The new array with the filled values.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const array = [1, 2, 3, 4, 5];
|
|
43
|
+
* let result = toFilled(array, '*', 2);
|
|
44
|
+
* console.log(result); // [1, 2, '*', '*', '*']
|
|
45
|
+
* console.log(array); // [1, 2, 3, 4, 5]
|
|
46
|
+
*
|
|
47
|
+
* result = toFilled(array, '*', 1, 4);
|
|
48
|
+
* console.log(result); // [1, '*', '*', '*', 5]
|
|
49
|
+
* console.log(array); // [1, 2, 3, 4, 5]
|
|
50
|
+
*
|
|
51
|
+
* result = toFilled(array, '*');
|
|
52
|
+
* console.log(result); // ['*', '*', '*', '*', '*']
|
|
53
|
+
* console.log(array); // [1, 2, 3, 4, 5]
|
|
54
|
+
*
|
|
55
|
+
* result = toFilled(array, '*', -4, -1);
|
|
56
|
+
* console.log(result); // [1, '*', '*', '*', 5]
|
|
57
|
+
* console.log(array); // [1, 2, 3, 4, 5]
|
|
58
|
+
*/
|
|
32
59
|
declare function toFilled<T, U>(arr: readonly T[], value: U, start: number): Array<T | U>;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a new array filled with the specified value from the start position up to, but not including, the end position.
|
|
62
|
+
* This function does not mutate the original array.
|
|
63
|
+
*
|
|
64
|
+
* @template T - The type of elements in the original array.
|
|
65
|
+
* @template U - The type of the value to fill the new array with.
|
|
66
|
+
* @param {Array<T>} arr - The array to base the new array on.
|
|
67
|
+
* @param {U} value - The value to fill the new array with.
|
|
68
|
+
* @param {number} [start=0] - The start position. Defaults to 0.
|
|
69
|
+
* @param {number} [end=arr.length] - The end position. Defaults to the array's length.
|
|
70
|
+
* @returns {Array<T | U>} The new array with the filled values.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* const array = [1, 2, 3, 4, 5];
|
|
74
|
+
* let result = toFilled(array, '*', 2);
|
|
75
|
+
* console.log(result); // [1, 2, '*', '*', '*']
|
|
76
|
+
* console.log(array); // [1, 2, 3, 4, 5]
|
|
77
|
+
*
|
|
78
|
+
* result = toFilled(array, '*', 1, 4);
|
|
79
|
+
* console.log(result); // [1, '*', '*', '*', 5]
|
|
80
|
+
* console.log(array); // [1, 2, 3, 4, 5]
|
|
81
|
+
*
|
|
82
|
+
* result = toFilled(array, '*');
|
|
83
|
+
* console.log(result); // ['*', '*', '*', '*', '*']
|
|
84
|
+
* console.log(array); // [1, 2, 3, 4, 5]
|
|
85
|
+
*
|
|
86
|
+
* result = toFilled(array, '*', -4, -1);
|
|
87
|
+
* console.log(result); // [1, '*', '*', '*', 5]
|
|
88
|
+
* console.log(array); // [1, 2, 3, 4, 5]
|
|
89
|
+
*/
|
|
33
90
|
declare function toFilled<T, U>(arr: readonly T[], value: U, start: number, end: number): Array<T | U>;
|
|
34
91
|
|
|
35
92
|
export { toFilled };
|