@hkdigital/lib-sveltekit 0.0.66 → 0.0.67

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,8 +1,18 @@
1
1
  /**
2
- * Ensure to return an URL instance
2
+ * Returns an URL instance
3
+ * - Prefixes the URL with the current orign if the url is relative
3
4
  *
4
5
  * @param {string|URL} url
5
6
  *
6
7
  * @returns {URL} url instance
7
8
  */
8
9
  export function toURL(url: string | URL): URL;
10
+ /**
11
+ * Checks if the url starts with a protocol specification such
12
+ * as https://
13
+ *
14
+ * @param {string} url
15
+ *
16
+ * @return {boolean} true if the value looks like an array
17
+ */
18
+ export function hasProtocol(url: string): boolean;
@@ -1,7 +1,8 @@
1
1
  import { TypeOrValueError } from '../../constants/errors/index.js';
2
2
 
3
3
  /**
4
- * Ensure to return an URL instance
4
+ * Returns an URL instance
5
+ * - Prefixes the URL with the current orign if the url is relative
5
6
  *
6
7
  * @param {string|URL} url
7
8
  *
@@ -9,7 +10,12 @@ import { TypeOrValueError } from '../../constants/errors/index.js';
9
10
  */
10
11
  export function toURL(url) {
11
12
  if (typeof url === 'string') {
12
- return new URL(url);
13
+ if (hasProtocol(url)) {
14
+ return new URL(url);
15
+ } else {
16
+ // Use location.origin aas baseUrl
17
+ return new URL(url, location.origin);
18
+ }
13
19
  } else if (!(url instanceof URL)) {
14
20
  throw new TypeOrValueError('Missing or invalid parameter [url]');
15
21
  }
@@ -17,3 +23,19 @@ export function toURL(url) {
17
23
  // already an URL instance
18
24
  return url;
19
25
  }
26
+
27
+ /**
28
+ * Checks if the url starts with a protocol specification such
29
+ * as https://
30
+ *
31
+ * @param {string} url
32
+ *
33
+ * @return {boolean} true if the value looks like an array
34
+ */
35
+ export function hasProtocol(url) {
36
+ if (/^([a-zA-Z]{2,})s?:\/\//.test(url)) {
37
+ return true;
38
+ }
39
+
40
+ return false;
41
+ }
@@ -1,3 +1,4 @@
1
+ /** Exports */
1
2
  /**
2
3
  * Check if a value looks like an array
3
4
  *
@@ -1,4 +1,4 @@
1
- /* ---------------------------------------------------------------- Internals */
1
+ /** Internals */
2
2
 
3
3
  //
4
4
  // @see https://developer.mozilla.org/
@@ -7,9 +7,7 @@
7
7
  const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;
8
8
  const objectToString = Object.prototype.toString;
9
9
 
10
- /* ------------------------------------------------------------------ Exports */
11
-
12
- // ---------------------------------------------------------------------- Method
10
+ /** Exports */
13
11
 
14
12
  /**
15
13
  * Check if a value looks like an array
@@ -30,8 +28,6 @@ export function isArrayLike(item) {
30
28
  return false;
31
29
  }
32
30
 
33
- // ---------------------------------------------------------------------- Method
34
-
35
31
  /**
36
32
  * Check if a value is an Arguments object
37
33
  *
@@ -43,8 +39,6 @@ export function isArguments(value) {
43
39
  return objectToString.call(value) === '[object Arguments]';
44
40
  }
45
41
 
46
- // ---------------------------------------------------------------------- Method
47
-
48
42
  /**
49
43
  * Check if a value is an array that only contains primitives
50
44
  * - A primitive is a not-object value
@@ -68,8 +62,6 @@ export function isArrayOfPrimitives(arr) {
68
62
  return true;
69
63
  }
70
64
 
71
- // ---------------------------------------------------------------------- Method
72
-
73
65
  /**
74
66
  * Check if the supplied value is async iterable
75
67
  * - Aync iterable objects must implement the "@@asyncIterator" method
@@ -86,8 +78,6 @@ export function isAsyncIterator(value) {
86
78
  return true;
87
79
  }
88
80
 
89
- // ---------------------------------------------------------------------- Method
90
-
91
81
  /**
92
82
  * Check if the supplied value is an async function
93
83
  * - Returns true for functions declared as "async function" or
@@ -108,8 +98,6 @@ export function isAsyncFunction(value) {
108
98
  return false;
109
99
  }
110
100
 
111
- // ---------------------------------------------------------------------- Method
112
-
113
101
  /**
114
102
  * Check if the supplied value is iterable
115
103
  * - Iterable objects must implement the "@@iterator" method
@@ -127,8 +115,6 @@ export function isIterable(value) {
127
115
  return true;
128
116
  }
129
117
 
130
- // ---------------------------------------------------------------------- Method
131
-
132
118
  /**
133
119
  * Check if the supplied value is an object bu not a promise
134
120
  * - Promises return false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-sveltekit",
3
- "version": "0.0.66",
3
+ "version": "0.0.67",
4
4
  "author": "Jens Kleinhout, HKdigital (https://hkdigital.nl)",
5
5
  "license": "ISC",
6
6
  "repository": {