util-helpers 4.23.6 → 4.23.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.23.6";
1
+ var VERSION = "4.23.7";
2
2
  var VERSION$1 = VERSION;
3
3
 
4
4
  export { VERSION$1 as default };
@@ -1,5 +1,5 @@
1
1
  import { __read } from 'tslib';
2
- import { isNaN } from 'ut2';
2
+ import { isString, isNumber, isNaN } from 'ut2';
3
3
  import { transformEffectiveNumber, checkBoundary, trimLeftZero } from './utils/math.util.js';
4
4
  import devWarn from './utils/devWarn.js';
5
5
  import isValidNumber from './isValidNumber.js';
@@ -41,10 +41,9 @@ function formatDec(decStr, precision, decimal) {
41
41
  return decimal + ret;
42
42
  }
43
43
  var formatMoney = function (num, options) {
44
- if (num === void 0) { num = ''; }
45
44
  if (options === void 0) { options = {}; }
46
- var _a = options.precision, precision = _a === void 0 ? 2 : _a, symbol = options.symbol, _b = options.thousand, thousand = _b === void 0 ? ',' : _b, _c = options.decimal, decimal = _c === void 0 ? '.' : _c;
47
- if (!checkNumber(num)) {
45
+ var _a = options.precision, precision = _a === void 0 ? 2 : _a, symbol = options.symbol, _b = options.thousand, thousand = _b === void 0 ? ',' : _b, _c = options.decimal, decimal = _c === void 0 ? '.' : _c, _d = options.strict, strict = _d === void 0 ? true : _d;
46
+ if (!checkNumber(num) || (strict && (!isString(num) || num === '') && !isNumber(num))) {
48
47
  return '';
49
48
  }
50
49
  if (typeof num === 'number' && !isFinite(num)) {
@@ -60,7 +59,7 @@ var formatMoney = function (num, options) {
60
59
  thousand = typeof thousand === 'string' ? thousand : ',';
61
60
  decimal = typeof decimal === 'string' ? decimal : '.';
62
61
  var strNum = transformEffectiveNumber(num) + '';
63
- var _d = __read(strNum.split('.'), 2), intStr = _d[0], decStr = _d[1];
62
+ var _e = __read(strNum.split('.'), 2), intStr = _e[0], decStr = _e[1];
64
63
  return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
65
64
  };
66
65
  var formatMoney$1 = formatMoney;
package/esm/index.js CHANGED
@@ -66,6 +66,6 @@ export { setDisableWarning } from './utils/config.js';
66
66
  export { default as VERSION } from './VERSION.js';
67
67
  export { default as AsyncMemo } from './AsyncMemo.js';
68
68
 
69
- var version = "4.23.6";
69
+ var version = "4.23.7";
70
70
 
71
71
  export { version };
package/lib/VERSION.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "4.23.6";
3
+ var VERSION = "4.23.7";
4
4
  var VERSION$1 = VERSION;
5
5
 
6
6
  module.exports = VERSION$1;
@@ -43,10 +43,9 @@ function formatDec(decStr, precision, decimal) {
43
43
  return decimal + ret;
44
44
  }
45
45
  var formatMoney = function (num, options) {
46
- if (num === void 0) { num = ''; }
47
46
  if (options === void 0) { options = {}; }
48
- var _a = options.precision, precision = _a === void 0 ? 2 : _a, symbol = options.symbol, _b = options.thousand, thousand = _b === void 0 ? ',' : _b, _c = options.decimal, decimal = _c === void 0 ? '.' : _c;
49
- if (!checkNumber(num)) {
47
+ var _a = options.precision, precision = _a === void 0 ? 2 : _a, symbol = options.symbol, _b = options.thousand, thousand = _b === void 0 ? ',' : _b, _c = options.decimal, decimal = _c === void 0 ? '.' : _c, _d = options.strict, strict = _d === void 0 ? true : _d;
48
+ if (!checkNumber(num) || (strict && (!ut2.isString(num) || num === '') && !ut2.isNumber(num))) {
50
49
  return '';
51
50
  }
52
51
  if (typeof num === 'number' && !isFinite(num)) {
@@ -62,7 +61,7 @@ var formatMoney = function (num, options) {
62
61
  thousand = typeof thousand === 'string' ? thousand : ',';
63
62
  decimal = typeof decimal === 'string' ? decimal : '.';
64
63
  var strNum = math_util.transformEffectiveNumber(num) + '';
65
- var _d = tslib.__read(strNum.split('.'), 2), intStr = _d[0], decStr = _d[1];
64
+ var _e = tslib.__read(strNum.split('.'), 2), intStr = _e[0], decStr = _e[1];
66
65
  return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
67
66
  };
68
67
  var formatMoney$1 = formatMoney;
package/lib/index.js CHANGED
@@ -68,7 +68,7 @@ var config = require('./utils/config.js');
68
68
  var VERSION = require('./VERSION.js');
69
69
  var AsyncMemo = require('./AsyncMemo.js');
70
70
 
71
- exports.version = "4.23.6";
71
+ exports.version = "4.23.7";
72
72
 
73
73
  exports.isMobile = isMobile;
74
74
  exports.isTelephone = isTelephone;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "4.23.6",
3
+ "version": "4.23.7",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -3,6 +3,7 @@ type Options = {
3
3
  symbol?: string;
4
4
  thousand?: string;
5
5
  decimal?: string;
6
+ strict?: boolean;
6
7
  };
7
8
  /**
8
9
  * 格式化金额
@@ -16,6 +17,7 @@ type Options = {
16
17
  * @param {string} [options.symbol] 货币符号
17
18
  * @param {string} [options.thousand=","] 千分位符号
18
19
  * @param {string} [options.decimal="."] 小数位符号
20
+ * @param {boolean} [options.strict=ture] 严格模式。开启后,只支持非空字符串和数字格式化,其他类型值如`null` `undefined` `true` `false`等将返回空字符串。
19
21
  * @returns {string} 格式化的金额
20
22
  * @example
21
23
  *