@hkdigital/lib-sveltekit 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.
@@ -26,4 +26,5 @@ export const ValidateUrlPath: v.SchemaWithPipe<[v.StringSchema<undefined>, v.Cus
|
|
26
26
|
* Schema to validate a relative URL
|
27
27
|
*/
|
28
28
|
export const ValidateRelativeUrl: v.SchemaWithPipe<[v.StringSchema<undefined>, v.CustomSchema<any, undefined>, v.CustomSchema<any, undefined>]>;
|
29
|
+
export const ValidateAbsOrRelUrl: v.SchemaWithPipe<[v.StringSchema<undefined>, v.CustomSchema<any, undefined>, v.CustomSchema<any, undefined>]>;
|
29
30
|
import * as v from 'valibot';
|
@@ -70,7 +70,25 @@ export const ValidateRelativeUrl = v.pipe(
|
|
70
70
|
})
|
71
71
|
);
|
72
72
|
|
73
|
-
|
73
|
+
export const ValidateAbsOrRelUrl = v.pipe(
|
74
|
+
v.string(),
|
75
|
+
ValidateTrim,
|
76
|
+
v.custom((value) => {
|
77
|
+
try {
|
78
|
+
if (/^https?:\/\//.test(value)) {
|
79
|
+
// Absolute url using protocol http(s)
|
80
|
+
return new URL(value);
|
81
|
+
} else {
|
82
|
+
// Relative URL
|
83
|
+
return new URL(value, 'http://localhost');
|
84
|
+
}
|
85
|
+
|
86
|
+
// eslint-disable-next-line no-unused-vars
|
87
|
+
} catch (e) {
|
88
|
+
throw new Error('Invalid relative URL');
|
89
|
+
}
|
90
|
+
})
|
91
|
+
);
|
74
92
|
|
75
93
|
/**
|
76
94
|
* Schema to validate an url that may miss the protocol part
|
@@ -23,3 +23,10 @@ export function urlPath(value: any): void;
|
|
23
23
|
* @param {any} value
|
24
24
|
*/
|
25
25
|
export function relativeUrl(value: any): void;
|
26
|
+
/**
|
27
|
+
* Throws a validation error if value is not an absolute
|
28
|
+
* or relative url
|
29
|
+
*
|
30
|
+
* @param {any} value
|
31
|
+
*/
|
32
|
+
export function absOrRelUrl(value: any): void;
|
package/dist/util/expect/url.js
CHANGED
@@ -6,7 +6,8 @@ import {
|
|
6
6
|
ValidateUrl,
|
7
7
|
ValidateUrlOrEmptyString,
|
8
8
|
ValidateUrlPath,
|
9
|
-
ValidateRelativeUrl
|
9
|
+
ValidateRelativeUrl,
|
10
|
+
ValidateAbsOrRelUrl
|
10
11
|
} from '../../schemas/validate-url.js';
|
11
12
|
|
12
13
|
// > Exports
|
@@ -47,3 +48,13 @@ export function urlPath(value) {
|
|
47
48
|
export function relativeUrl(value) {
|
48
49
|
v.parse(ValidateRelativeUrl, value);
|
49
50
|
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Throws a validation error if value is not an absolute
|
54
|
+
* or relative url
|
55
|
+
*
|
56
|
+
* @param {any} value
|
57
|
+
*/
|
58
|
+
export function absOrRelUrl(value) {
|
59
|
+
v.parse(ValidateAbsOrRelUrl, value);
|
60
|
+
}
|