util-helpers 4.21.6 → 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/esm/VERSION.js CHANGED
@@ -1,4 +1,4 @@
1
- var VERSION = "4.21.6";
1
+ var VERSION = "4.21.7";
2
2
  var VERSION$1 = VERSION;
3
3
 
4
4
  export { VERSION$1 as default };
@@ -1,11 +1,11 @@
1
1
  import { __read } from 'tslib';
2
2
  import { isNaN } from 'ut2';
3
- import { scientificToNumber, isScientificNumber, checkBoundary, trimLeftZero } from './utils/math.util.js';
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 ((typeof num !== 'number' && typeof num !== 'string') || (typeof num === 'number' && isNaN(num)) || (typeof num === 'string' && (!(reg.test(num) || isScientificNumber(num)) || num === ''))) {
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 = scientificToNumber(num) + '';
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
@@ -64,6 +64,6 @@ export { default as findTreeSelect } from './findTreeSelect.js';
64
64
  export { setDisableWarning } from './utils/config.js';
65
65
  export { default as VERSION } from './VERSION.js';
66
66
 
67
- var version = "4.21.6";
67
+ var version = "4.21.7";
68
68
 
69
69
  export { version };
@@ -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, scientificToNumber, strip, transformEffectiveNumber, trimLeftZero };
70
+ export { checkBoundary, digitLength, float2Fixed, isScientificNumber, strip, transformEffectiveNumber, trimLeftZero };
package/lib/VERSION.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "4.21.6";
3
+ var VERSION = "4.21.7";
4
4
  var VERSION$1 = VERSION;
5
5
 
6
6
  module.exports = VERSION$1;
@@ -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 ((typeof num !== 'number' && typeof num !== 'string') || (typeof num === 'number' && ut2.isNaN(num)) || (typeof num === 'string' && (!(reg.test(num) || math_util.isScientificNumber(num)) || num === ''))) {
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.scientificToNumber(num) + '';
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.6";
69
+ exports.version = "4.21.7";
70
70
 
71
71
  exports.isMobile = isMobile;
72
72
  exports.isTelephone = isTelephone;
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "4.21.6",
3
+ "version": "4.21.7",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",