@punks/backend-core 0.0.64 → 0.0.66

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
@@ -386,6 +386,13 @@ const pluralize = (word) => {
386
386
  function sleep(ms) {
387
387
  return new Promise((resolve) => setTimeout(resolve, ms));
388
388
  }
389
+ const mapAsync = async (array, callback) => {
390
+ const result = [];
391
+ for (let i = 0; i < array.length; i++) {
392
+ result.push(await callback(array[i], i, array));
393
+ }
394
+ return result;
395
+ };
389
396
 
390
397
  const buildNode = async (record, { ancestors, nodesDict, childrenDict, nodeBuilder, }) => {
391
398
  const children = childrenDict.get(nodeBuilder.idSelector(record)) || [];
@@ -433,6 +440,55 @@ const newUuid = () => {
433
440
  });
434
441
  };
435
442
 
443
+ function serializeQueryString(obj) {
444
+ let queryString = "";
445
+ for (let key in obj) {
446
+ if (obj.hasOwnProperty(key) && obj[key]) {
447
+ if (queryString.length > 0) {
448
+ queryString += "&";
449
+ }
450
+ queryString += key + "=" + encodeURIComponent(obj[key]);
451
+ }
452
+ }
453
+ return queryString;
454
+ }
455
+ const buildUrl = (path, query) => {
456
+ const queryString = serializeQueryString(query);
457
+ return queryString ? `${path}?${queryString}` : path;
458
+ };
459
+ function deserializeQueryString(queryString) {
460
+ const obj = {};
461
+ const pairs = queryString.substring(1).split("&");
462
+ for (let i = 0; i < pairs.length; i++) {
463
+ const pair = pairs[i].split("=");
464
+ const key = decodeURIComponent(pair[0]);
465
+ const value = decodeURIComponent(pair[1] || "");
466
+ if (obj[key]) {
467
+ if (Array.isArray(obj[key])) {
468
+ obj[key].push(value);
469
+ }
470
+ else {
471
+ obj[key] = [obj[key], value];
472
+ }
473
+ }
474
+ else {
475
+ obj[key] = value;
476
+ }
477
+ }
478
+ return obj;
479
+ }
480
+ const getQueryParameter = (name, location = window.location) => {
481
+ const urlParams = deserializeQueryString(location.search);
482
+ return urlParams[name];
483
+ };
484
+ const updateQueryParameters = (queryString, params) => {
485
+ const queryParams = deserializeQueryString(queryString);
486
+ for (const [key, value] of Object.entries(params)) {
487
+ queryParams[key] = value;
488
+ }
489
+ return serializeQueryString(queryParams);
490
+ };
491
+
436
492
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
437
493
 
438
494
  function commonjsRequire (path) {
@@ -28722,6 +28778,7 @@ exports.Log = Log;
28722
28778
  exports.addTime = addTime;
28723
28779
  exports.buildObject = buildObject;
28724
28780
  exports.buildTree = buildTree;
28781
+ exports.buildUrl = buildUrl;
28725
28782
  exports.byField = byField;
28726
28783
  exports.byFieldDesc = byFieldDesc;
28727
28784
  exports.camelToKebabCase = camelToKebabCase;
@@ -28729,6 +28786,7 @@ exports.camelToSnakeCase = camelToSnakeCase;
28729
28786
  exports.createDayPath = createDayPath;
28730
28787
  exports.csvBuild = csvBuild;
28731
28788
  exports.csvParse = csvParse;
28789
+ exports.deserializeQueryString = deserializeQueryString;
28732
28790
  exports.distinct = distinct;
28733
28791
  exports.distinctElements = distinctElements;
28734
28792
  exports.ensureDirectory = ensureDirectory;
@@ -28740,6 +28798,7 @@ exports.first = first;
28740
28798
  exports.flatten = flatten;
28741
28799
  exports.getDirectoryFilePaths = getDirectoryFilePaths;
28742
28800
  exports.getDirectoryPath = getDirectoryPath;
28801
+ exports.getQueryParameter = getQueryParameter;
28743
28802
  exports.groupBy = groupBy;
28744
28803
  exports.indexes = indexes;
28745
28804
  exports.isNullOrUndefined = isNullOrUndefined;
@@ -28749,6 +28808,7 @@ exports.jsonDistinct = jsonDistinct;
28749
28808
  exports.jsonSerialize = jsonSerialize;
28750
28809
  exports.last = last;
28751
28810
  exports.logMemoryUsage = logMemoryUsage;
28811
+ exports.mapAsync = mapAsync;
28752
28812
  exports.mapOrThrow = mapOrThrow;
28753
28813
  exports.mergeDeep = mergeDeep;
28754
28814
  exports.newUuid = newUuid;
@@ -28760,6 +28820,7 @@ exports.processArrayItemMove = processArrayItemMove;
28760
28820
  exports.range = range;
28761
28821
  exports.removeUndefinedProps = removeUndefinedProps;
28762
28822
  exports.selectMany = selectMany;
28823
+ exports.serializeQueryString = serializeQueryString;
28763
28824
  exports.sleep = sleep;
28764
28825
  exports.sort = sort;
28765
28826
  exports.splitPath = splitPath;
@@ -28775,4 +28836,5 @@ exports.toTitleCase = toTitleCase;
28775
28836
  exports.trim = trim$1;
28776
28837
  exports.trimEnd = trimEnd;
28777
28838
  exports.trimStart = trimStart;
28839
+ exports.updateQueryParameters = updateQueryParameters;
28778
28840
  //# sourceMappingURL=index.js.map