@hkdigital/lib-sveltekit 0.0.62 → 0.0.64

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 @@
1
+ export * from "./validate-url.js";
@@ -0,0 +1 @@
1
+ export * from './validate-url.js';
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Schema to validate an URL
3
+ */
4
+ export const ValidateUrl: v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>, v.CustomSchema<any, undefined>]>;
5
+ /**
6
+ * Schema to validate an URL or empty string.
7
+ */
8
+ export const ValidateUrlOrEmptyString: v.UnionSchema<[v.LiteralSchema<"", undefined>, v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>]>], undefined>;
9
+ /**
10
+ * Schema to validate an URL path
11
+ */
12
+ export const ValidateUrlPath: v.SchemaWithPipe<[v.StringSchema<undefined>, v.CustomSchema<any, undefined>, v.TransformAction<any, {
13
+ url: URL;
14
+ value: any;
15
+ }>, v.CustomSchema<{
16
+ url: URL;
17
+ value: any;
18
+ }, "Value should not contain search path">, v.CustomSchema<{
19
+ url: URL;
20
+ value: any;
21
+ }, "Value should not contain hash path">, v.TransformAction<{
22
+ url: URL;
23
+ value: any;
24
+ }, string>]>;
25
+ /**
26
+ * Schema to validate a relative URL
27
+ */
28
+ export const ValidateRelativeUrl: v.SchemaWithPipe<[v.StringSchema<undefined>, v.CustomSchema<any, undefined>, v.CustomSchema<any, undefined>]>;
29
+ import * as v from 'valibot';
@@ -0,0 +1,162 @@
1
+ // > Imports
2
+
3
+ import * as v from 'valibot';
4
+ // import { UrlOrEmptyString } from '../valibot/url.js';
5
+
6
+ const ValidateTrim = v.custom((value) => {
7
+ if (/^\s|\s$/.test(value)) {
8
+ throw new Error('Should not start or end with whitespace');
9
+ }
10
+ return true;
11
+ });
12
+
13
+ // > Exports
14
+
15
+ /**
16
+ * Schema to validate an URL
17
+ */
18
+ export const ValidateUrl = v.pipe(v.string(), v.url(), ValidateTrim);
19
+
20
+ /**
21
+ * Schema to validate an URL or empty string.
22
+ */
23
+ export const ValidateUrlOrEmptyString = v.union([v.literal(''), v.pipe(v.string(), v.url())]);
24
+
25
+ // export const ValidateHumanUrl
26
+
27
+ /**
28
+ * Schema to validate an URL path
29
+ */
30
+ export const ValidateUrlPath = v.pipe(
31
+ v.string(),
32
+ ValidateTrim,
33
+ v.transform((value) => {
34
+ return {
35
+ url: new URL(value, 'http://localhost'),
36
+ value
37
+ };
38
+ }),
39
+ v.custom(({ url }) => {
40
+ if (url.search) {
41
+ return false;
42
+ }
43
+ return true;
44
+ }, 'Value should not contain search path'),
45
+ v.custom(({ url }) => {
46
+ if (url.hash) {
47
+ return false;
48
+ }
49
+ return true;
50
+ }, 'Value should not contain hash path'),
51
+ v.transform(({ url }) => {
52
+ return url.pathname;
53
+ })
54
+ );
55
+
56
+ /**
57
+ * Schema to validate a relative URL
58
+ */
59
+ export const ValidateRelativeUrl = v.pipe(
60
+ v.string(),
61
+ ValidateTrim,
62
+ v.custom((value) => {
63
+ try {
64
+ return new URL(value, 'http://localhost');
65
+
66
+ // eslint-disable-next-line no-unused-vars
67
+ } catch (e) {
68
+ throw new Error('Invalid relative URL');
69
+ }
70
+ })
71
+ );
72
+
73
+ // export const ValidateAbsOrRelUrl
74
+
75
+ /**
76
+ * Schema to validate an url that may miss the protocol part
77
+ *
78
+ * @note an empty string is not allowed!
79
+ */
80
+ // export const HumanUrl = v.pipe(
81
+ // v.custom( ( value ) => {
82
+ // if( value.includes('://') )
83
+ // {
84
+ // v.parse( Url, value );
85
+ // return true;
86
+ // }
87
+ // } )
88
+ // );
89
+
90
+ // // v.transform((value) => {
91
+ // // if (!value.length || value.includes('://')) {
92
+ // // return value;
93
+ // // } else {
94
+ // // // Prefix 'url' with 'https://'
95
+ // // return `https://${value}`;
96
+ // // }
97
+ // // }),
98
+ // // v.url()
99
+ // );
100
+
101
+ /**
102
+ * Schema to validate url path, without a search and hash part
103
+ */
104
+ // export const UrlPath = v.pipe(
105
+ // v.string(),
106
+ // v.transform((value) => {
107
+ // // Convert relative url to URL object
108
+ // // @note removes ../../ parts
109
+ // try {
110
+ // return new URL(value, 'http://localhost');
111
+
112
+ // // eslint-disable-next-line no-unused-vars
113
+ // } catch (e) {
114
+ // return null;
115
+ // }
116
+ // }),
117
+ // v.custom((urlOrNull) => {
118
+ // return urlOrNull ? true : false;
119
+ // }, 'Invalid URL pathname'),
120
+ // v.transform((url) => {
121
+ // return url.pathname;
122
+ // })
123
+ // );
124
+
125
+ /**
126
+ * Schema to validate a url path, which consists of
127
+ * a path and optionally search and hash parts
128
+ */
129
+ // export const RelativeUrl = v.pipe(
130
+ // v.string(),
131
+ // v.transform((value) => {
132
+ // // Convert relative url to URL object
133
+ // // @note removes ../../ parts
134
+ // try {
135
+ // return new URL(value, 'http://localhost');
136
+
137
+ // // eslint-disable-next-line no-unused-vars
138
+ // } catch (e) {
139
+ // return null;
140
+ // }
141
+ // }),
142
+ // v.custom((urlOrNull) => {
143
+ // return urlOrNull ? true : false;
144
+ // }, 'Invalid URL pathname or search part'),
145
+ // v.transform((url) => {
146
+ // return (
147
+ // `${url.pathname}` +
148
+ // `${url.search.length <= 1 ? '' : url.search}` +
149
+ // `${url.hash.length <= 1 ? '' : url.hash}`
150
+ // );
151
+ // })
152
+ // );
153
+
154
+ /**
155
+ * Schema to validate an absolute or relative url
156
+ *
157
+ * @note an empty string is not allowed!
158
+ */
159
+ // export const AbsOrRelUrl = v.union([
160
+ // v.pipe(v.string(), v.trim(), v.url()),
161
+ // v.pipe(v.string(), v.nonEmpty(), RelativeUrl)
162
+ // ]);
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Throws a validation error if value is not an array of strings
3
+ *
4
+ * @param {any} value
5
+ */
6
+ export function stringArray(value: any): void;
7
+ /**
8
+ * Throws a validation error if value is not an array of objects
9
+ *
10
+ * @param {any} value
11
+ */
12
+ export function objectArray(value: any): void;
13
+ /**
14
+ * Throws a validation error if value is not array like
15
+ * - Checks if the value is an object and has a property `length`
16
+ *
17
+ * @param {any} value
18
+ */
19
+ export function arrayLike(value: any): void;
20
+ export { array_ as array };
21
+ /**
22
+ * Throws a validation error if value is not an array
23
+ *
24
+ * @param {any} value
25
+ */
26
+ declare function array_(value: any): void;
@@ -0,0 +1,42 @@
1
+ import * as v from 'valibot';
2
+
3
+ /**
4
+ * Throws a validation error if value is not an array
5
+ *
6
+ * @param {any} value
7
+ */
8
+ function array_(value) {
9
+ v.parse(v.instance(Array), value);
10
+ }
11
+
12
+ export { array_ as array };
13
+
14
+ /**
15
+ * Throws a validation error if value is not an array of strings
16
+ *
17
+ * @param {any} value
18
+ */
19
+ export function stringArray(value) {
20
+ v.parse(v.array(v.string()), value);
21
+ }
22
+
23
+ /**
24
+ * Throws a validation error if value is not an array of objects
25
+ *
26
+ * @param {any} value
27
+ */
28
+ export function objectArray(value) {
29
+ v.parse(v.array(v.looseObject({})), value);
30
+ }
31
+
32
+ // notEmptyArray
33
+
34
+ /**
35
+ * Throws a validation error if value is not array like
36
+ * - Checks if the value is an object and has a property `length`
37
+ *
38
+ * @param {any} value
39
+ */
40
+ export function arrayLike(value) {
41
+ v.parse(v.object({ length: v.number() }), value);
42
+ }
@@ -1,46 +1,3 @@
1
- /** Exports */
2
- /**
3
- * Throws a validation error if value is not a string
4
- *
5
- * @param {any} value
6
- */
7
- export function string(value: any): void;
8
- /**
9
- * Throws a validation error if value is not a boolean
10
- *
11
- * @param {any} value
12
- */
13
- export function boolean(value: any): void;
14
- /**
15
- * Throws a validation error if value is not a number
16
- *
17
- * @param {any} value
18
- */
19
- export function number(value: any): void;
20
- /**
21
- * Throws a validation error if value is not a Symbol
22
- *
23
- * @param {any} value
24
- */
25
- export function symbol(value: any): void;
26
- /**
27
- * Throws a validation error if value is not defined
28
- *
29
- * @param {any} value
30
- */
31
- export function defined(value: any): void;
32
- /**
33
- * Throws a validation error if value is not an array of strings
34
- *
35
- * @param {any} value
36
- */
37
- export function stringArray(value: any): void;
38
- /**
39
- * Throws a validation error if value is not an array of objects
40
- *
41
- * @param {any} value
42
- */
43
- export function objectArray(value: any): void;
44
1
  /**
45
2
  * Throws a validation error if value is not an Error instance
46
3
  *
@@ -78,13 +35,6 @@ export function iterable(value: any): void;
78
35
  * @param {any} value
79
36
  */
80
37
  export function store(value: any): void;
81
- /**
82
- * Throws a validation error if value is not array like
83
- * - Checks if the value is an object and has a property `length`
84
- *
85
- * @param {any} value
86
- */
87
- export function arrayLike(value: any): void;
88
38
  /**
89
39
  * Throws a validation error if value is not an object or the value
90
40
  * is an array
@@ -111,18 +61,15 @@ export function objectOrNull(value: any): void;
111
61
  * @param {any} value
112
62
  */
113
63
  export function arrayOrSet(value: any): void;
64
+ export * from "./arrays.js";
65
+ export * from "./primitives.js";
66
+ export * from "./url.js";
114
67
  /**
115
68
  * Throws a validation error if value is not an object
116
69
  *
117
70
  * @param {any} value
118
71
  */
119
72
  declare function object_(value: any): void;
120
- /**
121
- * Throws a validation error if value is not an array
122
- *
123
- * @param {any} value
124
- */
125
- declare function array_(value: any): void;
126
73
  /**
127
74
  * Throws a validation error if value is not a function
128
75
  *
@@ -147,4 +94,4 @@ declare function map_(value: any): void;
147
94
  * @param {any} value
148
95
  */
149
96
  declare function set_(value: any): void;
150
- export { object_ as object, array_ as array, function_ as function, _function as function, function_ as class, _class as class, promise_ as promise, map_ as map, set_ as set, error_ as error, _true as true, _true as true };
97
+ export { object_ as object, function_ as function, _function as function, function_ as class, _class as class, promise_ as promise, map_ as map, set_ as set, error_ as error, _true as true, _true as true };
@@ -27,61 +27,9 @@ const ObjectSchema = v.custom(isObject, `Invalid type: Expected object`);
27
27
 
28
28
  /** Exports */
29
29
 
30
- // > Primitives
31
-
32
- /**
33
- * Throws a validation error if value is not a string
34
- *
35
- * @param {any} value
36
- */
37
- export function string(value) {
38
- v.parse(v.string(), value);
39
- }
40
-
41
- /**
42
- * Throws a validation error if value is not a boolean
43
- *
44
- * @param {any} value
45
- */
46
- export function boolean(value) {
47
- v.parse(v.boolean(), value);
48
- }
49
-
50
- /**
51
- * Throws a validation error if value is not a number
52
- *
53
- * @param {any} value
54
- */
55
- export function number(value) {
56
- v.parse(v.number(), value);
57
- }
58
-
59
- /**
60
- * Throws a validation error if value is not a Symbol
61
- *
62
- * @param {any} value
63
- */
64
- export function symbol(value) {
65
- v.parse(v.symbol(), value);
66
- }
67
-
68
- /**
69
- * Throws a validation error if value is not defined
70
- *
71
- * @param {any} value
72
- */
73
- export function defined(value) {
74
- v.parse(
75
- v.custom((value) => {
76
- if (value === undefined) {
77
- return false;
78
- }
79
-
80
- return true;
81
- }, 'Invalid type: Expected any value, but received undefined'),
82
- value
83
- );
84
- }
30
+ export * from './arrays.js';
31
+ export * from './primitives.js';
32
+ export * from './url.js';
85
33
 
86
34
  // > Base objects
87
35
 
@@ -97,35 +45,6 @@ function object_(value) {
97
45
 
98
46
  export { object_ as object };
99
47
 
100
- /**
101
- * Throws a validation error if value is not an array
102
- *
103
- * @param {any} value
104
- */
105
- function array_(value) {
106
- v.parse(v.instance(Array), value);
107
- }
108
-
109
- export { array_ as array };
110
-
111
- /**
112
- * Throws a validation error if value is not an array of strings
113
- *
114
- * @param {any} value
115
- */
116
- export function stringArray(value) {
117
- v.parse(v.array(v.string()), value);
118
- }
119
-
120
- /**
121
- * Throws a validation error if value is not an array of objects
122
- *
123
- * @param {any} value
124
- */
125
- export function objectArray(value) {
126
- v.parse(v.array(v.looseObject({})), value);
127
- }
128
-
129
48
  /**
130
49
  * Throws a validation error if value is not a function
131
50
  *
@@ -263,18 +182,6 @@ export function store(value) {
263
182
  );
264
183
  }
265
184
 
266
- // notEmptyArray
267
- // arrayLike
268
- /**
269
- * Throws a validation error if value is not array like
270
- * - Checks if the value is an object and has a property `length`
271
- *
272
- * @param {any} value
273
- */
274
- export function arrayLike(value) {
275
- v.parse(v.object({ length: v.number() }), value);
276
- }
277
-
278
185
  // ArrayBuffer
279
186
  // arrayOrUndefined
280
187
  // arangoCollectionId
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Throws a validation error if value is not a string
3
+ *
4
+ * @param {any} value
5
+ */
6
+ export function string(value: any): void;
7
+ /**
8
+ * Throws a validation error if value is not a boolean
9
+ *
10
+ * @param {any} value
11
+ */
12
+ export function boolean(value: any): void;
13
+ /**
14
+ * Throws a validation error if value is not a number
15
+ *
16
+ * @param {any} value
17
+ */
18
+ export function number(value: any): void;
19
+ /**
20
+ * Throws a validation error if value is not a Symbol
21
+ *
22
+ * @param {any} value
23
+ */
24
+ export function symbol(value: any): void;
25
+ /**
26
+ * Throws a validation error if value is not defined
27
+ *
28
+ * @param {any} value
29
+ */
30
+ export function defined(value: any): void;
@@ -0,0 +1,55 @@
1
+ import * as v from 'valibot';
2
+
3
+ /**
4
+ * Throws a validation error if value is not a string
5
+ *
6
+ * @param {any} value
7
+ */
8
+ export function string(value) {
9
+ v.parse(v.string(), value);
10
+ }
11
+
12
+ /**
13
+ * Throws a validation error if value is not a boolean
14
+ *
15
+ * @param {any} value
16
+ */
17
+ export function boolean(value) {
18
+ v.parse(v.boolean(), value);
19
+ }
20
+
21
+ /**
22
+ * Throws a validation error if value is not a number
23
+ *
24
+ * @param {any} value
25
+ */
26
+ export function number(value) {
27
+ v.parse(v.number(), value);
28
+ }
29
+
30
+ /**
31
+ * Throws a validation error if value is not a Symbol
32
+ *
33
+ * @param {any} value
34
+ */
35
+ export function symbol(value) {
36
+ v.parse(v.symbol(), value);
37
+ }
38
+
39
+ /**
40
+ * Throws a validation error if value is not defined
41
+ *
42
+ * @param {any} value
43
+ */
44
+ export function defined(value) {
45
+ v.parse(
46
+ v.custom((value) => {
47
+ if (value === undefined) {
48
+ return false;
49
+ }
50
+
51
+ return true;
52
+ }, 'Invalid type: Expected any value, but received undefined'),
53
+ value
54
+ );
55
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Throws a validation error if value is not an url
3
+ *
4
+ * @param {any} value
5
+ */
6
+ export function url(value: any): void;
7
+ /**
8
+ * Throws a validation error if value is not an url or
9
+ * an empty string
10
+ *
11
+ * @param {any} value
12
+ */
13
+ export function urlOrEmptyString(value: any): void;
14
+ /**
15
+ * Throws a validation error if value is not a relative url
16
+ *
17
+ * @param {any} value
18
+ */
19
+ export function urlPath(value: any): void;
20
+ /**
21
+ * Throws a validation error if value is not a relative url
22
+ *
23
+ * @param {any} value
24
+ */
25
+ export function relativeUrl(value: any): void;
@@ -0,0 +1,49 @@
1
+ // > Imports
2
+
3
+ import * as v from 'valibot';
4
+
5
+ import {
6
+ ValidateUrl,
7
+ ValidateUrlOrEmptyString,
8
+ ValidateUrlPath,
9
+ ValidateRelativeUrl
10
+ } from '../../schemas/validate-url.js';
11
+
12
+ // > Exports
13
+
14
+ /**
15
+ * Throws a validation error if value is not an url
16
+ *
17
+ * @param {any} value
18
+ */
19
+ export function url(value) {
20
+ v.parse(ValidateUrl, value);
21
+ }
22
+
23
+ /**
24
+ * Throws a validation error if value is not an url or
25
+ * an empty string
26
+ *
27
+ * @param {any} value
28
+ */
29
+ export function urlOrEmptyString(value) {
30
+ v.parse(ValidateUrlOrEmptyString, value);
31
+ }
32
+
33
+ /**
34
+ * Throws a validation error if value is not a relative url
35
+ *
36
+ * @param {any} value
37
+ */
38
+ export function urlPath(value) {
39
+ v.parse(ValidateUrlPath, value);
40
+ }
41
+
42
+ /**
43
+ * Throws a validation error if value is not a relative url
44
+ *
45
+ * @param {any} value
46
+ */
47
+ export function relativeUrl(value) {
48
+ v.parse(ValidateRelativeUrl, value);
49
+ }
@@ -2,11 +2,11 @@ import { METHOD_GET, METHOD_POST } from '../../constants/http/methods.js';
2
2
 
3
3
  import { APPLICATION_JSON } from '../../constants/mime/application.js';
4
4
  import { CONTENT_TYPE } from '../../constants/http/headers.js';
5
+ import { ResponseError } from '../../constants/errors/index.js';
5
6
 
6
7
  import * as expect from '../expect/index.js';
7
8
 
8
9
  import { toURL } from './url.js';
9
- import { ResponseError } from './errors.js';
10
10
  import { httpRequest } from './http-request.js';
11
11
  import { waitForAndCheckResponse } from './response.js';
12
12
 
@@ -0,0 +1,10 @@
1
+ // > Imports
2
+
3
+ import * as v from 'valibot';
4
+
5
+ // > Exports
6
+
7
+ /**
8
+ * Schema to validate a Date or ISO timestamp.
9
+ */
10
+ export const DateOrIsoTimeStamp = v.union([v.date(), v.pipe(v.string(), v.isoTimestamp())]);
@@ -1,3 +1,4 @@
1
1
  export * from "./user.js";
2
+ export * from "./url.js";
2
3
  export default v;
3
4
  import * as v from 'valibot';
@@ -1,30 +1,9 @@
1
- /**
2
- * The following namespace style import can be used to acces the named exports
3
- * and als the JSdoc typedefs
4
- *
5
- * @example
6
- *
7
- * import * as Zods from '<path-to>/zod/all.js';
8
- *
9
- * JSdoc:
10
- * `@param {Zods.Name} name
11
- * `@param {Zods.Timeout} t
12
- *
13
- * Assert style:
14
- * Zods.String.parse(name);
15
- *
16
- * Parse style:
17
- * const name = Zods.Name.parse('Jens ');
18
- *
19
- * Use default export 'z':
20
- * // eslint-disable-next-line no-unused-vars
21
- * import z, * as Zods from '<path-to>/zod/all.js';
22
- *
23
- * z.string().parse(name);
24
- */
25
-
26
1
  import * as v from 'valibot';
27
2
 
3
+ // export * from './date.js';
4
+
28
5
  export * from './user.js';
29
6
 
7
+ export * from './url.js';
8
+
30
9
  export default v;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Schema to validate an URL or empty string.
3
+ */
4
+ export const UrlOrEmptyString: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UnionSchema<[v.LiteralSchema<"", undefined>, v.SchemaWithPipe<[v.StringSchema<undefined>, v.UrlAction<string, undefined>]>], undefined>]>;
5
+ /**
6
+ * Schema to validate an url that may miss the protocol part
7
+ *
8
+ * @note an empty string is not allowed!
9
+ */
10
+ export const HumanUrl: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction, v.TransformAction<string, string>, v.UrlAction<string, undefined>]>;
11
+ /**
12
+ * Schema to validate url path, without a search and hash part
13
+ */
14
+ export const UrlPath: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TransformAction<string, URL>, v.CustomSchema<URL, "Invalid URL pathname">, v.TransformAction<URL, string>]>;
15
+ /**
16
+ * Schema to validate a url path, which consists of
17
+ * a path and optionally search and hash parts
18
+ */
19
+ export const RelativeUrl: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TransformAction<string, URL>, v.CustomSchema<URL, "Invalid URL pathname or search part">, v.TransformAction<URL, string>]>;
20
+ /**
21
+ * Schema to validate an absolute or relative url
22
+ *
23
+ * @note an empty string is not allowed!
24
+ */
25
+ export const AbsOrRelUrl: v.UnionSchema<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction, v.UrlAction<string, undefined>]>, v.SchemaWithPipe<[v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.SchemaWithPipe<[v.StringSchema<undefined>, v.TransformAction<string, URL>, v.CustomSchema<URL, "Invalid URL pathname or search part">, v.TransformAction<URL, string>]>]>], undefined>;
26
+ import * as v from 'valibot';
@@ -0,0 +1,95 @@
1
+ // > Imports
2
+
3
+ import * as v from 'valibot';
4
+
5
+ // > Exports
6
+
7
+ /**
8
+ * Schema to validate an URL or empty string.
9
+ */
10
+ export const UrlOrEmptyString = v.pipe(
11
+ v.pipe(v.string(), v.trim()),
12
+ v.union([v.literal(''), v.pipe(v.string(), v.url())])
13
+ );
14
+
15
+ /**
16
+ * Schema to validate an url that may miss the protocol part
17
+ *
18
+ * @note an empty string is not allowed!
19
+ */
20
+ export const HumanUrl = v.pipe(
21
+ v.string(),
22
+ v.trim(),
23
+ v.transform((value) => {
24
+ if (!value.length || value.includes('://')) {
25
+ return value;
26
+ } else {
27
+ // Prefix 'url' with 'https://'
28
+ return `https://${value}`;
29
+ }
30
+ }),
31
+ v.url()
32
+ );
33
+
34
+ /**
35
+ * Schema to validate url path, without a search and hash part
36
+ */
37
+ export const UrlPath = v.pipe(
38
+ v.string(),
39
+ v.transform((value) => {
40
+ // Convert relative url to URL object
41
+ // @note removes ../../ parts
42
+ try {
43
+ return new URL(value, 'http://localhost');
44
+
45
+ // eslint-disable-next-line no-unused-vars
46
+ } catch (e) {
47
+ return null;
48
+ }
49
+ }),
50
+ v.custom((urlOrNull) => {
51
+ return urlOrNull ? true : false;
52
+ }, 'Invalid URL pathname'),
53
+ v.transform((url) => {
54
+ return url.pathname;
55
+ })
56
+ );
57
+
58
+ /**
59
+ * Schema to validate a url path, which consists of
60
+ * a path and optionally search and hash parts
61
+ */
62
+ export const RelativeUrl = v.pipe(
63
+ v.string(),
64
+ v.transform((value) => {
65
+ // Convert relative url to URL object
66
+ // @note removes ../../ parts
67
+ try {
68
+ return new URL(value, 'http://localhost');
69
+
70
+ // eslint-disable-next-line no-unused-vars
71
+ } catch (e) {
72
+ return null;
73
+ }
74
+ }),
75
+ v.custom((urlOrNull) => {
76
+ return urlOrNull ? true : false;
77
+ }, 'Invalid URL pathname or search part'),
78
+ v.transform((url) => {
79
+ return (
80
+ `${url.pathname}` +
81
+ `${url.search.length <= 1 ? '' : url.search}` +
82
+ `${url.hash.length <= 1 ? '' : url.hash}`
83
+ );
84
+ })
85
+ );
86
+
87
+ /**
88
+ * Schema to validate an absolute or relative url
89
+ *
90
+ * @note an empty string is not allowed!
91
+ */
92
+ export const AbsOrRelUrl = v.union([
93
+ v.pipe(v.string(), v.trim(), v.url()),
94
+ v.pipe(v.string(), v.nonEmpty(), RelativeUrl)
95
+ ]);
package/dist/zod/web.js CHANGED
@@ -16,41 +16,36 @@ import { z } from 'zod';
16
16
  * @returns {{ parse:function }}
17
17
  */
18
18
  export function UrlOrPath({ allowRelative = true, requireHttp = true } = {}) {
19
- // > URL parser
20
- return z.string().refine((value) => {
21
- let url;
22
-
23
- try {
24
- if (!allowRelative) {
25
- // > Ensure that URL is absolute
26
- url = new URL(value);
27
-
28
- if (requireHttp) {
29
- // > Ensure that protocol is http(s)
30
- if (url.protocol.startsWith('http')) {
31
- return null;
32
- }
33
- }
34
-
35
- return (
36
- `${url.origin}${url.pathname}` +
37
- `${url.search.length <= 1 ? '' : url.search}`
38
- );
39
- } else {
40
- // > Parse relative URL
41
- // @note removes ../../ parts
42
-
43
- url = new URL(value, 'http://localhost');
44
-
45
- return (
46
- `${url.pathname}` + `${url.search.length <= 1 ? '' : url.search}`
47
- );
48
- }
49
- // eslint-disable-next-line no-unused-vars
50
- } catch (e) {
51
- return null;
52
- }
53
- });
19
+ // > URL parser
20
+ return z.string().refine((value) => {
21
+ let url;
22
+
23
+ try {
24
+ if (!allowRelative) {
25
+ // > Ensure that URL is absolute
26
+ url = new URL(value);
27
+
28
+ if (requireHttp) {
29
+ // > Ensure that protocol is http(s)
30
+ if (url.protocol.startsWith('http')) {
31
+ return null;
32
+ }
33
+ }
34
+
35
+ return `${url.origin}${url.pathname}` + `${url.search.length <= 1 ? '' : url.search}`;
36
+ } else {
37
+ // > Parse relative URL
38
+ // @note removes ../../ parts
39
+
40
+ url = new URL(value, 'http://localhost');
41
+
42
+ return `${url.pathname}` + `${url.search.length <= 1 ? '' : url.search}`;
43
+ }
44
+ // eslint-disable-next-line no-unused-vars
45
+ } catch (e) {
46
+ return null;
47
+ }
48
+ });
54
49
  }
55
50
 
56
51
  export const AbsOrRelUrl = UrlOrPath();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-sveltekit",
3
- "version": "0.0.62",
3
+ "version": "0.0.64",
4
4
  "author": "Jens Kleinhout, HKdigital (https://hkdigital.nl)",
5
5
  "license": "ISC",
6
6
  "repository": {
@@ -117,6 +117,10 @@
117
117
  "types": "./dist/constants/regexp/index.d.ts",
118
118
  "svelte": "./dist/constants/regexp/index.js"
119
119
  },
120
+ "./schemas": {
121
+ "types": "./dist/schemas/index.d.ts",
122
+ "svelte": "./dist/schemas/index.js"
123
+ },
120
124
  "./server": {
121
125
  "types": "./dist/server/index.d.ts",
122
126
  "svelte": "./dist/server/index.js"
@@ -201,27 +205,27 @@
201
205
  "@playwright/test": "^1.49.1",
202
206
  "@sveltejs/adapter-auto": "^3.3.1",
203
207
  "@sveltejs/package": "^2.3.7",
204
- "@sveltejs/vite-plugin-svelte": "^5.0.2",
208
+ "@sveltejs/vite-plugin-svelte": "^5.0.3",
205
209
  "@types/eslint": "^9.6.1",
206
210
  "autoprefixer": "^10.4.20",
207
211
  "eslint": "^9.17.0",
208
212
  "eslint-config-prettier": "^9.1.0",
209
213
  "eslint-plugin-svelte": "^2.46.1",
210
- "globals": "^15.13.0",
214
+ "globals": "^15.14.0",
211
215
  "prettier": "^3.4.2",
212
216
  "prettier-plugin-svelte": "^3.3.2",
213
217
  "prettier-plugin-tailwindcss": "^0.6.9",
214
218
  "publint": "^0.2.12",
215
- "svelte": "^5.14.1",
219
+ "svelte": "^5.16.0",
216
220
  "svelte-check": "^4.1.1",
217
- "tailwindcss": "^3.4.16",
221
+ "tailwindcss": "^3.4.17",
218
222
  "typescript": "^5.7.2",
219
- "vite": "^6.0.3",
223
+ "vite": "^6.0.5",
220
224
  "vitest": "^2.1.8"
221
225
  },
222
226
  "dependencies": {
223
- "@sveltejs/kit": "^2.12.1",
224
- "runed": "^0.19.0",
227
+ "@sveltejs/kit": "^2.15.0",
228
+ "runed": "^0.22.0",
225
229
  "valibot": "^0.42.1",
226
230
  "zod": "^3.24.1"
227
231
  }