util-helpers 4.16.2 → 4.17.1
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 +1600 -4039
- 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/ajax.js +50 -146
- package/esm/blobToDataURL.js +4 -34
- package/esm/bytesToSize.js +12 -37
- package/esm/calculateCursorPosition.js +30 -52
- package/esm/dataURLToBlob.js +14 -28
- package/esm/divide.js +24 -48
- package/esm/download.js +83 -164
- package/esm/fileReader.js +18 -64
- package/esm/filterTree.js +25 -55
- package/esm/findTreeNode.js +39 -67
- package/esm/findTreeNodes.js +35 -66
- package/esm/findTreeSelect.js +38 -74
- package/esm/formatBankCard.js +13 -43
- package/esm/formatMobile.js +17 -43
- package/esm/formatMoney.js +59 -139
- package/esm/index.js +55 -130
- package/esm/isBankCard.js +22 -57
- package/esm/isBusinessLicense.js +32 -78
- package/esm/isChinese.js +23 -66
- package/esm/isEmail.js +6 -21
- package/esm/isHMCard.js +5 -28
- package/esm/isIPv4.js +5 -22
- package/esm/isIPv6.js +5 -36
- package/esm/isIdCard.js +27 -66
- package/esm/isMobile.js +5 -20
- package/esm/isPassport.js +5 -22
- package/esm/isPassword.js +7 -48
- package/esm/isPostcode.js +5 -20
- package/esm/isPromiseLike.js +3 -18
- package/esm/isQQ.js +5 -20
- package/esm/isSocialCreditCode.js +28 -83
- package/esm/isSwiftCode.js +6 -25
- package/esm/isTWCard.js +11 -37
- package/esm/isTelephone.js +6 -27
- package/esm/isUrl.js +5 -44
- package/esm/isVehicle.js +5 -28
- package/esm/isWX.js +5 -20
- package/esm/listToTree.js +51 -120
- package/esm/minus.js +21 -39
- package/esm/normalizeString.js +8 -29
- package/esm/numberToChinese.js +96 -215
- package/esm/padZero.js +14 -36
- package/esm/parseIdCard.js +64 -129
- package/esm/plus.js +21 -39
- package/esm/randomString.js +13 -45
- package/esm/replaceChar.js +27 -77
- package/esm/round.js +14 -31
- package/esm/safeDate.js +12 -55
- package/esm/setDataURLPrefix.js +6 -29
- package/esm/strlen.js +14 -30
- package/esm/times.js +24 -42
- package/esm/transformFieldNames.js +37 -93
- package/esm/treeToList.js +25 -84
- package/esm/utils/config.js +4 -14
- package/esm/utils/constants.js +4 -4
- package/esm/utils/convertToString.js +4 -9
- package/esm/utils/devWarn.js +11 -11
- package/esm/utils/math.util.js +95 -181
- package/esm/utils/type/isBlob.js +4 -24
- package/esm/utils/type/isNaN.js +4 -19
- package/esm/utils/type/isNil.js +5 -13
- package/esm/utils/type/isNull.js +3 -18
- package/esm/utils/type/isNumber.js +4 -28
- package/esm/utils/type/isObject.js +4 -23
- package/esm/utils/type/isString.js +4 -19
- package/esm/utils/type/isSymbol.js +4 -19
- package/esm/utils/type/isType.js +3 -12
- package/esm/utils/type/isUndefined.js +3 -21
- package/esm/validatePassword.js +86 -237
- package/esm/waitTime.js +7 -26
- package/lib/ajax.js +51 -152
- package/lib/blobToDataURL.js +5 -40
- package/lib/bytesToSize.js +13 -43
- package/lib/calculateCursorPosition.js +32 -58
- package/lib/dataURLToBlob.js +15 -34
- package/lib/divide.js +26 -60
- package/lib/download.js +85 -169
- package/lib/fileReader.js +19 -70
- package/lib/filterTree.js +27 -66
- package/lib/findTreeNode.js +40 -77
- package/lib/findTreeNodes.js +36 -76
- package/lib/findTreeSelect.js +40 -82
- package/lib/formatBankCard.js +15 -50
- package/lib/formatMobile.js +19 -50
- package/lib/formatMoney.js +60 -150
- package/lib/index.js +117 -395
- package/lib/isBankCard.js +24 -64
- package/lib/isBusinessLicense.js +34 -85
- package/lib/isChinese.js +24 -73
- package/lib/isEmail.js +7 -27
- package/lib/isHMCard.js +7 -35
- package/lib/isIPv4.js +7 -29
- package/lib/isIPv6.js +7 -43
- package/lib/isIdCard.js +29 -73
- package/lib/isMobile.js +7 -27
- package/lib/isPassport.js +7 -29
- package/lib/isPassword.js +9 -55
- package/lib/isPostcode.js +7 -27
- package/lib/isPromiseLike.js +4 -24
- package/lib/isQQ.js +7 -27
- package/lib/isSocialCreditCode.js +30 -90
- package/lib/isSwiftCode.js +7 -32
- package/lib/isTWCard.js +13 -44
- package/lib/isTelephone.js +7 -33
- package/lib/isUrl.js +6 -49
- package/lib/isVehicle.js +7 -35
- package/lib/isWX.js +7 -27
- package/lib/listToTree.js +53 -131
- package/lib/minus.js +23 -51
- package/lib/normalizeString.js +10 -36
- package/lib/numberToChinese.js +98 -222
- package/lib/padZero.js +16 -43
- package/lib/parseIdCard.js +65 -138
- package/lib/plus.js +23 -51
- package/lib/randomString.js +14 -51
- package/lib/replaceChar.js +28 -83
- package/lib/round.js +15 -37
- package/lib/safeDate.js +13 -63
- package/lib/setDataURLPrefix.js +7 -35
- package/lib/strlen.js +16 -37
- package/lib/times.js +26 -53
- package/lib/transformFieldNames.js +38 -101
- package/lib/treeToList.js +27 -94
- package/lib/utils/config.js +6 -23
- package/lib/utils/constants.js +3 -11
- package/lib/utils/convertToString.js +6 -16
- package/lib/utils/devWarn.js +13 -17
- package/lib/utils/math.util.js +95 -185
- package/lib/utils/type/isBlob.js +6 -31
- package/lib/utils/type/isNaN.js +6 -26
- package/lib/utils/type/isNil.js +7 -20
- package/lib/utils/type/isNull.js +4 -24
- package/lib/utils/type/isNumber.js +6 -35
- package/lib/utils/type/isObject.js +5 -29
- package/lib/utils/type/isString.js +6 -26
- package/lib/utils/type/isSymbol.js +6 -26
- package/lib/utils/type/isType.js +4 -18
- package/lib/utils/type/isUndefined.js +4 -27
- package/lib/validatePassword.js +87 -244
- package/lib/waitTime.js +8 -32
- package/package.json +21 -25
- package/types/ajax.d.ts +38 -95
- package/types/blobToDataURL.d.ts +2 -2
- package/types/bytesToSize.d.ts +7 -6
- package/types/calculateCursorPosition.d.ts +10 -9
- package/types/dataURLToBlob.d.ts +5 -5
- package/types/divide.d.ts +2 -2
- package/types/download.d.ts +22 -38
- package/types/fileReader.d.ts +35 -2
- package/types/filterTree.d.ts +6 -7
- package/types/findTreeNode.d.ts +5 -7
- package/types/findTreeNodes.d.ts +5 -7
- package/types/findTreeSelect.d.ts +5 -7
- package/types/formatBankCard.d.ts +8 -5
- package/types/formatMobile.d.ts +7 -4
- package/types/formatMoney.d.ts +8 -7
- package/types/index.d.ts +125 -55
- package/types/isBankCard.d.ts +9 -8
- package/types/isBusinessLicense.d.ts +8 -5
- package/types/isChinese.d.ts +9 -8
- package/types/isEmail.d.ts +1 -1
- package/types/isHMCard.d.ts +2 -2
- package/types/isIPv4.d.ts +1 -1
- package/types/isIPv6.d.ts +1 -1
- package/types/isIdCard.d.ts +8 -7
- package/types/isMobile.d.ts +1 -1
- package/types/isPassport.d.ts +2 -2
- package/types/isPassword.d.ts +4 -7
- package/types/isPostcode.d.ts +1 -1
- package/types/isPromiseLike.d.ts +1 -1
- package/types/isQQ.d.ts +1 -1
- package/types/isSocialCreditCode.d.ts +8 -5
- package/types/isSwiftCode.d.ts +2 -2
- package/types/isTWCard.d.ts +6 -5
- package/types/isTelephone.d.ts +1 -1
- package/types/isUrl.d.ts +2 -2
- package/types/isVehicle.d.ts +2 -2
- package/types/isWX.d.ts +1 -1
- package/types/listToTree.d.ts +12 -12
- package/types/minus.d.ts +3 -2
- package/types/normalizeString.d.ts +2 -2
- package/types/numberToChinese.d.ts +13 -12
- package/types/padZero.d.ts +2 -2
- package/types/parseIdCard.d.ts +17 -56
- package/types/plus.d.ts +3 -2
- package/types/randomString.d.ts +2 -2
- package/types/replaceChar.d.ts +15 -11
- package/types/round.d.ts +2 -2
- package/types/safeDate.d.ts +24 -2
- package/types/setDataURLPrefix.d.ts +5 -5
- package/types/strlen.d.ts +1 -1
- package/types/times.d.ts +3 -2
- package/types/transformFieldNames.d.ts +12 -10
- package/types/treeToList.d.ts +1 -1
- package/types/utils/config.d.ts +6 -5
- package/types/utils/constants.d.ts +2 -2
- package/types/utils/convertToString.d.ts +1 -1
- package/types/utils/devWarn.d.ts +1 -1
- package/types/utils/math.util.d.ts +15 -9
- package/types/utils/type/index.d.ts +7 -0
- package/types/utils/type/isArguments.d.ts +1 -1
- package/types/utils/type/isArray.d.ts +1 -1
- package/types/utils/type/isArrayBuffer.d.ts +1 -1
- package/types/utils/type/isBlob.d.ts +1 -1
- package/types/utils/type/isBoolean.d.ts +1 -1
- package/types/utils/type/isDate.d.ts +1 -1
- package/types/utils/type/isError.d.ts +1 -1
- package/types/utils/type/isFunction.d.ts +1 -1
- package/types/utils/type/isMap.d.ts +1 -1
- package/types/utils/type/isNaN.d.ts +1 -1
- package/types/utils/type/isNil.d.ts +1 -1
- package/types/utils/type/isNull.d.ts +1 -1
- package/types/utils/type/isNumber.d.ts +1 -1
- package/types/utils/type/isObject.d.ts +1 -1
- package/types/utils/type/isRegExp.d.ts +1 -1
- package/types/utils/type/isSet.d.ts +1 -1
- package/types/utils/type/isString.d.ts +1 -1
- package/types/utils/type/isSymbol.d.ts +1 -1
- package/types/utils/type/isType.d.ts +1 -1
- package/types/utils/type/isUndefined.d.ts +1 -1
- package/types/utils/type/isWeakMap.d.ts +1 -1
- package/types/utils/type/isWeakSet.d.ts +1 -1
- package/types/validatePassword.d.ts +17 -48
- package/types/waitTime.d.ts +2 -2
- package/esm/interface.doc.js +0 -125
- package/esm/interface.type.js +0 -17
- package/esm/utils/type/index.js +0 -29
- package/esm/utils/type/isArguments.js +0 -22
- package/esm/utils/type/isArray.js +0 -22
- package/esm/utils/type/isArrayBuffer.js +0 -25
- package/esm/utils/type/isBoolean.js +0 -22
- package/esm/utils/type/isDate.js +0 -22
- package/esm/utils/type/isError.js +0 -22
- package/esm/utils/type/isFunction.js +0 -22
- package/esm/utils/type/isMap.js +0 -22
- package/esm/utils/type/isRegExp.js +0 -22
- package/esm/utils/type/isSet.js +0 -22
- package/esm/utils/type/isWeakMap.js +0 -22
- package/esm/utils/type/isWeakSet.js +0 -22
- package/lib/interface.doc.js +0 -127
- package/lib/interface.type.js +0 -5
- package/lib/utils/type/index.js +0 -146
- package/lib/utils/type/isArguments.js +0 -29
- package/lib/utils/type/isArray.js +0 -29
- package/lib/utils/type/isArrayBuffer.js +0 -32
- package/lib/utils/type/isBoolean.js +0 -29
- package/lib/utils/type/isDate.js +0 -29
- package/lib/utils/type/isError.js +0 -29
- package/lib/utils/type/isFunction.js +0 -29
- package/lib/utils/type/isMap.js +0 -29
- package/lib/utils/type/isRegExp.js +0 -29
- package/lib/utils/type/isSet.js +0 -29
- package/lib/utils/type/isWeakMap.js +0 -29
- package/lib/utils/type/isWeakSet.js +0 -29
- package/types/interface.type.d.ts +0 -2
package/esm/findTreeNodes.js
CHANGED
|
@@ -1,71 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { isObject } from "./utils/type";
|
|
1
|
+
import { __values, __spreadArray, __read } from 'tslib';
|
|
2
|
+
import isObject from './utils/type/isObject.js';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* findTreeNodes(menus, item=>item.id === 'not found');
|
|
30
|
-
* // []
|
|
31
|
-
*/
|
|
32
|
-
function findTreeNodes(tree, predicate) {
|
|
33
|
-
var childrenField = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
|
|
34
|
-
var stack = [];
|
|
35
|
-
|
|
36
|
-
/** @type {T[]} */
|
|
37
|
-
var nodes = [];
|
|
38
|
-
if (!Array.isArray(tree)) {
|
|
39
|
-
return nodes;
|
|
40
|
-
}
|
|
41
|
-
var _iterator = _createForOfIteratorHelper(tree),
|
|
42
|
-
_step;
|
|
43
|
-
try {
|
|
44
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
45
|
-
var item = _step.value;
|
|
46
|
-
stack.push(item);
|
|
47
|
-
while (stack.length) {
|
|
48
|
-
/** @type {T} */
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
var temp = stack.pop();
|
|
51
|
-
if (predicate(temp)) {
|
|
52
|
-
nodes.push(temp);
|
|
4
|
+
function findTreeNodes(tree, predicate, childrenField) {
|
|
5
|
+
var e_1, _a;
|
|
6
|
+
if (childrenField === void 0) { childrenField = 'children'; }
|
|
7
|
+
var stack = [];
|
|
8
|
+
var nodes = [];
|
|
9
|
+
if (!Array.isArray(tree)) {
|
|
10
|
+
return nodes;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
for (var tree_1 = __values(tree), tree_1_1 = tree_1.next(); !tree_1_1.done; tree_1_1 = tree_1.next()) {
|
|
14
|
+
var item = tree_1_1.value;
|
|
15
|
+
stack.push(item);
|
|
16
|
+
while (stack.length) {
|
|
17
|
+
var temp = stack.pop();
|
|
18
|
+
if (predicate(temp)) {
|
|
19
|
+
nodes.push(temp);
|
|
20
|
+
}
|
|
21
|
+
if (isObject(temp)) {
|
|
22
|
+
var childs = temp[childrenField];
|
|
23
|
+
if (Array.isArray(childs) && childs.length > 0) {
|
|
24
|
+
stack.push.apply(stack, __spreadArray([], __read(childs), false));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
53
28
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
stack.push.apply(stack, _toConsumableArray(childs));
|
|
60
|
-
}
|
|
29
|
+
}
|
|
30
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
31
|
+
finally {
|
|
32
|
+
try {
|
|
33
|
+
if (tree_1_1 && !tree_1_1.done && (_a = tree_1.return)) _a.call(tree_1);
|
|
61
34
|
}
|
|
62
|
-
|
|
35
|
+
finally { if (e_1) throw e_1.error; }
|
|
63
36
|
}
|
|
64
|
-
|
|
65
|
-
_iterator.e(err);
|
|
66
|
-
} finally {
|
|
67
|
-
_iterator.f();
|
|
68
|
-
}
|
|
69
|
-
return nodes;
|
|
37
|
+
return nodes;
|
|
70
38
|
}
|
|
71
|
-
|
|
39
|
+
|
|
40
|
+
export { findTreeNodes as default };
|
package/esm/findTreeSelect.js
CHANGED
|
@@ -1,79 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { __values } from 'tslib';
|
|
2
|
+
import isObject from './utils/type/isObject.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var childs = item[childrenField];
|
|
34
|
-
if (Array.isArray(childs) && childs.length > 0) {
|
|
35
|
-
var findChildren = internalFindTreeSelect(childs, predicate, childrenField, path);
|
|
36
|
-
if (findChildren.length > 0) {
|
|
37
|
-
return findChildren;
|
|
38
|
-
}
|
|
4
|
+
function internalFindTreeSelect(tree, predicate, childrenField, path) {
|
|
5
|
+
var e_1, _a;
|
|
6
|
+
if (path === void 0) { path = []; }
|
|
7
|
+
if (!Array.isArray(tree)) {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
for (var tree_1 = __values(tree), tree_1_1 = tree_1.next(); !tree_1_1.done; tree_1_1 = tree_1.next()) {
|
|
12
|
+
var item = tree_1_1.value;
|
|
13
|
+
path.push(item);
|
|
14
|
+
if (predicate(item)) {
|
|
15
|
+
return path;
|
|
16
|
+
}
|
|
17
|
+
if (isObject(item)) {
|
|
18
|
+
var childs = item[childrenField];
|
|
19
|
+
if (Array.isArray(childs) && childs.length > 0) {
|
|
20
|
+
var findChildren = internalFindTreeSelect(childs, predicate, childrenField, path);
|
|
21
|
+
if (findChildren.length > 0) {
|
|
22
|
+
return findChildren;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
path.pop();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
30
|
+
finally {
|
|
31
|
+
try {
|
|
32
|
+
if (tree_1_1 && !tree_1_1.done && (_a = tree_1.return)) _a.call(tree_1);
|
|
39
33
|
}
|
|
40
|
-
|
|
41
|
-
path.pop();
|
|
34
|
+
finally { if (e_1) throw e_1.error; }
|
|
42
35
|
}
|
|
43
|
-
|
|
44
|
-
_iterator.e(err);
|
|
45
|
-
} finally {
|
|
46
|
-
_iterator.f();
|
|
47
|
-
}
|
|
48
|
-
return [];
|
|
36
|
+
return [];
|
|
49
37
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*
|
|
54
|
-
* @static
|
|
55
|
-
* @alias module:Tree.findTreeSelect
|
|
56
|
-
* @since 4.14.0
|
|
57
|
-
* @template {any} T
|
|
58
|
-
* @template {(item: T) => boolean} F
|
|
59
|
-
* @param {T[]} tree 树结构数据
|
|
60
|
-
* @param {F} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy 将返回包含该节点的所有父级节点
|
|
61
|
-
* @param {string} [childrenField='children'] 子级字段名
|
|
62
|
-
* @returns {T[]}
|
|
63
|
-
* @example
|
|
64
|
-
* const menus = [{ "id": "1", "name": "首页", "code": "trade", "pid": null }, { "id": "2", "name": "交易管理", "code": "trade", "pid": null, "children": [{ "id": "3", "name": "交易查询", "code": "trade-1", "pid": "2", "children": [{ "id": "4", "name": "交易查询-查询操作", "code": "trade-1-1", "pid": "3" }] }] }, { "id": "5", "name": "权限管理", "code": "authorization", "pid": null, "children": [{ "id": "6", "name": "角色管理", "code": "authorization-1", "pid": "5" }, { "id": "7", "name": "用户管理", "code": "authorization-2", "pid": "5" }] }];
|
|
65
|
-
*
|
|
66
|
-
* findTreeSelect(menus, item => item.id === '2');
|
|
67
|
-
* // [{"id":"2","name":"交易管理","code":"trade","pid":null,"children":[{"id":"3","name":"交易查询","code":"trade-1","pid":"2","children":[{"id":"4","name":"交易查询-查询操作","code":"trade-1-1","pid":"3"}]}]}]
|
|
68
|
-
*
|
|
69
|
-
* findTreeSelect(menus, item => item.id === '7');
|
|
70
|
-
* // [{"id":"5","name":"权限管理","code":"authorization","pid":null,"children":[{"id":"6","name":"角色管理","code":"authorization-1","pid":"5"},{"id":"7","name":"用户管理","code":"authorization-2","pid":"5"}]},{"id":"7","name":"用户管理","code":"authorization-2","pid":"5"}]
|
|
71
|
-
*
|
|
72
|
-
* findTreeSelect(menus, item => item.id === 'not found');
|
|
73
|
-
* // []
|
|
74
|
-
*/
|
|
75
|
-
function findTreeSelect(tree, predicate) {
|
|
76
|
-
var childrenField = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
|
|
77
|
-
return internalFindTreeSelect(tree, predicate, childrenField);
|
|
38
|
+
function findTreeSelect(tree, predicate, childrenField) {
|
|
39
|
+
if (childrenField === void 0) { childrenField = 'children'; }
|
|
40
|
+
return internalFindTreeSelect(tree, predicate, childrenField);
|
|
78
41
|
}
|
|
79
|
-
|
|
42
|
+
|
|
43
|
+
export { findTreeSelect as default };
|
package/esm/formatBankCard.js
CHANGED
|
@@ -1,45 +1,15 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* @returns {string} 格式化的银行卡号
|
|
14
|
-
* @example
|
|
15
|
-
*
|
|
16
|
-
* // 19位银行卡
|
|
17
|
-
* formatBankCard('6228480402564890018'); // 6228 4804 0256 4890 018
|
|
18
|
-
*
|
|
19
|
-
* // 16位银行卡
|
|
20
|
-
* formatBankCard('6228480402564890'); // 6228 4804 0256 4890
|
|
21
|
-
*
|
|
22
|
-
* // 脱敏银行卡
|
|
23
|
-
* formatBankCard('6228********890'); // 6228 **** **** 890
|
|
24
|
-
*
|
|
25
|
-
* // 16位银行卡,"-"间隔
|
|
26
|
-
* formatBankCard('6228480402564890', {spaceMark: '-'}); // 6228-4804-0256-4890
|
|
27
|
-
*
|
|
28
|
-
*/
|
|
29
|
-
function formatBankCard() {
|
|
30
|
-
var bankCardNo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
31
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
// TODO 下个版本废弃 char
|
|
34
|
-
var _options$char = options["char"],
|
|
35
|
-
_char = _options$char === void 0 ? ' ' : _options$char,
|
|
36
|
-
_options$length = options.length,
|
|
37
|
-
length = _options$length === void 0 ? 4 : _options$length;
|
|
38
|
-
var realSpaceMark = 'spaceMark' in options ? options.spaceMark : _char;
|
|
39
|
-
var reg = new RegExp("(.{".concat(length, "})"), 'g');
|
|
40
|
-
var regChar = new RegExp("".concat(realSpaceMark), 'g');
|
|
41
|
-
var realValue = normalizeString(bankCardNo).replace(regChar, '');
|
|
42
|
-
var str = realValue.replace(reg, "$1".concat(realSpaceMark));
|
|
43
|
-
return realValue.length % length === 0 ? str.substring(0, str.length - 1) : str;
|
|
3
|
+
function formatBankCard(bankCardNo, options) {
|
|
4
|
+
if (bankCardNo === void 0) { bankCardNo = ''; }
|
|
5
|
+
if (options === void 0) { options = {}; }
|
|
6
|
+
var _a = options.char, char = _a === void 0 ? ' ' : _a, _b = options.length, length = _b === void 0 ? 4 : _b;
|
|
7
|
+
var realSpaceMark = 'spaceMark' in options ? options.spaceMark : char;
|
|
8
|
+
var reg = new RegExp("(.{".concat(length, "})"), 'g');
|
|
9
|
+
var regChar = new RegExp("".concat(realSpaceMark), 'g');
|
|
10
|
+
var realValue = normalizeString(bankCardNo).replace(regChar, '');
|
|
11
|
+
var str = realValue.replace(reg, "$1".concat(realSpaceMark));
|
|
12
|
+
return realValue.length % length === 0 ? str.substring(0, str.length - 1) : str;
|
|
44
13
|
}
|
|
45
|
-
|
|
14
|
+
|
|
15
|
+
export { formatBankCard as default };
|
package/esm/formatMobile.js
CHANGED
|
@@ -1,45 +1,19 @@
|
|
|
1
|
-
import normalizeString from './normalizeString';
|
|
1
|
+
import normalizeString from './normalizeString.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
* // 脱敏手机号码
|
|
19
|
-
* formatMobile('133****1234'); // 133 **** 1234
|
|
20
|
-
* formatMobile('133****1234', { spaceMark: '-' }); // 133-****-1234
|
|
21
|
-
*
|
|
22
|
-
* // 手机号码位数不够
|
|
23
|
-
* formatMobile('133'); // 133
|
|
24
|
-
* formatMobile('133456'); // 133 456
|
|
25
|
-
* formatMobile('13345678'); // 133 4567 8
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
function formatMobile(mobileNo) {
|
|
29
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
// TODO 下个版本废弃 char
|
|
32
|
-
var _options$char = options["char"],
|
|
33
|
-
_char = _options$char === void 0 ? ' ' : _options$char;
|
|
34
|
-
var realSpaceMark = 'spaceMark' in options ? options.spaceMark : _char;
|
|
35
|
-
var regChar = new RegExp(realSpaceMark, 'g');
|
|
36
|
-
var realValue = normalizeString(mobileNo).replace(regChar, '').substring(0, 11);
|
|
37
|
-
if (realValue.length > 7) {
|
|
38
|
-
return realValue.replace(/^(...)(....)/g, "$1".concat(realSpaceMark, "$2").concat(realSpaceMark));
|
|
39
|
-
}
|
|
40
|
-
if (realValue.length > 3) {
|
|
41
|
-
return realValue.replace(/^(...)/g, "$1".concat(realSpaceMark));
|
|
42
|
-
}
|
|
43
|
-
return realValue;
|
|
3
|
+
function formatMobile(mobileNo, options) {
|
|
4
|
+
if (mobileNo === void 0) { mobileNo = ''; }
|
|
5
|
+
if (options === void 0) { options = {}; }
|
|
6
|
+
var _a = options.char, char = _a === void 0 ? ' ' : _a;
|
|
7
|
+
var realSpaceMark = 'spaceMark' in options ? options.spaceMark : char;
|
|
8
|
+
var regChar = new RegExp(realSpaceMark, 'g');
|
|
9
|
+
var realValue = normalizeString(mobileNo).replace(regChar, '').substring(0, 11);
|
|
10
|
+
if (realValue.length > 7) {
|
|
11
|
+
return realValue.replace(/^(...)(....)/g, "$1".concat(realSpaceMark, "$2").concat(realSpaceMark));
|
|
12
|
+
}
|
|
13
|
+
if (realValue.length > 3) {
|
|
14
|
+
return realValue.replace(/^(...)/g, "$1".concat(realSpaceMark));
|
|
15
|
+
}
|
|
16
|
+
return realValue;
|
|
44
17
|
}
|
|
45
|
-
|
|
18
|
+
|
|
19
|
+
export { formatMobile as default };
|
package/esm/formatMoney.js
CHANGED
|
@@ -1,147 +1,67 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import devWarn from './utils/devWarn';
|
|
6
|
-
var reg = /^[+-]?\d*\.?\d*$/;
|
|
1
|
+
import { __read } from 'tslib';
|
|
2
|
+
import { scientificToNumber, isScientificNumber, checkBoundary, trimLeftZero } from './utils/math.util.js';
|
|
3
|
+
import _isNaN from './utils/type/isNaN.js';
|
|
4
|
+
import devWarn from './utils/devWarn.js';
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
* 检查数字或数字字符串
|
|
10
|
-
*
|
|
11
|
-
* @private
|
|
12
|
-
* @param {string} num
|
|
13
|
-
* @returns 是否为数字
|
|
14
|
-
*/
|
|
6
|
+
var reg = /^[+-]?\d*\.?\d*$/;
|
|
15
7
|
function checkNumber(num) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
checkBoundary(num);
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
8
|
+
if ((typeof num !== 'number' && typeof num !== 'string') || (typeof num === 'number' && _isNaN(num)) || (typeof num === 'string' && (!(reg.test(num) || isScientificNumber(num)) || num === ''))) {
|
|
9
|
+
devWarn("".concat(num, " invalid parameter."));
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (typeof num === 'number') {
|
|
13
|
+
checkBoundary(num);
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
27
16
|
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 格式化整数部分
|
|
31
|
-
*
|
|
32
|
-
* @private
|
|
33
|
-
* @param {string} intStr 数字字符串
|
|
34
|
-
* @param {string} thousand 千分位符号
|
|
35
|
-
* @returns 格式化后的值
|
|
36
|
-
*/
|
|
37
17
|
function formatInt(intStr, thousand) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
18
|
+
var txt = '';
|
|
19
|
+
intStr = trimLeftZero(intStr);
|
|
20
|
+
intStr = intStr[0] === '+' ? intStr.substring(1) : intStr;
|
|
21
|
+
var negativeSymbol = Number(intStr) < 0 ? '-' : '';
|
|
22
|
+
var reArr = negativeSymbol ? intStr.substring(1).split('').reverse() : intStr.split('').reverse();
|
|
23
|
+
for (var i = 0; i < reArr.length; i++) {
|
|
24
|
+
txt += reArr[i] + ((i + 1) % 3 === 0 && i + 1 !== reArr.length ? thousand : '');
|
|
25
|
+
}
|
|
26
|
+
return negativeSymbol + txt.split('').reverse().join('');
|
|
47
27
|
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 格式化小数部分,如果使用 toFixed,超大额数字会自动被截断
|
|
51
|
-
*
|
|
52
|
-
* @private
|
|
53
|
-
* @param {string} decStr 小数点部分的字符串
|
|
54
|
-
* @param {number} precision 保留位数
|
|
55
|
-
* @param {string} decimal 小数点符号
|
|
56
|
-
* @returns 格式化后的值
|
|
57
|
-
*/
|
|
58
28
|
function formatDec(decStr, precision, decimal) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
29
|
+
if (precision === 0) {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
var zero = 0;
|
|
33
|
+
var ret = '';
|
|
34
|
+
if (decStr && Number(decStr) > 0) {
|
|
35
|
+
var tmpNum = parseFloat('0.' + decStr);
|
|
36
|
+
ret = tmpNum.toFixed(precision).substring(2);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
ret = zero.toFixed(precision).substring(2);
|
|
40
|
+
}
|
|
41
|
+
return decimal + ret;
|
|
71
42
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
*
|
|
94
|
-
* // 保留4位小数
|
|
95
|
-
* formatMoney(3000.03, { precision: 4 }); // 3,000.0300
|
|
96
|
-
*
|
|
97
|
-
* // 保留10位小数
|
|
98
|
-
* formatMoney(1500.2, { precision: 10 }); // 1,500.2000000000
|
|
99
|
-
*
|
|
100
|
-
* // 自定义单位符号
|
|
101
|
-
* formatMoney(1000.00, { symbol: '$' }); // $1,000.00
|
|
102
|
-
*
|
|
103
|
-
* // 自定义千位分割符(默认',')
|
|
104
|
-
* formatMoney(1000.00, { thousand: '|' }); // 1|000.00
|
|
105
|
-
*
|
|
106
|
-
* // 自定义小数位分割符(默认'.')
|
|
107
|
-
* formatMoney(1000.00, { decimal: '&' }); // 1,000&00
|
|
108
|
-
*
|
|
109
|
-
* // 字符串数字
|
|
110
|
-
* formatMoney('3000.03', { precision: 4 }); // 3,000.0300
|
|
111
|
-
*/
|
|
112
|
-
var formatMoney = function formatMoney(num) {
|
|
113
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
114
|
-
var _options$precision = options.precision,
|
|
115
|
-
precision = _options$precision === void 0 ? 2 : _options$precision,
|
|
116
|
-
symbol = options.symbol,
|
|
117
|
-
_options$thousand = options.thousand,
|
|
118
|
-
thousand = _options$thousand === void 0 ? ',' : _options$thousand,
|
|
119
|
-
_options$decimal = options.decimal,
|
|
120
|
-
decimal = _options$decimal === void 0 ? '.' : _options$decimal;
|
|
121
|
-
|
|
122
|
-
// 数字参数不正确,返回空字符串
|
|
123
|
-
// @ts-ignore
|
|
124
|
-
if (!checkNumber(num)) {
|
|
125
|
-
return '';
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// 参数规整化
|
|
129
|
-
if (typeof precision !== 'number' || isNaN(precision) || precision < 0) {
|
|
130
|
-
precision = 2;
|
|
131
|
-
} else if (precision > 10) {
|
|
132
|
-
precision = 10;
|
|
133
|
-
}
|
|
134
|
-
symbol = typeof symbol === 'string' ? symbol : '';
|
|
135
|
-
thousand = typeof thousand === 'string' ? thousand : ',';
|
|
136
|
-
decimal = typeof decimal === 'string' ? decimal : '.';
|
|
137
|
-
|
|
138
|
-
// 转换数字字符串,支持科学记数法
|
|
139
|
-
var strNum = scientificToNumber(num) + '';
|
|
140
|
-
// 整数和小数部分
|
|
141
|
-
var _strNum$split = strNum.split('.'),
|
|
142
|
-
_strNum$split2 = _slicedToArray(_strNum$split, 2),
|
|
143
|
-
intStr = _strNum$split2[0],
|
|
144
|
-
decStr = _strNum$split2[1];
|
|
145
|
-
return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
|
|
43
|
+
var formatMoney = function (num, options) {
|
|
44
|
+
if (options === void 0) { options = {}; }
|
|
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;
|
|
46
|
+
if (!checkNumber(num)) {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
if (typeof num === 'number' && !isFinite(num)) {
|
|
50
|
+
return num + '';
|
|
51
|
+
}
|
|
52
|
+
if (typeof precision !== 'number' || _isNaN(precision) || precision < 0) {
|
|
53
|
+
precision = 2;
|
|
54
|
+
}
|
|
55
|
+
else if (precision > 10) {
|
|
56
|
+
precision = 10;
|
|
57
|
+
}
|
|
58
|
+
symbol = typeof symbol === 'string' ? symbol : '';
|
|
59
|
+
thousand = typeof thousand === 'string' ? thousand : ',';
|
|
60
|
+
decimal = typeof decimal === 'string' ? decimal : '.';
|
|
61
|
+
var strNum = scientificToNumber(num) + '';
|
|
62
|
+
var _d = __read(strNum.split('.'), 2), intStr = _d[0], decStr = _d[1];
|
|
63
|
+
return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
|
|
146
64
|
};
|
|
147
|
-
|
|
65
|
+
var formatMoney$1 = formatMoney;
|
|
66
|
+
|
|
67
|
+
export { formatMoney$1 as default };
|