util-helpers 4.13.0 → 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 +3 -3
- 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 +8 -7
- 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 +9 -7
- 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/types/utils/config.d.ts +1 -2
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _type = require("./utils/type");
|
|
8
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
+
/**
|
|
15
|
+
* 递归处理空子级
|
|
16
|
+
*
|
|
17
|
+
* @private
|
|
18
|
+
* @template {Record<string,any>} [T=Record<string,any>]
|
|
19
|
+
* @param {T[]} arr 列表数据
|
|
20
|
+
* @param {object} options 配置项
|
|
21
|
+
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
22
|
+
* @param {'none'|'null'|'array'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
|
|
23
|
+
*/
|
|
24
|
+
function processEmptyChildren(arr) {
|
|
25
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
26
|
+
var _options$childrenFiel = options.childrenField,
|
|
27
|
+
childrenField = _options$childrenFiel === void 0 ? 'children' : _options$childrenFiel,
|
|
28
|
+
_options$emptyChildre = options.emptyChildrenValue,
|
|
29
|
+
emptyChildrenValue = _options$emptyChildre === void 0 ? 'none' : _options$emptyChildre;
|
|
30
|
+
arr.forEach(function (item) {
|
|
31
|
+
if ((0, _type.isObject)(item) && Array.isArray(item[childrenField])) {
|
|
32
|
+
if (item[childrenField].length <= 0) {
|
|
33
|
+
if (emptyChildrenValue === 'null') {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
item[childrenField] = null;
|
|
36
|
+
} else if (emptyChildrenValue === 'none') {
|
|
37
|
+
delete item[childrenField];
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
processEmptyChildren(item[childrenField], options);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 列表数据转树结构
|
|
48
|
+
*
|
|
49
|
+
* @static
|
|
50
|
+
* @alias module:Processor.listToTree
|
|
51
|
+
* @since 4.14.0
|
|
52
|
+
* @template {Record<string,any>} [T=Record<string,any>]
|
|
53
|
+
* @template {*} [R=T&Record<string,any>]
|
|
54
|
+
* @param {T[]} list 列表数据
|
|
55
|
+
* @param {object} options 配置项
|
|
56
|
+
* @param {string} [options.keyField='id'] 当前数据的键值字段名称
|
|
57
|
+
* @param {string} [options.parentField='pid'] 当前数据的父级字段名称
|
|
58
|
+
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
59
|
+
* @param {'none'|'null'|'array'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
|
|
60
|
+
* @returns {R[]} 树结构
|
|
61
|
+
* @example
|
|
62
|
+
*
|
|
63
|
+
* const menus = [
|
|
64
|
+
* { id: '1', name: '首页', code: 'trade', pid: null },
|
|
65
|
+
* { id: '2', name: '交易管理', code: 'trade', pid: null },
|
|
66
|
+
* { id: '3', name: '交易查询', code: 'trade-1', pid: '2' },
|
|
67
|
+
* { id: '4', name: '交易查询-查询操作', code: 'trade-1-1', pid: '3' },
|
|
68
|
+
* { id: '5', name: '权限管理', code: 'authorization', pid: null },
|
|
69
|
+
* { id: '6', name: '角色管理', code: 'authorization-1', pid: '5' },
|
|
70
|
+
* { id: '7', name: '用户管理', code: 'authorization-2', pid: '5' }
|
|
71
|
+
* ];
|
|
72
|
+
* listToTree(menus);
|
|
73
|
+
* // [{"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"}]}]
|
|
74
|
+
*
|
|
75
|
+
* // 自定义子级字段名
|
|
76
|
+
* listToTree(basicMenus, { childrenField: 'childs' });
|
|
77
|
+
* // [{"id":"1","name":"首页","code":"trade","pid":null},{"id":"2","name":"交易管理","code":"trade","pid":null,"childs":[{"id":"3","name":"交易查询","code":"trade-1","pid":"2","childs":[{"id":"4","name":"交易查询-查询操作","code":"trade-1-1","pid":"3"}]}]},{"id":"5","name":"权限管理","code":"authorization","pid":null,"childs":[{"id":"6","name":"角色管理","code":"authorization-1","pid":"5"},{"id":"7","name":"用户管理","code":"authorization-2","pid":"5"}]}]
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
function listToTree(list) {
|
|
81
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
82
|
+
var _options$keyField = options.keyField,
|
|
83
|
+
keyField = _options$keyField === void 0 ? 'id' : _options$keyField,
|
|
84
|
+
_options$parentField = options.parentField,
|
|
85
|
+
parentField = _options$parentField === void 0 ? 'pid' : _options$parentField,
|
|
86
|
+
_options$childrenFiel2 = options.childrenField,
|
|
87
|
+
childrenField = _options$childrenFiel2 === void 0 ? 'children' : _options$childrenFiel2,
|
|
88
|
+
_options$emptyChildre2 = options.emptyChildrenValue,
|
|
89
|
+
emptyChildrenValue = _options$emptyChildre2 === void 0 ? 'none' : _options$emptyChildre2;
|
|
90
|
+
|
|
91
|
+
/** @type {R[]} */
|
|
92
|
+
var tree = [];
|
|
93
|
+
|
|
94
|
+
/** @type {Object.<string, T[]>} */
|
|
95
|
+
var record = {};
|
|
96
|
+
list.forEach(function (item) {
|
|
97
|
+
if ((0, _type.isObject)(item)) {
|
|
98
|
+
var newItem = _objectSpread({}, item);
|
|
99
|
+
|
|
100
|
+
/** @type {string} */
|
|
101
|
+
var id = newItem[keyField];
|
|
102
|
+
|
|
103
|
+
/** @type {string} */
|
|
104
|
+
var pid = newItem[parentField];
|
|
105
|
+
if (record[id]) {
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
newItem[childrenField] = record[id];
|
|
108
|
+
} else {
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
newItem[childrenField] = record[id] = [];
|
|
111
|
+
}
|
|
112
|
+
if (pid) {
|
|
113
|
+
if (!record[pid]) {
|
|
114
|
+
record[pid] = [newItem];
|
|
115
|
+
} else {
|
|
116
|
+
record[pid].push(newItem);
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
tree.push(newItem);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
if (emptyChildrenValue !== 'array') {
|
|
125
|
+
// @ts-ignore
|
|
126
|
+
processEmptyChildren(tree, options);
|
|
127
|
+
}
|
|
128
|
+
return tree;
|
|
129
|
+
}
|
|
130
|
+
var _default = listToTree;
|
|
131
|
+
exports["default"] = _default;
|
package/lib/minus.js
CHANGED
|
@@ -4,25 +4,15 @@ 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 _times = _interopRequireDefault(require("./times"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
|
|
14
10
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
15
|
-
|
|
16
11
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
17
|
-
|
|
18
12
|
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); }
|
|
19
|
-
|
|
20
13
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
21
|
-
|
|
22
14
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
23
|
-
|
|
24
15
|
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; }
|
|
25
|
-
|
|
26
16
|
/**
|
|
27
17
|
* 精确减法,支持多个数相减,减数默认为 0 。
|
|
28
18
|
*
|
|
@@ -42,27 +32,23 @@ function minus() {
|
|
|
42
32
|
for (var _len = arguments.length, nums = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
43
33
|
nums[_key] = arguments[_key];
|
|
44
34
|
}
|
|
45
|
-
|
|
46
35
|
var num1 = nums[0],
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
_nums$ = nums[1],
|
|
37
|
+
num2 = _nums$ === void 0 ? 0 : _nums$,
|
|
38
|
+
rest = nums.slice(2);
|
|
51
39
|
if (rest.length > 0) {
|
|
52
40
|
return minus.apply(void 0, [minus(num1, num2)].concat(_toConsumableArray(rest)));
|
|
53
41
|
}
|
|
54
|
-
|
|
55
42
|
num1 = (0, _math.transformEffectiveNumber)(num1);
|
|
56
|
-
num2 = (0, _math.transformEffectiveNumber)(num2);
|
|
57
|
-
// @ts-ignore
|
|
43
|
+
num2 = (0, _math.transformEffectiveNumber)(num2);
|
|
58
44
|
|
|
45
|
+
// 兼容处理,如果参数包含无效数值时,返回 NaN
|
|
46
|
+
// @ts-ignore
|
|
59
47
|
if (isNaN(num1) || isNaN(num2)) {
|
|
60
48
|
return Number.NaN;
|
|
61
49
|
}
|
|
62
|
-
|
|
63
50
|
var baseNum = Math.pow(10, Math.max((0, _math.digitLength)(num1), (0, _math.digitLength)(num2)));
|
|
64
51
|
return ((0, _times["default"])(num1, baseNum) - (0, _times["default"])(num2, baseNum)) / baseNum;
|
|
65
52
|
}
|
|
66
|
-
|
|
67
53
|
var _default = minus;
|
|
68
54
|
exports["default"] = _default;
|
package/lib/normalizeString.js
CHANGED
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _isNil = _interopRequireDefault(require("./utils/type/isNil"));
|
|
9
|
-
|
|
10
8
|
var _convertToString = _interopRequireDefault(require("./utils/convertToString"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* 规整化字符串。如果值为 undefined 或 null 将转为空字符串,如果值不是字符串类型将转为字符串。
|
|
16
12
|
*
|
|
@@ -37,9 +33,7 @@ function normalizeString(value) {
|
|
|
37
33
|
if ((0, _isNil["default"])(value)) {
|
|
38
34
|
return '';
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
return (0, _convertToString["default"])(value);
|
|
42
37
|
}
|
|
43
|
-
|
|
44
38
|
var _default = normalizeString;
|
|
45
39
|
exports["default"] = _default;
|
package/lib/numberToChinese.js
CHANGED
|
@@ -4,38 +4,37 @@ 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 _devWarn = _interopRequireDefault(require("./utils/devWarn"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
|
|
14
10
|
// 简体
|
|
15
11
|
var chnNumberChar = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
|
|
16
|
-
var chnUnitChar = ['', '十', '百', '千'];
|
|
12
|
+
var chnUnitChar = ['', '十', '百', '千'];
|
|
17
13
|
|
|
14
|
+
// 繁体
|
|
18
15
|
var big5NumberChar = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
19
|
-
var big5UnitChar = ['', '拾', '佰', '仟'];
|
|
16
|
+
var big5UnitChar = ['', '拾', '佰', '仟'];
|
|
17
|
+
|
|
18
|
+
// 数字字符、计数单位
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* @type {string[]}
|
|
23
22
|
* @private
|
|
24
23
|
*/
|
|
25
|
-
|
|
26
24
|
var numberChar;
|
|
25
|
+
|
|
27
26
|
/**
|
|
28
27
|
* @type {string[]}
|
|
29
28
|
* @private
|
|
30
29
|
*/
|
|
31
|
-
|
|
32
30
|
var unitChar;
|
|
31
|
+
|
|
33
32
|
/**
|
|
34
33
|
* @type {string[]}
|
|
35
34
|
* @private
|
|
36
35
|
*/
|
|
37
|
-
|
|
38
36
|
var unitSection;
|
|
37
|
+
|
|
39
38
|
/**
|
|
40
39
|
* 每个小节的内部进行转化
|
|
41
40
|
*
|
|
@@ -43,18 +42,16 @@ var unitSection;
|
|
|
43
42
|
* @param {number} section 数字
|
|
44
43
|
* @returns {string} 转化的数字
|
|
45
44
|
*/
|
|
46
|
-
|
|
47
45
|
function sectionToChinese(section) {
|
|
48
46
|
var str = '';
|
|
49
47
|
var chnstr = '';
|
|
50
48
|
var zero = false; //zero为是否进行补零, 第一次进行取余由于为个位数,默认不补零
|
|
51
|
-
|
|
52
49
|
var unitPos = 0;
|
|
53
|
-
|
|
54
50
|
while (section > 0) {
|
|
55
51
|
// 对数字取余10,得到的数即为个位数
|
|
56
|
-
var v = section % 10;
|
|
52
|
+
var v = section % 10;
|
|
57
53
|
|
|
54
|
+
//如果数字为零,则对字符串进行补零
|
|
58
55
|
if (v == 0) {
|
|
59
56
|
if (zero) {
|
|
60
57
|
//如果遇到连续多次取余都是0,那么只需补一个零即可
|
|
@@ -68,13 +65,12 @@ function sectionToChinese(section) {
|
|
|
68
65
|
str += unitChar[unitPos];
|
|
69
66
|
chnstr = str + chnstr;
|
|
70
67
|
}
|
|
71
|
-
|
|
72
68
|
unitPos++;
|
|
73
69
|
section = Math.floor(section / 10);
|
|
74
70
|
}
|
|
75
|
-
|
|
76
71
|
return chnstr;
|
|
77
72
|
}
|
|
73
|
+
|
|
78
74
|
/**
|
|
79
75
|
* 转换整数
|
|
80
76
|
*
|
|
@@ -82,26 +78,20 @@ function sectionToChinese(section) {
|
|
|
82
78
|
* @param {number} num 要转换的数字
|
|
83
79
|
* @returns {string} 中文数字
|
|
84
80
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
81
|
function convertInteger(num) {
|
|
88
82
|
var numInt = Math.floor(num);
|
|
89
83
|
var unitPos = 0;
|
|
90
84
|
var strIns = '';
|
|
91
85
|
var chnStr = '';
|
|
92
86
|
var needZero = false;
|
|
93
|
-
|
|
94
87
|
if (numInt === 0) {
|
|
95
88
|
return numberChar[0];
|
|
96
89
|
}
|
|
97
|
-
|
|
98
90
|
while (numInt > 0) {
|
|
99
91
|
var section = numInt % 10000;
|
|
100
|
-
|
|
101
92
|
if (needZero) {
|
|
102
93
|
chnStr = numberChar[0] + chnStr;
|
|
103
94
|
}
|
|
104
|
-
|
|
105
95
|
strIns = sectionToChinese(section);
|
|
106
96
|
strIns += section !== 0 ? unitSection[unitPos] : unitSection[0];
|
|
107
97
|
chnStr = strIns + chnStr;
|
|
@@ -109,29 +99,26 @@ function convertInteger(num) {
|
|
|
109
99
|
numInt = Math.floor(numInt / 10000);
|
|
110
100
|
unitPos++;
|
|
111
101
|
}
|
|
112
|
-
|
|
113
102
|
return chnStr;
|
|
114
103
|
}
|
|
104
|
+
|
|
115
105
|
/**
|
|
116
106
|
* 转换小数
|
|
117
107
|
*
|
|
118
108
|
* @private
|
|
119
109
|
* @param {number} num 要转换的数字
|
|
120
110
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
111
|
function convertDecimal(num) {
|
|
124
112
|
var strNum = num + '';
|
|
125
113
|
var index = strNum.indexOf('.');
|
|
126
114
|
var ret = '';
|
|
127
|
-
|
|
128
115
|
if (index > -1) {
|
|
129
116
|
var decimalStr = strNum.slice(index + 1);
|
|
130
117
|
ret = mapNumberChar(parseInt(decimalStr));
|
|
131
118
|
}
|
|
132
|
-
|
|
133
119
|
return ret;
|
|
134
120
|
}
|
|
121
|
+
|
|
135
122
|
/**
|
|
136
123
|
* 映射为中文数字
|
|
137
124
|
*
|
|
@@ -139,18 +126,15 @@ function convertDecimal(num) {
|
|
|
139
126
|
* @param {number} num 要处理的数字
|
|
140
127
|
* @returns {string} 返回中文数字的映射
|
|
141
128
|
*/
|
|
142
|
-
|
|
143
|
-
|
|
144
129
|
function mapNumberChar(num) {
|
|
145
130
|
var strNum = num + '';
|
|
146
131
|
var ret = '';
|
|
147
|
-
|
|
148
132
|
for (var i = 0, len = strNum.length; i < len; i++) {
|
|
149
133
|
ret += numberChar[parseInt(strNum[i])];
|
|
150
134
|
}
|
|
151
|
-
|
|
152
135
|
return ret;
|
|
153
136
|
}
|
|
137
|
+
|
|
154
138
|
/**
|
|
155
139
|
* 数字转中文数字
|
|
156
140
|
* 不在安全数字 -9007199254740991~9007199254740991 内,处理会有异常
|
|
@@ -188,31 +172,31 @@ function mapNumberChar(num) {
|
|
|
188
172
|
* numberToChinese(1990, {unit: false, zero:'〇'}); // 一九九〇
|
|
189
173
|
*
|
|
190
174
|
*/
|
|
191
|
-
|
|
192
|
-
|
|
193
175
|
function numberToChinese(num) {
|
|
194
176
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
195
177
|
var _options$big = options.big5,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
178
|
+
big5 = _options$big === void 0 ? false : _options$big,
|
|
179
|
+
_options$unit = options.unit,
|
|
180
|
+
unit = _options$unit === void 0 ? true : _options$unit,
|
|
181
|
+
_options$zero = options.zero,
|
|
182
|
+
zero = _options$zero === void 0 ? '' : _options$zero,
|
|
183
|
+
_options$negative = options.negative,
|
|
184
|
+
negative = _options$negative === void 0 ? '负' : _options$negative,
|
|
185
|
+
_options$unitConfig = options.unitConfig,
|
|
186
|
+
unitConfig = _options$unitConfig === void 0 ? {} : _options$unitConfig;
|
|
205
187
|
var _options$decimal = options.decimal,
|
|
206
|
-
|
|
188
|
+
decimal = _options$decimal === void 0 ? '' : _options$decimal;
|
|
207
189
|
|
|
190
|
+
// 非数字 或 NaN 不处理
|
|
208
191
|
if (typeof num !== 'number' || isNaN(num)) {
|
|
209
192
|
(0, _devWarn["default"])("\u53C2\u6570\u9519\u8BEF ".concat(num, "\uFF0C\u8BF7\u4F20\u5165\u6570\u5B57"));
|
|
210
193
|
return '';
|
|
211
|
-
}
|
|
212
|
-
|
|
194
|
+
}
|
|
213
195
|
|
|
214
|
-
|
|
196
|
+
// 超过安全数字提示
|
|
197
|
+
(0, _math.checkBoundary)(num);
|
|
215
198
|
|
|
199
|
+
// 设置数字字符和计数单位
|
|
216
200
|
if (big5) {
|
|
217
201
|
numberChar = big5NumberChar.slice();
|
|
218
202
|
unitChar = big5UnitChar.slice();
|
|
@@ -221,34 +205,36 @@ function numberToChinese(num) {
|
|
|
221
205
|
numberChar = chnNumberChar.slice();
|
|
222
206
|
unitChar = chnUnitChar.slice();
|
|
223
207
|
decimal = decimal || '点';
|
|
224
|
-
}
|
|
225
|
-
|
|
208
|
+
}
|
|
226
209
|
|
|
210
|
+
// 设置节点计数单位,万、亿、万亿
|
|
227
211
|
var unitWan = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.w) || '万';
|
|
228
212
|
var unitYi = (unitConfig === null || unitConfig === void 0 ? void 0 : unitConfig.y) || '亿';
|
|
229
213
|
var unitWanYi = unitWan + unitYi;
|
|
230
|
-
unitSection = ['', unitWan, unitYi, unitWanYi];
|
|
214
|
+
unitSection = ['', unitWan, unitYi, unitWanYi];
|
|
231
215
|
|
|
216
|
+
// 设置0
|
|
232
217
|
if (zero) {
|
|
233
218
|
numberChar[0] = zero;
|
|
234
|
-
}
|
|
235
|
-
|
|
219
|
+
}
|
|
236
220
|
|
|
237
|
-
|
|
221
|
+
// 前置字符,负数处理
|
|
222
|
+
var preStr = num < 0 ? negative : '';
|
|
238
223
|
|
|
224
|
+
// 整数和小数
|
|
239
225
|
var chnInteger, chnDecimal;
|
|
240
|
-
var numAbs = Math.abs(num);
|
|
226
|
+
var numAbs = Math.abs(num);
|
|
241
227
|
|
|
228
|
+
// 处理整数
|
|
242
229
|
if (unit) {
|
|
243
230
|
chnInteger = convertInteger(numAbs);
|
|
244
231
|
} else {
|
|
245
232
|
chnInteger = mapNumberChar(Math.floor(numAbs));
|
|
246
|
-
}
|
|
247
|
-
|
|
233
|
+
}
|
|
248
234
|
|
|
235
|
+
// 处理小数
|
|
249
236
|
chnDecimal = convertDecimal(numAbs);
|
|
250
237
|
return chnDecimal ? "".concat(preStr).concat(chnInteger).concat(decimal).concat(chnDecimal) : "".concat(preStr).concat(chnInteger);
|
|
251
238
|
}
|
|
252
|
-
|
|
253
239
|
var _default = numberToChinese;
|
|
254
240
|
exports["default"] = _default;
|
package/lib/padZero.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
|
*
|
|
@@ -36,17 +33,13 @@ function padZero(value) {
|
|
|
36
33
|
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
37
34
|
var str = (0, _normalizeString["default"])(value);
|
|
38
35
|
var len = str.length;
|
|
39
|
-
|
|
40
36
|
if (typeof size !== 'number' || size < 0) {
|
|
41
37
|
size = 0;
|
|
42
38
|
}
|
|
43
|
-
|
|
44
39
|
if (len < size) {
|
|
45
40
|
return '0'.repeat(size - len) + str;
|
|
46
41
|
}
|
|
47
|
-
|
|
48
42
|
return str;
|
|
49
43
|
}
|
|
50
|
-
|
|
51
44
|
var _default = padZero;
|
|
52
45
|
exports["default"] = _default;
|
package/lib/parseIdCard.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
4
|
-
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
15
|
-
|
|
16
|
-
var regIdCard = /*#__PURE__*/_wrapRegExp(/^([0-9]{2})([0-9]{2})([0-9]{2})((?:[0-9]{2})?[0-9]{2})([0-9]{2})([0-9]{2})[0-9]{2}([0-9])(?:[0-9]|X)?$/i, {
|
|
8
|
+
function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, void 0, groups); }; var _super = RegExp.prototype, _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); return _groups.set(_this, groups || _groups.get(re)), _setPrototypeOf(_this, BabelRegExp.prototype); } function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { var i = g[name]; if ("number" == typeof i) groups[name] = result[i];else { for (var k = 0; void 0 === result[i[k]] && k + 1 < i.length;) { k++; } groups[name] = result[i[k]]; } return groups; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) { result.groups = buildGroups(result, this); var indices = result.indices; indices && (indices.groups = buildGroups(indices, this)); } return result; }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if ("string" == typeof substitution) { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { var group = groups[name]; return "$" + (Array.isArray(group) ? group.join("$") : group); })); } if ("function" == typeof substitution) { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; return "object" != _typeof(args[args.length - 1]) && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); }); } return _super[Symbol.replace].call(this, str, substitution); }, _wrapRegExp.apply(this, arguments); }
|
|
9
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
10
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
11
|
+
var regIdCard = /*#__PURE__*/_wrapRegExp(/^(\d{2})(\d{2})(\d{2})((?:\d{2})?\d{2})(\d{2})(\d{2})\d{2}(\d)(?:\d|X)?$/i, {
|
|
17
12
|
province: 1,
|
|
18
13
|
city: 2,
|
|
19
14
|
area: 3,
|
|
@@ -22,18 +17,28 @@ var regIdCard = /*#__PURE__*/_wrapRegExp(/^([0-9]{2})([0-9]{2})([0-9]{2})((?:[0-
|
|
|
22
17
|
day: 6,
|
|
23
18
|
gender: 7
|
|
24
19
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
['11', '北京市'], ['12', '天津市'], ['13', '河北省'], ['14', '山西省'], ['15', '内蒙古自治区'],
|
|
28
|
-
|
|
29
|
-
['
|
|
30
|
-
|
|
31
|
-
['
|
|
32
|
-
|
|
33
|
-
['
|
|
20
|
+
var Provinces = [
|
|
21
|
+
// 华北地区:北京市|110000,天津市|120000,河北省|130000,山西省|140000,内蒙古自治区|150000
|
|
22
|
+
['11', '北京市'], ['12', '天津市'], ['13', '河北省'], ['14', '山西省'], ['15', '内蒙古自治区'],
|
|
23
|
+
// 东北地区: 辽宁省|210000,吉林省|220000,黑龙江省|230000
|
|
24
|
+
['21', '辽宁省'], ['22', '吉林省'], ['23', '黑龙江省'],
|
|
25
|
+
// 华东地区: 上海市|310000,江苏省|320000,浙江省|330000,安徽省|340000,福建省|350000,江西省|360000,山东省|370000
|
|
26
|
+
['31', '上海市'], ['32', '江苏省'], ['33', '浙江省'], ['34', '安徽省'], ['35', '福建省'], ['36', '江西省'], ['37', '山东省'],
|
|
27
|
+
// 华中地区: 河南省|410000,湖北省|420000,湖南省|430000
|
|
28
|
+
['41', '河南省'], ['42', '湖北省'], ['43', '湖南省'],
|
|
29
|
+
// 华南地区:广东省|440000,广西壮族自治区|450000,海南省|460000
|
|
30
|
+
['44', '广东省'], ['45', '广西壮族自治区'], ['46', '海南省'],
|
|
31
|
+
// 西南地区:重庆市|500000,四川省|510000,贵州省|520000,云南省|530000,西藏自治区|540000
|
|
32
|
+
['50', '重庆市'], ['51', '四川省'], ['52', '贵州省'], ['53', '云南省'], ['54', '西藏自治区'],
|
|
33
|
+
// 西北地区: 陕西省|610000,甘肃省|620000,青海省|630000,宁夏回族自治区|640000,新疆维吾尔自治区|650000
|
|
34
|
+
['61', '陕西省'], ['62', '甘肃省'], ['63', '青海省'], ['64', '宁夏回族自治区'], ['65', '新疆维吾尔自治区'],
|
|
35
|
+
// 台湾地区:台湾省|710000
|
|
34
36
|
// 台湾居民公民身份号码地址码为830000,参考 http://www.wanweibaike.com/wiki-中华人民共和国行政区划代码_(7区)、https://zh.wikipedia.org/wiki/港澳台居民居住证
|
|
35
|
-
['71', '台湾省'], ['83', '台湾省'],
|
|
36
|
-
|
|
37
|
+
['71', '台湾省'], ['83', '台湾省'],
|
|
38
|
+
// 港澳地区:香港特别行政区|810000,澳门特别行政区|820000
|
|
39
|
+
['81', '香港特别行政区'], ['82', '澳门特别行政区']];
|
|
40
|
+
|
|
41
|
+
// 第一位数字是以前的大区制代码。第二位是大区所在省市编码。全国共分为8个大区:华北(1)、东北(2)、华东(3)、中南(4)、西南(5)、西北(6)、台湾(7)和港澳(8)。
|
|
37
42
|
// const Regions = [
|
|
38
43
|
// ['1', '华北地区'],
|
|
39
44
|
// ['2', '东北地区'],
|
|
@@ -98,19 +103,17 @@ var Provinces = [// 华北地区:北京市|110000,天津市|120000,河北
|
|
|
98
103
|
* }
|
|
99
104
|
*
|
|
100
105
|
*/
|
|
101
|
-
|
|
102
106
|
function parseIdCard(id) {
|
|
103
107
|
if (!regIdCard.test(id)) {
|
|
104
108
|
return null;
|
|
105
109
|
}
|
|
110
|
+
|
|
106
111
|
/** @type {RegExpExecArray} */
|
|
107
112
|
// @ts-ignore
|
|
108
|
-
|
|
109
|
-
|
|
110
113
|
var info = regIdCard.exec(id);
|
|
114
|
+
|
|
111
115
|
/** @type {{ province: string, city: string, area: string, year: string, month: string, day: string, gender: string }} */
|
|
112
116
|
// @ts-ignore
|
|
113
|
-
|
|
114
117
|
var origin = (info === null || info === void 0 ? void 0 : info.groups) || {
|
|
115
118
|
province: info[1],
|
|
116
119
|
city: info[2],
|
|
@@ -123,13 +126,12 @@ function parseIdCard(id) {
|
|
|
123
126
|
var province = Provinces.find(function (item) {
|
|
124
127
|
return item[0] === origin.province;
|
|
125
128
|
});
|
|
126
|
-
|
|
127
129
|
if (!province) {
|
|
128
130
|
return null;
|
|
129
131
|
}
|
|
130
|
-
|
|
131
132
|
var birthday = "".concat(origin.year, "-").concat(origin.month, "-").concat(origin.day);
|
|
132
|
-
var gender = Number(origin.gender) % 2 === 0 ? '女' : '男';
|
|
133
|
+
var gender = Number(origin.gender) % 2 === 0 ? '女' : '男';
|
|
134
|
+
// const region = Regions.find(item => item[0] === origin.province?.substring(0, 1));
|
|
133
135
|
|
|
134
136
|
return {
|
|
135
137
|
// region,
|
|
@@ -139,6 +141,5 @@ function parseIdCard(id) {
|
|
|
139
141
|
origin: origin
|
|
140
142
|
};
|
|
141
143
|
}
|
|
142
|
-
|
|
143
144
|
var _default = parseIdCard;
|
|
144
145
|
exports["default"] = _default;
|