@karpeleslab/klbfw 0.1.12 → 0.2.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/CLAUDE.md +50 -0
- package/README.md +199 -35
- package/cookies.js +107 -41
- package/coverage/clover.xml +835 -0
- package/coverage/coverage-final.json +9 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/cookies.js.html +334 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/fw-wrapper.js.html +163 -0
- package/coverage/lcov-report/index.html +131 -0
- package/coverage/lcov-report/index.js.html +196 -0
- package/coverage/lcov-report/internal.js.html +604 -0
- package/coverage/lcov-report/klbfw/cookies.js.html +490 -0
- package/coverage/lcov-report/klbfw/fw-wrapper.js.html +745 -0
- package/coverage/lcov-report/klbfw/index.html +206 -0
- package/coverage/lcov-report/klbfw/index.js.html +235 -0
- package/coverage/lcov-report/klbfw/internal.js.html +811 -0
- package/coverage/lcov-report/klbfw/rest.js.html +565 -0
- package/coverage/lcov-report/klbfw/test/index.html +116 -0
- package/coverage/lcov-report/klbfw/test/setup.js.html +1105 -0
- package/coverage/lcov-report/klbfw/upload.js.html +3487 -0
- package/coverage/lcov-report/klbfw/util.js.html +388 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/rest.js.html +472 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/upload.js.html +1789 -0
- package/coverage/lcov-report/util.js.html +313 -0
- package/coverage/lcov.info +1617 -0
- package/fw-wrapper.js +221 -26
- package/index.js +16 -2
- package/internal.js +186 -102
- package/package.json +21 -3
- package/rest.js +129 -81
- package/test/README.md +62 -0
- package/test/api.test.js +102 -0
- package/test/cookies.test.js +65 -0
- package/test/integration.test.js +481 -0
- package/test/rest.test.js +93 -0
- package/test/setup.js +341 -0
- package/test/upload.test.js +689 -0
- package/test/util.test.js +46 -0
- package/upload.js +1012 -442
- package/util.js +59 -21
package/util.js
CHANGED
|
@@ -1,51 +1,88 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Utility functions for KLB Frontend Framework
|
|
4
|
+
*
|
|
5
|
+
* This module provides utility functions for internationalization
|
|
6
|
+
* and URL prefix handling.
|
|
7
|
+
*/
|
|
8
|
+
|
|
2
9
|
const internalFW = require('./fw-wrapper');
|
|
3
10
|
|
|
4
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Fetches internationalization data for the specified language
|
|
13
|
+
* @param {string} language - Language code (e.g., 'en-US')
|
|
14
|
+
* @returns {Promise<Object>} Promise resolving to internationalization data
|
|
15
|
+
*/
|
|
16
|
+
const getI18N = (language) => {
|
|
17
|
+
// Use language from parameters or get from framework
|
|
5
18
|
language = language || internalFW.getLocale();
|
|
6
19
|
|
|
20
|
+
// Handle platform-specific i18n implementations
|
|
7
21
|
if (typeof __platformAsyncI18N !== "undefined") {
|
|
8
|
-
//
|
|
22
|
+
// New SSR mode
|
|
9
23
|
return __platformAsyncI18N(language);
|
|
10
24
|
}
|
|
25
|
+
|
|
11
26
|
if (typeof __platformGetI18N !== "undefined") {
|
|
12
|
-
//
|
|
13
|
-
return
|
|
14
|
-
resolve(__platformGetI18N(language));
|
|
15
|
-
});
|
|
27
|
+
// Legacy SSR mode
|
|
28
|
+
return Promise.resolve(__platformGetI18N(language));
|
|
16
29
|
}
|
|
17
30
|
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
return new Promise(function (resolve, reject) {
|
|
21
|
-
// a simple GET is straightforward
|
|
31
|
+
// Use fetch in browser environment
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
22
33
|
fetch("/_special/locale/" + language + ".json")
|
|
23
|
-
.then(
|
|
24
|
-
res.
|
|
25
|
-
|
|
34
|
+
.then(res => {
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
reject({
|
|
37
|
+
message: `HTTP Error: ${res.status} ${res.statusText}`,
|
|
38
|
+
status: res.status
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
res.json()
|
|
44
|
+
.then(resolve)
|
|
45
|
+
.catch(error => {
|
|
46
|
+
reject(error || new Error('Failed to parse JSON response'));
|
|
47
|
+
});
|
|
48
|
+
})
|
|
49
|
+
.catch(error => {
|
|
50
|
+
reject(error || new Error('Failed to fetch locale data'));
|
|
51
|
+
});
|
|
26
52
|
});
|
|
27
|
-
}
|
|
53
|
+
};
|
|
28
54
|
|
|
29
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Extracts prefixes from a URL path
|
|
57
|
+
* @param {string} url - URL path to process
|
|
58
|
+
* @returns {Array} Array containing [prefixObject, remainingPath]
|
|
59
|
+
*/
|
|
60
|
+
const trimPrefix = (url) => {
|
|
30
61
|
let currentPrefix = '';
|
|
31
62
|
let currentText = '';
|
|
32
63
|
const prefix = {};
|
|
33
64
|
|
|
34
65
|
for (let i = 0; i < url.length; i++) {
|
|
35
66
|
const currentChar = url[i];
|
|
67
|
+
|
|
68
|
+
// Skip consecutive slashes
|
|
36
69
|
if (currentChar === '/' && !currentText) continue;
|
|
37
70
|
|
|
38
|
-
|
|
71
|
+
// If we have text and not in a prefix, we're done with prefixes
|
|
72
|
+
if (!currentPrefix && currentText.length > 1) {
|
|
39
73
|
currentText = currentText + url.substr(i);
|
|
40
74
|
break;
|
|
41
75
|
}
|
|
42
76
|
|
|
77
|
+
// Handle slash after text
|
|
43
78
|
if (currentChar === '/' && currentText) {
|
|
44
79
|
if (currentText.length === 1) {
|
|
80
|
+
// This is a prefix indicator (e.g., /l/ for language)
|
|
45
81
|
currentPrefix = currentText;
|
|
46
82
|
currentText = '';
|
|
47
83
|
continue;
|
|
48
84
|
} else {
|
|
85
|
+
// This is a prefix value (e.g., /l/en-US/)
|
|
49
86
|
prefix[currentPrefix] = currentText;
|
|
50
87
|
currentPrefix = '';
|
|
51
88
|
currentText = '';
|
|
@@ -53,12 +90,13 @@ function trimPrefix(url) {
|
|
|
53
90
|
}
|
|
54
91
|
}
|
|
55
92
|
|
|
56
|
-
|
|
93
|
+
// Add character to current text
|
|
94
|
+
currentText += currentChar;
|
|
57
95
|
}
|
|
58
96
|
|
|
59
|
-
return [prefix, '/' + currentText]
|
|
60
|
-
}
|
|
61
|
-
|
|
97
|
+
return [prefix, '/' + currentText];
|
|
98
|
+
};
|
|
62
99
|
|
|
100
|
+
// Export functions
|
|
63
101
|
module.exports.getI18N = getI18N;
|
|
64
|
-
module.exports.trimPrefix = trimPrefix;
|
|
102
|
+
module.exports.trimPrefix = trimPrefix;
|