@punks/backend-core 0.0.64 → 0.0.65

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
@@ -433,6 +433,55 @@ const newUuid = () => {
433
433
  });
434
434
  };
435
435
 
436
+ function serializeQueryString(obj) {
437
+ let queryString = "";
438
+ for (let key in obj) {
439
+ if (obj.hasOwnProperty(key) && obj[key]) {
440
+ if (queryString.length > 0) {
441
+ queryString += "&";
442
+ }
443
+ queryString += key + "=" + encodeURIComponent(obj[key]);
444
+ }
445
+ }
446
+ return queryString;
447
+ }
448
+ const buildUrl = (path, query) => {
449
+ const queryString = serializeQueryString(query);
450
+ return queryString ? `${path}?${queryString}` : path;
451
+ };
452
+ function deserializeQueryString(queryString) {
453
+ const obj = {};
454
+ const pairs = queryString.substring(1).split("&");
455
+ for (let i = 0; i < pairs.length; i++) {
456
+ const pair = pairs[i].split("=");
457
+ const key = decodeURIComponent(pair[0]);
458
+ const value = decodeURIComponent(pair[1] || "");
459
+ if (obj[key]) {
460
+ if (Array.isArray(obj[key])) {
461
+ obj[key].push(value);
462
+ }
463
+ else {
464
+ obj[key] = [obj[key], value];
465
+ }
466
+ }
467
+ else {
468
+ obj[key] = value;
469
+ }
470
+ }
471
+ return obj;
472
+ }
473
+ const getQueryParameter = (name, location = window.location) => {
474
+ const urlParams = deserializeQueryString(location.search);
475
+ return urlParams[name];
476
+ };
477
+ const updateQueryParameters = (queryString, params) => {
478
+ const queryParams = deserializeQueryString(queryString);
479
+ for (const [key, value] of Object.entries(params)) {
480
+ queryParams[key] = value;
481
+ }
482
+ return serializeQueryString(queryParams);
483
+ };
484
+
436
485
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
437
486
 
438
487
  function commonjsRequire (path) {
@@ -28722,6 +28771,7 @@ exports.Log = Log;
28722
28771
  exports.addTime = addTime;
28723
28772
  exports.buildObject = buildObject;
28724
28773
  exports.buildTree = buildTree;
28774
+ exports.buildUrl = buildUrl;
28725
28775
  exports.byField = byField;
28726
28776
  exports.byFieldDesc = byFieldDesc;
28727
28777
  exports.camelToKebabCase = camelToKebabCase;
@@ -28729,6 +28779,7 @@ exports.camelToSnakeCase = camelToSnakeCase;
28729
28779
  exports.createDayPath = createDayPath;
28730
28780
  exports.csvBuild = csvBuild;
28731
28781
  exports.csvParse = csvParse;
28782
+ exports.deserializeQueryString = deserializeQueryString;
28732
28783
  exports.distinct = distinct;
28733
28784
  exports.distinctElements = distinctElements;
28734
28785
  exports.ensureDirectory = ensureDirectory;
@@ -28740,6 +28791,7 @@ exports.first = first;
28740
28791
  exports.flatten = flatten;
28741
28792
  exports.getDirectoryFilePaths = getDirectoryFilePaths;
28742
28793
  exports.getDirectoryPath = getDirectoryPath;
28794
+ exports.getQueryParameter = getQueryParameter;
28743
28795
  exports.groupBy = groupBy;
28744
28796
  exports.indexes = indexes;
28745
28797
  exports.isNullOrUndefined = isNullOrUndefined;
@@ -28760,6 +28812,7 @@ exports.processArrayItemMove = processArrayItemMove;
28760
28812
  exports.range = range;
28761
28813
  exports.removeUndefinedProps = removeUndefinedProps;
28762
28814
  exports.selectMany = selectMany;
28815
+ exports.serializeQueryString = serializeQueryString;
28763
28816
  exports.sleep = sleep;
28764
28817
  exports.sort = sort;
28765
28818
  exports.splitPath = splitPath;
@@ -28775,4 +28828,5 @@ exports.toTitleCase = toTitleCase;
28775
28828
  exports.trim = trim$1;
28776
28829
  exports.trimEnd = trimEnd;
28777
28830
  exports.trimStart = trimStart;
28831
+ exports.updateQueryParameters = updateQueryParameters;
28778
28832
  //# sourceMappingURL=index.js.map