@augment-vir/common 24.0.0 → 25.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.
- package/dist/cjs/index.js +0 -1
- package/dist/esm/index.js +0 -1
- package/dist/types/index.d.ts +0 -1
- package/package.json +1 -1
- package/dist/cjs/augments/string/search-params.js +0 -52
- package/dist/esm/augments/string/search-params.js +0 -47
- package/dist/types/augments/string/search-params.d.ts +0 -5
package/dist/cjs/index.js
CHANGED
|
@@ -49,7 +49,6 @@ __exportStar(require("./augments/promise/wait"), exports);
|
|
|
49
49
|
__exportStar(require("./augments/random"), exports);
|
|
50
50
|
__exportStar(require("./augments/regexp"), exports);
|
|
51
51
|
__exportStar(require("./augments/string/prefixes"), exports);
|
|
52
|
-
__exportStar(require("./augments/string/search-params"), exports);
|
|
53
52
|
__exportStar(require("./augments/string/suffixes"), exports);
|
|
54
53
|
__exportStar(require("./augments/string/uuid"), exports);
|
|
55
54
|
__exportStar(require("./augments/time"), exports);
|
package/dist/esm/index.js
CHANGED
|
@@ -33,7 +33,6 @@ export * from './augments/promise/wait';
|
|
|
33
33
|
export * from './augments/random';
|
|
34
34
|
export * from './augments/regexp';
|
|
35
35
|
export * from './augments/string/prefixes';
|
|
36
|
-
export * from './augments/string/search-params';
|
|
37
36
|
export * from './augments/string/suffixes';
|
|
38
37
|
export * from './augments/string/uuid';
|
|
39
38
|
export * from './augments/time';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -33,7 +33,6 @@ export * from './augments/promise/wait';
|
|
|
33
33
|
export * from './augments/random';
|
|
34
34
|
export * from './augments/regexp';
|
|
35
35
|
export * from './augments/string/prefixes';
|
|
36
|
-
export * from './augments/string/search-params';
|
|
37
36
|
export * from './augments/string/suffixes';
|
|
38
37
|
export * from './augments/string/uuid';
|
|
39
38
|
export * from './augments/time';
|
package/package.json
CHANGED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.urlToSearchParamsObject = exports.objectToSearchParamsString = void 0;
|
|
4
|
-
const run_time_assertions_1 = require("run-time-assertions");
|
|
5
|
-
const boolean_1 = require("../boolean");
|
|
6
|
-
const common_string_1 = require("../common-string");
|
|
7
|
-
const matches_object_shape_1 = require("../object/matches-object-shape");
|
|
8
|
-
const prefixes_1 = require("./prefixes");
|
|
9
|
-
function objectToSearchParamsString(inputObject) {
|
|
10
|
-
const valueStrings = Object.entries(inputObject)
|
|
11
|
-
.map(([key, value,]) => {
|
|
12
|
-
if (value == undefined) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
return `${key}=${String(value)}`;
|
|
16
|
-
})
|
|
17
|
-
.filter(boolean_1.isTruthy);
|
|
18
|
-
if (valueStrings.length) {
|
|
19
|
-
return `?${valueStrings.join('&')}`;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return '';
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.objectToSearchParamsString = objectToSearchParamsString;
|
|
26
|
-
function splitSearchString(searchString) {
|
|
27
|
-
const params = (0, prefixes_1.removePrefix)({ value: searchString, prefix: '?' }).split('&');
|
|
28
|
-
const paramEntries = params
|
|
29
|
-
.map((param) => {
|
|
30
|
-
const [key, ...everythingElse] = (0, common_string_1.typedSplit)(param, '=');
|
|
31
|
-
const value = everythingElse.join('');
|
|
32
|
-
if (!value && !key) {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
return [
|
|
36
|
-
key,
|
|
37
|
-
value,
|
|
38
|
-
];
|
|
39
|
-
})
|
|
40
|
-
.filter(boolean_1.isTruthy);
|
|
41
|
-
return paramEntries;
|
|
42
|
-
}
|
|
43
|
-
function urlToSearchParamsObject(inputUrl, verifyShape) {
|
|
44
|
-
const ensuredUrl = (0, run_time_assertions_1.isRunTimeType)(inputUrl, 'string') ? new URL(inputUrl) : inputUrl;
|
|
45
|
-
const searchEntries = splitSearchString(ensuredUrl.search);
|
|
46
|
-
const paramsObject = Object.fromEntries(searchEntries);
|
|
47
|
-
if (verifyShape) {
|
|
48
|
-
(0, matches_object_shape_1.assertMatchesObjectShape)(paramsObject, verifyShape);
|
|
49
|
-
}
|
|
50
|
-
return paramsObject;
|
|
51
|
-
}
|
|
52
|
-
exports.urlToSearchParamsObject = urlToSearchParamsObject;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { isRunTimeType } from 'run-time-assertions';
|
|
2
|
-
import { isTruthy } from '../boolean';
|
|
3
|
-
import { typedSplit } from '../common-string';
|
|
4
|
-
import { assertMatchesObjectShape } from '../object/matches-object-shape';
|
|
5
|
-
import { removePrefix } from './prefixes';
|
|
6
|
-
export function objectToSearchParamsString(inputObject) {
|
|
7
|
-
const valueStrings = Object.entries(inputObject)
|
|
8
|
-
.map(([key, value,]) => {
|
|
9
|
-
if (value == undefined) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
return `${key}=${String(value)}`;
|
|
13
|
-
})
|
|
14
|
-
.filter(isTruthy);
|
|
15
|
-
if (valueStrings.length) {
|
|
16
|
-
return `?${valueStrings.join('&')}`;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
return '';
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function splitSearchString(searchString) {
|
|
23
|
-
const params = removePrefix({ value: searchString, prefix: '?' }).split('&');
|
|
24
|
-
const paramEntries = params
|
|
25
|
-
.map((param) => {
|
|
26
|
-
const [key, ...everythingElse] = typedSplit(param, '=');
|
|
27
|
-
const value = everythingElse.join('');
|
|
28
|
-
if (!value && !key) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
return [
|
|
32
|
-
key,
|
|
33
|
-
value,
|
|
34
|
-
];
|
|
35
|
-
})
|
|
36
|
-
.filter(isTruthy);
|
|
37
|
-
return paramEntries;
|
|
38
|
-
}
|
|
39
|
-
export function urlToSearchParamsObject(inputUrl, verifyShape) {
|
|
40
|
-
const ensuredUrl = isRunTimeType(inputUrl, 'string') ? new URL(inputUrl) : inputUrl;
|
|
41
|
-
const searchEntries = splitSearchString(ensuredUrl.search);
|
|
42
|
-
const paramsObject = Object.fromEntries(searchEntries);
|
|
43
|
-
if (verifyShape) {
|
|
44
|
-
assertMatchesObjectShape(paramsObject, verifyShape);
|
|
45
|
-
}
|
|
46
|
-
return paramsObject;
|
|
47
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
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, 'search'>, verifyShape: VerifyShapeGeneric): VerifyShapeGeneric;
|
|
5
|
-
export declare function urlToSearchParamsObject<VerifyShapeGeneric extends SearchParamObjectBase>(inputUrl: string | Pick<URL, 'search'>, verifyShape?: VerifyShapeGeneric | undefined): Record<string, string>;
|