util-helpers 4.12.3 → 4.12.6
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 +1 -1
- package/dist/util-helpers.js +10 -22
- 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/parseIdCard.js +5 -14
- package/esm/utils/config.js +1 -1
- package/esm/utils/math.util.js +4 -41
- package/lib/parseIdCard.js +5 -16
- package/lib/utils/config.js +1 -1
- package/lib/utils/math.util.js +4 -43
- package/package.json +1 -1
- package/types/src/utils/math.util.d.ts +0 -8
package/esm/parseIdCard.js
CHANGED
|
@@ -4,8 +4,6 @@ import _setPrototypeOf from "@babel/runtime/helpers/setPrototypeOf";
|
|
|
4
4
|
|
|
5
5
|
function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, undefined, groups); }; var _super = RegExp.prototype; var _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); _groups.set(_this, groups || _groups.get(re)); return _setPrototypeOf(_this, BabelRegExp.prototype); } _inherits(BabelRegExp, RegExp); BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) result.groups = buildGroups(result, this); return result; }; BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if (typeof substitution === "string") { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } else if (typeof substitution === "function") { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; if (_typeof(args[args.length - 1]) !== "object") { args = [].slice.call(args); args.push(buildGroups(args, _this)); } return substitution.apply(this, args); }); } else { return _super[Symbol.replace].call(this, str, substitution); } }; function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { groups[name] = result[g[name]]; return groups; }, Object.create(null)); } return _wrapRegExp.apply(this, arguments); }
|
|
6
6
|
|
|
7
|
-
import isIdCard from './isIdCard';
|
|
8
|
-
|
|
9
7
|
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, {
|
|
10
8
|
province: 1,
|
|
11
9
|
city: 2,
|
|
@@ -93,24 +91,17 @@ var Provinces = [// 华北地区:北京市|110000,天津市|120000,河北
|
|
|
93
91
|
*/
|
|
94
92
|
|
|
95
93
|
function parseIdCard(id) {
|
|
96
|
-
if (!
|
|
97
|
-
loose: true
|
|
98
|
-
})) {
|
|
94
|
+
if (!regIdCard.test(id)) {
|
|
99
95
|
return null;
|
|
100
96
|
}
|
|
97
|
+
/** @type {RegExpExecArray} */
|
|
98
|
+
// @ts-ignore
|
|
101
99
|
|
|
102
|
-
var info = regIdCard.exec(id);
|
|
103
100
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* @type {{ province: string, city: string, area: string, year: string, month: string, day: string, gender: string }}
|
|
109
|
-
*
|
|
110
|
-
*/
|
|
101
|
+
var info = regIdCard.exec(id);
|
|
102
|
+
/** @type {{ province: string, city: string, area: string, year: string, month: string, day: string, gender: string }} */
|
|
111
103
|
// @ts-ignore
|
|
112
104
|
|
|
113
|
-
|
|
114
105
|
var origin = (info === null || info === void 0 ? void 0 : info.groups) || {
|
|
115
106
|
province: info[1],
|
|
116
107
|
city: info[2],
|
package/esm/utils/config.js
CHANGED
package/esm/utils/math.util.js
CHANGED
|
@@ -7,38 +7,6 @@
|
|
|
7
7
|
import { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } from './constants';
|
|
8
8
|
import devWarn from './devWarn';
|
|
9
9
|
import { isNumber, isString, isSymbol } from './type';
|
|
10
|
-
/**
|
|
11
|
-
* 值是否为有效的数值
|
|
12
|
-
*
|
|
13
|
-
* @deprecated 已废弃
|
|
14
|
-
* @param {*} value 待检测的值
|
|
15
|
-
* @returns {boolean} 是否为有效的数值
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
export function isEffectiveNumeric() {
|
|
19
|
-
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
20
|
-
|
|
21
|
-
if (isNumber(value) && !isNaN(value)) {
|
|
22
|
-
return true;
|
|
23
|
-
} // 避免空字符串 或 带空格的字符串
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (isString(value)) {
|
|
27
|
-
var fmtStrValue = value.trim(); // 带空格的字符串也不转换数字
|
|
28
|
-
// Number(' ') => 0
|
|
29
|
-
|
|
30
|
-
if (fmtStrValue === value) {
|
|
31
|
-
var numValue = fmtStrValue ? Number(fmtStrValue) : NaN;
|
|
32
|
-
|
|
33
|
-
if (!isNaN(numValue)) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
devWarn("".concat(value, " is not a valid number."));
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
10
|
/**
|
|
43
11
|
* 将值转换为有效数值
|
|
44
12
|
*
|
|
@@ -60,18 +28,13 @@ export function transformEffectiveNumber(value) {
|
|
|
60
28
|
ret = Number.NaN;
|
|
61
29
|
}
|
|
62
30
|
} else if (isSymbol(value)) {
|
|
63
|
-
ret = Number.NaN;
|
|
64
|
-
} else if (!isNumber(value)) {
|
|
65
|
-
// 其余非数字类型通过 Number 转换
|
|
66
31
|
// 例如 Symbol 包装器对象将会报错
|
|
67
32
|
// symObj = Object(Symbol());
|
|
68
33
|
// Number(symObj); // TypeError: Cannot convert a Symbol value to a number
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
console.error(err);
|
|
74
|
-
}
|
|
34
|
+
ret = Number.NaN;
|
|
35
|
+
} else if (!isNumber(value)) {
|
|
36
|
+
// 其余非数字类型通过 Number 转换
|
|
37
|
+
ret = Number(value);
|
|
75
38
|
} else {
|
|
76
39
|
ret = value;
|
|
77
40
|
}
|
package/lib/parseIdCard.js
CHANGED
|
@@ -7,10 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports["default"] = void 0;
|
|
9
9
|
|
|
10
|
-
var _isIdCard = _interopRequireDefault(require("./isIdCard"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
|
|
14
10
|
function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, undefined, groups); }; var _super = RegExp.prototype; var _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); _groups.set(_this, groups || _groups.get(re)); return _setPrototypeOf(_this, BabelRegExp.prototype); } _inherits(BabelRegExp, RegExp); BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) result.groups = buildGroups(result, this); return result; }; BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if (typeof substitution === "string") { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } else if (typeof substitution === "function") { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; if (_typeof(args[args.length - 1]) !== "object") { args = [].slice.call(args); args.push(buildGroups(args, _this)); } return substitution.apply(this, args); }); } else { return _super[Symbol.replace].call(this, str, substitution); } }; function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { groups[name] = result[g[name]]; return groups; }, Object.create(null)); } return _wrapRegExp.apply(this, arguments); }
|
|
15
11
|
|
|
16
12
|
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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
@@ -104,24 +100,17 @@ var Provinces = [// 华北地区:北京市|110000,天津市|120000,河北
|
|
|
104
100
|
*/
|
|
105
101
|
|
|
106
102
|
function parseIdCard(id) {
|
|
107
|
-
if (!(
|
|
108
|
-
loose: true
|
|
109
|
-
})) {
|
|
103
|
+
if (!regIdCard.test(id)) {
|
|
110
104
|
return null;
|
|
111
105
|
}
|
|
106
|
+
/** @type {RegExpExecArray} */
|
|
107
|
+
// @ts-ignore
|
|
112
108
|
|
|
113
|
-
var info = regIdCard.exec(id);
|
|
114
109
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* @type {{ province: string, city: string, area: string, year: string, month: string, day: string, gender: string }}
|
|
120
|
-
*
|
|
121
|
-
*/
|
|
110
|
+
var info = regIdCard.exec(id);
|
|
111
|
+
/** @type {{ province: string, city: string, area: string, year: string, month: string, day: string, gender: string }} */
|
|
122
112
|
// @ts-ignore
|
|
123
113
|
|
|
124
|
-
|
|
125
114
|
var origin = (info === null || info === void 0 ? void 0 : info.groups) || {
|
|
126
115
|
province: info[1],
|
|
127
116
|
city: info[2],
|
package/lib/utils/config.js
CHANGED
package/lib/utils/math.util.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isEffectiveNumeric = isEffectiveNumeric;
|
|
7
6
|
exports.transformEffectiveNumber = transformEffectiveNumber;
|
|
8
7
|
exports.isScientificNumber = isScientificNumber;
|
|
9
8
|
exports.strip = strip;
|
|
@@ -28,45 +27,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
28
27
|
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
|
|
29
28
|
*/
|
|
30
29
|
|
|
31
|
-
/**
|
|
32
|
-
* 值是否为有效的数值
|
|
33
|
-
*
|
|
34
|
-
* @deprecated 已废弃
|
|
35
|
-
* @param {*} value 待检测的值
|
|
36
|
-
* @returns {boolean} 是否为有效的数值
|
|
37
|
-
*/
|
|
38
|
-
function isEffectiveNumeric() {
|
|
39
|
-
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
40
|
-
|
|
41
|
-
if ((0, _type.isNumber)(value) && !isNaN(value)) {
|
|
42
|
-
return true;
|
|
43
|
-
} // 避免空字符串 或 带空格的字符串
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if ((0, _type.isString)(value)) {
|
|
47
|
-
var fmtStrValue = value.trim(); // 带空格的字符串也不转换数字
|
|
48
|
-
// Number(' ') => 0
|
|
49
|
-
|
|
50
|
-
if (fmtStrValue === value) {
|
|
51
|
-
var numValue = fmtStrValue ? Number(fmtStrValue) : NaN;
|
|
52
|
-
|
|
53
|
-
if (!isNaN(numValue)) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
(0, _devWarn["default"])("".concat(value, " is not a valid number."));
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
30
|
/**
|
|
63
31
|
* 将值转换为有效数值
|
|
64
32
|
*
|
|
65
33
|
* @param {*} value 要转换的值
|
|
66
34
|
* @returns {number|string} 有效数值
|
|
67
35
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
36
|
function transformEffectiveNumber(value) {
|
|
71
37
|
/** @type {string|number|undefined} */
|
|
72
38
|
var ret;
|
|
@@ -81,18 +47,13 @@ function transformEffectiveNumber(value) {
|
|
|
81
47
|
ret = Number.NaN;
|
|
82
48
|
}
|
|
83
49
|
} else if ((0, _type.isSymbol)(value)) {
|
|
84
|
-
ret = Number.NaN;
|
|
85
|
-
} else if (!(0, _type.isNumber)(value)) {
|
|
86
|
-
// 其余非数字类型通过 Number 转换
|
|
87
50
|
// 例如 Symbol 包装器对象将会报错
|
|
88
51
|
// symObj = Object(Symbol());
|
|
89
52
|
// Number(symObj); // TypeError: Cannot convert a Symbol value to a number
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
console.error(err);
|
|
95
|
-
}
|
|
53
|
+
ret = Number.NaN;
|
|
54
|
+
} else if (!(0, _type.isNumber)(value)) {
|
|
55
|
+
// 其余非数字类型通过 Number 转换
|
|
56
|
+
ret = Number(value);
|
|
96
57
|
} else {
|
|
97
58
|
ret = value;
|
|
98
59
|
}
|
package/package.json
CHANGED