@alicloud/alfa-core 1.4.35 → 1.4.37
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/es/utils/index.js +25 -21
- package/es/utils/locale.js +4 -7
- package/lib/utils/index.js +25 -21
- package/lib/utils/locale.js +4 -7
- package/package.json +1 -1
package/es/utils/index.js
CHANGED
|
@@ -68,28 +68,32 @@ function trimArray(arr) {
|
|
|
68
68
|
* @returns
|
|
69
69
|
*/
|
|
70
70
|
export var getRelativePath = function getRelativePath(from, to, base) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
try {
|
|
72
|
+
var _URL = new URL(from, base || from),
|
|
73
|
+
fromHost = _URL.host,
|
|
74
|
+
fromPath = _URL.pathname;
|
|
75
|
+
var _URL2 = new URL(to, base || from),
|
|
76
|
+
toHost = _URL2.host,
|
|
77
|
+
toPath = _URL2.pathname;
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
// from 'g.alicdn.com' to 'dev.g.alicdn.com' regarded as same host
|
|
80
|
+
if (fromHost !== toHost && (toHost !== 'g.alicdn.com' || fromHost !== 'dev.g.alicdn.com')) return to;
|
|
81
|
+
var fromParts = trimArray(fromPath.split('/'));
|
|
82
|
+
var toParts = trimArray(toPath.split('/'));
|
|
83
|
+
var length = Math.min(fromParts.length, toParts.length);
|
|
84
|
+
var samePartsLength = length;
|
|
85
|
+
for (var i = 0; i < length; i++) {
|
|
86
|
+
if (fromParts[i] !== toParts[i]) {
|
|
87
|
+
samePartsLength = i;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
88
90
|
}
|
|
91
|
+
var outputParts = [];
|
|
92
|
+
for (var _i = samePartsLength; _i < fromParts.length; _i++) {
|
|
93
|
+
outputParts.push('..');
|
|
94
|
+
}
|
|
95
|
+
return outputParts.concat(toParts.slice(samePartsLength)).join('/');
|
|
96
|
+
} catch (e) {
|
|
97
|
+
return to;
|
|
89
98
|
}
|
|
90
|
-
var outputParts = [];
|
|
91
|
-
for (var _i = samePartsLength; _i < fromParts.length; _i++) {
|
|
92
|
-
outputParts.push('..');
|
|
93
|
-
}
|
|
94
|
-
return outputParts.concat(toParts.slice(samePartsLength)).join('/');
|
|
95
99
|
};
|
package/es/utils/locale.js
CHANGED
|
@@ -9,18 +9,15 @@ var localeMap = {
|
|
|
9
9
|
fr: 'fr_FR',
|
|
10
10
|
de: 'de_DE'
|
|
11
11
|
};
|
|
12
|
-
var getLocaleFromCookie = function getLocaleFromCookie() {
|
|
13
|
-
var lang = getCookie('aliyun_lang');
|
|
14
|
-
return lang && localeMap[lang];
|
|
15
|
-
};
|
|
16
12
|
|
|
17
13
|
/**
|
|
18
|
-
* x-X-Y to x_X_Y
|
|
14
|
+
* 1. x-X-Y to x_X_Y
|
|
15
|
+
* 2. zh to zh_CN
|
|
19
16
|
* @param key
|
|
20
17
|
* @returns
|
|
21
18
|
*/
|
|
22
19
|
var formatLocale = function formatLocale(key) {
|
|
23
|
-
return key.replace('-', '_');
|
|
20
|
+
return localeMap[key] ? localeMap[key] : key.replace('-', '_');
|
|
24
21
|
};
|
|
25
22
|
|
|
26
23
|
/**
|
|
@@ -29,5 +26,5 @@ var formatLocale = function formatLocale(key) {
|
|
|
29
26
|
*/
|
|
30
27
|
export var getLocale = function getLocale(key) {
|
|
31
28
|
var _window, _window$ALIYUN_CONSOL;
|
|
32
|
-
return formatLocale(key || ((_window = window) === null || _window === void 0 ? void 0 : (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.LOCALE) ||
|
|
29
|
+
return formatLocale(key || ((_window = window) === null || _window === void 0 ? void 0 : (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.LOCALE) || getCookie('aliyun_lang') || globalLocale);
|
|
33
30
|
};
|
package/lib/utils/index.js
CHANGED
|
@@ -90,29 +90,33 @@ function trimArray(arr) {
|
|
|
90
90
|
* @returns
|
|
91
91
|
*/
|
|
92
92
|
var getRelativePath = function getRelativePath(from, to, base) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
try {
|
|
94
|
+
var _URL = new URL(from, base || from),
|
|
95
|
+
fromHost = _URL.host,
|
|
96
|
+
fromPath = _URL.pathname;
|
|
97
|
+
var _URL2 = new URL(to, base || from),
|
|
98
|
+
toHost = _URL2.host,
|
|
99
|
+
toPath = _URL2.pathname;
|
|
99
100
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
101
|
+
// from 'g.alicdn.com' to 'dev.g.alicdn.com' regarded as same host
|
|
102
|
+
if (fromHost !== toHost && (toHost !== 'g.alicdn.com' || fromHost !== 'dev.g.alicdn.com')) return to;
|
|
103
|
+
var fromParts = trimArray(fromPath.split('/'));
|
|
104
|
+
var toParts = trimArray(toPath.split('/'));
|
|
105
|
+
var length = Math.min(fromParts.length, toParts.length);
|
|
106
|
+
var samePartsLength = length;
|
|
107
|
+
for (var i = 0; i < length; i++) {
|
|
108
|
+
if (fromParts[i] !== toParts[i]) {
|
|
109
|
+
samePartsLength = i;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
110
112
|
}
|
|
113
|
+
var outputParts = [];
|
|
114
|
+
for (var _i = samePartsLength; _i < fromParts.length; _i++) {
|
|
115
|
+
outputParts.push('..');
|
|
116
|
+
}
|
|
117
|
+
return outputParts.concat(toParts.slice(samePartsLength)).join('/');
|
|
118
|
+
} catch (e) {
|
|
119
|
+
return to;
|
|
111
120
|
}
|
|
112
|
-
var outputParts = [];
|
|
113
|
-
for (var _i = samePartsLength; _i < fromParts.length; _i++) {
|
|
114
|
-
outputParts.push('..');
|
|
115
|
-
}
|
|
116
|
-
return outputParts.concat(toParts.slice(samePartsLength)).join('/');
|
|
117
121
|
};
|
|
118
122
|
exports.getRelativePath = getRelativePath;
|
package/lib/utils/locale.js
CHANGED
|
@@ -15,18 +15,15 @@ var localeMap = {
|
|
|
15
15
|
fr: 'fr_FR',
|
|
16
16
|
de: 'de_DE'
|
|
17
17
|
};
|
|
18
|
-
var getLocaleFromCookie = function getLocaleFromCookie() {
|
|
19
|
-
var lang = (0, _cookie.getCookie)('aliyun_lang');
|
|
20
|
-
return lang && localeMap[lang];
|
|
21
|
-
};
|
|
22
18
|
|
|
23
19
|
/**
|
|
24
|
-
* x-X-Y to x_X_Y
|
|
20
|
+
* 1. x-X-Y to x_X_Y
|
|
21
|
+
* 2. zh to zh_CN
|
|
25
22
|
* @param key
|
|
26
23
|
* @returns
|
|
27
24
|
*/
|
|
28
25
|
var formatLocale = function formatLocale(key) {
|
|
29
|
-
return key.replace('-', '_');
|
|
26
|
+
return localeMap[key] ? localeMap[key] : key.replace('-', '_');
|
|
30
27
|
};
|
|
31
28
|
|
|
32
29
|
/**
|
|
@@ -35,6 +32,6 @@ var formatLocale = function formatLocale(key) {
|
|
|
35
32
|
*/
|
|
36
33
|
var getLocale = function getLocale(key) {
|
|
37
34
|
var _window, _window$ALIYUN_CONSOL;
|
|
38
|
-
return formatLocale(key || ((_window = window) === null || _window === void 0 ? void 0 : (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.LOCALE) ||
|
|
35
|
+
return formatLocale(key || ((_window = window) === null || _window === void 0 ? void 0 : (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.LOCALE) || (0, _cookie.getCookie)('aliyun_lang') || globalLocale);
|
|
39
36
|
};
|
|
40
37
|
exports.getLocale = getLocale;
|