@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.
@@ -1,2 +1,3 @@
1
1
  import { PortableTextBlock } from "@portabletext/types";
2
2
  export type RichText = PortableTextBlock[];
3
+ export type Optional<T> = T | undefined;
@@ -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";
@@ -1 +1,2 @@
1
1
  export declare function sleep(ms: number): Promise<unknown>;
2
+ export declare const mapAsync: <T, R>(array: T[], callback: (value: T, index: number, array: T[]) => Promise<R>) => Promise<R[]>;
@@ -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
@@ -358,6 +358,13 @@ const pluralize = (word) => {
358
358
  function sleep(ms) {
359
359
  return new Promise((resolve) => setTimeout(resolve, ms));
360
360
  }
361
+ const mapAsync = async (array, callback) => {
362
+ const result = [];
363
+ for (let i = 0; i < array.length; i++) {
364
+ result.push(await callback(array[i], i, array));
365
+ }
366
+ return result;
367
+ };
361
368
 
362
369
  const buildNode = async (record, { ancestors, nodesDict, childrenDict, nodeBuilder, }) => {
363
370
  const children = childrenDict.get(nodeBuilder.idSelector(record)) || [];
@@ -405,6 +412,55 @@ const newUuid = () => {
405
412
  });
406
413
  };
407
414
 
415
+ function serializeQueryString(obj) {
416
+ let queryString = "";
417
+ for (let key in obj) {
418
+ if (obj.hasOwnProperty(key) && obj[key]) {
419
+ if (queryString.length > 0) {
420
+ queryString += "&";
421
+ }
422
+ queryString += key + "=" + encodeURIComponent(obj[key]);
423
+ }
424
+ }
425
+ return queryString;
426
+ }
427
+ const buildUrl = (path, query) => {
428
+ const queryString = serializeQueryString(query);
429
+ return queryString ? `${path}?${queryString}` : path;
430
+ };
431
+ function deserializeQueryString(queryString) {
432
+ const obj = {};
433
+ const pairs = queryString.substring(1).split("&");
434
+ for (let i = 0; i < pairs.length; i++) {
435
+ const pair = pairs[i].split("=");
436
+ const key = decodeURIComponent(pair[0]);
437
+ const value = decodeURIComponent(pair[1] || "");
438
+ if (obj[key]) {
439
+ if (Array.isArray(obj[key])) {
440
+ obj[key].push(value);
441
+ }
442
+ else {
443
+ obj[key] = [obj[key], value];
444
+ }
445
+ }
446
+ else {
447
+ obj[key] = value;
448
+ }
449
+ }
450
+ return obj;
451
+ }
452
+ const getQueryParameter = (name, location = window.location) => {
453
+ const urlParams = deserializeQueryString(location.search);
454
+ return urlParams[name];
455
+ };
456
+ const updateQueryParameters = (queryString, params) => {
457
+ const queryParams = deserializeQueryString(queryString);
458
+ for (const [key, value] of Object.entries(params)) {
459
+ queryParams[key] = value;
460
+ }
461
+ return serializeQueryString(queryParams);
462
+ };
463
+
408
464
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
409
465
 
410
466
  function commonjsRequire (path) {
@@ -28687,5 +28743,5 @@ const processArrayItemMove = (items, input) => {
28687
28743
  }));
28688
28744
  };
28689
28745
 
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 };
28746
+ 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, mapAsync, 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
28747
  //# sourceMappingURL=index.js.map