@vettvangur/vanilla 0.0.57 → 0.0.59
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/data.esm.js +80 -96
- package/dist/dom.esm.js +30 -30
- package/dist/index.esm.js +192 -213
- package/dist/server.esm.js +43 -56
- package/dist/string.esm.js +71 -76
- package/package.json +1 -1
package/dist/data.esm.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vanilla :: index.mjs.
|
|
3
|
-
*
|
|
4
|
-
* Vanilla JS helper utilities.
|
|
5
|
-
*
|
|
6
|
-
* These docs are generated from inline JSDoc in the repo and are intended for contributors.
|
|
7
|
-
*
|
|
8
|
-
* @generated
|
|
9
|
-
* @module vanilla
|
|
1
|
+
/**
|
|
2
|
+
* vanilla :: index.mjs.
|
|
3
|
+
*
|
|
4
|
+
* Vanilla JS helper utilities.
|
|
5
|
+
*
|
|
6
|
+
* These docs are generated from inline JSDoc in the repo and are intended for contributors.
|
|
7
|
+
*
|
|
8
|
+
* @generated
|
|
9
|
+
* @module vanilla
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* Fetcher.
|
|
15
|
-
*
|
|
16
|
-
* @param {object} options - Options object.
|
|
17
|
-
* @param {string} options.url - Value.
|
|
18
|
-
* @param {any} [options.options=null] - Options that control behavior.
|
|
19
|
-
* @param {boolean} [options.throwOnError=false] - Value.
|
|
20
|
-
* @returns Result of the operation.
|
|
21
|
-
* @throws When the operation fails.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
25
|
-
* // import { fetcher } from '@vettvangur/vanilla'
|
|
26
|
-
*
|
|
27
|
-
* await fetcher({ url: url, options: {}, throwOnError: throwOnError })
|
|
13
|
+
/**
|
|
14
|
+
* Fetcher.
|
|
15
|
+
*
|
|
16
|
+
* @param {object} options - Options object.
|
|
17
|
+
* @param {string} options.url - Value.
|
|
18
|
+
* @param {any} [options.options=null] - Options that control behavior.
|
|
19
|
+
* @param {boolean} [options.throwOnError=false] - Value.
|
|
20
|
+
* @returns Result of the operation.
|
|
21
|
+
* @throws When the operation fails.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
25
|
+
* // import { fetcher } from '@vettvangur/vanilla'
|
|
26
|
+
*
|
|
27
|
+
* await fetcher({ url: url, options: {}, throwOnError: throwOnError })
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
async function fetcher({
|
|
@@ -36,35 +36,27 @@ async function fetcher({
|
|
|
36
36
|
try {
|
|
37
37
|
const request = await fetch(url, options);
|
|
38
38
|
if (!request.ok) {
|
|
39
|
-
const errorDetails = await request.text();
|
|
40
|
-
const fullErrorMessage = `${errorMessage} - Status: ${request.status}, ${request.statusText}, Details: ${errorDetails}`;
|
|
41
|
-
console.error(fullErrorMessage);
|
|
42
39
|
if (throwOnError) {
|
|
43
|
-
|
|
40
|
+
const errorDetails = await request.text();
|
|
41
|
+
throw new Error(`${errorMessage} - Status: ${request.status}, ${request.statusText}, Details: ${errorDetails}`);
|
|
44
42
|
}
|
|
45
|
-
|
|
46
|
-
// Return null instead of undefined on error for predictable handling
|
|
47
43
|
return null;
|
|
48
44
|
}
|
|
49
45
|
return await request.json();
|
|
50
46
|
} catch (error) {
|
|
51
|
-
const fullErrorMessage = `${errorMessage} - ${error}`;
|
|
52
|
-
console.error(fullErrorMessage);
|
|
53
47
|
if (throwOnError) {
|
|
54
48
|
throw error;
|
|
55
49
|
}
|
|
56
|
-
|
|
57
|
-
// Return null instead of undefined on error for predictable handling
|
|
58
50
|
return null;
|
|
59
51
|
}
|
|
60
52
|
}
|
|
61
53
|
|
|
62
|
-
/**
|
|
63
|
-
* Checks if a given string is a valid regular expression pattern.
|
|
64
|
-
*
|
|
65
|
-
* @ignore
|
|
66
|
-
* @param {string} pattern - The regex pattern to validate.
|
|
67
|
-
* @returns {boolean} Returns `true` if the pattern is a valid regex, otherwise `false`.
|
|
54
|
+
/**
|
|
55
|
+
* Checks if a given string is a valid regular expression pattern.
|
|
56
|
+
*
|
|
57
|
+
* @ignore
|
|
58
|
+
* @param {string} pattern - The regex pattern to validate.
|
|
59
|
+
* @returns {boolean} Returns `true` if the pattern is a valid regex, otherwise `false`.
|
|
68
60
|
*/
|
|
69
61
|
function isValidRegex(pattern) {
|
|
70
62
|
try {
|
|
@@ -75,25 +67,25 @@ function isValidRegex(pattern) {
|
|
|
75
67
|
}
|
|
76
68
|
}
|
|
77
69
|
|
|
78
|
-
/**
|
|
79
|
-
* Regexr.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* console.log(regexr)
|
|
70
|
+
/**
|
|
71
|
+
* Regexr.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* console.log(regexr)
|
|
83
75
|
*/
|
|
84
76
|
const regexr = {
|
|
85
|
-
/**
|
|
86
|
-
* Tests whether a given value matches a regex pattern.
|
|
87
|
-
*
|
|
88
|
-
* @param {Object} params - Parameters for testing regex.
|
|
89
|
-
* @param {string} params.value - The string to test against the regex.
|
|
90
|
-
* @param {string} params.pattern - The regex pattern to match.
|
|
91
|
-
* @param {string} [params.flags='g'] - Regex flags (default: 'g').
|
|
92
|
-
* @returns {boolean} Returns `true` if the value matches the pattern, otherwise `false`.
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* const isMatch = regexr.match(pattern)
|
|
96
|
-
* console.log(isMatch) // return true or false
|
|
77
|
+
/**
|
|
78
|
+
* Tests whether a given value matches a regex pattern.
|
|
79
|
+
*
|
|
80
|
+
* @param {Object} params - Parameters for testing regex.
|
|
81
|
+
* @param {string} params.value - The string to test against the regex.
|
|
82
|
+
* @param {string} params.pattern - The regex pattern to match.
|
|
83
|
+
* @param {string} [params.flags='g'] - Regex flags (default: 'g').
|
|
84
|
+
* @returns {boolean} Returns `true` if the value matches the pattern, otherwise `false`.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* const isMatch = regexr.match(pattern)
|
|
88
|
+
* console.log(isMatch) // return true or false
|
|
97
89
|
*/
|
|
98
90
|
test({
|
|
99
91
|
value,
|
|
@@ -106,14 +98,14 @@ const regexr = {
|
|
|
106
98
|
const regexp = new RegExp(pattern, flags);
|
|
107
99
|
return regexp.test(value);
|
|
108
100
|
},
|
|
109
|
-
/**
|
|
110
|
-
* Matches a given value against a regex pattern and returns the matches.
|
|
111
|
-
*
|
|
112
|
-
* @param {Object} params - Parameters for matching regex.
|
|
113
|
-
* @param {string} params.value - The string to match against the regex.
|
|
114
|
-
* @param {string} params.pattern - The regex pattern to match.
|
|
115
|
-
* @param {string} [params.flags='g'] - Regex flags (default: 'g').
|
|
116
|
-
* @returns {Array<string>|null} Returns an array of matches, or `null` if no match is found.
|
|
101
|
+
/**
|
|
102
|
+
* Matches a given value against a regex pattern and returns the matches.
|
|
103
|
+
*
|
|
104
|
+
* @param {Object} params - Parameters for matching regex.
|
|
105
|
+
* @param {string} params.value - The string to match against the regex.
|
|
106
|
+
* @param {string} params.pattern - The regex pattern to match.
|
|
107
|
+
* @param {string} [params.flags='g'] - Regex flags (default: 'g').
|
|
108
|
+
* @returns {Array<string>|null} Returns an array of matches, or `null` if no match is found.
|
|
117
109
|
*/
|
|
118
110
|
match({
|
|
119
111
|
value,
|
|
@@ -128,40 +120,32 @@ const regexr = {
|
|
|
128
120
|
}
|
|
129
121
|
};
|
|
130
122
|
|
|
131
|
-
/**
|
|
132
|
-
* Flatten.
|
|
133
|
-
*
|
|
134
|
-
* @param obj - Value.
|
|
135
|
-
* @param prefix - Value.
|
|
136
|
-
* @returns Result of the operation.
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
140
|
-
* // import { flatten } from '@vettvangur/vanilla'
|
|
141
|
-
*
|
|
142
|
-
* flatten(obj, prefix)
|
|
123
|
+
/**
|
|
124
|
+
* Flatten.
|
|
125
|
+
*
|
|
126
|
+
* @param obj - Value.
|
|
127
|
+
* @param prefix - Value.
|
|
128
|
+
* @returns Result of the operation.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
132
|
+
* // import { flatten } from '@vettvangur/vanilla'
|
|
133
|
+
*
|
|
134
|
+
* flatten(obj, prefix)
|
|
143
135
|
*/
|
|
144
136
|
const flatten = (obj, prefix = '') => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
console.error('❌ FLATTEN ERROR: Received invalid data:', obj);
|
|
148
|
-
return {};
|
|
149
|
-
}
|
|
150
|
-
return Object.keys(obj).reduce((acc, key) => {
|
|
151
|
-
const fullKey = key === 'DEFAULT' ? prefix : prefix ? `${prefix}-${key}` : key;
|
|
152
|
-
if (typeof obj[key] === 'object' && key !== 'DEFAULT') {
|
|
153
|
-
Object.assign(acc, flatten(obj[key], fullKey));
|
|
154
|
-
} else if (typeof obj[key] === 'string') {
|
|
155
|
-
acc[fullKey] = obj[key];
|
|
156
|
-
} else {
|
|
157
|
-
console.warn('! Skipping Invalid Key:', key, 'Value:', obj[key]);
|
|
158
|
-
}
|
|
159
|
-
return acc;
|
|
160
|
-
}, {});
|
|
161
|
-
} catch (error) {
|
|
162
|
-
console.error('🚨 Flatten Function Error:', error);
|
|
163
|
-
return {}; // Prevents Tailwind from crashing
|
|
137
|
+
if (!obj || typeof obj !== 'object') {
|
|
138
|
+
return {};
|
|
164
139
|
}
|
|
140
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
141
|
+
const fullKey = key === 'DEFAULT' ? prefix : prefix ? `${prefix}-${key}` : key;
|
|
142
|
+
if (typeof obj[key] === 'object' && key !== 'DEFAULT') {
|
|
143
|
+
Object.assign(acc, flatten(obj[key], fullKey));
|
|
144
|
+
} else if (typeof obj[key] === 'string') {
|
|
145
|
+
acc[fullKey] = obj[key];
|
|
146
|
+
}
|
|
147
|
+
return acc;
|
|
148
|
+
}, {});
|
|
165
149
|
};
|
|
166
150
|
|
|
167
151
|
export { fetcher, flatten, regexr };
|
package/dist/dom.esm.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vanilla :: index.mjs.
|
|
3
|
-
*
|
|
4
|
-
* Vanilla JS helper utilities.
|
|
5
|
-
*
|
|
6
|
-
* These docs are generated from inline JSDoc in the repo and are intended for contributors.
|
|
7
|
-
*
|
|
8
|
-
* @generated
|
|
9
|
-
* @module vanilla
|
|
1
|
+
/**
|
|
2
|
+
* vanilla :: index.mjs.
|
|
3
|
+
*
|
|
4
|
+
* Vanilla JS helper utilities.
|
|
5
|
+
*
|
|
6
|
+
* These docs are generated from inline JSDoc in the repo and are intended for contributors.
|
|
7
|
+
*
|
|
8
|
+
* @generated
|
|
9
|
+
* @module vanilla
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* Preload timeout.
|
|
15
|
-
*
|
|
16
|
-
* @returns Nothing.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
20
|
-
* // import { preloadTimeout } from '@vettvangur/vanilla'
|
|
21
|
-
*
|
|
22
|
-
* preloadTimeout()
|
|
13
|
+
/**
|
|
14
|
+
* Preload timeout.
|
|
15
|
+
*
|
|
16
|
+
* @returns Nothing.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
20
|
+
* // import { preloadTimeout } from '@vettvangur/vanilla'
|
|
21
|
+
*
|
|
22
|
+
* preloadTimeout()
|
|
23
23
|
*/
|
|
24
24
|
function preloadTimeout() {
|
|
25
25
|
const body = document.querySelector('.body');
|
|
@@ -33,17 +33,17 @@ function preloadTimeout() {
|
|
|
33
33
|
}, 400);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
* Click outside.
|
|
38
|
-
*
|
|
39
|
-
* @param callback - Value.
|
|
40
|
-
* @returns Nothing.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
44
|
-
* // import { clickOutside } from '@vettvangur/vanilla'
|
|
45
|
-
*
|
|
46
|
-
* clickOutside(callback)
|
|
36
|
+
/**
|
|
37
|
+
* Click outside.
|
|
38
|
+
*
|
|
39
|
+
* @param callback - Value.
|
|
40
|
+
* @returns Nothing.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
44
|
+
* // import { clickOutside } from '@vettvangur/vanilla'
|
|
45
|
+
*
|
|
46
|
+
* clickOutside(callback)
|
|
47
47
|
*/
|
|
48
48
|
function clickOutside(callback) {
|
|
49
49
|
// Clicks
|
package/dist/index.esm.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vanilla :: index.mjs.
|
|
3
|
-
*
|
|
4
|
-
* Vanilla JS helper utilities.
|
|
5
|
-
*
|
|
6
|
-
* These docs are generated from inline JSDoc in the repo and are intended for contributors.
|
|
7
|
-
*
|
|
8
|
-
* @generated
|
|
9
|
-
* @module vanilla
|
|
1
|
+
/**
|
|
2
|
+
* vanilla :: index.mjs.
|
|
3
|
+
*
|
|
4
|
+
* Vanilla JS helper utilities.
|
|
5
|
+
*
|
|
6
|
+
* These docs are generated from inline JSDoc in the repo and are intended for contributors.
|
|
7
|
+
*
|
|
8
|
+
* @generated
|
|
9
|
+
* @module vanilla
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* @memberof @vettvangur/vanilla
|
|
12
|
+
/**
|
|
13
|
+
* @memberof @vettvangur/vanilla
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* Capitalize.
|
|
18
|
-
*
|
|
19
|
-
* @param value - Value.
|
|
20
|
-
* @param lowerRest - Value.
|
|
21
|
-
* @returns Result of the operation.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
25
|
-
* // import { capitalize } from '@vettvangur/vanilla'
|
|
26
|
-
*
|
|
27
|
-
* capitalize(value, lowerRest)
|
|
16
|
+
/**
|
|
17
|
+
* Capitalize.
|
|
18
|
+
*
|
|
19
|
+
* @param value - Value.
|
|
20
|
+
* @param lowerRest - Value.
|
|
21
|
+
* @returns Result of the operation.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
25
|
+
* // import { capitalize } from '@vettvangur/vanilla'
|
|
26
|
+
*
|
|
27
|
+
* capitalize(value, lowerRest)
|
|
28
28
|
*/
|
|
29
29
|
function capitalize(value, lowerRest = false) {
|
|
30
30
|
if (!value) {
|
|
@@ -35,19 +35,19 @@ function capitalize(value, lowerRest = false) {
|
|
|
35
35
|
return firstChar + rest;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
* Dictionary.
|
|
40
|
-
*
|
|
41
|
-
* @param key - Value.
|
|
42
|
-
* @param data - Value.
|
|
43
|
-
* @param culture - Value.
|
|
44
|
-
* @returns Result of the operation.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
48
|
-
* // import { dictionary } from '@vettvangur/vanilla'
|
|
49
|
-
*
|
|
50
|
-
* dictionary(key, data, culture)
|
|
38
|
+
/**
|
|
39
|
+
* Dictionary.
|
|
40
|
+
*
|
|
41
|
+
* @param key - Value.
|
|
42
|
+
* @param data - Value.
|
|
43
|
+
* @param culture - Value.
|
|
44
|
+
* @returns Result of the operation.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
48
|
+
* // import { dictionary } from '@vettvangur/vanilla'
|
|
49
|
+
*
|
|
50
|
+
* dictionary(key, data, culture)
|
|
51
51
|
*/
|
|
52
52
|
function dictionary(key, data, culture = 'is-IS') {
|
|
53
53
|
const notFound = '[Translation not found]';
|
|
@@ -64,21 +64,21 @@ function dictionary(key, data, culture = 'is-IS') {
|
|
|
64
64
|
return notFound;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/**
|
|
68
|
-
* Fetcher.
|
|
69
|
-
*
|
|
70
|
-
* @param {object} options - Options object.
|
|
71
|
-
* @param {string} options.url - Value.
|
|
72
|
-
* @param {any} [options.options=null] - Options that control behavior.
|
|
73
|
-
* @param {boolean} [options.throwOnError=false] - Value.
|
|
74
|
-
* @returns Result of the operation.
|
|
75
|
-
* @throws When the operation fails.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
79
|
-
* // import { fetcher } from '@vettvangur/vanilla'
|
|
80
|
-
*
|
|
81
|
-
* await fetcher({ url: url, options: {}, throwOnError: throwOnError })
|
|
67
|
+
/**
|
|
68
|
+
* Fetcher.
|
|
69
|
+
*
|
|
70
|
+
* @param {object} options - Options object.
|
|
71
|
+
* @param {string} options.url - Value.
|
|
72
|
+
* @param {any} [options.options=null] - Options that control behavior.
|
|
73
|
+
* @param {boolean} [options.throwOnError=false] - Value.
|
|
74
|
+
* @returns Result of the operation.
|
|
75
|
+
* @throws When the operation fails.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
79
|
+
* // import { fetcher } from '@vettvangur/vanilla'
|
|
80
|
+
*
|
|
81
|
+
* await fetcher({ url: url, options: {}, throwOnError: throwOnError })
|
|
82
82
|
*/
|
|
83
83
|
|
|
84
84
|
async function fetcher({
|
|
@@ -90,35 +90,27 @@ async function fetcher({
|
|
|
90
90
|
try {
|
|
91
91
|
const request = await fetch(url, options);
|
|
92
92
|
if (!request.ok) {
|
|
93
|
-
const errorDetails = await request.text();
|
|
94
|
-
const fullErrorMessage = `${errorMessage} - Status: ${request.status}, ${request.statusText}, Details: ${errorDetails}`;
|
|
95
|
-
console.error(fullErrorMessage);
|
|
96
93
|
if (throwOnError) {
|
|
97
|
-
|
|
94
|
+
const errorDetails = await request.text();
|
|
95
|
+
throw new Error(`${errorMessage} - Status: ${request.status}, ${request.statusText}, Details: ${errorDetails}`);
|
|
98
96
|
}
|
|
99
|
-
|
|
100
|
-
// Return null instead of undefined on error for predictable handling
|
|
101
97
|
return null;
|
|
102
98
|
}
|
|
103
99
|
return await request.json();
|
|
104
100
|
} catch (error) {
|
|
105
|
-
const fullErrorMessage = `${errorMessage} - ${error}`;
|
|
106
|
-
console.error(fullErrorMessage);
|
|
107
101
|
if (throwOnError) {
|
|
108
102
|
throw error;
|
|
109
103
|
}
|
|
110
|
-
|
|
111
|
-
// Return null instead of undefined on error for predictable handling
|
|
112
104
|
return null;
|
|
113
105
|
}
|
|
114
106
|
}
|
|
115
107
|
|
|
116
|
-
/**
|
|
117
|
-
* Checks if a given string is a valid regular expression pattern.
|
|
118
|
-
*
|
|
119
|
-
* @ignore
|
|
120
|
-
* @param {string} pattern - The regex pattern to validate.
|
|
121
|
-
* @returns {boolean} Returns `true` if the pattern is a valid regex, otherwise `false`.
|
|
108
|
+
/**
|
|
109
|
+
* Checks if a given string is a valid regular expression pattern.
|
|
110
|
+
*
|
|
111
|
+
* @ignore
|
|
112
|
+
* @param {string} pattern - The regex pattern to validate.
|
|
113
|
+
* @returns {boolean} Returns `true` if the pattern is a valid regex, otherwise `false`.
|
|
122
114
|
*/
|
|
123
115
|
function isValidRegex(pattern) {
|
|
124
116
|
try {
|
|
@@ -129,25 +121,25 @@ function isValidRegex(pattern) {
|
|
|
129
121
|
}
|
|
130
122
|
}
|
|
131
123
|
|
|
132
|
-
/**
|
|
133
|
-
* Regexr.
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* console.log(regexr)
|
|
124
|
+
/**
|
|
125
|
+
* Regexr.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* console.log(regexr)
|
|
137
129
|
*/
|
|
138
130
|
const regexr = {
|
|
139
|
-
/**
|
|
140
|
-
* Tests whether a given value matches a regex pattern.
|
|
141
|
-
*
|
|
142
|
-
* @param {Object} params - Parameters for testing regex.
|
|
143
|
-
* @param {string} params.value - The string to test against the regex.
|
|
144
|
-
* @param {string} params.pattern - The regex pattern to match.
|
|
145
|
-
* @param {string} [params.flags='g'] - Regex flags (default: 'g').
|
|
146
|
-
* @returns {boolean} Returns `true` if the value matches the pattern, otherwise `false`.
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* const isMatch = regexr.match(pattern)
|
|
150
|
-
* console.log(isMatch) // return true or false
|
|
131
|
+
/**
|
|
132
|
+
* Tests whether a given value matches a regex pattern.
|
|
133
|
+
*
|
|
134
|
+
* @param {Object} params - Parameters for testing regex.
|
|
135
|
+
* @param {string} params.value - The string to test against the regex.
|
|
136
|
+
* @param {string} params.pattern - The regex pattern to match.
|
|
137
|
+
* @param {string} [params.flags='g'] - Regex flags (default: 'g').
|
|
138
|
+
* @returns {boolean} Returns `true` if the value matches the pattern, otherwise `false`.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* const isMatch = regexr.match(pattern)
|
|
142
|
+
* console.log(isMatch) // return true or false
|
|
151
143
|
*/
|
|
152
144
|
test({
|
|
153
145
|
value,
|
|
@@ -160,14 +152,14 @@ const regexr = {
|
|
|
160
152
|
const regexp = new RegExp(pattern, flags);
|
|
161
153
|
return regexp.test(value);
|
|
162
154
|
},
|
|
163
|
-
/**
|
|
164
|
-
* Matches a given value against a regex pattern and returns the matches.
|
|
165
|
-
*
|
|
166
|
-
* @param {Object} params - Parameters for matching regex.
|
|
167
|
-
* @param {string} params.value - The string to match against the regex.
|
|
168
|
-
* @param {string} params.pattern - The regex pattern to match.
|
|
169
|
-
* @param {string} [params.flags='g'] - Regex flags (default: 'g').
|
|
170
|
-
* @returns {Array<string>|null} Returns an array of matches, or `null` if no match is found.
|
|
155
|
+
/**
|
|
156
|
+
* Matches a given value against a regex pattern and returns the matches.
|
|
157
|
+
*
|
|
158
|
+
* @param {Object} params - Parameters for matching regex.
|
|
159
|
+
* @param {string} params.value - The string to match against the regex.
|
|
160
|
+
* @param {string} params.pattern - The regex pattern to match.
|
|
161
|
+
* @param {string} [params.flags='g'] - Regex flags (default: 'g').
|
|
162
|
+
* @returns {Array<string>|null} Returns an array of matches, or `null` if no match is found.
|
|
171
163
|
*/
|
|
172
164
|
match({
|
|
173
165
|
value,
|
|
@@ -182,54 +174,46 @@ const regexr = {
|
|
|
182
174
|
}
|
|
183
175
|
};
|
|
184
176
|
|
|
185
|
-
/**
|
|
186
|
-
* Flatten.
|
|
187
|
-
*
|
|
188
|
-
* @param obj - Value.
|
|
189
|
-
* @param prefix - Value.
|
|
190
|
-
* @returns Result of the operation.
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
194
|
-
* // import { flatten } from '@vettvangur/vanilla'
|
|
195
|
-
*
|
|
196
|
-
* flatten(obj, prefix)
|
|
177
|
+
/**
|
|
178
|
+
* Flatten.
|
|
179
|
+
*
|
|
180
|
+
* @param obj - Value.
|
|
181
|
+
* @param prefix - Value.
|
|
182
|
+
* @returns Result of the operation.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
186
|
+
* // import { flatten } from '@vettvangur/vanilla'
|
|
187
|
+
*
|
|
188
|
+
* flatten(obj, prefix)
|
|
197
189
|
*/
|
|
198
190
|
const flatten = (obj, prefix = '') => {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
console.error('❌ FLATTEN ERROR: Received invalid data:', obj);
|
|
202
|
-
return {};
|
|
203
|
-
}
|
|
204
|
-
return Object.keys(obj).reduce((acc, key) => {
|
|
205
|
-
const fullKey = key === 'DEFAULT' ? prefix : prefix ? `${prefix}-${key}` : key;
|
|
206
|
-
if (typeof obj[key] === 'object' && key !== 'DEFAULT') {
|
|
207
|
-
Object.assign(acc, flatten(obj[key], fullKey));
|
|
208
|
-
} else if (typeof obj[key] === 'string') {
|
|
209
|
-
acc[fullKey] = obj[key];
|
|
210
|
-
} else {
|
|
211
|
-
console.warn('! Skipping Invalid Key:', key, 'Value:', obj[key]);
|
|
212
|
-
}
|
|
213
|
-
return acc;
|
|
214
|
-
}, {});
|
|
215
|
-
} catch (error) {
|
|
216
|
-
console.error('🚨 Flatten Function Error:', error);
|
|
217
|
-
return {}; // Prevents Tailwind from crashing
|
|
191
|
+
if (!obj || typeof obj !== 'object') {
|
|
192
|
+
return {};
|
|
218
193
|
}
|
|
194
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
195
|
+
const fullKey = key === 'DEFAULT' ? prefix : prefix ? `${prefix}-${key}` : key;
|
|
196
|
+
if (typeof obj[key] === 'object' && key !== 'DEFAULT') {
|
|
197
|
+
Object.assign(acc, flatten(obj[key], fullKey));
|
|
198
|
+
} else if (typeof obj[key] === 'string') {
|
|
199
|
+
acc[fullKey] = obj[key];
|
|
200
|
+
}
|
|
201
|
+
return acc;
|
|
202
|
+
}, {});
|
|
219
203
|
};
|
|
220
204
|
|
|
221
|
-
/**
|
|
222
|
-
* Get template.
|
|
223
|
-
*
|
|
224
|
-
* @param alias - Value.
|
|
225
|
-
* @param templates - Value.
|
|
226
|
-
* @returns Result of the operation.
|
|
227
|
-
*
|
|
228
|
-
* @example
|
|
229
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
230
|
-
* // import { getTemplate } from '@vettvangur/vanilla'
|
|
231
|
-
*
|
|
232
|
-
* getTemplate(alias, templates)
|
|
205
|
+
/**
|
|
206
|
+
* Get template.
|
|
207
|
+
*
|
|
208
|
+
* @param alias - Value.
|
|
209
|
+
* @param templates - Value.
|
|
210
|
+
* @returns Result of the operation.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
214
|
+
* // import { getTemplate } from '@vettvangur/vanilla'
|
|
215
|
+
*
|
|
216
|
+
* getTemplate(alias, templates)
|
|
233
217
|
*/
|
|
234
218
|
function getTemplate(alias, templates) {
|
|
235
219
|
const template = templates[capitalize(alias)];
|
|
@@ -239,18 +223,18 @@ function getTemplate(alias, templates) {
|
|
|
239
223
|
return template;
|
|
240
224
|
}
|
|
241
225
|
|
|
242
|
-
/**
|
|
243
|
-
* Get block.
|
|
244
|
-
*
|
|
245
|
-
* @param alias - Value.
|
|
246
|
-
* @param blocks - Value.
|
|
247
|
-
* @returns Result of the operation.
|
|
248
|
-
*
|
|
249
|
-
* @example
|
|
250
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
251
|
-
* // import { getBlock } from '@vettvangur/vanilla'
|
|
252
|
-
*
|
|
253
|
-
* getBlock(alias, blocks)
|
|
226
|
+
/**
|
|
227
|
+
* Get block.
|
|
228
|
+
*
|
|
229
|
+
* @param alias - Value.
|
|
230
|
+
* @param blocks - Value.
|
|
231
|
+
* @returns Result of the operation.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
235
|
+
* // import { getBlock } from '@vettvangur/vanilla'
|
|
236
|
+
*
|
|
237
|
+
* getBlock(alias, blocks)
|
|
254
238
|
*/
|
|
255
239
|
function getBlock(alias, blocks) {
|
|
256
240
|
if (!blocks) {
|
|
@@ -263,17 +247,17 @@ function getBlock(alias, blocks) {
|
|
|
263
247
|
return block;
|
|
264
248
|
}
|
|
265
249
|
|
|
266
|
-
/**
|
|
267
|
-
* Return whether empty is enabled.
|
|
268
|
-
*
|
|
269
|
-
* @param value - Value.
|
|
270
|
-
* @returns Boolean indicating whether empty is enabled.
|
|
271
|
-
*
|
|
272
|
-
* @example
|
|
273
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
274
|
-
* // import { isEmpty } from '@vettvangur/vanilla'
|
|
275
|
-
*
|
|
276
|
-
* isEmpty(value)
|
|
250
|
+
/**
|
|
251
|
+
* Return whether empty is enabled.
|
|
252
|
+
*
|
|
253
|
+
* @param value - Value.
|
|
254
|
+
* @returns Boolean indicating whether empty is enabled.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
258
|
+
* // import { isEmpty } from '@vettvangur/vanilla'
|
|
259
|
+
*
|
|
260
|
+
* isEmpty(value)
|
|
277
261
|
*/
|
|
278
262
|
function isEmpty(value) {
|
|
279
263
|
if (value === '' || value === undefined || value === null) {
|
|
@@ -282,16 +266,16 @@ function isEmpty(value) {
|
|
|
282
266
|
return false;
|
|
283
267
|
}
|
|
284
268
|
|
|
285
|
-
/**
|
|
286
|
-
* Preload timeout.
|
|
287
|
-
*
|
|
288
|
-
* @returns Nothing.
|
|
289
|
-
*
|
|
290
|
-
* @example
|
|
291
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
292
|
-
* // import { preloadTimeout } from '@vettvangur/vanilla'
|
|
293
|
-
*
|
|
294
|
-
* preloadTimeout()
|
|
269
|
+
/**
|
|
270
|
+
* Preload timeout.
|
|
271
|
+
*
|
|
272
|
+
* @returns Nothing.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
276
|
+
* // import { preloadTimeout } from '@vettvangur/vanilla'
|
|
277
|
+
*
|
|
278
|
+
* preloadTimeout()
|
|
295
279
|
*/
|
|
296
280
|
function preloadTimeout() {
|
|
297
281
|
const body = document.querySelector('.body');
|
|
@@ -305,17 +289,17 @@ function preloadTimeout() {
|
|
|
305
289
|
}, 400);
|
|
306
290
|
}
|
|
307
291
|
|
|
308
|
-
/**
|
|
309
|
-
* Click outside.
|
|
310
|
-
*
|
|
311
|
-
* @param callback - Value.
|
|
312
|
-
* @returns Nothing.
|
|
313
|
-
*
|
|
314
|
-
* @example
|
|
315
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
316
|
-
* // import { clickOutside } from '@vettvangur/vanilla'
|
|
317
|
-
*
|
|
318
|
-
* clickOutside(callback)
|
|
292
|
+
/**
|
|
293
|
+
* Click outside.
|
|
294
|
+
*
|
|
295
|
+
* @param callback - Value.
|
|
296
|
+
* @returns Nothing.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
300
|
+
* // import { clickOutside } from '@vettvangur/vanilla'
|
|
301
|
+
*
|
|
302
|
+
* clickOutside(callback)
|
|
319
303
|
*/
|
|
320
304
|
function clickOutside(callback) {
|
|
321
305
|
// Clicks
|
|
@@ -360,11 +344,11 @@ function clickOutside(callback) {
|
|
|
360
344
|
});
|
|
361
345
|
}
|
|
362
346
|
|
|
363
|
-
/**
|
|
364
|
-
* Umbraco.
|
|
365
|
-
*
|
|
366
|
-
* @example
|
|
367
|
-
* console.log(Umbraco)
|
|
347
|
+
/**
|
|
348
|
+
* Umbraco.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* console.log(Umbraco)
|
|
368
352
|
*/
|
|
369
353
|
const Umbraco = Object.freeze({
|
|
370
354
|
NODE: 'node',
|
|
@@ -374,42 +358,37 @@ const Umbraco = Object.freeze({
|
|
|
374
358
|
EXTRA: 'extra'
|
|
375
359
|
});
|
|
376
360
|
|
|
377
|
-
/**
|
|
378
|
-
* Get translation.
|
|
379
|
-
*
|
|
380
|
-
* @param key - Value.
|
|
381
|
-
* @param translations - Value.
|
|
382
|
-
* @returns Result of the operation.
|
|
383
|
-
*
|
|
384
|
-
* @example
|
|
385
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
386
|
-
* // import { getTranslation } from '@vettvangur/vanilla'
|
|
387
|
-
*
|
|
388
|
-
* getTranslation(key, translations)
|
|
361
|
+
/**
|
|
362
|
+
* Get translation.
|
|
363
|
+
*
|
|
364
|
+
* @param key - Value.
|
|
365
|
+
* @param translations - Value.
|
|
366
|
+
* @returns Result of the operation.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
370
|
+
* // import { getTranslation } from '@vettvangur/vanilla'
|
|
371
|
+
*
|
|
372
|
+
* getTranslation(key, translations)
|
|
389
373
|
*/
|
|
390
374
|
function getTranslation(key, translations) {
|
|
391
375
|
if (!translations) {
|
|
392
376
|
return;
|
|
393
377
|
}
|
|
394
|
-
|
|
395
|
-
if (!translation) {
|
|
396
|
-
console.error(`[vettvangur-vanilla :: getTranslation] No translation for key ${key} found.`);
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
return translation;
|
|
378
|
+
return translations[key];
|
|
400
379
|
}
|
|
401
380
|
|
|
402
|
-
/**
|
|
403
|
-
* Get culture.
|
|
404
|
-
*
|
|
405
|
-
* @param path - Value.
|
|
406
|
-
* @returns Result of the operation.
|
|
407
|
-
*
|
|
408
|
-
* @example
|
|
409
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
410
|
-
* // import { getCulture } from '@vettvangur/vanilla'
|
|
411
|
-
*
|
|
412
|
-
* getCulture(path)
|
|
381
|
+
/**
|
|
382
|
+
* Get culture.
|
|
383
|
+
*
|
|
384
|
+
* @param path - Value.
|
|
385
|
+
* @returns Result of the operation.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
389
|
+
* // import { getCulture } from '@vettvangur/vanilla'
|
|
390
|
+
*
|
|
391
|
+
* getCulture(path)
|
|
413
392
|
*/
|
|
414
393
|
function getCulture(path) {
|
|
415
394
|
const match = path.match(/^\/([a-z]{2})(\/|$)/i);
|
package/dist/server.esm.js
CHANGED
|
@@ -2,33 +2,33 @@ import path from 'node:path';
|
|
|
2
2
|
import process from 'node:process';
|
|
3
3
|
import dotenv from 'dotenv';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* vanilla :: index.mjs.
|
|
7
|
-
*
|
|
8
|
-
* Vanilla JS helper utilities.
|
|
9
|
-
*
|
|
10
|
-
* These docs are generated from inline JSDoc in the repo and are intended for contributors.
|
|
11
|
-
*
|
|
12
|
-
* @generated
|
|
13
|
-
* @module vanilla
|
|
5
|
+
/**
|
|
6
|
+
* vanilla :: index.mjs.
|
|
7
|
+
*
|
|
8
|
+
* Vanilla JS helper utilities.
|
|
9
|
+
*
|
|
10
|
+
* These docs are generated from inline JSDoc in the repo and are intended for contributors.
|
|
11
|
+
*
|
|
12
|
+
* @generated
|
|
13
|
+
* @module vanilla
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Fetcher.
|
|
19
|
-
*
|
|
20
|
-
* @param {object} options - Options object.
|
|
21
|
-
* @param {string} options.url - Value.
|
|
22
|
-
* @param {any} [options.options=null] - Options that control behavior.
|
|
23
|
-
* @param {boolean} [options.throwOnError=false] - Value.
|
|
24
|
-
* @returns Result of the operation.
|
|
25
|
-
* @throws When the operation fails.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
29
|
-
* // import { fetcher } from '@vettvangur/vanilla'
|
|
30
|
-
*
|
|
31
|
-
* await fetcher({ url: url, options: {}, throwOnError: throwOnError })
|
|
17
|
+
/**
|
|
18
|
+
* Fetcher.
|
|
19
|
+
*
|
|
20
|
+
* @param {object} options - Options object.
|
|
21
|
+
* @param {string} options.url - Value.
|
|
22
|
+
* @param {any} [options.options=null] - Options that control behavior.
|
|
23
|
+
* @param {boolean} [options.throwOnError=false] - Value.
|
|
24
|
+
* @returns Result of the operation.
|
|
25
|
+
* @throws When the operation fails.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
29
|
+
* // import { fetcher } from '@vettvangur/vanilla'
|
|
30
|
+
*
|
|
31
|
+
* await fetcher({ url: url, options: {}, throwOnError: throwOnError })
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
34
|
async function fetcher({
|
|
@@ -40,34 +40,26 @@ async function fetcher({
|
|
|
40
40
|
try {
|
|
41
41
|
const request = await fetch(url, options);
|
|
42
42
|
if (!request.ok) {
|
|
43
|
-
const errorDetails = await request.text();
|
|
44
|
-
const fullErrorMessage = `${errorMessage} - Status: ${request.status}, ${request.statusText}, Details: ${errorDetails}`;
|
|
45
|
-
console.error(fullErrorMessage);
|
|
46
43
|
if (throwOnError) {
|
|
47
|
-
|
|
44
|
+
const errorDetails = await request.text();
|
|
45
|
+
throw new Error(`${errorMessage} - Status: ${request.status}, ${request.statusText}, Details: ${errorDetails}`);
|
|
48
46
|
}
|
|
49
|
-
|
|
50
|
-
// Return null instead of undefined on error for predictable handling
|
|
51
47
|
return null;
|
|
52
48
|
}
|
|
53
49
|
return await request.json();
|
|
54
50
|
} catch (error) {
|
|
55
|
-
const fullErrorMessage = `${errorMessage} - ${error}`;
|
|
56
|
-
console.error(fullErrorMessage);
|
|
57
51
|
if (throwOnError) {
|
|
58
52
|
throw error;
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
// Return null instead of undefined on error for predictable handling
|
|
62
54
|
return null;
|
|
63
55
|
}
|
|
64
56
|
}
|
|
65
57
|
|
|
66
|
-
/**
|
|
67
|
-
* Umbraco.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* console.log(Umbraco)
|
|
58
|
+
/**
|
|
59
|
+
* Umbraco.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* console.log(Umbraco)
|
|
71
63
|
*/
|
|
72
64
|
const Umbraco = Object.freeze({
|
|
73
65
|
NODE: 'node',
|
|
@@ -140,11 +132,11 @@ async function loadEnvFiles(showMessage = true) {
|
|
|
140
132
|
* @param {string} [options.expand=''] - Fields to expand.
|
|
141
133
|
* @param {string} [options.node=''] - Specific node to fetch extras for (if applicable).
|
|
142
134
|
* @param {string} [options.contentType=''] - Type of content - used to fetch extraData for that specific type.
|
|
143
|
-
* @returns {string} The constructed URL for fetching Umbraco content.
|
|
135
|
+
* @returns {Promise<string>} The constructed URL for fetching Umbraco content.
|
|
144
136
|
* @throws Will throw an error if an unsupported fetch type is provided.
|
|
145
137
|
*/
|
|
146
|
-
function getUmbracoFetchUrl(route, fetchType, options = {}) {
|
|
147
|
-
loadEnvFiles();
|
|
138
|
+
async function getUmbracoFetchUrl(route, fetchType, options = {}) {
|
|
139
|
+
await loadEnvFiles(false);
|
|
148
140
|
const params = {
|
|
149
141
|
skip: options.skip || 0,
|
|
150
142
|
take: options.take || 9999,
|
|
@@ -197,21 +189,16 @@ async function getUmbracoData({
|
|
|
197
189
|
options = {},
|
|
198
190
|
fetchOptions = {}
|
|
199
191
|
}) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
throw new Error(`Invalid fetch type: ${fetchType}`);
|
|
205
|
-
}
|
|
206
|
-
const umbracofetchUrl = getUmbracoFetchUrl(route, fetchType, options);
|
|
207
|
-
return await fetcher({
|
|
208
|
-
url: umbracofetchUrl,
|
|
209
|
-
options: fetchOptions
|
|
210
|
-
});
|
|
211
|
-
} catch (error) {
|
|
212
|
-
console.error('[@vettvangur/vanilla :: getUmbracoData]', error);
|
|
213
|
-
return null;
|
|
192
|
+
/** @type {string[]} */
|
|
193
|
+
const validFetchTypes = Object.values(Umbraco);
|
|
194
|
+
if (!validFetchTypes.includes(fetchType)) {
|
|
195
|
+
throw new Error(`Invalid fetch type: ${fetchType}`);
|
|
214
196
|
}
|
|
197
|
+
const umbracofetchUrl = await getUmbracoFetchUrl(route, fetchType, options);
|
|
198
|
+
return fetcher({
|
|
199
|
+
url: umbracofetchUrl,
|
|
200
|
+
options: fetchOptions
|
|
201
|
+
});
|
|
215
202
|
}
|
|
216
203
|
|
|
217
204
|
export { getUmbracoData, loadEnvFiles };
|
package/dist/string.esm.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vanilla :: index.mjs.
|
|
3
|
-
*
|
|
4
|
-
* Vanilla JS helper utilities.
|
|
5
|
-
*
|
|
6
|
-
* These docs are generated from inline JSDoc in the repo and are intended for contributors.
|
|
7
|
-
*
|
|
8
|
-
* @generated
|
|
9
|
-
* @module vanilla
|
|
1
|
+
/**
|
|
2
|
+
* vanilla :: index.mjs.
|
|
3
|
+
*
|
|
4
|
+
* Vanilla JS helper utilities.
|
|
5
|
+
*
|
|
6
|
+
* These docs are generated from inline JSDoc in the repo and are intended for contributors.
|
|
7
|
+
*
|
|
8
|
+
* @generated
|
|
9
|
+
* @module vanilla
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* @memberof @vettvangur/vanilla
|
|
12
|
+
/**
|
|
13
|
+
* @memberof @vettvangur/vanilla
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* Capitalize.
|
|
18
|
-
*
|
|
19
|
-
* @param value - Value.
|
|
20
|
-
* @param lowerRest - Value.
|
|
21
|
-
* @returns Result of the operation.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
25
|
-
* // import { capitalize } from '@vettvangur/vanilla'
|
|
26
|
-
*
|
|
27
|
-
* capitalize(value, lowerRest)
|
|
16
|
+
/**
|
|
17
|
+
* Capitalize.
|
|
18
|
+
*
|
|
19
|
+
* @param value - Value.
|
|
20
|
+
* @param lowerRest - Value.
|
|
21
|
+
* @returns Result of the operation.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
25
|
+
* // import { capitalize } from '@vettvangur/vanilla'
|
|
26
|
+
*
|
|
27
|
+
* capitalize(value, lowerRest)
|
|
28
28
|
*/
|
|
29
29
|
function capitalize(value, lowerRest = false) {
|
|
30
30
|
if (!value) {
|
|
@@ -35,19 +35,19 @@ function capitalize(value, lowerRest = false) {
|
|
|
35
35
|
return firstChar + rest;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
* Dictionary.
|
|
40
|
-
*
|
|
41
|
-
* @param key - Value.
|
|
42
|
-
* @param data - Value.
|
|
43
|
-
* @param culture - Value.
|
|
44
|
-
* @returns Result of the operation.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
48
|
-
* // import { dictionary } from '@vettvangur/vanilla'
|
|
49
|
-
*
|
|
50
|
-
* dictionary(key, data, culture)
|
|
38
|
+
/**
|
|
39
|
+
* Dictionary.
|
|
40
|
+
*
|
|
41
|
+
* @param key - Value.
|
|
42
|
+
* @param data - Value.
|
|
43
|
+
* @param culture - Value.
|
|
44
|
+
* @returns Result of the operation.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
48
|
+
* // import { dictionary } from '@vettvangur/vanilla'
|
|
49
|
+
*
|
|
50
|
+
* dictionary(key, data, culture)
|
|
51
51
|
*/
|
|
52
52
|
function dictionary(key, data, culture = 'is-IS') {
|
|
53
53
|
const notFound = '[Translation not found]';
|
|
@@ -64,17 +64,17 @@ function dictionary(key, data, culture = 'is-IS') {
|
|
|
64
64
|
return notFound;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/**
|
|
68
|
-
* Return whether empty is enabled.
|
|
69
|
-
*
|
|
70
|
-
* @param value - Value.
|
|
71
|
-
* @returns Boolean indicating whether empty is enabled.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
75
|
-
* // import { isEmpty } from '@vettvangur/vanilla'
|
|
76
|
-
*
|
|
77
|
-
* isEmpty(value)
|
|
67
|
+
/**
|
|
68
|
+
* Return whether empty is enabled.
|
|
69
|
+
*
|
|
70
|
+
* @param value - Value.
|
|
71
|
+
* @returns Boolean indicating whether empty is enabled.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
75
|
+
* // import { isEmpty } from '@vettvangur/vanilla'
|
|
76
|
+
*
|
|
77
|
+
* isEmpty(value)
|
|
78
78
|
*/
|
|
79
79
|
function isEmpty(value) {
|
|
80
80
|
if (value === '' || value === undefined || value === null) {
|
|
@@ -83,42 +83,37 @@ function isEmpty(value) {
|
|
|
83
83
|
return false;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
/**
|
|
87
|
-
* Get translation.
|
|
88
|
-
*
|
|
89
|
-
* @param key - Value.
|
|
90
|
-
* @param translations - Value.
|
|
91
|
-
* @returns Result of the operation.
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
95
|
-
* // import { getTranslation } from '@vettvangur/vanilla'
|
|
96
|
-
*
|
|
97
|
-
* getTranslation(key, translations)
|
|
86
|
+
/**
|
|
87
|
+
* Get translation.
|
|
88
|
+
*
|
|
89
|
+
* @param key - Value.
|
|
90
|
+
* @param translations - Value.
|
|
91
|
+
* @returns Result of the operation.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
95
|
+
* // import { getTranslation } from '@vettvangur/vanilla'
|
|
96
|
+
*
|
|
97
|
+
* getTranslation(key, translations)
|
|
98
98
|
*/
|
|
99
99
|
function getTranslation(key, translations) {
|
|
100
100
|
if (!translations) {
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
|
-
|
|
104
|
-
if (!translation) {
|
|
105
|
-
console.error(`[vettvangur-vanilla :: getTranslation] No translation for key ${key} found.`);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
return translation;
|
|
103
|
+
return translations[key];
|
|
109
104
|
}
|
|
110
105
|
|
|
111
|
-
/**
|
|
112
|
-
* Get culture.
|
|
113
|
-
*
|
|
114
|
-
* @param path - Value.
|
|
115
|
-
* @returns Result of the operation.
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
119
|
-
* // import { getCulture } from '@vettvangur/vanilla'
|
|
120
|
-
*
|
|
121
|
-
* getCulture(path)
|
|
106
|
+
/**
|
|
107
|
+
* Get culture.
|
|
108
|
+
*
|
|
109
|
+
* @param path - Value.
|
|
110
|
+
* @returns Result of the operation.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* // vanilla (src/tools/javascript/vanilla/index.mjs)
|
|
114
|
+
* // import { getCulture } from '@vettvangur/vanilla'
|
|
115
|
+
*
|
|
116
|
+
* getCulture(path)
|
|
122
117
|
*/
|
|
123
118
|
function getCulture(path) {
|
|
124
119
|
const match = path.match(/^\/([a-z]{2})(\/|$)/i);
|