util-helpers 4.13.1 → 4.14.0
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 +16 -6
- package/dist/util-helpers.js +935 -536
- 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/blobToDataURL.js +2 -4
- package/esm/bytesToSize.js +13 -5
- package/esm/calculateCursorPosition.js +7 -12
- package/esm/dataURLToBlob.js +2 -5
- package/esm/divide.js +9 -13
- package/esm/findTreeNode.js +66 -0
- package/esm/findTreeSelect.js +80 -0
- package/esm/formatBankCard.js +11 -11
- package/esm/formatMobile.js +11 -14
- package/esm/formatMoney.js +24 -35
- package/esm/index.js +9 -4
- package/esm/isBankCard.js +9 -13
- package/esm/isBusinessLicense.js +19 -20
- package/esm/isChinese.js +6 -6
- package/esm/isEmail.js +3 -3
- package/esm/isHMCard.js +3 -3
- package/esm/isIPv4.js +3 -3
- package/esm/isIPv6.js +3 -3
- package/esm/isIdCard.js +9 -17
- package/esm/isMobile.js +3 -3
- package/esm/isPassport.js +3 -3
- package/esm/isPassword.js +6 -7
- package/esm/isPostcode.js +3 -3
- package/esm/isPromiseLike.js +0 -2
- package/esm/isQQ.js +3 -3
- package/esm/isSocialCreditCode.js +29 -28
- package/esm/isSwiftCode.js +1 -2
- package/esm/isTWCard.js +6 -7
- package/esm/isTelephone.js +3 -3
- package/esm/isUrl.js +7 -3
- package/esm/isVehicle.js +3 -3
- package/esm/isWX.js +3 -3
- package/esm/listToTree.js +122 -0
- package/esm/minus.js +7 -11
- package/esm/normalizeString.js +1 -3
- package/esm/numberToChinese.js +43 -52
- package/esm/padZero.js +1 -5
- package/esm/parseIdCard.js +27 -23
- package/esm/plus.js +7 -11
- package/esm/randomString.js +2 -8
- package/esm/replaceChar.js +11 -16
- package/esm/round.js +4 -5
- package/esm/safeDate.js +5 -7
- package/esm/setDataURLPrefix.js +0 -1
- package/esm/strlen.js +1 -5
- package/esm/times.js +7 -11
- package/esm/transformFieldNames.doc.js +34 -0
- package/esm/transformFieldNames.js +98 -0
- package/esm/transformFieldNames.type.js +19 -0
- package/esm/treeToList.js +88 -0
- package/esm/utils/config.js +4 -4
- package/esm/utils/constants.js +2 -2
- package/esm/utils/convertToString.js +1 -2
- package/esm/utils/devWarn.js +1 -3
- package/esm/utils/math.util.js +20 -29
- package/esm/utils/type/index.js +1 -1
- package/esm/utils/type/isArguments.js +1 -2
- package/esm/utils/type/isArray.js +1 -2
- package/esm/utils/type/isBoolean.js +1 -2
- package/esm/utils/type/isDate.js +1 -2
- package/esm/utils/type/isError.js +1 -2
- package/esm/utils/type/isFunction.js +1 -2
- package/esm/utils/type/isMap.js +1 -2
- package/esm/utils/type/isNaN.js +1 -2
- package/esm/utils/type/isNil.js +1 -2
- package/esm/utils/type/isNull.js +0 -1
- package/esm/utils/type/isNumber.js +1 -2
- package/esm/utils/type/isObject.js +0 -3
- package/esm/utils/type/isRegExp.js +1 -2
- package/esm/utils/type/isSet.js +1 -2
- package/esm/utils/type/isString.js +1 -2
- package/esm/utils/type/isSymbol.js +1 -2
- package/esm/utils/type/isType.js +1 -2
- package/esm/utils/type/isUndefined.js +0 -1
- package/esm/utils/type/isWeakMap.js +1 -2
- package/esm/utils/type/isWeakSet.js +1 -2
- package/esm/validatePassword.js +27 -50
- package/esm/waitTime.js +0 -1
- package/lib/blobToDataURL.js +2 -5
- package/lib/bytesToSize.js +13 -6
- package/lib/calculateCursorPosition.js +4 -13
- package/lib/dataURLToBlob.js +2 -6
- package/lib/divide.js +8 -22
- package/lib/findTreeNode.js +76 -0
- package/lib/findTreeSelect.js +86 -0
- package/lib/formatBankCard.js +10 -13
- package/lib/formatMobile.js +10 -16
- package/lib/formatMoney.js +25 -47
- package/lib/index.js +115 -126
- package/lib/isBankCard.js +7 -15
- package/lib/isBusinessLicense.js +17 -22
- package/lib/isChinese.js +6 -9
- package/lib/isEmail.js +1 -5
- package/lib/isHMCard.js +1 -5
- package/lib/isIPv4.js +1 -5
- package/lib/isIPv6.js +1 -5
- package/lib/isIdCard.js +7 -19
- package/lib/isMobile.js +1 -5
- package/lib/isPassport.js +1 -5
- package/lib/isPassword.js +5 -9
- package/lib/isPostcode.js +1 -5
- package/lib/isPromiseLike.js +1 -4
- package/lib/isQQ.js +1 -5
- package/lib/isSocialCreditCode.js +27 -30
- package/lib/isSwiftCode.js +1 -5
- package/lib/isTWCard.js +4 -9
- package/lib/isTelephone.js +1 -5
- package/lib/isUrl.js +5 -5
- package/lib/isVehicle.js +1 -5
- package/lib/isWX.js +1 -5
- package/lib/listToTree.js +131 -0
- package/lib/minus.js +6 -20
- package/lib/normalizeString.js +0 -6
- package/lib/numberToChinese.js +41 -55
- package/lib/padZero.js +0 -7
- package/lib/parseIdCard.js +30 -29
- package/lib/plus.js +6 -20
- package/lib/randomString.js +2 -8
- package/lib/replaceChar.js +10 -18
- package/lib/round.js +3 -9
- package/lib/safeDate.js +4 -13
- package/lib/setDataURLPrefix.js +0 -2
- package/lib/strlen.js +0 -7
- package/lib/times.js +6 -18
- package/lib/transformFieldNames.doc.js +41 -0
- package/lib/transformFieldNames.js +104 -0
- package/lib/transformFieldNames.type.js +5 -0
- package/lib/treeToList.js +96 -0
- package/lib/utils/config.js +6 -6
- package/lib/utils/constants.js +2 -2
- package/lib/utils/convertToString.js +0 -4
- package/lib/utils/devWarn.js +0 -4
- package/lib/utils/math.util.js +23 -45
- package/lib/utils/type/index.js +20 -39
- package/lib/utils/type/isArguments.js +0 -4
- package/lib/utils/type/isArray.js +0 -4
- package/lib/utils/type/isBoolean.js +0 -4
- package/lib/utils/type/isDate.js +0 -4
- package/lib/utils/type/isError.js +0 -4
- package/lib/utils/type/isFunction.js +0 -4
- package/lib/utils/type/isMap.js +0 -4
- package/lib/utils/type/isNaN.js +0 -4
- package/lib/utils/type/isNil.js +0 -5
- package/lib/utils/type/isNull.js +0 -2
- package/lib/utils/type/isNumber.js +0 -4
- package/lib/utils/type/isObject.js +1 -5
- package/lib/utils/type/isRegExp.js +0 -4
- package/lib/utils/type/isSet.js +0 -4
- package/lib/utils/type/isString.js +0 -4
- package/lib/utils/type/isSymbol.js +0 -4
- package/lib/utils/type/isType.js +1 -2
- package/lib/utils/type/isUndefined.js +0 -2
- package/lib/utils/type/isWeakMap.js +0 -4
- package/lib/utils/type/isWeakSet.js +0 -4
- package/lib/validatePassword.js +27 -53
- package/lib/waitTime.js +0 -2
- package/package.json +6 -5
- package/types/bytesToSize.d.ts +9 -1
- package/types/findTreeNode.d.ts +26 -0
- package/types/findTreeSelect.d.ts +26 -0
- package/types/formatBankCard.d.ts +3 -3
- package/types/formatMobile.d.ts +4 -4
- package/types/index.d.ts +5 -0
- package/types/isIdCard.d.ts +2 -0
- package/types/isUrl.d.ts +2 -0
- package/types/listToTree.d.ts +41 -0
- package/types/transformFieldNames.d.ts +34 -0
- package/types/transformFieldNames.type.d.ts +2 -0
- package/types/treeToList.d.ts +20 -0
package/lib/formatMobile.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _normalizeString = _interopRequireDefault(require("./normalizeString"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* 格式化手机号码
|
|
14
11
|
*
|
|
@@ -17,16 +14,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
17
14
|
* @since 4.5.0
|
|
18
15
|
* @param {string} mobileNo 手机号码
|
|
19
16
|
* @param {object} [options] 配置项
|
|
20
|
-
* @param {string} [options.
|
|
17
|
+
* @param {string} [options.spaceMark=' '] 间隔字符
|
|
21
18
|
* @returns {string} 格式化后的手机号码
|
|
22
19
|
* @example
|
|
23
20
|
*
|
|
24
21
|
* formatMobile('13345678900'); // 133 4567 8900
|
|
25
|
-
* formatMobile('13345678900', {
|
|
22
|
+
* formatMobile('13345678900', { spaceMark: '-' }); // 133-4567-8900
|
|
26
23
|
*
|
|
27
24
|
* // 脱敏手机号码
|
|
28
25
|
* formatMobile('133****1234'); // 133 **** 1234
|
|
29
|
-
* formatMobile('133****1234', {
|
|
26
|
+
* formatMobile('133****1234', { spaceMark: '-' }); // 133-****-1234
|
|
30
27
|
*
|
|
31
28
|
* // 手机号码位数不够
|
|
32
29
|
* formatMobile('133'); // 133
|
|
@@ -36,23 +33,20 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
36
33
|
*/
|
|
37
34
|
function formatMobile(mobileNo) {
|
|
38
35
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
39
|
-
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
// TODO 下个版本废弃 char
|
|
40
38
|
var _options$char = options["char"],
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var regChar = new RegExp(
|
|
39
|
+
_char = _options$char === void 0 ? ' ' : _options$char;
|
|
40
|
+
var realSpaceMark = 'spaceMark' in options ? options.spaceMark : _char;
|
|
41
|
+
var regChar = new RegExp(realSpaceMark, 'g');
|
|
44
42
|
var realValue = (0, _normalizeString["default"])(mobileNo).replace(regChar, '').substring(0, 11);
|
|
45
|
-
|
|
46
43
|
if (realValue.length > 7) {
|
|
47
|
-
return realValue.replace(/^(...)(....)/g, "$1".concat(
|
|
44
|
+
return realValue.replace(/^(...)(....)/g, "$1".concat(realSpaceMark, "$2").concat(realSpaceMark));
|
|
48
45
|
}
|
|
49
|
-
|
|
50
46
|
if (realValue.length > 3) {
|
|
51
|
-
return realValue.replace(/^(...)/g, "$1".concat(
|
|
47
|
+
return realValue.replace(/^(...)/g, "$1".concat(realSpaceMark));
|
|
52
48
|
}
|
|
53
|
-
|
|
54
49
|
return realValue;
|
|
55
50
|
}
|
|
56
|
-
|
|
57
51
|
var _default = formatMobile;
|
|
58
52
|
exports["default"] = _default;
|
package/lib/formatMoney.js
CHANGED
|
@@ -4,28 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _math = require("./utils/math.util");
|
|
9
|
-
|
|
10
8
|
var _isNaN = _interopRequireDefault(require("./utils/type/isNaN"));
|
|
11
|
-
|
|
12
9
|
var _devWarn = _interopRequireDefault(require("./utils/devWarn"));
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
|
-
|
|
16
11
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
17
|
-
|
|
18
12
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
19
|
-
|
|
20
13
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
21
|
-
|
|
22
14
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
23
|
-
|
|
24
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]); if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
25
|
-
|
|
15
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
26
16
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
27
|
-
|
|
28
17
|
var reg = /^[+-]?\d*\.?\d*$/;
|
|
18
|
+
|
|
29
19
|
/**
|
|
30
20
|
* 检查数字或数字字符串
|
|
31
21
|
*
|
|
@@ -33,21 +23,20 @@ var reg = /^[+-]?\d*\.?\d*$/;
|
|
|
33
23
|
* @param {string} num
|
|
34
24
|
* @returns 是否为数字
|
|
35
25
|
*/
|
|
36
|
-
|
|
37
26
|
function checkNumber(num) {
|
|
38
27
|
if (!(reg.test(num) || (0, _math.isScientificNumber)(num)) || (0, _isNaN["default"])(num) || typeof num !== 'number' && typeof num !== 'string' || num === '') {
|
|
39
28
|
(0, _devWarn["default"])("".concat(num, " invalid parameter."));
|
|
40
29
|
return false;
|
|
41
|
-
}
|
|
42
|
-
// 如 1111111111111111111111 // => 1.1111111111111111e+21
|
|
43
|
-
|
|
30
|
+
}
|
|
44
31
|
|
|
32
|
+
// 数字超限如果不是是字符串,可能有异常
|
|
33
|
+
// 如 1111111111111111111111 // => 1.1111111111111111e+21
|
|
45
34
|
if (typeof num === 'number') {
|
|
46
35
|
(0, _math.checkBoundary)(num);
|
|
47
36
|
}
|
|
48
|
-
|
|
49
37
|
return true;
|
|
50
38
|
}
|
|
39
|
+
|
|
51
40
|
/**
|
|
52
41
|
* 格式化整数部分
|
|
53
42
|
*
|
|
@@ -56,22 +45,18 @@ function checkNumber(num) {
|
|
|
56
45
|
* @param {string} thousand 千分位符号
|
|
57
46
|
* @returns 格式化后的值
|
|
58
47
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
48
|
function formatInt(intStr, thousand) {
|
|
62
49
|
var txt = '';
|
|
63
50
|
intStr = (0, _math.trimLeftZero)(intStr);
|
|
64
51
|
intStr = intStr[0] === '+' ? intStr.substring(1) : intStr; // 去掉+符号
|
|
65
|
-
|
|
66
52
|
var negativeSymbol = Number(intStr) < 0 ? '-' : '';
|
|
67
53
|
var reArr = negativeSymbol ? intStr.substring(1).split('').reverse() : intStr.split('').reverse();
|
|
68
|
-
|
|
69
54
|
for (var i = 0; i < reArr.length; i++) {
|
|
70
55
|
txt += reArr[i] + ((i + 1) % 3 === 0 && i + 1 !== reArr.length ? thousand : '');
|
|
71
56
|
}
|
|
72
|
-
|
|
73
57
|
return negativeSymbol + txt.split('').reverse().join('');
|
|
74
58
|
}
|
|
59
|
+
|
|
75
60
|
/**
|
|
76
61
|
* 格式化小数部分,如果使用 toFixed,超大额数字会自动被截断
|
|
77
62
|
*
|
|
@@ -81,25 +66,21 @@ function formatInt(intStr, thousand) {
|
|
|
81
66
|
* @param {string} decimal 小数点符号
|
|
82
67
|
* @returns 格式化后的值
|
|
83
68
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
69
|
function formatDec(decStr, precision, decimal) {
|
|
87
70
|
if (precision === 0) {
|
|
88
71
|
return '';
|
|
89
72
|
}
|
|
90
|
-
|
|
91
73
|
var zero = 0;
|
|
92
74
|
var ret = '';
|
|
93
|
-
|
|
94
75
|
if (decStr && Number(decStr) > 0) {
|
|
95
76
|
var tmpNum = parseFloat('0.' + decStr);
|
|
96
77
|
ret = tmpNum.toFixed(precision).substring(2);
|
|
97
78
|
} else {
|
|
98
79
|
ret = zero.toFixed(precision).substring(2);
|
|
99
80
|
}
|
|
100
|
-
|
|
101
81
|
return decimal + ret;
|
|
102
82
|
}
|
|
83
|
+
|
|
103
84
|
/**
|
|
104
85
|
* 格式化金额
|
|
105
86
|
*
|
|
@@ -137,43 +118,40 @@ function formatDec(decStr, precision, decimal) {
|
|
|
137
118
|
* formatMoney(1000.00, { decimal: '&' }); // 1,000&00
|
|
138
119
|
*
|
|
139
120
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
121
|
var formatMoney = function formatMoney(num) {
|
|
143
122
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
144
123
|
var _options$precision = options.precision,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
124
|
+
precision = _options$precision === void 0 ? 2 : _options$precision,
|
|
125
|
+
symbol = options.symbol,
|
|
126
|
+
_options$thousand = options.thousand,
|
|
127
|
+
thousand = _options$thousand === void 0 ? ',' : _options$thousand,
|
|
128
|
+
_options$decimal = options.decimal,
|
|
129
|
+
decimal = _options$decimal === void 0 ? '.' : _options$decimal;
|
|
130
|
+
|
|
131
|
+
// 数字参数不正确,返回空字符串
|
|
151
132
|
// @ts-ignore
|
|
152
|
-
|
|
153
133
|
if (!checkNumber(num)) {
|
|
154
134
|
return '';
|
|
155
|
-
}
|
|
156
|
-
|
|
135
|
+
}
|
|
157
136
|
|
|
137
|
+
// 参数规整化
|
|
158
138
|
if (typeof precision !== 'number' || (0, _isNaN["default"])(precision) || precision < 0) {
|
|
159
139
|
precision = 2;
|
|
160
140
|
} else if (precision > 10) {
|
|
161
141
|
precision = 10;
|
|
162
142
|
}
|
|
163
|
-
|
|
164
143
|
symbol = typeof symbol === 'string' ? symbol : '';
|
|
165
144
|
thousand = typeof thousand === 'string' ? thousand : ',';
|
|
166
|
-
decimal = typeof decimal === 'string' ? decimal : '.';
|
|
167
|
-
|
|
168
|
-
var strNum = (0, _math.scientificToNumber)(num) + ''; // 整数和小数部分
|
|
145
|
+
decimal = typeof decimal === 'string' ? decimal : '.';
|
|
169
146
|
|
|
147
|
+
// 转换数字字符串,支持科学记数法
|
|
148
|
+
var strNum = (0, _math.scientificToNumber)(num) + '';
|
|
149
|
+
// 整数和小数部分
|
|
170
150
|
var _strNum$split = strNum.split('.'),
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
151
|
+
_strNum$split2 = _slicedToArray(_strNum$split, 2),
|
|
152
|
+
intStr = _strNum$split2[0],
|
|
153
|
+
decStr = _strNum$split2[1];
|
|
175
154
|
return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
|
|
176
155
|
};
|
|
177
|
-
|
|
178
156
|
var _default = formatMoney;
|
|
179
157
|
exports["default"] = _default;
|