@punks/backend-core 0.0.21 → 0.0.23
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.
|
@@ -3,8 +3,10 @@ export declare const indexes: (startIndex: number, count: number) => number[];
|
|
|
3
3
|
export interface Dict<TVal> {
|
|
4
4
|
[key: string]: TVal;
|
|
5
5
|
}
|
|
6
|
-
export declare const toDict: <TVal>(array: TVal[],
|
|
6
|
+
export declare const toDict: <TVal>(array: TVal[], keySelector: (value: TVal) => string) => Dict<TVal>;
|
|
7
|
+
export declare const toItemsDict: <TItem, TVal>(array: TItem[], keySelector: (value: TItem) => string, elementSelector: (value: TItem) => TVal) => Dict<TVal>;
|
|
7
8
|
export declare const toMap: <TKey, TVal>(array: TVal[], key: (val: TVal) => TKey) => Map<TKey, TVal>;
|
|
9
|
+
export declare const toItemsMap: <TItem, TKey, TVal>(array: TItem[], key: (val: TItem) => TKey, element: (val: TItem) => TVal) => Map<TKey, TVal>;
|
|
8
10
|
export declare const last: <T>(arr: T[]) => T;
|
|
9
11
|
export declare const first: <T>(arr: T[]) => T;
|
|
10
12
|
type ArrayComparer<T> = (a: T, b: T) => number;
|
package/dist/esm/index.js
CHANGED
|
@@ -131,10 +131,17 @@ const range = (start, end) => {
|
|
|
131
131
|
return new Array(end - start + 1).fill(undefined).map((x, i) => i + start);
|
|
132
132
|
};
|
|
133
133
|
const indexes = (startIndex, count) => range(startIndex, startIndex + count - 1);
|
|
134
|
-
const toDict = (array,
|
|
134
|
+
const toDict = (array, keySelector) => {
|
|
135
135
|
const data = {};
|
|
136
136
|
for (const item of array) {
|
|
137
|
-
data[
|
|
137
|
+
data[keySelector(item)] = item;
|
|
138
|
+
}
|
|
139
|
+
return data;
|
|
140
|
+
};
|
|
141
|
+
const toItemsDict = (array, keySelector, elementSelector) => {
|
|
142
|
+
const data = {};
|
|
143
|
+
for (const item of array) {
|
|
144
|
+
data[keySelector(item)] = elementSelector(item);
|
|
138
145
|
}
|
|
139
146
|
return data;
|
|
140
147
|
};
|
|
@@ -143,6 +150,11 @@ const toMap = (array, key) => {
|
|
|
143
150
|
array.forEach((x) => map.set(key(x), x));
|
|
144
151
|
return map;
|
|
145
152
|
};
|
|
153
|
+
const toItemsMap = (array, key, element) => {
|
|
154
|
+
const map = new Map();
|
|
155
|
+
array.forEach((x) => map.set(key(x), element(x)));
|
|
156
|
+
return map;
|
|
157
|
+
};
|
|
146
158
|
const last = (arr) => arr[arr.length - 1];
|
|
147
159
|
const first = (arr) => arr[0];
|
|
148
160
|
const compareFields = (a, b, selector) => {
|
|
@@ -28334,5 +28346,5 @@ const excelParse = (file, options) => {
|
|
|
28334
28346
|
.map((x) => aggregateRow(header, x, options));
|
|
28335
28347
|
};
|
|
28336
28348
|
|
|
28337
|
-
export { ExcelKeyTransform, Log, LogLevel, byField, byFieldDesc, camelToKebabCase, camelToSnakeCase, csvBuild, csvParse, distinct, distinctElements, ensureDirectory, ensureStartSlash, ensureTailingSlash, excelBuild, excelParse, first, flatten, getDirectoryFilePaths, getDirectoryPath, indexes, isNullOrUndefined, iterate, joinPath, jsonDistinct, last, newUuid, notNull, notUndefined, pluralize, range, removeUndefinedProps, selectMany, sleep, sort, splitPath, toCamelCase, toDict, toMap, toTitleCase, trim$1 as trim, trimEnd, trimStart };
|
|
28349
|
+
export { ExcelKeyTransform, Log, LogLevel, byField, byFieldDesc, camelToKebabCase, camelToSnakeCase, csvBuild, csvParse, distinct, distinctElements, ensureDirectory, ensureStartSlash, ensureTailingSlash, excelBuild, excelParse, first, flatten, getDirectoryFilePaths, getDirectoryPath, indexes, isNullOrUndefined, iterate, joinPath, jsonDistinct, last, newUuid, notNull, notUndefined, pluralize, range, removeUndefinedProps, selectMany, sleep, sort, splitPath, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim$1 as trim, trimEnd, trimStart };
|
|
28338
28350
|
//# sourceMappingURL=index.js.map
|