util-helpers 4.2.1 → 4.5.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 +3 -2
- package/dist/util-helpers.js +223 -24
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/formatBankCard.js +4 -3
- package/esm/formatMobile.js +38 -0
- package/esm/index.js +3 -0
- package/esm/isHMCard.js +12 -0
- package/esm/isIdCard.js +1 -1
- package/esm/isTWCard.js +6 -0
- package/esm/normalizeString.js +32 -0
- package/esm/parseIdCard.js +34 -14
- package/esm/safeDate.js +41 -0
- package/esm/setDataURLPrefix.js +1 -2
- package/esm/utils/type/isNil.js +17 -0
- package/esm/validatePassword.js +17 -1
- package/lib/formatBankCard.js +6 -3
- package/lib/formatMobile.js +48 -0
- package/lib/index.js +24 -0
- package/lib/isHMCard.js +12 -0
- package/lib/isIdCard.js +1 -1
- package/lib/isTWCard.js +6 -0
- package/lib/normalizeString.js +43 -0
- package/lib/parseIdCard.js +34 -14
- package/lib/safeDate.js +57 -0
- package/lib/setDataURLPrefix.js +1 -2
- package/lib/utils/type/isNil.js +28 -0
- package/lib/validatePassword.js +17 -1
- package/package.json +1 -1
- package/types/formatMobile.d.ts +20 -0
- package/types/index.d.ts +3 -0
- package/types/isHMCard.d.ts +12 -0
- package/types/isTWCard.d.ts +6 -0
- package/types/normalizeString.d.ts +22 -0
- package/types/parseIdCard.d.ts +84 -25
- package/types/safeDate.d.ts +22 -0
- package/types/setDataURLPrefix.d.ts +1 -2
- package/types/utils/type/isNil.d.ts +11 -0
- package/types/validatePassword.d.ts +58 -12
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import normalizeString from './normalizeString';
|
|
2
|
+
/**
|
|
3
|
+
* 格式化手机号码
|
|
4
|
+
*
|
|
5
|
+
* @static
|
|
6
|
+
* @alias module:Processor.formatMobile
|
|
7
|
+
* @since 4.5.0
|
|
8
|
+
* @param {string} mobileNo 手机号码
|
|
9
|
+
* @param {object} [options] 配置项
|
|
10
|
+
* @param {string} [options.char=' '] 间隔字符
|
|
11
|
+
* @returns {string} 格式化后的手机号码
|
|
12
|
+
* @example
|
|
13
|
+
* formatMobile('13345678900') // '133 4567 8900'
|
|
14
|
+
* formatMobile('13345678900', { char: '-' }) // '133-4567-8900'
|
|
15
|
+
* formatMobile('133****1234') // '133 **** 1234'
|
|
16
|
+
* formatMobile('133****1234', { char: '-' }) // '133-****-1234'
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
function formatMobile(mobileNo) {
|
|
20
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
21
|
+
_ref$char = _ref["char"],
|
|
22
|
+
_char = _ref$char === void 0 ? ' ' : _ref$char;
|
|
23
|
+
|
|
24
|
+
var regChar = new RegExp(_char, 'g');
|
|
25
|
+
var realValue = normalizeString(mobileNo).replace(regChar, '').substring(0, 11);
|
|
26
|
+
|
|
27
|
+
if (realValue.length > 7) {
|
|
28
|
+
return realValue.replace(/^(...)(....)/g, "$1".concat(_char, "$2").concat(_char));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (realValue.length > 3) {
|
|
32
|
+
return realValue.replace(/^(...)/g, "$1".concat(_char));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return realValue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default formatMobile;
|
package/esm/index.js
CHANGED
|
@@ -41,6 +41,9 @@ export { default as parseIdCard } from './parseIdCard';
|
|
|
41
41
|
export { default as blobToDataURL } from './blobToDataURL';
|
|
42
42
|
export { default as dataURLToBlob } from './dataURLToBlob';
|
|
43
43
|
export { default as setDataURLPrefix } from './setDataURLPrefix';
|
|
44
|
+
export { default as normalizeString } from './normalizeString';
|
|
45
|
+
export { default as safeDate } from './safeDate';
|
|
46
|
+
export { default as formatMobile } from './formatMobile';
|
|
44
47
|
/**
|
|
45
48
|
* 数学计算,修正浮点数计算问题
|
|
46
49
|
*
|
package/esm/isHMCard.js
CHANGED
|
@@ -10,6 +10,18 @@ var regHMCard = /^[hm]{1}([0-9]{10}|[0-9]{8})$/i;
|
|
|
10
10
|
* @see 参考 {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证|港澳居民来往内地通行证}
|
|
11
11
|
* @param {*} value 要检测的值
|
|
12
12
|
* @returns {boolean} 是否为港澳居民来往内地通行证
|
|
13
|
+
* @example
|
|
14
|
+
* // 第一代 11 位
|
|
15
|
+
* isHMCard('h3203117707') // true
|
|
16
|
+
* isHMCard('H3203117707') // true
|
|
17
|
+
* isHMCard('m3203117707') // true
|
|
18
|
+
* isHMCard('M3203117707') // true
|
|
19
|
+
*
|
|
20
|
+
* // 第二代 9 位
|
|
21
|
+
* isHMCard('h32031177') // true
|
|
22
|
+
* isHMCard('H32031177') // true
|
|
23
|
+
* isHMCard('m32031177') // true
|
|
24
|
+
* isHMCard('M32031177') // true
|
|
13
25
|
*/
|
|
14
26
|
|
|
15
27
|
function isHMCard(value) {
|
package/esm/isIdCard.js
CHANGED
|
@@ -8,7 +8,7 @@ var regIdCard = /^[1-9]\d{5}(19|20)?\d{2}((0[1-9])|(1[012]))(([0-2][1-9])|10|20|
|
|
|
8
8
|
* @see 参考 {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码|中华人民共和国公民身份号码}
|
|
9
9
|
* @see 参考 {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
|
|
10
10
|
* @param {string} id 身份证号码
|
|
11
|
-
* @returns 校验码是否正确
|
|
11
|
+
* @returns {boolean} 校验码是否正确
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
function check(id) {
|
package/esm/isTWCard.js
CHANGED
|
@@ -10,6 +10,12 @@ var regTWCard = /^(\d{8}|[\da-z]{10})$/i;
|
|
|
10
10
|
* @see 参考 {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
|
|
11
11
|
* @param {*} value 要检测的值
|
|
12
12
|
* @returns {boolean} 是否为台湾居民来往大陆通行证
|
|
13
|
+
* @example
|
|
14
|
+
* isTWCard('12345678') // true
|
|
15
|
+
* isTWCard('07257456') // true
|
|
16
|
+
*
|
|
17
|
+
* // 一次性短期
|
|
18
|
+
* isTWCard('F290299977') // true
|
|
13
19
|
*/
|
|
14
20
|
|
|
15
21
|
function isTWCard(value) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import isNil from './utils/type/isNil';
|
|
2
|
+
import convertToString from './utils/convertToString';
|
|
3
|
+
/**
|
|
4
|
+
* 规整化字符串。如果值为 undefined 或 null 将转为空字符串,如果值不是字符串类型将转为字符串。
|
|
5
|
+
*
|
|
6
|
+
* @static
|
|
7
|
+
* @alias module:Processor.normalizeString
|
|
8
|
+
* @see 参考 {@link tttps://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
|
|
9
|
+
* @since 4.3.0
|
|
10
|
+
* @param {*} value 待处理的值
|
|
11
|
+
* @returns {string} 规整化的值
|
|
12
|
+
* @example
|
|
13
|
+
* normalizeString(); // ''
|
|
14
|
+
* normalizeString(undefined); // ''
|
|
15
|
+
* normalizeString(void 0); // ''
|
|
16
|
+
* normalizeString(null); // ''
|
|
17
|
+
*
|
|
18
|
+
* normalizeString(true); // 'true'
|
|
19
|
+
* normalizeString(NaN); // 'NaN'
|
|
20
|
+
* normalizeString(1); // '1'
|
|
21
|
+
* normalizeString('a'); // 'a'
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function normalizeString(value) {
|
|
25
|
+
if (isNil(value)) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return convertToString(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default normalizeString;
|
package/esm/parseIdCard.js
CHANGED
|
@@ -38,38 +38,58 @@ var Provinces = [// 华北地区:北京市|110000,天津市|120000,河北
|
|
|
38
38
|
// ['8', '港澳地区']
|
|
39
39
|
// ];
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* @typedef {Object} IdCardOrigin - 解析身份证原数据
|
|
43
|
+
* @property {string} province - 省份编码
|
|
44
|
+
* @property {string} city - 城市编码
|
|
45
|
+
* @property {string} area - 地区编码
|
|
46
|
+
* @property {string} year - 出生年
|
|
47
|
+
* @property {string} month - 出生月
|
|
48
|
+
* @property {string} day - 出生日
|
|
49
|
+
* @property {string} gender - 性别 能整除2为女,否则为男
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @typedef {Object} IdCardInfo - 身份证信息
|
|
54
|
+
* @property {string} province - 省份
|
|
55
|
+
* @property {string} birthday - 生日
|
|
56
|
+
* @property {string} gender - 性别
|
|
57
|
+
* @property {IdCardOrigin} origin - 解析身份证原数据
|
|
58
|
+
*/
|
|
59
|
+
|
|
41
60
|
/**
|
|
42
61
|
* 解析身份证号码,支持15、18位身份证号码
|
|
43
|
-
*
|
|
62
|
+
*
|
|
44
63
|
* @static
|
|
45
64
|
* @alias module:Processor.parseIdCard
|
|
46
65
|
* @since 4.0.0
|
|
47
66
|
* @see 参考 {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
|
|
48
67
|
* @param {string} id 身份证号码,支持15位
|
|
49
|
-
* @returns null 或 省份、生日、性别,省/市/区/年/月/日/性别编码
|
|
68
|
+
* @returns {null|IdCardInfo} null 或 省份、生日、性别,省/市/区/年/月/日/性别编码
|
|
50
69
|
* @example
|
|
51
70
|
* parseIdCard('123456789123456');
|
|
52
71
|
* // => null
|
|
53
|
-
*
|
|
72
|
+
*
|
|
54
73
|
* // 18位身份证号码
|
|
55
74
|
* parseIdCard('130701199310302288')
|
|
56
75
|
* // =>
|
|
57
76
|
* {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
77
|
+
* birthday: "1993-10-30",
|
|
78
|
+
* gender: "女",
|
|
79
|
+
* origin: { province: "13", city: "07", area: "01", year: "1993", month: "10", day: "30", gender: "8" },
|
|
80
|
+
* province: "河北省"
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
63
83
|
* // 15位身份证号码
|
|
64
84
|
* parseIdCard('130701931030228');
|
|
65
85
|
* // =>
|
|
66
86
|
* {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
*
|
|
87
|
+
* birthday: "93-10-30",
|
|
88
|
+
* gender: "女",
|
|
89
|
+
* origin: { province: "13", city: "07", area: "01", year: "93", month: "10", day: "30", gender: "8" },
|
|
90
|
+
* province: "河北省"
|
|
91
|
+
* }
|
|
92
|
+
*
|
|
73
93
|
*/
|
|
74
94
|
|
|
75
95
|
function parseIdCard(id) {
|
package/esm/safeDate.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import _construct from "@babel/runtime/helpers/construct";
|
|
2
|
+
import isNil from './utils/type/isNil'; // TODO: 函数重载,类型参照 Date
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 创建一个 Date 实例日期对象,同 new Date() 。<br/>
|
|
6
|
+
* 规避了苹果设备浏览器不支持部分格式(YYYY-MM-DD HH-mm 或 YYYY.MM.DD)。
|
|
7
|
+
*
|
|
8
|
+
* @static
|
|
9
|
+
* @alias module:Processor.safeDate
|
|
10
|
+
* @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date|Date}
|
|
11
|
+
* @since 4.4.0
|
|
12
|
+
* @param {string|number|Date} [value] 日期时间字符串、毫秒数、日期对象
|
|
13
|
+
* @param {...number} args 月/日/时/分/秒/毫秒
|
|
14
|
+
* @returns {Date} Date 实例日期对象
|
|
15
|
+
* @example
|
|
16
|
+
* safeDate('2022-1-1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
|
|
17
|
+
* safeDate('2022/1/1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
|
|
18
|
+
* safeDate('2022.1.1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
|
|
19
|
+
* safeDate('2022.1.1 11:11'); // Sat Jan 01 2022 11:11:00 GMT+0800 (中国标准时间)
|
|
20
|
+
* safeDate(99, 1); // Mon Feb 01 1999 00:00:00 GMT+0800 (中国标准时间)
|
|
21
|
+
* safeDate(1646711233171); // Tue Mar 08 2022 11:47:13 GMT+0800 (中国标准时间)
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
function safeDate(value) {
|
|
26
|
+
var safeValue = typeof value === 'string' ? value.replace(/[\\.-]/g, '/') : value;
|
|
27
|
+
|
|
28
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
29
|
+
args[_key - 1] = arguments[_key];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (args && args.length > 0) {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
return _construct(Date, [safeValue].concat(args));
|
|
35
|
+
} // @ts-ignore
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
return isNil(safeValue) ? new Date() : new Date(safeValue);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default safeDate;
|
package/esm/setDataURLPrefix.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import isUndefined from './isUndefined';
|
|
2
|
+
import isNull from './isNull';
|
|
3
|
+
/**
|
|
4
|
+
* 检查值是否为 undefined 或 null
|
|
5
|
+
*
|
|
6
|
+
* @static
|
|
7
|
+
* @alias module:Type.isNaN
|
|
8
|
+
* @since 4.3.0
|
|
9
|
+
* @param {*} value 检查值
|
|
10
|
+
* @returns {boolean} 是否为 undefined 或 null
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
function isNil(value) {
|
|
14
|
+
return isUndefined(value) || isNull(value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default isNil;
|
package/esm/validatePassword.js
CHANGED
|
@@ -118,6 +118,22 @@ function hasUnallowableCharacter(val) {
|
|
|
118
118
|
});
|
|
119
119
|
return ret;
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* @typedef {Object} PasswordContaines - 验证密码的包含内容
|
|
123
|
+
* @property {boolean} number - 包含数字
|
|
124
|
+
* @property {boolean} lowerCaseLetter - 包含小写字母
|
|
125
|
+
* @property {boolean} upperCaseLetter - 包含大写字母
|
|
126
|
+
* @property {boolean} specialCharacter - 包含特殊字符
|
|
127
|
+
* @property {boolean} unallowableCharacter - 包含非法字符
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @typedef {Object} ValidatePasswordReturn - 验证结果
|
|
132
|
+
* @property {boolean} validated - 验证结果,根据密码强度、是否包含非法字符得出
|
|
133
|
+
* @property {number} level - 强度级别,包含数字/大小写字母/特殊字符
|
|
134
|
+
* @property {PasswordContaines} containes - 包含内容
|
|
135
|
+
*/
|
|
136
|
+
|
|
121
137
|
/**
|
|
122
138
|
* 验证密码(数字、大小写字母、特殊字符、非法字符)
|
|
123
139
|
*
|
|
@@ -130,7 +146,7 @@ function hasUnallowableCharacter(val) {
|
|
|
130
146
|
* @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
|
|
131
147
|
* @param {boolean} [options.ignoreCase=false] 是否忽略大小写,为 ture 时,大小写字母视为一种字符
|
|
132
148
|
* @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符
|
|
133
|
-
* @returns 验证结果
|
|
149
|
+
* @returns {ValidatePasswordReturn} 验证结果
|
|
134
150
|
* @example
|
|
135
151
|
*
|
|
136
152
|
* validatePassword('a12345678');
|
package/lib/formatBankCard.js
CHANGED
|
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
|
|
8
|
+
var _normalizeString = _interopRequireDefault(require("./normalizeString"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* 格式化银行卡号
|
|
10
14
|
*
|
|
@@ -46,10 +50,9 @@ function formatBankCard() {
|
|
|
46
50
|
|
|
47
51
|
var reg = new RegExp("(.{".concat(length, "})"), 'g');
|
|
48
52
|
var regChar = new RegExp("".concat(_char), 'g');
|
|
49
|
-
var realValue = bankCardNo.replace(regChar, '');
|
|
50
|
-
var needRemoveLastChar = realValue.length % length === 0;
|
|
53
|
+
var realValue = (0, _normalizeString["default"])(bankCardNo).replace(regChar, '');
|
|
51
54
|
var str = realValue.replace(reg, "$1".concat(_char));
|
|
52
|
-
return
|
|
55
|
+
return realValue.length % length === 0 ? str.substring(0, str.length - 1) : str;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
var _default = formatBankCard;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _normalizeString = _interopRequireDefault(require("./normalizeString"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 格式化手机号码
|
|
14
|
+
*
|
|
15
|
+
* @static
|
|
16
|
+
* @alias module:Processor.formatMobile
|
|
17
|
+
* @since 4.5.0
|
|
18
|
+
* @param {string} mobileNo 手机号码
|
|
19
|
+
* @param {object} [options] 配置项
|
|
20
|
+
* @param {string} [options.char=' '] 间隔字符
|
|
21
|
+
* @returns {string} 格式化后的手机号码
|
|
22
|
+
* @example
|
|
23
|
+
* formatMobile('13345678900') // '133 4567 8900'
|
|
24
|
+
* formatMobile('13345678900', { char: '-' }) // '133-4567-8900'
|
|
25
|
+
* formatMobile('133****1234') // '133 **** 1234'
|
|
26
|
+
* formatMobile('133****1234', { char: '-' }) // '133-****-1234'
|
|
27
|
+
*/
|
|
28
|
+
function formatMobile(mobileNo) {
|
|
29
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
30
|
+
_ref$char = _ref["char"],
|
|
31
|
+
_char = _ref$char === void 0 ? ' ' : _ref$char;
|
|
32
|
+
|
|
33
|
+
var regChar = new RegExp(_char, 'g');
|
|
34
|
+
var realValue = (0, _normalizeString["default"])(mobileNo).replace(regChar, '').substring(0, 11);
|
|
35
|
+
|
|
36
|
+
if (realValue.length > 7) {
|
|
37
|
+
return realValue.replace(/^(...)(....)/g, "$1".concat(_char, "$2").concat(_char));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (realValue.length > 3) {
|
|
41
|
+
return realValue.replace(/^(...)/g, "$1".concat(_char));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return realValue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var _default = formatMobile;
|
|
48
|
+
exports["default"] = _default;
|
package/lib/index.js
CHANGED
|
@@ -183,6 +183,24 @@ Object.defineProperty(exports, "setDataURLPrefix", {
|
|
|
183
183
|
return _setDataURLPrefix["default"];
|
|
184
184
|
}
|
|
185
185
|
});
|
|
186
|
+
Object.defineProperty(exports, "normalizeString", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function get() {
|
|
189
|
+
return _normalizeString["default"];
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
Object.defineProperty(exports, "safeDate", {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function get() {
|
|
195
|
+
return _safeDate["default"];
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
Object.defineProperty(exports, "formatMobile", {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
get: function get() {
|
|
201
|
+
return _formatMobile["default"];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
186
204
|
Object.defineProperty(exports, "plus", {
|
|
187
205
|
enumerable: true,
|
|
188
206
|
get: function get() {
|
|
@@ -286,6 +304,12 @@ var _dataURLToBlob = _interopRequireDefault(require("./dataURLToBlob"));
|
|
|
286
304
|
|
|
287
305
|
var _setDataURLPrefix = _interopRequireDefault(require("./setDataURLPrefix"));
|
|
288
306
|
|
|
307
|
+
var _normalizeString = _interopRequireDefault(require("./normalizeString"));
|
|
308
|
+
|
|
309
|
+
var _safeDate = _interopRequireDefault(require("./safeDate"));
|
|
310
|
+
|
|
311
|
+
var _formatMobile = _interopRequireDefault(require("./formatMobile"));
|
|
312
|
+
|
|
289
313
|
var _plus = _interopRequireDefault(require("./plus"));
|
|
290
314
|
|
|
291
315
|
var _minus = _interopRequireDefault(require("./minus"));
|
package/lib/isHMCard.js
CHANGED
|
@@ -20,6 +20,18 @@ var regHMCard = /^[hm]{1}([0-9]{10}|[0-9]{8})$/i;
|
|
|
20
20
|
* @see 参考 {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证|港澳居民来往内地通行证}
|
|
21
21
|
* @param {*} value 要检测的值
|
|
22
22
|
* @returns {boolean} 是否为港澳居民来往内地通行证
|
|
23
|
+
* @example
|
|
24
|
+
* // 第一代 11 位
|
|
25
|
+
* isHMCard('h3203117707') // true
|
|
26
|
+
* isHMCard('H3203117707') // true
|
|
27
|
+
* isHMCard('m3203117707') // true
|
|
28
|
+
* isHMCard('M3203117707') // true
|
|
29
|
+
*
|
|
30
|
+
* // 第二代 9 位
|
|
31
|
+
* isHMCard('h32031177') // true
|
|
32
|
+
* isHMCard('H32031177') // true
|
|
33
|
+
* isHMCard('m32031177') // true
|
|
34
|
+
* isHMCard('M32031177') // true
|
|
23
35
|
*/
|
|
24
36
|
|
|
25
37
|
function isHMCard(value) {
|
package/lib/isIdCard.js
CHANGED
|
@@ -18,7 +18,7 @@ var regIdCard = /^[1-9]\d{5}(19|20)?\d{2}((0[1-9])|(1[012]))(([0-2][1-9])|10|20|
|
|
|
18
18
|
* @see 参考 {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码|中华人民共和国公民身份号码}
|
|
19
19
|
* @see 参考 {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
|
|
20
20
|
* @param {string} id 身份证号码
|
|
21
|
-
* @returns 校验码是否正确
|
|
21
|
+
* @returns {boolean} 校验码是否正确
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
function check(id) {
|
package/lib/isTWCard.js
CHANGED
|
@@ -20,6 +20,12 @@ var regTWCard = /^(\d{8}|[\da-z]{10})$/i;
|
|
|
20
20
|
* @see 参考 {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
|
|
21
21
|
* @param {*} value 要检测的值
|
|
22
22
|
* @returns {boolean} 是否为台湾居民来往大陆通行证
|
|
23
|
+
* @example
|
|
24
|
+
* isTWCard('12345678') // true
|
|
25
|
+
* isTWCard('07257456') // true
|
|
26
|
+
*
|
|
27
|
+
* // 一次性短期
|
|
28
|
+
* isTWCard('F290299977') // true
|
|
23
29
|
*/
|
|
24
30
|
|
|
25
31
|
function isTWCard(value) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _isNil = _interopRequireDefault(require("./utils/type/isNil"));
|
|
9
|
+
|
|
10
|
+
var _convertToString = _interopRequireDefault(require("./utils/convertToString"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 规整化字符串。如果值为 undefined 或 null 将转为空字符串,如果值不是字符串类型将转为字符串。
|
|
16
|
+
*
|
|
17
|
+
* @static
|
|
18
|
+
* @alias module:Processor.normalizeString
|
|
19
|
+
* @see 参考 {@link tttps://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
|
|
20
|
+
* @since 4.3.0
|
|
21
|
+
* @param {*} value 待处理的值
|
|
22
|
+
* @returns {string} 规整化的值
|
|
23
|
+
* @example
|
|
24
|
+
* normalizeString(); // ''
|
|
25
|
+
* normalizeString(undefined); // ''
|
|
26
|
+
* normalizeString(void 0); // ''
|
|
27
|
+
* normalizeString(null); // ''
|
|
28
|
+
*
|
|
29
|
+
* normalizeString(true); // 'true'
|
|
30
|
+
* normalizeString(NaN); // 'NaN'
|
|
31
|
+
* normalizeString(1); // '1'
|
|
32
|
+
* normalizeString('a'); // 'a'
|
|
33
|
+
*/
|
|
34
|
+
function normalizeString(value) {
|
|
35
|
+
if ((0, _isNil["default"])(value)) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (0, _convertToString["default"])(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var _default = normalizeString;
|
|
43
|
+
exports["default"] = _default;
|
package/lib/parseIdCard.js
CHANGED
|
@@ -49,38 +49,58 @@ var Provinces = [// 华北地区:北京市|110000,天津市|120000,河北
|
|
|
49
49
|
// ['8', '港澳地区']
|
|
50
50
|
// ];
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* @typedef {Object} IdCardOrigin - 解析身份证原数据
|
|
54
|
+
* @property {string} province - 省份编码
|
|
55
|
+
* @property {string} city - 城市编码
|
|
56
|
+
* @property {string} area - 地区编码
|
|
57
|
+
* @property {string} year - 出生年
|
|
58
|
+
* @property {string} month - 出生月
|
|
59
|
+
* @property {string} day - 出生日
|
|
60
|
+
* @property {string} gender - 性别 能整除2为女,否则为男
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @typedef {Object} IdCardInfo - 身份证信息
|
|
65
|
+
* @property {string} province - 省份
|
|
66
|
+
* @property {string} birthday - 生日
|
|
67
|
+
* @property {string} gender - 性别
|
|
68
|
+
* @property {IdCardOrigin} origin - 解析身份证原数据
|
|
69
|
+
*/
|
|
70
|
+
|
|
52
71
|
/**
|
|
53
72
|
* 解析身份证号码,支持15、18位身份证号码
|
|
54
|
-
*
|
|
73
|
+
*
|
|
55
74
|
* @static
|
|
56
75
|
* @alias module:Processor.parseIdCard
|
|
57
76
|
* @since 4.0.0
|
|
58
77
|
* @see 参考 {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
|
|
59
78
|
* @param {string} id 身份证号码,支持15位
|
|
60
|
-
* @returns null 或 省份、生日、性别,省/市/区/年/月/日/性别编码
|
|
79
|
+
* @returns {null|IdCardInfo} null 或 省份、生日、性别,省/市/区/年/月/日/性别编码
|
|
61
80
|
* @example
|
|
62
81
|
* parseIdCard('123456789123456');
|
|
63
82
|
* // => null
|
|
64
|
-
*
|
|
83
|
+
*
|
|
65
84
|
* // 18位身份证号码
|
|
66
85
|
* parseIdCard('130701199310302288')
|
|
67
86
|
* // =>
|
|
68
87
|
* {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
88
|
+
* birthday: "1993-10-30",
|
|
89
|
+
* gender: "女",
|
|
90
|
+
* origin: { province: "13", city: "07", area: "01", year: "1993", month: "10", day: "30", gender: "8" },
|
|
91
|
+
* province: "河北省"
|
|
92
|
+
* }
|
|
93
|
+
*
|
|
74
94
|
* // 15位身份证号码
|
|
75
95
|
* parseIdCard('130701931030228');
|
|
76
96
|
* // =>
|
|
77
97
|
* {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
*
|
|
98
|
+
* birthday: "93-10-30",
|
|
99
|
+
* gender: "女",
|
|
100
|
+
* origin: { province: "13", city: "07", area: "01", year: "93", month: "10", day: "30", gender: "8" },
|
|
101
|
+
* province: "河北省"
|
|
102
|
+
* }
|
|
103
|
+
*
|
|
84
104
|
*/
|
|
85
105
|
|
|
86
106
|
function parseIdCard(id) {
|
package/lib/safeDate.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _isNil = _interopRequireDefault(require("./utils/type/isNil"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
12
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
13
|
+
|
|
14
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
15
|
+
|
|
16
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
17
|
+
|
|
18
|
+
// TODO: 函数重载,类型参照 Date
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 创建一个 Date 实例日期对象,同 new Date() 。<br/>
|
|
22
|
+
* 规避了苹果设备浏览器不支持部分格式(YYYY-MM-DD HH-mm 或 YYYY.MM.DD)。
|
|
23
|
+
*
|
|
24
|
+
* @static
|
|
25
|
+
* @alias module:Processor.safeDate
|
|
26
|
+
* @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date|Date}
|
|
27
|
+
* @since 4.4.0
|
|
28
|
+
* @param {string|number|Date} [value] 日期时间字符串、毫秒数、日期对象
|
|
29
|
+
* @param {...number} args 月/日/时/分/秒/毫秒
|
|
30
|
+
* @returns {Date} Date 实例日期对象
|
|
31
|
+
* @example
|
|
32
|
+
* safeDate('2022-1-1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
|
|
33
|
+
* safeDate('2022/1/1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
|
|
34
|
+
* safeDate('2022.1.1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
|
|
35
|
+
* safeDate('2022.1.1 11:11'); // Sat Jan 01 2022 11:11:00 GMT+0800 (中国标准时间)
|
|
36
|
+
* safeDate(99, 1); // Mon Feb 01 1999 00:00:00 GMT+0800 (中国标准时间)
|
|
37
|
+
* safeDate(1646711233171); // Tue Mar 08 2022 11:47:13 GMT+0800 (中国标准时间)
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
function safeDate(value) {
|
|
41
|
+
var safeValue = typeof value === 'string' ? value.replace(/[\\.-]/g, '/') : value;
|
|
42
|
+
|
|
43
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
44
|
+
args[_key - 1] = arguments[_key];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (args && args.length > 0) {
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
return _construct(Date, [safeValue].concat(args));
|
|
50
|
+
} // @ts-ignore
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
return (0, _isNil["default"])(safeValue) ? new Date() : new Date(safeValue);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var _default = safeDate;
|
|
57
|
+
exports["default"] = _default;
|
package/lib/setDataURLPrefix.js
CHANGED
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* 设置 DataURL 前缀、MIME 类型、base64 标识。<br
|
|
10
|
-
*
|
|
9
|
+
* 设置 DataURL 前缀、MIME 类型、base64 标识。<br/>
|
|
11
10
|
* 如果你需要获取DataURL 的 MIME 类型和数据本身,推荐使用 <a href="https://www.npmjs.com/package/data-urls">data-urls</a>。
|
|
12
11
|
*
|
|
13
12
|
* @static
|