@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.
@@ -10,4 +10,5 @@ export * from "./threading";
10
10
  export { buildTree, TreeNodeBuilder } from "./trees";
11
11
  export * from "./mappings";
12
12
  export * from "./uid";
13
+ export { serializeQueryString, buildUrl, deserializeQueryString, getQueryParameter, updateQueryParameters, } from "./urls";
13
14
  export { ExcelSheetDefinition, ExcelKeyTransform, ExcelColumnDefinition as ExcelRowBuilder, ExcelParseOptions, excelBuild, excelParse, } from "./xls";
@@ -0,0 +1,13 @@
1
+ export declare function serializeQueryString(obj: {
2
+ [key: string]: any;
3
+ }): string;
4
+ export declare const buildUrl: (path: string, query: {
5
+ [key: string]: any;
6
+ }) => string;
7
+ export declare function deserializeQueryString(queryString: string): {
8
+ [key: string]: any;
9
+ };
10
+ export declare const getQueryParameter: (name: string, location?: Location) => any;
11
+ export declare const updateQueryParameters: (queryString: string, params: {
12
+ [key: string]: any;
13
+ }) => string;
package/dist/esm/index.js CHANGED
@@ -405,6 +405,55 @@ const newUuid = () => {
405
405
  });
406
406
  };
407
407
 
408
+ function serializeQueryString(obj) {
409
+ let queryString = "";
410
+ for (let key in obj) {
411
+ if (obj.hasOwnProperty(key) && obj[key]) {
412
+ if (queryString.length > 0) {
413
+ queryString += "&";
414
+ }
415
+ queryString += key + "=" + encodeURIComponent(obj[key]);
416
+ }
417
+ }
418
+ return queryString;
419
+ }
420
+ const buildUrl = (path, query) => {
421
+ const queryString = serializeQueryString(query);
422
+ return queryString ? `${path}?${queryString}` : path;
423
+ };
424
+ function deserializeQueryString(queryString) {
425
+ const obj = {};
426
+ const pairs = queryString.substring(1).split("&");
427
+ for (let i = 0; i < pairs.length; i++) {
428
+ const pair = pairs[i].split("=");
429
+ const key = decodeURIComponent(pair[0]);
430
+ const value = decodeURIComponent(pair[1] || "");
431
+ if (obj[key]) {
432
+ if (Array.isArray(obj[key])) {
433
+ obj[key].push(value);
434
+ }
435
+ else {
436
+ obj[key] = [obj[key], value];
437
+ }
438
+ }
439
+ else {
440
+ obj[key] = value;
441
+ }
442
+ }
443
+ return obj;
444
+ }
445
+ const getQueryParameter = (name, location = window.location) => {
446
+ const urlParams = deserializeQueryString(location.search);
447
+ return urlParams[name];
448
+ };
449
+ const updateQueryParameters = (queryString, params) => {
450
+ const queryParams = deserializeQueryString(queryString);
451
+ for (const [key, value] of Object.entries(params)) {
452
+ queryParams[key] = value;
453
+ }
454
+ return serializeQueryString(queryParams);
455
+ };
456
+
408
457
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
409
458
 
410
459
  function commonjsRequire (path) {
@@ -28687,5 +28736,5 @@ const processArrayItemMove = (items, input) => {
28687
28736
  }));
28688
28737
  };
28689
28738
 
28690
- export { ConsoleLogger, DatadogLogger, ExcelKeyTransform, FileLogger, Log, LogLevel, MetaSerializationType, addTime, buildObject, buildTree, byField, byFieldDesc, camelToKebabCase, camelToSnakeCase, createDayPath, csvBuild, csvParse, distinct, distinctElements, ensureDirectory, ensureStartSlash, ensureTailingSlash, excelBuild, excelParse, first, flatten, getDirectoryFilePaths, getDirectoryPath, groupBy, indexes, isNullOrUndefined, iterate, joinPath, jsonDistinct, jsonSerialize, last, logMemoryUsage, mapOrThrow, mergeDeep, newUuid, notNull, notUndefined, pluralize, processArrayDifferences, processArrayItemMove, range, removeUndefinedProps, selectMany, sleep, sort, splitPath, subArrays, subtractTime, toArrayDict, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim$1 as trim, trimEnd, trimStart };
28739
+ export { ConsoleLogger, DatadogLogger, ExcelKeyTransform, FileLogger, Log, LogLevel, MetaSerializationType, addTime, buildObject, buildTree, buildUrl, byField, byFieldDesc, camelToKebabCase, camelToSnakeCase, createDayPath, csvBuild, csvParse, deserializeQueryString, distinct, distinctElements, ensureDirectory, ensureStartSlash, ensureTailingSlash, excelBuild, excelParse, first, flatten, getDirectoryFilePaths, getDirectoryPath, getQueryParameter, groupBy, indexes, isNullOrUndefined, iterate, joinPath, jsonDistinct, jsonSerialize, last, logMemoryUsage, mapOrThrow, mergeDeep, newUuid, notNull, notUndefined, pluralize, processArrayDifferences, processArrayItemMove, range, removeUndefinedProps, selectMany, serializeQueryString, sleep, sort, splitPath, subArrays, subtractTime, toArrayDict, toCamelCase, toDict, toItemsDict, toItemsMap, toMap, toTitleCase, trim$1 as trim, trimEnd, trimStart, updateQueryParameters };
28691
28740
  //# sourceMappingURL=index.js.map