@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 CHANGED
@@ -68,28 +68,32 @@ function trimArray(arr) {
68
68
  * @returns
69
69
  */
70
70
  export var getRelativePath = function getRelativePath(from, to, base) {
71
- var _URL = new URL(from, base || from),
72
- fromHost = _URL.host,
73
- fromPath = _URL.pathname;
74
- var _URL2 = new URL(to, base || from),
75
- toHost = _URL2.host,
76
- toPath = _URL2.pathname;
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
- // from 'g.alicdn.com' to 'dev.g.alicdn.com' regarded as same host
79
- if (fromHost !== toHost && (toHost !== 'g.alicdn.com' || fromHost !== 'dev.g.alicdn.com')) return to;
80
- var fromParts = trimArray(fromPath.split('/'));
81
- var toParts = trimArray(toPath.split('/'));
82
- var length = Math.min(fromParts.length, toParts.length);
83
- var samePartsLength = length;
84
- for (var i = 0; i < length; i++) {
85
- if (fromParts[i] !== toParts[i]) {
86
- samePartsLength = i;
87
- break;
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
  };
@@ -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) || getLocaleFromCookie() || globalLocale);
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
  };
@@ -90,29 +90,33 @@ function trimArray(arr) {
90
90
  * @returns
91
91
  */
92
92
  var getRelativePath = function getRelativePath(from, to, base) {
93
- var _URL = new URL(from, base || from),
94
- fromHost = _URL.host,
95
- fromPath = _URL.pathname;
96
- var _URL2 = new URL(to, base || from),
97
- toHost = _URL2.host,
98
- toPath = _URL2.pathname;
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
- // from 'g.alicdn.com' to 'dev.g.alicdn.com' regarded as same host
101
- if (fromHost !== toHost && (toHost !== 'g.alicdn.com' || fromHost !== 'dev.g.alicdn.com')) return to;
102
- var fromParts = trimArray(fromPath.split('/'));
103
- var toParts = trimArray(toPath.split('/'));
104
- var length = Math.min(fromParts.length, toParts.length);
105
- var samePartsLength = length;
106
- for (var i = 0; i < length; i++) {
107
- if (fromParts[i] !== toParts[i]) {
108
- samePartsLength = i;
109
- break;
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;
@@ -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) || getLocaleFromCookie() || globalLocale);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/alfa-core",
3
- "version": "1.4.35",
3
+ "version": "1.4.37",
4
4
  "description": "MicroFront End SDK for alicloud",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",