@nu-art/ts-common 0.202.67 → 0.202.69
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/package.json +1 -1
- package/utils/array-tools.d.ts +11 -11
- package/utils/array-tools.js +2 -1
package/package.json
CHANGED
package/utils/array-tools.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NestedArrayType } from './types';
|
|
1
|
+
import { NestedArrayType, TypedMap } from './types';
|
|
2
2
|
export declare function filterInOut<T>(input: T[], filter: (object: T) => boolean): {
|
|
3
3
|
filteredIn: T[];
|
|
4
4
|
filteredOut: T[];
|
|
@@ -55,18 +55,17 @@ export declare function arrayToMap<T>(array: T[] | Readonly<T[]>, getKey: (item:
|
|
|
55
55
|
}): {
|
|
56
56
|
[k: string]: T;
|
|
57
57
|
};
|
|
58
|
-
|
|
59
|
-
* turns array into object that is similar to hashmap
|
|
60
|
-
* */
|
|
61
|
-
export declare function reduceToMap<Input, Output = Input>(array: (Input[] | Readonly<Input[]>), keyResolver: (item: Input, index: number, map: {
|
|
58
|
+
type KeyResolver<Input, Output = Input> = (item: Input, index: number, map: {
|
|
62
59
|
[k: string]: Output;
|
|
63
|
-
}) => string | number
|
|
64
|
-
|
|
65
|
-
}) => Output, map?: {
|
|
66
|
-
[k: string]: Output;
|
|
67
|
-
}): {
|
|
60
|
+
}) => string | number;
|
|
61
|
+
type Mapper<Input, Output = Input> = (item: Input, index: number, map: {
|
|
68
62
|
[k: string]: Output;
|
|
69
|
-
};
|
|
63
|
+
}) => Output;
|
|
64
|
+
/**
|
|
65
|
+
* turns array into object that is similar to hashmap
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
export declare function reduceToMap<Input, Output = Input>(array: (Input[] | Readonly<Input[]>), keyResolver: KeyResolver<Input, Output>, mapper: Mapper<Input, Output>, map?: TypedMap<Output>): TypedMap<Output>;
|
|
70
69
|
/**
|
|
71
70
|
* sorts array
|
|
72
71
|
* */
|
|
@@ -113,3 +112,4 @@ export declare function asOptionalArray<T extends any>(toBeArray?: T | T[]): T[]
|
|
|
113
112
|
export declare function lastElement<T extends any>(array: T[] | undefined): T | undefined;
|
|
114
113
|
export declare function firstElement<T extends any>(array?: T[]): T | undefined;
|
|
115
114
|
export declare function arrayIncludesAny<T extends any>(arr1: T[], arr2: T[]): boolean;
|
|
115
|
+
export {};
|
package/utils/array-tools.js
CHANGED
|
@@ -139,7 +139,8 @@ function arrayToMap(array, getKey, map = {}) {
|
|
|
139
139
|
exports.arrayToMap = arrayToMap;
|
|
140
140
|
/**
|
|
141
141
|
* turns array into object that is similar to hashmap
|
|
142
|
-
*
|
|
142
|
+
*
|
|
143
|
+
*/
|
|
143
144
|
function reduceToMap(array, keyResolver, mapper, map = {}) {
|
|
144
145
|
return array.reduce((toRet, element, index) => {
|
|
145
146
|
toRet[keyResolver(element, index, toRet)] = mapper(element, index, toRet);
|