util-helpers 4.21.5 → 4.21.7
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/util-helpers.js +37 -69
- 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/compressImage.js +2 -1
- package/esm/download.js +2 -2
- package/esm/formatMoney.js +4 -4
- package/esm/index.js +1 -1
- package/esm/isChinese.js +2 -2
- package/esm/utils/math.util.js +7 -39
- package/esm/utils/native.js +2 -1
- package/lib/VERSION.js +1 -1
- package/lib/compressImage.js +2 -1
- package/lib/download.js +1 -1
- package/lib/formatMoney.js +3 -3
- package/lib/index.js +1 -1
- package/lib/isChinese.js +1 -1
- package/lib/utils/math.util.js +5 -38
- package/lib/utils/native.js +1 -0
- package/package.json +1 -1
- package/types/utils/native.d.ts +1 -0
package/esm/VERSION.js
CHANGED
package/esm/compressImage.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { toNumber } from 'ut2';
|
|
2
2
|
import loadImageWithBlob from './loadImageWithBlob.js';
|
|
3
|
+
import { nativeUndefined } from './utils/native.js';
|
|
3
4
|
|
|
4
5
|
function canvasToBlob(canvas, type, quality) {
|
|
5
6
|
return new Promise(function (resolve) {
|
|
@@ -41,7 +42,7 @@ var compressImage = function (img, options) {
|
|
|
41
42
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
42
43
|
}
|
|
43
44
|
var internalOffset = [0, 0];
|
|
44
|
-
if (rotate !==
|
|
45
|
+
if (rotate !== nativeUndefined) {
|
|
45
46
|
ctx.translate(image.width / 2, image.height / 2);
|
|
46
47
|
internalOffset = [-image.width / 2, -image.height / 2];
|
|
47
48
|
ctx.rotate((rotate * Math.PI) / 180);
|
package/esm/download.js
CHANGED
|
@@ -3,7 +3,7 @@ import { isBlob, isPromiseLike } from 'ut2';
|
|
|
3
3
|
import dataURLToBlob from './dataURLToBlob.js';
|
|
4
4
|
import isUrl from './isUrl.js';
|
|
5
5
|
import ajax from './ajax.js';
|
|
6
|
-
import { createObjectURL, revokeObjectURL } from './utils/native.js';
|
|
6
|
+
import { createObjectURL, revokeObjectURL, nativeUndefined } from './utils/native.js';
|
|
7
7
|
|
|
8
8
|
function saver(blobUrl, fileName) {
|
|
9
9
|
if (fileName === void 0) { fileName = ''; }
|
|
@@ -59,7 +59,7 @@ function download(data, options) {
|
|
|
59
59
|
case 5:
|
|
60
60
|
res = _a.sent();
|
|
61
61
|
currentFileName = fileName || data.split('?')[0].split('#')[0].split('/').pop();
|
|
62
|
-
return [2, download(res, { fileName: currentFileName, type: type || (isBlob(res) ? res.type :
|
|
62
|
+
return [2, download(res, { fileName: currentFileName, type: type || (isBlob(res) ? res.type : nativeUndefined) })];
|
|
63
63
|
case 6:
|
|
64
64
|
payload = new Blob([data], { type: type || 'text/plain' });
|
|
65
65
|
_a.label = 7;
|
package/esm/formatMoney.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __read } from 'tslib';
|
|
2
2
|
import { isNaN } from 'ut2';
|
|
3
|
-
import {
|
|
3
|
+
import { transformEffectiveNumber, checkBoundary, trimLeftZero } from './utils/math.util.js';
|
|
4
4
|
import devWarn from './utils/devWarn.js';
|
|
5
|
+
import isValidNumber from './isValidNumber.js';
|
|
5
6
|
|
|
6
|
-
var reg = /^[+-]?\d*\.?\d*$/;
|
|
7
7
|
function checkNumber(num) {
|
|
8
|
-
if (
|
|
8
|
+
if (!isValidNumber(num)) {
|
|
9
9
|
devWarn("".concat(num, " invalid parameter."));
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
@@ -59,7 +59,7 @@ var formatMoney = function (num, options) {
|
|
|
59
59
|
symbol = typeof symbol === 'string' ? symbol : '';
|
|
60
60
|
thousand = typeof thousand === 'string' ? thousand : ',';
|
|
61
61
|
decimal = typeof decimal === 'string' ? decimal : '.';
|
|
62
|
-
var strNum =
|
|
62
|
+
var strNum = transformEffectiveNumber(num) + '';
|
|
63
63
|
var _d = __read(strNum.split('.'), 2), intStr = _d[0], decStr = _d[1];
|
|
64
64
|
return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
|
|
65
65
|
};
|
package/esm/index.js
CHANGED
package/esm/isChinese.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toString } from 'ut2';
|
|
2
|
-
import { objectValues } from './utils/native.js';
|
|
2
|
+
import { objectValues, nativeUndefined } from './utils/native.js';
|
|
3
3
|
|
|
4
4
|
var chineseDictionary = {
|
|
5
5
|
chineseBasic: '[\u4e00-\u9fa5]',
|
|
@@ -29,7 +29,7 @@ function isChinese(value, options) {
|
|
|
29
29
|
var extendRegExp = loose ? looseChineseExtendRegExp : chineseExtendRegExp;
|
|
30
30
|
var hasExtend = useExtend && supportRegExpUnicode;
|
|
31
31
|
var resultRegExp = hasExtend ? extendRegExp : basicRegExp;
|
|
32
|
-
var flag = hasExtend ? 'u' :
|
|
32
|
+
var flag = hasExtend ? 'u' : nativeUndefined;
|
|
33
33
|
var reg = new RegExp(resultRegExp, flag);
|
|
34
34
|
return reg.test(valueStr);
|
|
35
35
|
}
|
package/esm/utils/math.util.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { isString, isNaN, isSymbol, isNumber, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } from 'ut2';
|
|
1
|
+
import { isString, toNumber, isNaN, isSymbol, isNumber, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } from 'ut2';
|
|
2
2
|
import devWarn from './devWarn.js';
|
|
3
3
|
|
|
4
|
+
var radixReg = /^[-+]?0[b|o|x]\d+/i;
|
|
5
|
+
var dotNumberStringReg = /^\.\d+/;
|
|
4
6
|
function transformEffectiveNumber(value) {
|
|
5
7
|
var ret;
|
|
6
8
|
if (isString(value)) {
|
|
@@ -8,6 +10,9 @@ function transformEffectiveNumber(value) {
|
|
|
8
10
|
if (ret === '') {
|
|
9
11
|
ret = Number(ret);
|
|
10
12
|
}
|
|
13
|
+
else if (radixReg.test(ret) || dotNumberStringReg.test(ret)) {
|
|
14
|
+
ret = toNumber(ret);
|
|
15
|
+
}
|
|
11
16
|
else if (isNaN(Number(ret))) {
|
|
12
17
|
ret = Number.NaN;
|
|
13
18
|
}
|
|
@@ -61,42 +66,5 @@ function trimLeftZero(num) {
|
|
|
61
66
|
}
|
|
62
67
|
return num;
|
|
63
68
|
}
|
|
64
|
-
function scientificToNumber(num) {
|
|
65
|
-
var strNum = String(num);
|
|
66
|
-
if (!isScientificNumber(strNum)) {
|
|
67
|
-
return num;
|
|
68
|
-
}
|
|
69
|
-
var ret;
|
|
70
|
-
var zero = '0';
|
|
71
|
-
var parts = strNum.toLowerCase().split('e');
|
|
72
|
-
var e = parts.pop();
|
|
73
|
-
var l = Math.abs(e);
|
|
74
|
-
var sign = e / l;
|
|
75
|
-
var coeff_array = parts[0].split('.');
|
|
76
|
-
if (sign === -1) {
|
|
77
|
-
var intVal = trimLeftZero(coeff_array[0]);
|
|
78
|
-
if (intVal.length > l) {
|
|
79
|
-
var thanLen = intVal.length - l;
|
|
80
|
-
var dec = coeff_array[1] || '';
|
|
81
|
-
ret = intVal.slice(0, thanLen);
|
|
82
|
-
if (intVal.slice(thanLen) !== '0' || dec) {
|
|
83
|
-
ret += '.' + intVal.slice(thanLen) + dec;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
ret = zero + '.' + new Array(l - intVal.length + 1).join(zero) + coeff_array.join('');
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
var dec = coeff_array[1] || '';
|
|
92
|
-
if (l - dec.length < 0) {
|
|
93
|
-
ret = trimLeftZero(coeff_array[0] + dec.substring(0, l)) + '.' + dec.substring(l);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
ret = coeff_array.join('') + new Array(l - dec.length + 1).join(zero);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return trimLeftZero(ret);
|
|
100
|
-
}
|
|
101
69
|
|
|
102
|
-
export { checkBoundary, digitLength, float2Fixed, isScientificNumber,
|
|
70
|
+
export { checkBoundary, digitLength, float2Fixed, isScientificNumber, strip, transformEffectiveNumber, trimLeftZero };
|
package/esm/utils/native.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { constant, noop } from 'ut2';
|
|
2
2
|
import { URLExisted } from './setup.js';
|
|
3
3
|
|
|
4
|
+
var nativeUndefined = void 0;
|
|
4
5
|
var objectKeys = Object.keys;
|
|
5
6
|
var objectValues = Object.values;
|
|
6
7
|
var createObjectURL = URLExisted ? URL.createObjectURL : constant('');
|
|
7
8
|
var revokeObjectURL = URLExisted ? URL.revokeObjectURL : noop;
|
|
8
9
|
|
|
9
|
-
export { createObjectURL, objectKeys, objectValues, revokeObjectURL };
|
|
10
|
+
export { createObjectURL, nativeUndefined, objectKeys, objectValues, revokeObjectURL };
|
package/lib/VERSION.js
CHANGED
package/lib/compressImage.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var ut2 = require('ut2');
|
|
4
4
|
var loadImageWithBlob = require('./loadImageWithBlob.js');
|
|
5
|
+
var native = require('./utils/native.js');
|
|
5
6
|
|
|
6
7
|
function canvasToBlob(canvas, type, quality) {
|
|
7
8
|
return new Promise(function (resolve) {
|
|
@@ -43,7 +44,7 @@ var compressImage = function (img, options) {
|
|
|
43
44
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
44
45
|
}
|
|
45
46
|
var internalOffset = [0, 0];
|
|
46
|
-
if (rotate !==
|
|
47
|
+
if (rotate !== native.nativeUndefined) {
|
|
47
48
|
ctx.translate(image.width / 2, image.height / 2);
|
|
48
49
|
internalOffset = [-image.width / 2, -image.height / 2];
|
|
49
50
|
ctx.rotate((rotate * Math.PI) / 180);
|
package/lib/download.js
CHANGED
|
@@ -61,7 +61,7 @@ function download(data, options) {
|
|
|
61
61
|
case 5:
|
|
62
62
|
res = _a.sent();
|
|
63
63
|
currentFileName = fileName || data.split('?')[0].split('#')[0].split('/').pop();
|
|
64
|
-
return [2, download(res, { fileName: currentFileName, type: type || (ut2.isBlob(res) ? res.type :
|
|
64
|
+
return [2, download(res, { fileName: currentFileName, type: type || (ut2.isBlob(res) ? res.type : native.nativeUndefined) })];
|
|
65
65
|
case 6:
|
|
66
66
|
payload = new Blob([data], { type: type || 'text/plain' });
|
|
67
67
|
_a.label = 7;
|
package/lib/formatMoney.js
CHANGED
|
@@ -4,10 +4,10 @@ var tslib = require('tslib');
|
|
|
4
4
|
var ut2 = require('ut2');
|
|
5
5
|
var math_util = require('./utils/math.util.js');
|
|
6
6
|
var devWarn = require('./utils/devWarn.js');
|
|
7
|
+
var isValidNumber = require('./isValidNumber.js');
|
|
7
8
|
|
|
8
|
-
var reg = /^[+-]?\d*\.?\d*$/;
|
|
9
9
|
function checkNumber(num) {
|
|
10
|
-
if (
|
|
10
|
+
if (!isValidNumber(num)) {
|
|
11
11
|
devWarn("".concat(num, " invalid parameter."));
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
@@ -61,7 +61,7 @@ var formatMoney = function (num, options) {
|
|
|
61
61
|
symbol = typeof symbol === 'string' ? symbol : '';
|
|
62
62
|
thousand = typeof thousand === 'string' ? thousand : ',';
|
|
63
63
|
decimal = typeof decimal === 'string' ? decimal : '.';
|
|
64
|
-
var strNum = math_util.
|
|
64
|
+
var strNum = math_util.transformEffectiveNumber(num) + '';
|
|
65
65
|
var _d = tslib.__read(strNum.split('.'), 2), intStr = _d[0], decStr = _d[1];
|
|
66
66
|
return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
|
|
67
67
|
};
|
package/lib/index.js
CHANGED
|
@@ -66,7 +66,7 @@ var findTreeSelect = require('./findTreeSelect.js');
|
|
|
66
66
|
var config = require('./utils/config.js');
|
|
67
67
|
var VERSION = require('./VERSION.js');
|
|
68
68
|
|
|
69
|
-
exports.version = "4.21.
|
|
69
|
+
exports.version = "4.21.7";
|
|
70
70
|
|
|
71
71
|
exports.isMobile = isMobile;
|
|
72
72
|
exports.isTelephone = isTelephone;
|
package/lib/isChinese.js
CHANGED
|
@@ -31,7 +31,7 @@ function isChinese(value, options) {
|
|
|
31
31
|
var extendRegExp = loose ? looseChineseExtendRegExp : chineseExtendRegExp;
|
|
32
32
|
var hasExtend = useExtend && supportRegExpUnicode;
|
|
33
33
|
var resultRegExp = hasExtend ? extendRegExp : basicRegExp;
|
|
34
|
-
var flag = hasExtend ? 'u' :
|
|
34
|
+
var flag = hasExtend ? 'u' : native.nativeUndefined;
|
|
35
35
|
var reg = new RegExp(resultRegExp, flag);
|
|
36
36
|
return reg.test(valueStr);
|
|
37
37
|
}
|
package/lib/utils/math.util.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
var ut2 = require('ut2');
|
|
4
4
|
var devWarn = require('./devWarn.js');
|
|
5
5
|
|
|
6
|
+
var radixReg = /^[-+]?0[b|o|x]\d+/i;
|
|
7
|
+
var dotNumberStringReg = /^\.\d+/;
|
|
6
8
|
function transformEffectiveNumber(value) {
|
|
7
9
|
var ret;
|
|
8
10
|
if (ut2.isString(value)) {
|
|
@@ -10,6 +12,9 @@ function transformEffectiveNumber(value) {
|
|
|
10
12
|
if (ret === '') {
|
|
11
13
|
ret = Number(ret);
|
|
12
14
|
}
|
|
15
|
+
else if (radixReg.test(ret) || dotNumberStringReg.test(ret)) {
|
|
16
|
+
ret = ut2.toNumber(ret);
|
|
17
|
+
}
|
|
13
18
|
else if (ut2.isNaN(Number(ret))) {
|
|
14
19
|
ret = Number.NaN;
|
|
15
20
|
}
|
|
@@ -63,49 +68,11 @@ function trimLeftZero(num) {
|
|
|
63
68
|
}
|
|
64
69
|
return num;
|
|
65
70
|
}
|
|
66
|
-
function scientificToNumber(num) {
|
|
67
|
-
var strNum = String(num);
|
|
68
|
-
if (!isScientificNumber(strNum)) {
|
|
69
|
-
return num;
|
|
70
|
-
}
|
|
71
|
-
var ret;
|
|
72
|
-
var zero = '0';
|
|
73
|
-
var parts = strNum.toLowerCase().split('e');
|
|
74
|
-
var e = parts.pop();
|
|
75
|
-
var l = Math.abs(e);
|
|
76
|
-
var sign = e / l;
|
|
77
|
-
var coeff_array = parts[0].split('.');
|
|
78
|
-
if (sign === -1) {
|
|
79
|
-
var intVal = trimLeftZero(coeff_array[0]);
|
|
80
|
-
if (intVal.length > l) {
|
|
81
|
-
var thanLen = intVal.length - l;
|
|
82
|
-
var dec = coeff_array[1] || '';
|
|
83
|
-
ret = intVal.slice(0, thanLen);
|
|
84
|
-
if (intVal.slice(thanLen) !== '0' || dec) {
|
|
85
|
-
ret += '.' + intVal.slice(thanLen) + dec;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
ret = zero + '.' + new Array(l - intVal.length + 1).join(zero) + coeff_array.join('');
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
var dec = coeff_array[1] || '';
|
|
94
|
-
if (l - dec.length < 0) {
|
|
95
|
-
ret = trimLeftZero(coeff_array[0] + dec.substring(0, l)) + '.' + dec.substring(l);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
ret = coeff_array.join('') + new Array(l - dec.length + 1).join(zero);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return trimLeftZero(ret);
|
|
102
|
-
}
|
|
103
71
|
|
|
104
72
|
exports.checkBoundary = checkBoundary;
|
|
105
73
|
exports.digitLength = digitLength;
|
|
106
74
|
exports.float2Fixed = float2Fixed;
|
|
107
75
|
exports.isScientificNumber = isScientificNumber;
|
|
108
|
-
exports.scientificToNumber = scientificToNumber;
|
|
109
76
|
exports.strip = strip;
|
|
110
77
|
exports.transformEffectiveNumber = transformEffectiveNumber;
|
|
111
78
|
exports.trimLeftZero = trimLeftZero;
|
package/lib/utils/native.js
CHANGED
package/package.json
CHANGED
package/types/utils/native.d.ts
CHANGED