util-helpers 4.18.1 → 4.19.1

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
 
@@ -129,6 +129,44 @@
129
129
  return typeof value === 'symbol' || (isObjectLike(value) && isType(value, 'Symbol'));
130
130
  }
131
131
 
132
+ var reIsBinary = /^0b[01]+$/i;
133
+ var reIsOctal = /^0o[0-7]+$/i;
134
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
135
+ function toNumber(value) {
136
+ if (typeof value === 'number') {
137
+ return value;
138
+ }
139
+ if (isSymbol(value)) {
140
+ return NaN;
141
+ }
142
+ if (isObject(value)) {
143
+ value = Number(value);
144
+ }
145
+ if (typeof value !== 'string') {
146
+ return value === 0 ? value : +value;
147
+ }
148
+ value = value.trim();
149
+ var isBinary = reIsBinary.test(value);
150
+ return isBinary || reIsOctal.test(value)
151
+ ? parseInt(value.slice(2), isBinary ? 2 : 8)
152
+ : reIsBadHex.test(value)
153
+ ? NaN
154
+ : +value;
155
+ }
156
+
157
+ function toInteger(value) {
158
+ var result = toNumber(value);
159
+ if (!result || result === Infinity || result === -Infinity) {
160
+ return result === result ? result : 0;
161
+ }
162
+ var remainder = result % 1;
163
+ return remainder ? result - remainder : result;
164
+ }
165
+
166
+ var argType = 'Arguments';
167
+ isType((function () { return arguments; })(), argType);
168
+ var numberIsFinite = Number.isFinite;
169
+
132
170
  /******************************************************************************
133
171
  Copyright (c) Microsoft Corporation.
134
172
 
@@ -157,6 +195,18 @@
157
195
  return __assign.apply(this, arguments);
158
196
  };
159
197
 
198
+ function __rest(s, e) {
199
+ var t = {};
200
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
201
+ t[p] = s[p];
202
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
203
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
204
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
205
+ t[p[i]] = s[p[i]];
206
+ }
207
+ return t;
208
+ }
209
+
160
210
  function __awaiter(thisArg, _arguments, P, generator) {
161
211
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
162
212
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -234,6 +284,10 @@
234
284
  return to.concat(ar || Array.prototype.slice.call(from));
235
285
  }
236
286
 
287
+ function isFinite$1(value) {
288
+ return numberIsFinite ? numberIsFinite(value) : typeof value === 'number' && root.isFinite(value);
289
+ }
290
+
237
291
  function baseToString(value) {
238
292
  if (typeof value === 'string') {
239
293
  return value;
@@ -251,6 +305,24 @@
251
305
  return value == null ? '' : baseToString(value);
252
306
  }
253
307
 
308
+ function decimalAdjust(type, value, precision) {
309
+ if (precision === void 0) { precision = 0; }
310
+ var func = Math[type];
311
+ value = toNumber(value);
312
+ precision = Math.min(toInteger(precision), 292);
313
+ if (precision === 0 || !isFinite$1(value)) {
314
+ return func(value);
315
+ }
316
+ var pair = toString(value).split('e');
317
+ value = func(+(pair[0] + 'e' + (pair[1] ? +pair[1] + precision : precision)));
318
+ pair = toString(value).split('e');
319
+ return +(pair[0] + 'e' + (pair[1] ? +pair[1] - precision : -precision));
320
+ }
321
+
322
+ function round(number, precision) {
323
+ return decimalAdjust('round', number, precision);
324
+ }
325
+
254
326
  function isBlob(value) {
255
327
  return (blobExisted && value instanceof Blob) || isType(value, ['Blob', 'File']);
256
328
  }
@@ -1233,14 +1305,9 @@
1233
1305
  return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
1234
1306
  }
1235
1307
 
1236
- function round(num, precision) {
1308
+ function _round(num, precision) {
1237
1309
  if (precision === void 0) { precision = 0; }
1238
- num = transformEffectiveNumber(num);
1239
- if (isNaN$1(num)) {
1240
- return Number.NaN;
1241
- }
1242
- var base = Math.pow(10, precision);
1243
- return divide(Math.round(times(num, base)), base);
1310
+ return round(num, precision);
1244
1311
  }
1245
1312
 
1246
1313
  function ajax(url, options) {
@@ -1407,6 +1474,42 @@
1407
1474
  });
1408
1475
  }
1409
1476
 
1477
+ function loadScript(src, options) {
1478
+ return new Promise(function (resolve, reject) {
1479
+ var head = document.head;
1480
+ var script = document.createElement('script');
1481
+ var _a = options || {}, attrs = _a.attrs, _b = _a.destroyOnError, destroyOnError = _b === void 0 ? true : _b, restOptions = __rest(_a, ["attrs", "destroyOnError"]);
1482
+ var props = __assign(__assign({ async: true, type: 'text/javascript' }, restOptions), { src: src });
1483
+ for (var key in props) {
1484
+ if (key === 'onload' || key === 'onerror') {
1485
+ continue;
1486
+ }
1487
+ script[key] = props[key];
1488
+ }
1489
+ if (typeof attrs === 'object') {
1490
+ Object.keys(attrs).forEach(function (key) {
1491
+ script.setAttribute(key, attrs[key]);
1492
+ });
1493
+ }
1494
+ script.onload = function (ev) {
1495
+ var _a;
1496
+ this.onerror = this.onload = null;
1497
+ (_a = props.onload) === null || _a === void 0 ? void 0 : _a.call(this, ev);
1498
+ resolve(script);
1499
+ };
1500
+ script.onerror = function (ev) {
1501
+ var _a;
1502
+ this.onerror = this.onload = null;
1503
+ (_a = props.onerror) === null || _a === void 0 ? void 0 : _a.call(this, ev);
1504
+ if (destroyOnError) {
1505
+ head.removeChild(script);
1506
+ }
1507
+ reject(new URIError('Failed to load ' + this.src));
1508
+ };
1509
+ head.appendChild(script);
1510
+ });
1511
+ }
1512
+
1410
1513
  var numberChars = '0123456789';
1411
1514
  var letterChars = 'abcdefghijklmnopqrstuvwxyz';
1412
1515
  var defaultChars = numberChars + letterChars + letterChars.toUpperCase();
@@ -1700,9 +1803,9 @@
1700
1803
  return internalFindTreeSelect(tree, predicate, childrenField);
1701
1804
  }
1702
1805
 
1703
- var VERSION = "4.18.1";
1806
+ var VERSION = "4.19.1";
1704
1807
 
1705
- var version = "4.18.1";
1808
+ var version = "4.19.1";
1706
1809
 
1707
1810
  exports.VERSION = VERSION;
1708
1811
  exports.ajax = ajax;
@@ -1743,6 +1846,7 @@
1743
1846
  exports.isVehicle = isVehicle;
1744
1847
  exports.isWX = isWX;
1745
1848
  exports.listToTree = listToTree;
1849
+ exports.loadScript = loadScript;
1746
1850
  exports.minus = minus;
1747
1851
  exports.normalizeString = normalizeString;
1748
1852
  exports.numberToChinese = numberToChinese;
@@ -1751,7 +1855,7 @@
1751
1855
  exports.plus = plus;
1752
1856
  exports.randomString = randomString;
1753
1857
  exports.replaceChar = replaceChar;
1754
- exports.round = round;
1858
+ exports.round = _round;
1755
1859
  exports.safeDate = safeDate;
1756
1860
  exports.setDataURLPrefix = setDataURLPrefix;
1757
1861
  exports.setDisableWarning = setDisableWarning;