@punks/backend-core 0.0.21 → 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) => {
@@ -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;