@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.
package/dist/cjs/index.js CHANGED
@@ -140,10 +140,17 @@ const range = (start, end) => {
140
140
  return new Array(end - start + 1).fill(undefined).map((x, i) => i + start);
141
141
  };
142
142
  const indexes = (startIndex, count) => range(startIndex, startIndex + count - 1);
143
- const toDict = (array, selector) => {
143
+ const toDict = (array, keySelector) => {
144
144
  const data = {};
145
145
  for (const item of array) {
146
- data[selector(item)] = item;
146
+ data[keySelector(item)] = item;
147
+ }
148
+ return data;
149
+ };
150
+ const toItemsDict = (array, keySelector, elementSelector) => {
151
+ const data = {};
152
+ for (const item of array) {
153
+ data[keySelector(item)] = elementSelector(item);
147
154
  }
148
155
  return data;
149
156
  };
@@ -152,6 +159,11 @@ const toMap = (array, key) => {
152
159
  array.forEach((x) => map.set(key(x), x));
153
160
  return map;
154
161
  };
162
+ const toItemsMap = (array, key, element) => {
163
+ const map = new Map();
164
+ array.forEach((x) => map.set(key(x), element(x)));
165
+ return map;
166
+ };
155
167
  const last = (arr) => arr[arr.length - 1];
156
168
  const first = (arr) => arr[0];
157
169
  const compareFields = (a, b, selector) => {
@@ -220,7 +232,7 @@ const splitRows = (data) => {
220
232
  }
221
233
  return data;
222
234
  };
223
- const csvParseRaw = (data, separator = DEFAULT_DELIMITER) => {
235
+ const csvParse = (data, separator = DEFAULT_DELIMITER) => {
224
236
  const rows = splitRows(data);
225
237
  const records = [];
226
238
  if (rows.length === 0) {
@@ -28349,7 +28361,7 @@ exports.byFieldDesc = byFieldDesc;
28349
28361
  exports.camelToKebabCase = camelToKebabCase;
28350
28362
  exports.camelToSnakeCase = camelToSnakeCase;
28351
28363
  exports.csvBuild = csvBuild;
28352
- exports.csvParseRaw = csvParseRaw;
28364
+ exports.csvParse = csvParse;
28353
28365
  exports.distinct = distinct;
28354
28366
  exports.distinctElements = distinctElements;
28355
28367
  exports.ensureDirectory = ensureDirectory;
@@ -28379,6 +28391,8 @@ exports.sort = sort;
28379
28391
  exports.splitPath = splitPath;
28380
28392
  exports.toCamelCase = toCamelCase;
28381
28393
  exports.toDict = toDict;
28394
+ exports.toItemsDict = toItemsDict;
28395
+ exports.toItemsMap = toItemsMap;
28382
28396
  exports.toMap = toMap;
28383
28397
  exports.toTitleCase = toTitleCase;
28384
28398
  exports.trim = trim$1;