@whitesev/utils 1.5.3 → 1.5.5

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/index.amd.js CHANGED
@@ -1506,13 +1506,14 @@ define((function () { 'use strict';
1506
1506
  },
1507
1507
  /**
1508
1508
  * 成功的回调
1509
- * @param response
1509
+ * @param response 响应
1510
+ * @param details 请求的配置
1510
1511
  */
1511
- successResponseCallBack(response) {
1512
+ successResponseCallBack(response, details) {
1512
1513
  for (let index = 0; index < this.$config.configList.length; index++) {
1513
1514
  let item = this.$config.configList[index];
1514
1515
  if (typeof item.successFn === "function") {
1515
- if (item.successFn(response) == null) {
1516
+ if (item.successFn(response, details) == null) {
1516
1517
  return;
1517
1518
  }
1518
1519
  }
@@ -1521,7 +1522,7 @@ define((function () { 'use strict';
1521
1522
  },
1522
1523
  /**
1523
1524
  * 失败的回调
1524
- * @param response
1525
+ * @param data 配置
1525
1526
  */
1526
1527
  errorResponseCallBack(data) {
1527
1528
  for (let index = 0; index < this.$config.configList.length; index++) {
@@ -1784,6 +1785,7 @@ define((function () { 'use strict';
1784
1785
  type: "onabort",
1785
1786
  error: new TypeError("request canceled"),
1786
1787
  response: null,
1788
+ details: details,
1787
1789
  }) == null) {
1788
1790
  return;
1789
1791
  }
@@ -1815,6 +1817,7 @@ define((function () { 'use strict';
1815
1817
  type: "onerror",
1816
1818
  error: new TypeError("request error"),
1817
1819
  response: response,
1820
+ details: details,
1818
1821
  }) == null) {
1819
1822
  return;
1820
1823
  }
@@ -1843,6 +1846,7 @@ define((function () { 'use strict';
1843
1846
  type: "ontimeout",
1844
1847
  error: new TypeError("request timeout"),
1845
1848
  response: (argumentsList || [null])[0],
1849
+ details: details,
1846
1850
  }) == null) {
1847
1851
  return;
1848
1852
  }
@@ -1926,8 +1930,7 @@ define((function () { 'use strict';
1926
1930
  }
1927
1931
  /* 状态码2xx都是成功的 */
1928
1932
  if (Math.floor(Response.status / 100) === 2) {
1929
- if (this.context.HttpxResponseHook.successResponseCallBack(Response) ==
1930
- null) {
1933
+ if (this.context.HttpxResponseHook.successResponseCallBack(Response, details) == null) {
1931
1934
  return;
1932
1935
  }
1933
1936
  resolve({
@@ -2048,7 +2051,7 @@ define((function () { 'use strict';
2048
2051
  let responseText = "";
2049
2052
  /** 响应xml文档 */
2050
2053
  let responseXML = "";
2051
- let arrayBuffer = await resp.arrayBuffer;
2054
+ let arrayBuffer = await resp.arrayBuffer();
2052
2055
  let encoding = "utf-8";
2053
2056
  if (resp.headers.has("Content-Type")) {
2054
2057
  let charsetMatched = resp.headers
@@ -2059,7 +2062,7 @@ define((function () { 'use strict';
2059
2062
  }
2060
2063
  }
2061
2064
  let textDecoder = new TextDecoder(encoding);
2062
- responseText = textDecoder.decode(await resp.arrayBuffer());
2065
+ responseText = textDecoder.decode(arrayBuffer);
2063
2066
  response = responseText;
2064
2067
  if (details.responseType === "arraybuffer") {
2065
2068
  response = arrayBuffer;
@@ -6215,6 +6218,33 @@ define((function () { 'use strict';
6215
6218
  });
6216
6219
  return formData;
6217
6220
  }
6221
+ /**
6222
+ * 将链接转为URL对象,自动补充URL的protocol或者origin
6223
+ * @param text 需要转换的链接字符串
6224
+ * @example
6225
+ * Utils.toUrl("//www.baidu.com/s?word=666");
6226
+ * Utils.toUrl("/s?word=666");
6227
+ */
6228
+ toUrl(text) {
6229
+ if (typeof text !== "string") {
6230
+ throw new TypeError("toUrl: text must be string");
6231
+ }
6232
+ text = text.trim();
6233
+ if (text === "") {
6234
+ throw new TypeError("toUrl: text must not be empty");
6235
+ }
6236
+ if (text.startsWith("//")) {
6237
+ /* //www.baidu.com/xxxxxxx */
6238
+ /* 没有protocol,加上 */
6239
+ text = UtilsCore.globalThis.location.protocol + text;
6240
+ }
6241
+ else if (text.startsWith("/")) {
6242
+ /* /xxx/info?xxx=xxx */
6243
+ /* 没有Origin,加上 */
6244
+ text = UtilsCore.globalThis.location.origin + text;
6245
+ }
6246
+ return new URL(text);
6247
+ }
6218
6248
  /**
6219
6249
  * 生成uuid
6220
6250
  * @example