util-helpers 4.23.5 → 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/dist/util-helpers.js +7 -8
- 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/formatMoney.js +4 -5
- package/esm/index.js +1 -1
- package/esm/parseIdCard.js +2 -2
- package/lib/VERSION.js +1 -1
- package/lib/formatMoney.js +3 -4
- package/lib/index.js +1 -1
- package/lib/parseIdCard.js +2 -2
- package/package.json +1 -1
- package/types/formatMoney.d.ts +2 -0
package/esm/VERSION.js
CHANGED
package/esm/formatMoney.js
CHANGED
|
@@ -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
|
|
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
package/esm/parseIdCard.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var regIdCard = /^(
|
|
1
|
+
var regIdCard = /^(\d{2})(\d{2})(\d{2})((?:\d{2})?\d{2})(\d{2})(\d{2})\d{2}(\d)(?:\d|X)?$/i;
|
|
2
2
|
var Provinces = [
|
|
3
3
|
['11', '北京市'],
|
|
4
4
|
['12', '天津市'],
|
|
@@ -41,7 +41,7 @@ function parseIdCard(id) {
|
|
|
41
41
|
if (!match) {
|
|
42
42
|
return null;
|
|
43
43
|
}
|
|
44
|
-
var origin =
|
|
44
|
+
var origin = {
|
|
45
45
|
province: match[1],
|
|
46
46
|
city: match[2],
|
|
47
47
|
area: match[3],
|
package/lib/VERSION.js
CHANGED
package/lib/formatMoney.js
CHANGED
|
@@ -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
|
|
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.
|
|
71
|
+
exports.version = "4.23.7";
|
|
72
72
|
|
|
73
73
|
exports.isMobile = isMobile;
|
|
74
74
|
exports.isTelephone = isTelephone;
|
package/lib/parseIdCard.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var regIdCard = /^(
|
|
3
|
+
var regIdCard = /^(\d{2})(\d{2})(\d{2})((?:\d{2})?\d{2})(\d{2})(\d{2})\d{2}(\d)(?:\d|X)?$/i;
|
|
4
4
|
var Provinces = [
|
|
5
5
|
['11', '北京市'],
|
|
6
6
|
['12', '天津市'],
|
|
@@ -43,7 +43,7 @@ function parseIdCard(id) {
|
|
|
43
43
|
if (!match) {
|
|
44
44
|
return null;
|
|
45
45
|
}
|
|
46
|
-
var origin =
|
|
46
|
+
var origin = {
|
|
47
47
|
province: match[1],
|
|
48
48
|
city: match[2],
|
|
49
49
|
area: match[3],
|
package/package.json
CHANGED
package/types/formatMoney.d.ts
CHANGED
|
@@ -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
|
*
|