@augment-vir/common 16.4.2 → 18.0.0

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.
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.urlToSearchParamsObject = exports.objectToSearchParamsString = void 0;
4
+ const boolean_1 = require("../boolean");
5
+ const matches_object_shape_1 = require("../object/matches-object-shape");
6
+ const runtime_type_of_1 = require("../runtime-type-of");
7
+ function objectToSearchParamsString(inputObject) {
8
+ const valueStrings = Object.entries(inputObject)
9
+ .map(([key, value,]) => {
10
+ if (value == undefined) {
11
+ return undefined;
12
+ }
13
+ return `${key}=${String(value)}`;
14
+ })
15
+ .filter(boolean_1.isTruthy);
16
+ if (valueStrings.length) {
17
+ return `?${valueStrings.join('&')}`;
18
+ }
19
+ else {
20
+ return '';
21
+ }
22
+ }
23
+ exports.objectToSearchParamsString = objectToSearchParamsString;
24
+ function urlToSearchParamsObject(inputUrl, verifyShape) {
25
+ const urlForSearchParams = (0, runtime_type_of_1.isRuntimeTypeOf)(inputUrl, 'string') ? new URL(inputUrl) : inputUrl;
26
+ const searchEntries = Array.from(urlForSearchParams.searchParams.entries());
27
+ const paramsObject = Object.fromEntries(searchEntries);
28
+ if (verifyShape) {
29
+ (0, matches_object_shape_1.assertMatchesObjectShape)(paramsObject, verifyShape);
30
+ }
31
+ return paramsObject;
32
+ }
33
+ exports.urlToSearchParamsObject = urlToSearchParamsObject;
package/dist/cjs/index.js CHANGED
@@ -41,6 +41,7 @@ __exportStar(require("./augments/object/typed-has-property"), exports);
41
41
  __exportStar(require("./augments/promise"), exports);
42
42
  __exportStar(require("./augments/regexp"), exports);
43
43
  __exportStar(require("./augments/runtime-type-of"), exports);
44
+ __exportStar(require("./augments/string/search-params"), exports);
44
45
  __exportStar(require("./augments/string/suffixes"), exports);
45
46
  __exportStar(require("./augments/string/url"), exports);
46
47
  __exportStar(require("./augments/string/uuid"), exports);
@@ -0,0 +1,28 @@
1
+ import { isTruthy } from '../boolean';
2
+ import { assertMatchesObjectShape } from '../object/matches-object-shape';
3
+ import { isRuntimeTypeOf } from '../runtime-type-of';
4
+ export function objectToSearchParamsString(inputObject) {
5
+ const valueStrings = Object.entries(inputObject)
6
+ .map(([key, value,]) => {
7
+ if (value == undefined) {
8
+ return undefined;
9
+ }
10
+ return `${key}=${String(value)}`;
11
+ })
12
+ .filter(isTruthy);
13
+ if (valueStrings.length) {
14
+ return `?${valueStrings.join('&')}`;
15
+ }
16
+ else {
17
+ return '';
18
+ }
19
+ }
20
+ export function urlToSearchParamsObject(inputUrl, verifyShape) {
21
+ const urlForSearchParams = isRuntimeTypeOf(inputUrl, 'string') ? new URL(inputUrl) : inputUrl;
22
+ const searchEntries = Array.from(urlForSearchParams.searchParams.entries());
23
+ const paramsObject = Object.fromEntries(searchEntries);
24
+ if (verifyShape) {
25
+ assertMatchesObjectShape(paramsObject, verifyShape);
26
+ }
27
+ return paramsObject;
28
+ }
package/dist/esm/index.js CHANGED
@@ -25,6 +25,7 @@ export * from './augments/object/typed-has-property';
25
25
  export * from './augments/promise';
26
26
  export * from './augments/regexp';
27
27
  export * from './augments/runtime-type-of';
28
+ export * from './augments/string/search-params';
28
29
  export * from './augments/string/suffixes';
29
30
  export * from './augments/string/url';
30
31
  export * from './augments/string/uuid';
@@ -0,0 +1,5 @@
1
+ import { Primitive } from 'type-fest';
2
+ export type SearchParamObjectBase = Record<string, Exclude<Primitive, symbol>>;
3
+ export declare function objectToSearchParamsString(inputObject: SearchParamObjectBase): string;
4
+ export declare function urlToSearchParamsObject<VerifyShapeGeneric extends SearchParamObjectBase>(inputUrl: string | Pick<URL, 'searchParams'>, verifyShape: VerifyShapeGeneric): VerifyShapeGeneric;
5
+ export declare function urlToSearchParamsObject<VerifyShapeGeneric extends SearchParamObjectBase>(inputUrl: string | Pick<URL, 'searchParams'>, verifyShape?: VerifyShapeGeneric | undefined): Record<string, string>;
@@ -25,6 +25,7 @@ export * from './augments/object/typed-has-property';
25
25
  export * from './augments/promise';
26
26
  export * from './augments/regexp';
27
27
  export * from './augments/runtime-type-of';
28
+ export * from './augments/string/search-params';
28
29
  export * from './augments/string/suffixes';
29
30
  export * from './augments/string/url';
30
31
  export * from './augments/string/uuid';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "16.4.2",
3
+ "version": "18.0.0",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"