@punks/backend-core 0.0.20 → 0.0.22

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[], selector: (value: TVal) => string) => Dict<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;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- export declare const csvParseRaw: (data: string | string[] | Buffer, separator?: string) => Record<string, any>[];
2
+ export declare const csvParse: (data: string | string[] | Buffer, separator?: string) => Record<string, any>[];
3
3
  export interface CsvColumnDefinition<T> {
4
4
  name: string;
5
5
  value: (item: T) => any;
@@ -1,5 +1,5 @@
1
1
  export * from "./array";
2
- export { CsvColumnDefinition as ColumnDefinition, CsvBuildOptions, csvBuild, csvParseRaw, } from "./csv";
2
+ export { CsvColumnDefinition as ColumnDefinition, CsvBuildOptions, csvBuild, csvParse, } from "./csv";
3
3
  export { getDirectoryFilePaths } from "./files";
4
4
  export { joinPath, splitPath, ensureDirectory, getDirectoryPath } from "./paths";
5
5
  export * from "./strings";
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, selector) => {
134
+ const toDict = (array, keySelector) => {
135
135
  const data = {};
136
136
  for (const item of array) {
137
- data[selector(item)] = item;
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) => {
@@ -211,7 +223,7 @@ const splitRows = (data) => {
211
223
  }
212
224
  return data;
213
225
  };
214
- const csvParseRaw = (data, separator = DEFAULT_DELIMITER) => {
226
+ const csvParse = (data, separator = DEFAULT_DELIMITER) => {
215
227
  const rows = splitRows(data);
216
228
  const records = [];
217
229
  if (rows.length === 0) {
@@ -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, csvParseRaw, 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