util-helpers 4.20.4 → 4.20.6
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 +4 -2
- package/dist/util-helpers.js +25 -18
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/VERSION.js +1 -1
- package/esm/bytesToSize.js +2 -0
- package/esm/index.js +1 -1
- package/esm/isValidNumber.js +2 -2
- package/esm/numberToChinese.js +1 -0
- package/esm/randomString.js +3 -1
- package/esm/utils/math.util.js +3 -3
- package/esm/utils/native.js +4 -2
- package/lib/VERSION.js +1 -1
- package/lib/bytesToSize.js +3 -1
- package/lib/index.js +1 -1
- package/lib/isValidNumber.js +1 -1
- package/lib/numberToChinese.js +2 -1
- package/lib/randomString.js +3 -1
- package/lib/utils/math.util.js +2 -2
- package/lib/utils/native.js +4 -2
- package/package.json +5 -8
package/README.md
CHANGED
|
@@ -14,12 +14,14 @@
|
|
|
14
14
|
npm install util-helpers
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
或者你使用 `yarn`
|
|
18
|
-
|
|
19
17
|
```shell
|
|
20
18
|
yarn add util-helpers
|
|
21
19
|
```
|
|
22
20
|
|
|
21
|
+
```shell
|
|
22
|
+
pnpm add util-helpers
|
|
23
|
+
```
|
|
24
|
+
|
|
23
25
|
### 浏览器引入
|
|
24
26
|
|
|
25
27
|
如果你的项目使用的是原生方式开发,可以在浏览器中使用 `script` 标签直接引入文件,并使用全局变量 `utilHelpers` 。
|
package/dist/util-helpers.js
CHANGED
|
@@ -81,10 +81,9 @@
|
|
|
81
81
|
return value == null ? '' : baseToString(value);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
var freeGlobalThis = typeof globalThis === 'object' && globalThis && globalThis.Object === Object && globalThis;
|
|
85
84
|
var freeGlobal = typeof global === 'object' && global && global.Object === Object && global;
|
|
86
85
|
var freeSelf = typeof self === 'object' && self && self.Object === Object && self;
|
|
87
|
-
var root =
|
|
86
|
+
var root = freeGlobal || freeSelf || Function('return this')() || {};
|
|
88
87
|
var root$1 = root;
|
|
89
88
|
|
|
90
89
|
var blobExisted = typeof Blob !== 'undefined';
|
|
@@ -103,7 +102,7 @@
|
|
|
103
102
|
return typeof value === 'number' || objectToString.call(value) === numberTag;
|
|
104
103
|
}
|
|
105
104
|
|
|
106
|
-
function isNaN
|
|
105
|
+
function isNaN(value) {
|
|
107
106
|
return isNumber(value) && root$1.isNaN(value);
|
|
108
107
|
}
|
|
109
108
|
|
|
@@ -133,6 +132,14 @@
|
|
|
133
132
|
return decimalAdjust('round', number, precision);
|
|
134
133
|
}
|
|
135
134
|
|
|
135
|
+
function constant(value) {
|
|
136
|
+
return function () {
|
|
137
|
+
return value;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function noop() { }
|
|
142
|
+
|
|
136
143
|
function sleep(ms) {
|
|
137
144
|
if (ms === void 0) { ms = 1000; }
|
|
138
145
|
return new Promise(function (resolve) {
|
|
@@ -539,7 +546,7 @@
|
|
|
539
546
|
ret = Number(value);
|
|
540
547
|
}
|
|
541
548
|
}
|
|
542
|
-
return typeof ret === 'number' && !
|
|
549
|
+
return typeof ret === 'number' && !isNaN(ret);
|
|
543
550
|
}
|
|
544
551
|
|
|
545
552
|
/******************************************************************************
|
|
@@ -671,7 +678,7 @@
|
|
|
671
678
|
if (ret === '') {
|
|
672
679
|
ret = Number(ret);
|
|
673
680
|
}
|
|
674
|
-
else if (
|
|
681
|
+
else if (isNaN(Number(ret))) {
|
|
675
682
|
ret = Number.NaN;
|
|
676
683
|
}
|
|
677
684
|
}
|
|
@@ -684,7 +691,7 @@
|
|
|
684
691
|
else {
|
|
685
692
|
ret = value;
|
|
686
693
|
}
|
|
687
|
-
if (
|
|
694
|
+
if (isNaN(ret)) {
|
|
688
695
|
return Number.NaN;
|
|
689
696
|
}
|
|
690
697
|
return ret;
|
|
@@ -764,7 +771,7 @@
|
|
|
764
771
|
|
|
765
772
|
var reg = /^[+-]?\d*\.?\d*$/;
|
|
766
773
|
function checkNumber(num) {
|
|
767
|
-
if ((typeof num !== 'number' && typeof num !== 'string') || (typeof num === 'number' && isNaN
|
|
774
|
+
if ((typeof num !== 'number' && typeof num !== 'string') || (typeof num === 'number' && isNaN(num)) || (typeof num === 'string' && (!(reg.test(num) || isScientificNumber(num)) || num === ''))) {
|
|
768
775
|
devWarn("".concat(num, " invalid parameter."));
|
|
769
776
|
return false;
|
|
770
777
|
}
|
|
@@ -809,7 +816,7 @@
|
|
|
809
816
|
if (typeof num === 'number' && !isFinite(num)) {
|
|
810
817
|
return num + '';
|
|
811
818
|
}
|
|
812
|
-
if (typeof precision !== 'number' || isNaN
|
|
819
|
+
if (typeof precision !== 'number' || isNaN(precision) || precision < 0) {
|
|
813
820
|
precision = 2;
|
|
814
821
|
}
|
|
815
822
|
else if (precision > 10) {
|
|
@@ -1153,7 +1160,7 @@
|
|
|
1153
1160
|
}
|
|
1154
1161
|
num1 = transformEffectiveNumber(num1);
|
|
1155
1162
|
num2 = transformEffectiveNumber(num2);
|
|
1156
|
-
if (isNaN
|
|
1163
|
+
if (isNaN(num1) || isNaN(num2)) {
|
|
1157
1164
|
return Number.NaN;
|
|
1158
1165
|
}
|
|
1159
1166
|
var num1Changed = float2Fixed(num1);
|
|
@@ -1177,7 +1184,7 @@
|
|
|
1177
1184
|
}
|
|
1178
1185
|
num1 = transformEffectiveNumber(num1);
|
|
1179
1186
|
num2 = transformEffectiveNumber(num2);
|
|
1180
|
-
if (isNaN
|
|
1187
|
+
if (isNaN(num1) || isNaN(num2)) {
|
|
1181
1188
|
return Number.NaN;
|
|
1182
1189
|
}
|
|
1183
1190
|
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
@@ -1197,7 +1204,7 @@
|
|
|
1197
1204
|
}
|
|
1198
1205
|
num1 = transformEffectiveNumber(num1);
|
|
1199
1206
|
num2 = transformEffectiveNumber(num2);
|
|
1200
|
-
if (isNaN
|
|
1207
|
+
if (isNaN(num1) || isNaN(num2)) {
|
|
1201
1208
|
return Number.NaN;
|
|
1202
1209
|
}
|
|
1203
1210
|
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
@@ -1217,7 +1224,7 @@
|
|
|
1217
1224
|
}
|
|
1218
1225
|
num1 = transformEffectiveNumber(num1);
|
|
1219
1226
|
num2 = transformEffectiveNumber(num2);
|
|
1220
|
-
if (isNaN
|
|
1227
|
+
if (isNaN(num1) || isNaN(num2)) {
|
|
1221
1228
|
return Number.NaN;
|
|
1222
1229
|
}
|
|
1223
1230
|
var num1Changed = float2Fixed(num1);
|
|
@@ -1245,7 +1252,7 @@
|
|
|
1245
1252
|
}
|
|
1246
1253
|
num1 = Math.abs(round(num1));
|
|
1247
1254
|
num2 = Math.abs(round(num2));
|
|
1248
|
-
if (isNaN
|
|
1255
|
+
if (isNaN(num1) || isNaN(num2)) {
|
|
1249
1256
|
return Number.NaN;
|
|
1250
1257
|
}
|
|
1251
1258
|
if (num1 === 0 && num2 === 0) {
|
|
@@ -1285,8 +1292,8 @@
|
|
|
1285
1292
|
}
|
|
1286
1293
|
|
|
1287
1294
|
var objectKeys = Object.keys;
|
|
1288
|
-
var createObjectURL = URL.createObjectURL;
|
|
1289
|
-
var revokeObjectURL = URL.revokeObjectURL;
|
|
1295
|
+
var createObjectURL = typeof URL !== 'undefined' ? URL.createObjectURL : constant('');
|
|
1296
|
+
var revokeObjectURL = typeof URL !== 'undefined' ? URL.revokeObjectURL : noop;
|
|
1290
1297
|
|
|
1291
1298
|
function ajax(url, options) {
|
|
1292
1299
|
var _a = options || {}, _b = _a.method, method = _b === void 0 ? 'get' : _b, _c = _a.data, data = _c === void 0 ? null : _c, timeout = _a.timeout, headers = _a.headers, _d = _a.withCredentials, withCredentials = _d === void 0 ? false : _d, _e = _a.async, async = _e === void 0 ? true : _e, _f = _a.user, user = _f === void 0 ? null : _f, _g = _a.password, password = _g === void 0 ? null : _g, responseType = _a.responseType, onReadyStateChange = _a.onReadyStateChange, onLoadStart = _a.onLoadStart, onProgress = _a.onProgress, onAbort = _a.onAbort, onTimeout = _a.onTimeout, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd;
|
|
@@ -1693,7 +1700,7 @@
|
|
|
1693
1700
|
function randomString(len, optionalChars) {
|
|
1694
1701
|
if (len === void 0) { len = 0; }
|
|
1695
1702
|
var realChars = typeof optionalChars === 'string' && optionalChars ? optionalChars : defaultChars;
|
|
1696
|
-
return internalRandomString(len, realChars);
|
|
1703
|
+
return internalRandomString(toNumber(len), realChars);
|
|
1697
1704
|
}
|
|
1698
1705
|
|
|
1699
1706
|
function strlen(str) {
|
|
@@ -1976,9 +1983,9 @@
|
|
|
1976
1983
|
return internalFindTreeSelect(tree, predicate, childrenField);
|
|
1977
1984
|
}
|
|
1978
1985
|
|
|
1979
|
-
var VERSION = "4.20.
|
|
1986
|
+
var VERSION = "4.20.6";
|
|
1980
1987
|
|
|
1981
|
-
var version = "4.20.
|
|
1988
|
+
var version = "4.20.6";
|
|
1982
1989
|
|
|
1983
1990
|
exports.VERSION = VERSION;
|
|
1984
1991
|
exports.ajax = ajax;
|