@vanillaes/absurdum 2.0.7 → 2.0.11
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/README.md +3 -3
- package/index.d.ts +3 -3
- package/index.js +2 -0
- package/index.min.js +3 -3
- package/package.json +6 -13
- package/src/arrays/chunk.d.ts +5 -6
- package/src/arrays/chunk.js +6 -6
- package/src/arrays/compact.d.ts +4 -5
- package/src/arrays/compact.js +5 -6
- package/src/arrays/difference.d.ts +5 -6
- package/src/arrays/difference.js +6 -7
- package/src/arrays/drop.d.ts +5 -6
- package/src/arrays/drop.js +5 -6
- package/src/arrays/dropRight.d.ts +5 -6
- package/src/arrays/dropRight.js +5 -6
- package/src/arrays/fill.d.ts +6 -7
- package/src/arrays/fill.js +5 -6
- package/src/arrays/filter.d.ts +4 -5
- package/src/arrays/filter.js +5 -6
- package/src/arrays/find.d.ts +3 -4
- package/src/arrays/find.js +7 -6
- package/src/arrays/findIndex.d.ts +3 -4
- package/src/arrays/findIndex.js +3 -4
- package/src/arrays/findLastIndex.d.ts +3 -4
- package/src/arrays/findLastIndex.js +4 -5
- package/src/arrays/flat.d.ts +5 -6
- package/src/arrays/flat.js +5 -6
- package/src/arrays/frequency.d.ts +6 -5
- package/src/arrays/frequency.js +8 -7
- package/src/arrays/intersection.d.ts +5 -6
- package/src/arrays/intersection.js +7 -6
- package/src/arrays/map.d.ts +4 -5
- package/src/arrays/map.js +5 -6
- package/src/arrays/pull.d.ts +4 -5
- package/src/arrays/pull.js +5 -6
- package/src/arrays/take.d.ts +5 -6
- package/src/arrays/take.js +5 -6
- package/src/arrays/takeRight.d.ts +5 -6
- package/src/arrays/takeRight.js +5 -6
- package/src/arrays/union.d.ts +4 -5
- package/src/arrays/union.js +4 -5
- package/src/arrays/unique.d.ts +4 -5
- package/src/arrays/unique.js +4 -5
- package/src/arrays/unzip.d.ts +4 -5
- package/src/arrays/unzip.js +6 -5
- package/src/arrays/without.d.ts +4 -4
- package/src/arrays/without.js +5 -6
- package/src/arrays/xor.d.ts +4 -5
- package/src/arrays/xor.js +5 -6
- package/src/arrays/zip.d.ts +6 -7
- package/src/arrays/zip.js +7 -8
- package/src/objects/assign.d.ts +1 -3
- package/src/objects/assign.js +3 -3
- package/src/objects/at.d.ts +2 -4
- package/src/objects/at.js +3 -3
- package/src/objects/defaults.d.ts +1 -3
- package/src/objects/defaults.js +3 -3
- package/src/objects/defaultsDeep.d.ts +1 -3
- package/src/objects/defaultsDeep.js +3 -3
- package/src/objects/entries.d.ts +1 -3
- package/src/objects/entries.js +3 -3
- package/src/objects/filter.d.ts +3 -5
- package/src/objects/filter.js +2 -3
- package/src/objects/findKey.d.ts +2 -4
- package/src/objects/findKey.js +2 -3
- package/src/objects/findLastKey.d.ts +2 -4
- package/src/objects/findLastKey.js +2 -3
- package/src/objects/forIn.d.ts +3 -5
- package/src/objects/forIn.js +3 -4
- package/src/objects/fromEntries.d.ts +1 -3
- package/src/objects/fromEntries.js +3 -3
- package/src/objects/get.d.ts +1 -4
- package/src/objects/get.js +2 -3
- package/src/objects/has.d.ts +1 -4
- package/src/objects/has.js +3 -3
- package/src/objects/invert.d.ts +1 -3
- package/src/objects/invert.js +3 -3
- package/src/objects/mapKeys.d.ts +3 -5
- package/src/objects/mapKeys.js +2 -3
- package/src/objects/mapValues.d.ts +3 -5
- package/src/objects/mapValues.js +2 -3
- package/src/objects/merge.d.ts +1 -3
- package/src/objects/merge.js +3 -3
- package/src/objects/pick.d.ts +1 -3
- package/src/objects/pick.js +3 -3
- package/src/objects/result.d.ts +1 -4
- package/src/objects/result.js +2 -3
- package/src/objects/transform.d.ts +3 -5
- package/src/objects/transform.js +2 -3
- package/src/objects/values.d.ts +2 -4
- package/src/objects/values.js +3 -3
- package/src/strings/camelCase.d.ts +2 -4
- package/src/strings/camelCase.js +2 -4
- package/src/strings/chomp.d.ts +1 -4
- package/src/strings/chomp.js +1 -3
- package/src/strings/deburr.d.ts +2 -4
- package/src/strings/deburr.js +3 -4
- package/src/strings/endsWith.d.ts +1 -4
- package/src/strings/endsWith.js +3 -3
- package/src/strings/includes.d.ts +1 -3
- package/src/strings/includes.js +1 -3
- package/src/strings/kebabCase.d.ts +2 -4
- package/src/strings/kebabCase.js +2 -4
- package/src/strings/pad.d.ts +2 -6
- package/src/strings/pad.js +1 -3
- package/src/strings/padEnd.d.ts +2 -6
- package/src/strings/padEnd.js +2 -4
- package/src/strings/padStart.d.ts +2 -6
- package/src/strings/padStart.js +2 -4
- package/src/strings/pascalCase.d.ts +2 -4
- package/src/strings/pascalCase.js +2 -4
- package/src/strings/repeat.d.ts +1 -3
- package/src/strings/repeat.js +1 -3
- package/src/strings/reverse.d.ts +0 -2
- package/src/strings/reverse.js +1 -3
- package/src/strings/snakeCase.d.ts +2 -4
- package/src/strings/snakeCase.js +2 -4
- package/src/strings/startsWith.d.ts +0 -3
- package/src/strings/startsWith.js +3 -3
- package/src/strings/trimEnd.d.ts +3 -5
- package/src/strings/trimEnd.js +2 -4
- package/src/strings/trimStart.d.ts +3 -5
- package/src/strings/trimStart.js +2 -4
- package/src/strings/truncate.d.ts +9 -11
- package/src/strings/truncate.js +3 -5
- package/src/strings/words.d.ts +3 -7
- package/src/strings/words.js +3 -5
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* FindLastIndex method returns the value of Last element at which a provided function is true,
|
|
3
3
|
* or undefined if no elements in the array satisfy the function.
|
|
4
|
-
*
|
|
5
|
-
* @param {
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {T[]} array input array
|
|
6
6
|
* @param {Function} predicate to be run against each element of the array
|
|
7
7
|
* @param {*} [thisArg] this argument in the function
|
|
8
8
|
* @returns {*} value of element that satisfied function.
|
|
9
|
-
*
|
|
10
9
|
* @example
|
|
11
10
|
* const result = arrays.findLastIndex([5, 12, 8, 130, 44], (x) => x < 10);
|
|
12
11
|
* console.log(result);
|
|
@@ -16,4 +15,4 @@
|
|
|
16
15
|
* console.log(result);
|
|
17
16
|
* > 3
|
|
18
17
|
*/
|
|
19
|
-
export function findLastIndex(array:
|
|
18
|
+
export function findLastIndex<T>(array: T[], predicate: Function, thisArg?: any): any;
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* FindLastIndex method returns the value of Last element at which a provided function is true,
|
|
5
5
|
* or undefined if no elements in the array satisfy the function.
|
|
6
|
-
* @
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {T[]} array input array
|
|
7
8
|
* @param {Function} predicate to be run against each element of the array
|
|
8
9
|
* @param {*} [thisArg] this argument in the function
|
|
9
10
|
* @returns {*} value of element that satisfied function.
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
* console.log(result);
|
|
17
18
|
* > 3
|
|
18
19
|
*/
|
|
19
|
-
function findLastIndex (array, predicate, thisArg) {
|
|
20
|
+
export function findLastIndex (array, predicate, thisArg) {
|
|
20
21
|
if (array.length === 0) return -1
|
|
21
22
|
if (typeof predicate !== 'function') { throw TypeError('predicate must be a function') }
|
|
22
23
|
if (predicate.call(thisArg, array[array.length - 1])) return array.length - 1
|
|
@@ -26,7 +27,5 @@ function findLastIndex (array, predicate, thisArg) {
|
|
|
26
27
|
if (i === array.length - 2) return predicate.call(thisArg, cur) ? i : -1
|
|
27
28
|
if (res < 0 && predicate.call(thisArg, cur)) return i
|
|
28
29
|
return res
|
|
29
|
-
})
|
|
30
|
+
}, -1)
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
export { findLastIndex }
|
package/src/arrays/flat.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flat flattens an array of nested arrays
|
|
3
|
-
*
|
|
4
|
-
* @param {
|
|
5
|
-
* @param {number} [depth
|
|
6
|
-
* @returns {
|
|
7
|
-
*
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} array input array
|
|
5
|
+
* @param {number} [depth] depth of array elements to flat (default 1)
|
|
6
|
+
* @returns {T[]} the flattened array
|
|
8
7
|
* @example
|
|
9
8
|
* const result = arrays.flat([1, [2, [3, [4]]]]);
|
|
10
9
|
* console.log(result);
|
|
11
10
|
* > [1, 2, [3, [4]]]
|
|
12
11
|
*/
|
|
13
|
-
export function flat(array:
|
|
12
|
+
export function flat<T>(array: T[], depth?: number): T[];
|
package/src/arrays/flat.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flat flattens an array of nested arrays
|
|
3
|
-
* @
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} array input array
|
|
4
5
|
* @param {number} [depth] depth of array elements to flat (default 1)
|
|
5
|
-
* @returns {
|
|
6
|
+
* @returns {T[]} the flattened array
|
|
6
7
|
* @example
|
|
7
8
|
* const result = arrays.flat([1, [2, [3, [4]]]]);
|
|
8
9
|
* console.log(result);
|
|
9
10
|
* > [1, 2, [3, [4]]]
|
|
10
11
|
*/
|
|
11
|
-
function flat (array, depth = 1) {
|
|
12
|
-
return array.reduce((acc, curr) => {
|
|
12
|
+
export function flat (array, depth = 1) {
|
|
13
|
+
return array.reduce((/** @type {T[]} */ acc, curr) => {
|
|
13
14
|
if (Array.isArray(curr) && depth > 0) {
|
|
14
15
|
acc.push(...flat(curr, depth - 1))
|
|
15
16
|
} else {
|
|
@@ -18,5 +19,3 @@ function flat (array, depth = 1) {
|
|
|
18
19
|
return acc
|
|
19
20
|
}, [])
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
export { flat }
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Frequency returns an object mapping each unique item in an array
|
|
3
3
|
* to the number of items it occurs in the array.
|
|
4
|
-
*
|
|
5
|
-
* @param {
|
|
6
|
-
* @returns {
|
|
7
|
-
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {T[]} array input array
|
|
6
|
+
* @returns {{[key: T]: number}} object of uniq values and their frequency of occurrence
|
|
8
7
|
* @example
|
|
9
8
|
* const result = arrays.frequency(['a', 'b', 'a', 'c', 'a', 'c', 'b']);
|
|
10
9
|
* console.log(result)
|
|
11
10
|
* > { a: 3, b: 2, c: 2 }
|
|
12
11
|
*/
|
|
13
|
-
export function frequency(array:
|
|
12
|
+
export function frequency<T>(array: T[]): {
|
|
13
|
+
[key: T]: number;
|
|
14
|
+
};
|
package/src/arrays/frequency.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/check-types */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Frequency returns an object mapping each unique item in an array
|
|
3
5
|
* to the number of items it occurs in the array.
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {T[]} array input array
|
|
8
|
+
* @returns {{[key: T]: number}} object of uniq values and their frequency of occurrence
|
|
6
9
|
* @example
|
|
7
10
|
* const result = arrays.frequency(['a', 'b', 'a', 'c', 'a', 'c', 'b']);
|
|
8
11
|
* console.log(result)
|
|
9
12
|
* > { a: 3, b: 2, c: 2 }
|
|
10
13
|
*/
|
|
11
|
-
function frequency (array) {
|
|
12
|
-
return array.reduce((acc, curr) => {
|
|
13
|
-
acc[curr] = acc[curr] ?
|
|
14
|
+
export function frequency (array) {
|
|
15
|
+
return array.reduce((/** @type {Object.<T, number>} */ acc, curr) => {
|
|
16
|
+
acc[curr] = acc[curr] ? acc[curr] += 1 : 1
|
|
14
17
|
return acc
|
|
15
18
|
}, {})
|
|
16
19
|
}
|
|
17
|
-
|
|
18
|
-
export { frequency }
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Intersection creates an array of unique values that are included in all given arrays
|
|
3
|
-
*
|
|
4
|
-
* @param {
|
|
5
|
-
* @returns {
|
|
6
|
-
*
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} arrays input array(s)
|
|
5
|
+
* @returns {T[]} an array containing the unique intersecting values between all input arrays
|
|
7
6
|
* @example
|
|
8
|
-
* const result = arrays.intersection([4, 2, 1], [2, 3, 4])
|
|
7
|
+
* const result = arrays.intersection([4, 2, 1], [2, 3, 4]);
|
|
9
8
|
* console.log(result);
|
|
10
9
|
* > [4, 2]
|
|
11
10
|
*/
|
|
12
|
-
export function intersection(...arrays:
|
|
11
|
+
export function intersection<T>(...arrays: T[]): T[];
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Intersection creates an array of unique values that are included in all given arrays
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
5
|
+
* @template T
|
|
6
|
+
* @param {T[]} arrays input array(s)
|
|
7
|
+
* @returns {T[]} an array containing the unique intersecting values between all input arrays
|
|
5
8
|
* @example
|
|
6
|
-
* const result = arrays.intersection([4, 2, 1], [2, 3, 4])
|
|
9
|
+
* const result = arrays.intersection([4, 2, 1], [2, 3, 4]);
|
|
7
10
|
* console.log(result);
|
|
8
11
|
* > [4, 2]
|
|
9
12
|
*/
|
|
10
|
-
function intersection (...arrays) {
|
|
13
|
+
export function intersection (...arrays) {
|
|
11
14
|
return [...new Set(arguments[0])].reduce((acc, curr) => {
|
|
12
15
|
if (arrays.slice(1).reduce((every, array, i) => {
|
|
13
16
|
if (every && !new Set(array).has(curr)) return false
|
|
@@ -18,5 +21,3 @@ function intersection (...arrays) {
|
|
|
18
21
|
return acc
|
|
19
22
|
}, [])
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
export { intersection }
|
package/src/arrays/map.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Map iterates over an array of values and applies a function to each value
|
|
3
|
-
*
|
|
4
|
-
* @param {
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} array input array
|
|
5
5
|
* @param {Function} func function describing how to map values
|
|
6
|
-
* @returns {
|
|
7
|
-
*
|
|
6
|
+
* @returns {T[]} array of mutated values
|
|
8
7
|
* @example
|
|
9
8
|
* const result = arrays.map([1, 2, 3, 4], (x) => x + 2);
|
|
10
9
|
* console.log(result)
|
|
11
10
|
* > [ 3, 4, 5, 6 ]
|
|
12
11
|
*/
|
|
13
|
-
export function map(array:
|
|
12
|
+
export function map<T>(array: T[], func: Function): T[];
|
package/src/arrays/map.js
CHANGED
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Map iterates over an array of values and applies a function to each value
|
|
5
|
-
* @
|
|
5
|
+
* @template T
|
|
6
|
+
* @param {T[]} array input array
|
|
6
7
|
* @param {Function} func function describing how to map values
|
|
7
|
-
* @returns {
|
|
8
|
+
* @returns {T[]} array of mutated values
|
|
8
9
|
* @example
|
|
9
10
|
* const result = arrays.map([1, 2, 3, 4], (x) => x + 2);
|
|
10
11
|
* console.log(result)
|
|
11
12
|
* > [ 3, 4, 5, 6 ]
|
|
12
13
|
*/
|
|
13
|
-
function map (array, func) {
|
|
14
|
+
export function map (array, func) {
|
|
14
15
|
if (!func) { return array }
|
|
15
|
-
return array.reduce((acc, curr) => {
|
|
16
|
+
return array.reduce((/** @type {T[]} */ acc, curr) => {
|
|
16
17
|
acc.push(func(curr))
|
|
17
18
|
return acc
|
|
18
19
|
}, [])
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
export { map }
|
package/src/arrays/pull.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pull removes all of the given values from an array
|
|
3
|
-
*
|
|
4
|
-
* @param {
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} array input array
|
|
5
5
|
* @param {...*} values values to be removed from the array
|
|
6
|
-
* @returns {
|
|
7
|
-
*
|
|
6
|
+
* @returns {T[]} array of with values removed
|
|
8
7
|
* @example
|
|
9
8
|
* const result = arrays.pull([1, 2, 3, 4], 2, 4);
|
|
10
9
|
* console.log(result)
|
|
11
10
|
* > [1, 3]
|
|
12
11
|
*/
|
|
13
|
-
export function pull(array:
|
|
12
|
+
export function pull<T>(array: T[], ...values: any[]): T[];
|
package/src/arrays/pull.js
CHANGED
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Pull removes all of the given values from an array
|
|
5
|
-
* @
|
|
5
|
+
* @template T
|
|
6
|
+
* @param {T[]} array input array
|
|
6
7
|
* @param {...*} values values to be removed from the array
|
|
7
|
-
* @returns {
|
|
8
|
+
* @returns {T[]} array of with values removed
|
|
8
9
|
* @example
|
|
9
10
|
* const result = arrays.pull([1, 2, 3, 4], 2, 4);
|
|
10
11
|
* console.log(result)
|
|
11
12
|
* > [1, 3]
|
|
12
13
|
*/
|
|
13
|
-
function pull (array, ...values) {
|
|
14
|
+
export function pull (array, ...values) {
|
|
14
15
|
const valueSet = new Set(values)
|
|
15
|
-
return array.reduce((acc, curr) => {
|
|
16
|
+
return array.reduce((/** @type {T[]} */ acc, curr) => {
|
|
16
17
|
if (!valueSet.has(curr)) { acc.push(curr) }
|
|
17
18
|
return acc
|
|
18
19
|
}, [])
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
export { pull }
|
package/src/arrays/take.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Take method returns a slice of array with 'count' number of elements from the beginning
|
|
3
|
-
*
|
|
4
|
-
* @param {
|
|
5
|
-
* @param {
|
|
6
|
-
* @returns {
|
|
7
|
-
*
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} array input array
|
|
5
|
+
* @param {number} [count] number of elements in the slice of the array (default 1)
|
|
6
|
+
* @returns {T[]} the slice of the array of length 'count'
|
|
8
7
|
* @example
|
|
9
8
|
* const result = arrays.take(['Amy', 'Brie', 'Cam', 'Dimitri']);
|
|
10
9
|
* console.log(result);
|
|
@@ -14,4 +13,4 @@
|
|
|
14
13
|
* console.log(result);
|
|
15
14
|
* > ['Amy', 'Brie', 'Cam']
|
|
16
15
|
*/
|
|
17
|
-
export function take(array:
|
|
16
|
+
export function take<T>(array: T[], count?: number): T[];
|
package/src/arrays/take.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Take method returns a slice of array with 'count' number of elements from the beginning
|
|
3
|
-
* @
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} array input array
|
|
4
5
|
* @param {number} [count] number of elements in the slice of the array (default 1)
|
|
5
|
-
* @returns {
|
|
6
|
+
* @returns {T[]} the slice of the array of length 'count'
|
|
6
7
|
* @example
|
|
7
8
|
* const result = arrays.take(['Amy', 'Brie', 'Cam', 'Dimitri']);
|
|
8
9
|
* console.log(result);
|
|
@@ -12,11 +13,9 @@
|
|
|
12
13
|
* console.log(result);
|
|
13
14
|
* > ['Amy', 'Brie', 'Cam']
|
|
14
15
|
*/
|
|
15
|
-
function take (array, count = 1) {
|
|
16
|
-
return array.reduce((res, cur, i) => {
|
|
16
|
+
export function take (array, count = 1) {
|
|
17
|
+
return array.reduce((/** @type {T[]} */ res, cur, i) => {
|
|
17
18
|
if (i < count) { res.push(cur) }
|
|
18
19
|
return res
|
|
19
20
|
}, [])
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
export { take }
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Take method returns a slice of array with 'count' number of elements from the end of the array
|
|
3
|
-
*
|
|
4
|
-
* @param {
|
|
5
|
-
* @param {
|
|
6
|
-
* @returns {
|
|
7
|
-
*
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} array input array
|
|
5
|
+
* @param {number} [count] number of elements in the slice of the array (default 1)
|
|
6
|
+
* @returns {T[]} the slice of the array of length 'count'
|
|
8
7
|
* @example
|
|
9
8
|
* const result = arrays.some(['Amy', 'Brie', 'Cam', 'Dimitri']);
|
|
10
9
|
* console.log(result);
|
|
@@ -14,4 +13,4 @@
|
|
|
14
13
|
* console.log(result);
|
|
15
14
|
* > ['Brie', 'Cam', 'Dimitri']
|
|
16
15
|
*/
|
|
17
|
-
export function takeRight(array:
|
|
16
|
+
export function takeRight<T>(array: T[], count?: number): T[];
|
package/src/arrays/takeRight.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Take method returns a slice of array with 'count' number of elements from the end of the array
|
|
3
|
-
* @
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} array input array
|
|
4
5
|
* @param {number} [count] number of elements in the slice of the array (default 1)
|
|
5
|
-
* @returns {
|
|
6
|
+
* @returns {T[]} the slice of the array of length 'count'
|
|
6
7
|
* @example
|
|
7
8
|
* const result = arrays.some(['Amy', 'Brie', 'Cam', 'Dimitri']);
|
|
8
9
|
* console.log(result);
|
|
@@ -12,12 +13,10 @@
|
|
|
12
13
|
* console.log(result);
|
|
13
14
|
* > ['Brie', 'Cam', 'Dimitri']
|
|
14
15
|
*/
|
|
15
|
-
function takeRight (array, count = 1) {
|
|
16
|
+
export function takeRight (array, count = 1) {
|
|
16
17
|
const start = array.length - 1 - count
|
|
17
|
-
return array.reduce((res, cur, i) => {
|
|
18
|
+
return array.reduce((/** @type {T[]} */ res, cur, i) => {
|
|
18
19
|
if (i > start) { res.push(cur) }
|
|
19
20
|
return res
|
|
20
21
|
}, [])
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
export { takeRight }
|
package/src/arrays/union.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Union creates an array of unique elements from all given arrays in order encountered
|
|
3
|
-
*
|
|
4
|
-
* @param {
|
|
5
|
-
* @returns {
|
|
6
|
-
*
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} arrays input arrays
|
|
5
|
+
* @returns {T[]} an array of unique elements from all given arrays
|
|
7
6
|
* @example
|
|
8
7
|
* const result = arrays.union([2], [1, 2, 3, 1]);
|
|
9
8
|
* > [2, 1, 3]
|
|
10
9
|
*/
|
|
11
|
-
export function union(...arrays:
|
|
10
|
+
export function union<T>(...arrays: T[]): T[];
|
package/src/arrays/union.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Union creates an array of unique elements from all given arrays in order encountered
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} arrays input arrays
|
|
5
|
+
* @returns {T[]} an array of unique elements from all given arrays
|
|
5
6
|
* @example
|
|
6
7
|
* const result = arrays.union([2], [1, 2, 3, 1]);
|
|
7
8
|
* > [2, 1, 3]
|
|
8
9
|
*/
|
|
9
|
-
function union (...arrays) {
|
|
10
|
+
export function union (...arrays) {
|
|
10
11
|
return Array.from([...arrays].reduce((acc, curr) => {
|
|
11
12
|
if (Array.isArray(curr)) {
|
|
12
13
|
curr.reduce((res, cur) => {
|
|
@@ -17,5 +18,3 @@ function union (...arrays) {
|
|
|
17
18
|
return acc
|
|
18
19
|
}, new Set()))
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
export { union }
|
package/src/arrays/unique.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Removes all duplicate items of an array
|
|
3
|
-
*
|
|
4
|
-
* @param {
|
|
5
|
-
* @returns {
|
|
6
|
-
*
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} array input array
|
|
5
|
+
* @returns {T[]} an array of unique values
|
|
7
6
|
* @example
|
|
8
7
|
* const result = arrays.unique([2, 1, 2]);
|
|
9
8
|
* console.log(result);
|
|
10
9
|
* > [2, 1]
|
|
11
10
|
*/
|
|
12
|
-
export function unique(array:
|
|
11
|
+
export function unique<T>(array: T[]): T[];
|
package/src/arrays/unique.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Removes all duplicate items of an array
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} array input array
|
|
5
|
+
* @returns {T[]} an array of unique values
|
|
5
6
|
* @example
|
|
6
7
|
* const result = arrays.unique([2, 1, 2]);
|
|
7
8
|
* console.log(result);
|
|
8
9
|
* > [2, 1]
|
|
9
10
|
*/
|
|
10
|
-
function unique (array) {
|
|
11
|
+
export function unique (array) {
|
|
11
12
|
return [...array.reduce((acc, curr) => {
|
|
12
13
|
acc.add(curr)
|
|
13
14
|
return acc
|
|
14
15
|
}, new Set())]
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
export { unique }
|
package/src/arrays/unzip.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Performs a manipulation to undo the zip command
|
|
3
|
-
*
|
|
4
|
-
* @param {
|
|
5
|
-
* @returns {
|
|
6
|
-
*
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} array input array
|
|
5
|
+
* @returns {T[]} an array of unique values
|
|
7
6
|
* @example
|
|
8
7
|
* const result = arrays.unzip([['a', 'b', 'c'], [1, 2, 3], [true, false, true]]);
|
|
9
8
|
* console.log(result);
|
|
10
9
|
* > [['a', 1, true], ['b', 2, false], ['c', 3, true]]
|
|
11
10
|
*/
|
|
12
|
-
export function unzip(array:
|
|
11
|
+
export function unzip<T>(array: T[]): T[];
|
package/src/arrays/unzip.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
// @ts-nocheck TODO: Fix types on this later
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Performs a manipulation to undo the zip command
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
5
|
+
* @template T
|
|
6
|
+
* @param {T[]} array input array
|
|
7
|
+
* @returns {T[]} an array of unique values
|
|
5
8
|
* @example
|
|
6
9
|
* const result = arrays.unzip([['a', 'b', 'c'], [1, 2, 3], [true, false, true]]);
|
|
7
10
|
* console.log(result);
|
|
8
11
|
* > [['a', 1, true], ['b', 2, false], ['c', 3, true]]
|
|
9
12
|
*/
|
|
10
|
-
function unzip (array) {
|
|
13
|
+
export function unzip (array) {
|
|
11
14
|
const res = new Array(array.reduce((acc, curr) => {
|
|
12
15
|
return curr.length > acc ? curr.length : acc
|
|
13
16
|
}, 0)).fill(undefined)
|
|
@@ -21,5 +24,3 @@ function unzip (array) {
|
|
|
21
24
|
return acc
|
|
22
25
|
}, [])
|
|
23
26
|
}
|
|
24
|
-
|
|
25
|
-
export { unzip }
|
package/src/arrays/without.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Without, returns an array with all values parameters removed from the input array
|
|
3
|
-
*
|
|
4
|
-
* @param {
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T[]} array input array
|
|
5
5
|
* @param {...*} values input values
|
|
6
|
-
* @returns {
|
|
6
|
+
* @returns {T[]} an array of unique values
|
|
7
7
|
* @example
|
|
8
8
|
* const result = arrays.without(['a', 'b', 'c', ['d']], 'b', ['d']);
|
|
9
9
|
* console.log(result);
|
|
10
10
|
* > ['a', 'c', ['d']]
|
|
11
11
|
*/
|
|
12
|
-
export function without(array:
|
|
12
|
+
export function without<T>(array: T[], ...values: any[]): T[];
|
package/src/arrays/without.js
CHANGED
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Without, returns an array with all values parameters removed from the input array
|
|
5
|
-
* @
|
|
5
|
+
* @template T
|
|
6
|
+
* @param {T[]} array input array
|
|
6
7
|
* @param {...*} values input values
|
|
7
|
-
* @returns {
|
|
8
|
+
* @returns {T[]} an array of unique values
|
|
8
9
|
* @example
|
|
9
10
|
* const result = arrays.without(['a', 'b', 'c', ['d']], 'b', ['d']);
|
|
10
11
|
* console.log(result);
|
|
11
12
|
* > ['a', 'c', ['d']]
|
|
12
13
|
*/
|
|
13
|
-
function without (array, ...values) {
|
|
14
|
+
export function without (array, ...values) {
|
|
14
15
|
const toExclude = new Set(values)
|
|
15
|
-
return array.reduce((acc, curr) => {
|
|
16
|
+
return array.reduce((/** @type {T[]} */ acc, curr) => {
|
|
16
17
|
if (!toExclude.has(curr)) { acc.push(curr) }
|
|
17
18
|
return acc
|
|
18
19
|
}, [])
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
export { without }
|
package/src/arrays/xor.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates an array of unique values that is the symmetric difference of the given arrays
|
|
3
|
-
*
|
|
4
|
-
* @param {...
|
|
5
|
-
* @returns {
|
|
6
|
-
*
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {...T[]} arrays input arrays
|
|
5
|
+
* @returns {T[]} an array of unique values
|
|
7
6
|
* @example
|
|
8
7
|
* const result = arrays.xor(['a', 1, [5]], ['b', 1, 'a'], ['b', 'c', 5]);
|
|
9
8
|
* console.log(result);
|
|
10
9
|
* > [[5], 'c', 5]
|
|
11
10
|
*/
|
|
12
|
-
export function xor(...arrays:
|
|
11
|
+
export function xor<T>(...arrays: T[][]): T[];
|
package/src/arrays/xor.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates an array of unique values that is the symmetric difference of the given arrays
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {...T[]} arrays input arrays
|
|
5
|
+
* @returns {T[]} an array of unique values
|
|
5
6
|
* @example
|
|
6
7
|
* const result = arrays.xor(['a', 1, [5]], ['b', 1, 'a'], ['b', 'c', 5]);
|
|
7
8
|
* console.log(result);
|
|
8
9
|
* > [[5], 'c', 5]
|
|
9
10
|
*/
|
|
10
|
-
function xor (...arrays) {
|
|
11
|
+
export function xor (...arrays) {
|
|
11
12
|
if (arrays.length < 2) {
|
|
12
13
|
if (arrays.length === 0) { return [] }
|
|
13
14
|
return arrays[0]
|
|
@@ -15,7 +16,7 @@ function xor (...arrays) {
|
|
|
15
16
|
|
|
16
17
|
const duplicates = new Set()
|
|
17
18
|
const allUniq = arrays.reduce((collect, array) => {
|
|
18
|
-
const checker = array.reduce((acc, curr) => {
|
|
19
|
+
const checker = array.reduce((/** @type {T[]} */ acc, curr) => {
|
|
19
20
|
if (collect.has(curr)) { acc.push(curr) }
|
|
20
21
|
return acc
|
|
21
22
|
}, [])
|
|
@@ -27,5 +28,3 @@ function xor (...arrays) {
|
|
|
27
28
|
duplicates.forEach(val => allUniq.delete(val))
|
|
28
29
|
return [...allUniq]
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
export { xor }
|
package/src/arrays/zip.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Zip applies a specified function to the corresponding elements of two sequences,
|
|
3
3
|
* producing a sequence of the results.
|
|
4
|
-
*
|
|
5
|
-
* @param {
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {Function} [func
|
|
8
|
-
* @returns {
|
|
9
|
-
*
|
|
4
|
+
* @template T
|
|
5
|
+
* @param {T[]} arrayA input array
|
|
6
|
+
* @param {T[]} ArrayB input array
|
|
7
|
+
* @param {Function} [func] to be applied to corresponding values (default (a, b)=>[a, b])
|
|
8
|
+
* @returns {T[]} input array filled value pairs after the function has been applied
|
|
10
9
|
* @example
|
|
11
10
|
* const result = zip([5, 12, 8, 130, 44], ["ham", "cheese", "bread"]);
|
|
12
11
|
* console.log(result)
|
|
@@ -16,4 +15,4 @@
|
|
|
16
15
|
* console.log(result)
|
|
17
16
|
* > [ 'ham 5', 'cheese 12', 'bread 8' ]
|
|
18
17
|
*/
|
|
19
|
-
export function zip(arrayA:
|
|
18
|
+
export function zip<T>(arrayA: T[], ArrayB: T[], func?: Function): T[];
|