util-helpers 4.18.1 → 4.19.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/README.md CHANGED
@@ -97,6 +97,7 @@ formatBankCard('6228480402564890018', { spaceMark: '-' }); // 6228-4804-0256-489
97
97
  - [ajax](https://doly-dev.github.io/util-helpers/module-Other.html#.ajax) - 请求
98
98
  - [calculateCursorPosition](https://doly-dev.github.io/util-helpers/module-Other.html#.calculateCursorPosition) - 计算光标位置
99
99
  - [download](https://doly-dev.github.io/util-helpers/module-Other.html#.download) - 下载
100
+ - [loadScript](https://doly-dev.github.io/util-helpers/module-Other.html#.loadScript) - 加载 js 文件
100
101
  - [randomString](https://doly-dev.github.io/util-helpers/module-Other.html#.randomString) - 随机字符串
101
102
  - [strlen](https://doly-dev.github.io/util-helpers/module-Other.html#.strlen) - 字符长度
102
103
 
@@ -157,6 +157,18 @@
157
157
  return __assign.apply(this, arguments);
158
158
  };
159
159
 
160
+ function __rest(s, e) {
161
+ var t = {};
162
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
163
+ t[p] = s[p];
164
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
165
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
166
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
167
+ t[p[i]] = s[p[i]];
168
+ }
169
+ return t;
170
+ }
171
+
160
172
  function __awaiter(thisArg, _arguments, P, generator) {
161
173
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
162
174
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -1407,6 +1419,42 @@
1407
1419
  });
1408
1420
  }
1409
1421
 
1422
+ function loadScript(src, options) {
1423
+ return new Promise(function (resolve, reject) {
1424
+ var head = document.head;
1425
+ var script = document.createElement('script');
1426
+ var _a = options || {}, attrs = _a.attrs, _b = _a.destroyOnError, destroyOnError = _b === void 0 ? true : _b, restOptions = __rest(_a, ["attrs", "destroyOnError"]);
1427
+ var props = __assign(__assign({ async: true, type: 'text/javascript' }, restOptions), { src: src });
1428
+ for (var key in props) {
1429
+ if (key === 'onload' || key === 'onerror') {
1430
+ continue;
1431
+ }
1432
+ script[key] = props[key];
1433
+ }
1434
+ if (typeof attrs === 'object') {
1435
+ Object.keys(attrs).forEach(function (key) {
1436
+ script.setAttribute(key, attrs[key]);
1437
+ });
1438
+ }
1439
+ script.onload = function (ev) {
1440
+ var _a;
1441
+ this.onerror = this.onload = null;
1442
+ (_a = props.onload) === null || _a === void 0 ? void 0 : _a.call(this, ev);
1443
+ resolve(script);
1444
+ };
1445
+ script.onerror = function (ev) {
1446
+ var _a;
1447
+ this.onerror = this.onload = null;
1448
+ (_a = props.onerror) === null || _a === void 0 ? void 0 : _a.call(this, ev);
1449
+ if (destroyOnError) {
1450
+ head.removeChild(script);
1451
+ }
1452
+ reject(new URIError('Failed to load ' + this.src));
1453
+ };
1454
+ head.appendChild(script);
1455
+ });
1456
+ }
1457
+
1410
1458
  var numberChars = '0123456789';
1411
1459
  var letterChars = 'abcdefghijklmnopqrstuvwxyz';
1412
1460
  var defaultChars = numberChars + letterChars + letterChars.toUpperCase();
@@ -1700,9 +1748,9 @@
1700
1748
  return internalFindTreeSelect(tree, predicate, childrenField);
1701
1749
  }
1702
1750
 
1703
- var VERSION = "4.18.1";
1751
+ var VERSION = "4.19.0";
1704
1752
 
1705
- var version = "4.18.1";
1753
+ var version = "4.19.0";
1706
1754
 
1707
1755
  exports.VERSION = VERSION;
1708
1756
  exports.ajax = ajax;
@@ -1743,6 +1791,7 @@
1743
1791
  exports.isVehicle = isVehicle;
1744
1792
  exports.isWX = isWX;
1745
1793
  exports.listToTree = listToTree;
1794
+ exports.loadScript = loadScript;
1746
1795
  exports.minus = minus;
1747
1796
  exports.normalizeString = normalizeString;
1748
1797
  exports.numberToChinese = numberToChinese;