util-helpers 4.3.0 → 4.6.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 +8 -5
- package/dist/util-helpers.js +201 -23
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/calculateCursorPosition.js +62 -0
- package/esm/formatBankCard.js +1 -2
- package/esm/formatMobile.js +45 -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 +1 -0
- package/esm/parseIdCard.js +34 -14
- package/esm/safeDate.js +41 -0
- package/esm/setDataURLPrefix.js +1 -2
- package/esm/validatePassword.js +17 -1
- package/lib/calculateCursorPosition.js +73 -0
- package/lib/formatBankCard.js +1 -2
- package/lib/formatMobile.js +55 -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 +1 -0
- package/lib/parseIdCard.js +34 -14
- package/lib/safeDate.js +57 -0
- package/lib/setDataURLPrefix.js +1 -2
- package/lib/validatePassword.js +17 -1
- package/package.json +1 -1
- package/types/calculateCursorPosition.d.ts +25 -0
- package/types/formatMobile.d.ts +27 -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 +1 -0
- package/types/parseIdCard.d.ts +84 -25
- package/types/safeDate.d.ts +22 -0
- package/types/setDataURLPrefix.d.ts +1 -2
- package/types/validatePassword.d.ts +58 -12
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
|
package/lib/validatePassword.js
CHANGED
|
@@ -126,6 +126,22 @@ function hasUnallowableCharacter(val) {
|
|
|
126
126
|
});
|
|
127
127
|
return ret;
|
|
128
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* @typedef {Object} PasswordContaines - 验证密码的包含内容
|
|
131
|
+
* @property {boolean} number - 包含数字
|
|
132
|
+
* @property {boolean} lowerCaseLetter - 包含小写字母
|
|
133
|
+
* @property {boolean} upperCaseLetter - 包含大写字母
|
|
134
|
+
* @property {boolean} specialCharacter - 包含特殊字符
|
|
135
|
+
* @property {boolean} unallowableCharacter - 包含非法字符
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @typedef {Object} ValidatePasswordReturn - 验证结果
|
|
140
|
+
* @property {boolean} validated - 验证结果,根据密码强度、是否包含非法字符得出
|
|
141
|
+
* @property {number} level - 强度级别,包含数字/大小写字母/特殊字符
|
|
142
|
+
* @property {PasswordContaines} containes - 包含内容
|
|
143
|
+
*/
|
|
144
|
+
|
|
129
145
|
/**
|
|
130
146
|
* 验证密码(数字、大小写字母、特殊字符、非法字符)
|
|
131
147
|
*
|
|
@@ -138,7 +154,7 @@ function hasUnallowableCharacter(val) {
|
|
|
138
154
|
* @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
|
|
139
155
|
* @param {boolean} [options.ignoreCase=false] 是否忽略大小写,为 ture 时,大小写字母视为一种字符
|
|
140
156
|
* @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符
|
|
141
|
-
* @returns 验证结果
|
|
157
|
+
* @returns {ValidatePasswordReturn} 验证结果
|
|
142
158
|
* @example
|
|
143
159
|
*
|
|
144
160
|
* validatePassword('a12345678');
|
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default calculateCursorPosition;
|
|
2
|
+
/**
|
|
3
|
+
* 计算输入框的值格式化后光标位置
|
|
4
|
+
*
|
|
5
|
+
* @static
|
|
6
|
+
* @alias module:Other.calculateCursorPosition
|
|
7
|
+
* @since 4.6.0
|
|
8
|
+
* @see 格式化手机号码 {@link https://doly-dev.github.io/util-helpers/module-Processor.html#.formatMobile|formatMobile}
|
|
9
|
+
* @see 格式化银行卡号 {@link https://doly-dev.github.io/util-helpers/module-Processor.html#.formatBankCard|formatBankCard}
|
|
10
|
+
* @see 示例 {@link https://2950v9.csb.app/|点击查看}
|
|
11
|
+
* @param {number} prevPos 赋值前的光标位置,onChange/onInput的光标位置 e.target.selectionEnd
|
|
12
|
+
* @param {string} prevCtrlValue 上一个格式化后的值
|
|
13
|
+
* @param {string} rawValue 当前输入原值
|
|
14
|
+
* @param {string} ctrlValue 当前格式化后的值
|
|
15
|
+
* @param {Object} [options] 配置项
|
|
16
|
+
* @param {string[]|string} [options.placeholderChar=' '] 占位符
|
|
17
|
+
* @param {RegExp} [options.maskReg=/\D/g] 需要遮盖的字符规则。默认去掉非数字,意味着 ctrlValue 需要去掉非数字。
|
|
18
|
+
* @param {'mobile'|'bankCard'} [options.type] 格式化类型,内置手机号码和银行卡号特殊处理
|
|
19
|
+
* @returns {number} 格式化后的光标位置
|
|
20
|
+
*/
|
|
21
|
+
declare function calculateCursorPosition(prevPos: number, prevCtrlValue: string, rawValue: string, ctrlValue: string, { placeholderChar, maskReg, type }?: {
|
|
22
|
+
placeholderChar?: string | string[] | undefined;
|
|
23
|
+
maskReg?: RegExp | undefined;
|
|
24
|
+
type?: "mobile" | "bankCard" | undefined;
|
|
25
|
+
} | undefined): number;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default formatMobile;
|
|
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
|
+
*
|
|
16
|
+
* // 脱敏手机号码
|
|
17
|
+
* formatMobile('133****1234') // '133 **** 1234'
|
|
18
|
+
* formatMobile('133****1234', { char: '-' }) // '133-****-1234'
|
|
19
|
+
*
|
|
20
|
+
* // 手机号码位数不够
|
|
21
|
+
* formatMobile('133') // '133'
|
|
22
|
+
* formatMobile('133456') // '133 456'
|
|
23
|
+
* formatMobile('13345678') // '133 4567 8'
|
|
24
|
+
*/
|
|
25
|
+
declare function formatMobile(mobileNo: string, { char }?: {
|
|
26
|
+
char?: string | undefined;
|
|
27
|
+
} | undefined): string;
|
package/types/index.d.ts
CHANGED
|
@@ -29,10 +29,13 @@ export { default as blobToDataURL } from "./blobToDataURL";
|
|
|
29
29
|
export { default as dataURLToBlob } from "./dataURLToBlob";
|
|
30
30
|
export { default as setDataURLPrefix } from "./setDataURLPrefix";
|
|
31
31
|
export { default as normalizeString } from "./normalizeString";
|
|
32
|
+
export { default as safeDate } from "./safeDate";
|
|
33
|
+
export { default as formatMobile } from "./formatMobile";
|
|
32
34
|
export { default as plus } from "./plus";
|
|
33
35
|
export { default as minus } from "./minus";
|
|
34
36
|
export { default as times } from "./times";
|
|
35
37
|
export { default as divide } from "./divide";
|
|
36
38
|
export { default as round } from "./round";
|
|
37
39
|
export { default as waitTime } from "./waitTime";
|
|
40
|
+
export { default as calculateCursorPosition } from "./calculateCursorPosition";
|
|
38
41
|
export { setDisableWarning } from "./utils/config";
|
package/types/isHMCard.d.ts
CHANGED
|
@@ -8,5 +8,17 @@ export default isHMCard;
|
|
|
8
8
|
* @see 参考 {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证|港澳居民来往内地通行证}
|
|
9
9
|
* @param {*} value 要检测的值
|
|
10
10
|
* @returns {boolean} 是否为港澳居民来往内地通行证
|
|
11
|
+
* @example
|
|
12
|
+
* // 第一代 11 位
|
|
13
|
+
* isHMCard('h3203117707') // true
|
|
14
|
+
* isHMCard('H3203117707') // true
|
|
15
|
+
* isHMCard('m3203117707') // true
|
|
16
|
+
* isHMCard('M3203117707') // true
|
|
17
|
+
*
|
|
18
|
+
* // 第二代 9 位
|
|
19
|
+
* isHMCard('h32031177') // true
|
|
20
|
+
* isHMCard('H32031177') // true
|
|
21
|
+
* isHMCard('m32031177') // true
|
|
22
|
+
* isHMCard('M32031177') // true
|
|
11
23
|
*/
|
|
12
24
|
declare function isHMCard(value: any): boolean;
|
package/types/isTWCard.d.ts
CHANGED
|
@@ -8,5 +8,11 @@ export default isTWCard;
|
|
|
8
8
|
* @see 参考 {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证|台湾居民来往大陆通行证}
|
|
9
9
|
* @param {*} value 要检测的值
|
|
10
10
|
* @returns {boolean} 是否为台湾居民来往大陆通行证
|
|
11
|
+
* @example
|
|
12
|
+
* isTWCard('12345678') // true
|
|
13
|
+
* isTWCard('07257456') // true
|
|
14
|
+
*
|
|
15
|
+
* // 一次性短期
|
|
16
|
+
* isTWCard('F290299977') // true
|
|
11
17
|
*/
|
|
12
18
|
declare function isTWCard(value: any): boolean;
|
|
@@ -4,6 +4,7 @@ export default normalizeString;
|
|
|
4
4
|
*
|
|
5
5
|
* @static
|
|
6
6
|
* @alias module:Processor.normalizeString
|
|
7
|
+
* @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances|String}
|
|
7
8
|
* @since 4.3.0
|
|
8
9
|
* @param {*} value 待处理的值
|
|
9
10
|
* @returns {string} 规整化的值
|
package/types/parseIdCard.d.ts
CHANGED
|
@@ -1,4 +1,75 @@
|
|
|
1
1
|
export default parseIdCard;
|
|
2
|
+
/**
|
|
3
|
+
* - 解析身份证原数据
|
|
4
|
+
*/
|
|
5
|
+
export type IdCardOrigin = {
|
|
6
|
+
/**
|
|
7
|
+
* - 省份编码
|
|
8
|
+
*/
|
|
9
|
+
province: string;
|
|
10
|
+
/**
|
|
11
|
+
* - 城市编码
|
|
12
|
+
*/
|
|
13
|
+
city: string;
|
|
14
|
+
/**
|
|
15
|
+
* - 地区编码
|
|
16
|
+
*/
|
|
17
|
+
area: string;
|
|
18
|
+
/**
|
|
19
|
+
* - 出生年
|
|
20
|
+
*/
|
|
21
|
+
year: string;
|
|
22
|
+
/**
|
|
23
|
+
* - 出生月
|
|
24
|
+
*/
|
|
25
|
+
month: string;
|
|
26
|
+
/**
|
|
27
|
+
* - 出生日
|
|
28
|
+
*/
|
|
29
|
+
day: string;
|
|
30
|
+
/**
|
|
31
|
+
* - 性别 能整除2为女,否则为男
|
|
32
|
+
*/
|
|
33
|
+
gender: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* - 身份证信息
|
|
37
|
+
*/
|
|
38
|
+
export type IdCardInfo = {
|
|
39
|
+
/**
|
|
40
|
+
* - 省份
|
|
41
|
+
*/
|
|
42
|
+
province: string;
|
|
43
|
+
/**
|
|
44
|
+
* - 生日
|
|
45
|
+
*/
|
|
46
|
+
birthday: string;
|
|
47
|
+
/**
|
|
48
|
+
* - 性别
|
|
49
|
+
*/
|
|
50
|
+
gender: string;
|
|
51
|
+
/**
|
|
52
|
+
* - 解析身份证原数据
|
|
53
|
+
*/
|
|
54
|
+
origin: IdCardOrigin;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* @typedef {Object} IdCardOrigin - 解析身份证原数据
|
|
58
|
+
* @property {string} province - 省份编码
|
|
59
|
+
* @property {string} city - 城市编码
|
|
60
|
+
* @property {string} area - 地区编码
|
|
61
|
+
* @property {string} year - 出生年
|
|
62
|
+
* @property {string} month - 出生月
|
|
63
|
+
* @property {string} day - 出生日
|
|
64
|
+
* @property {string} gender - 性别 能整除2为女,否则为男
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* @typedef {Object} IdCardInfo - 身份证信息
|
|
68
|
+
* @property {string} province - 省份
|
|
69
|
+
* @property {string} birthday - 生日
|
|
70
|
+
* @property {string} gender - 性别
|
|
71
|
+
* @property {IdCardOrigin} origin - 解析身份证原数据
|
|
72
|
+
*/
|
|
2
73
|
/**
|
|
3
74
|
* 解析身份证号码,支持15、18位身份证号码
|
|
4
75
|
*
|
|
@@ -7,7 +78,7 @@ export default parseIdCard;
|
|
|
7
78
|
* @since 4.0.0
|
|
8
79
|
* @see 参考 {@link https://baike.baidu.com/item/居民身份证号码|居民身份证号码}
|
|
9
80
|
* @param {string} id 身份证号码,支持15位
|
|
10
|
-
* @returns null 或 省份、生日、性别,省/市/区/年/月/日/性别编码
|
|
81
|
+
* @returns {null|IdCardInfo} null 或 省份、生日、性别,省/市/区/年/月/日/性别编码
|
|
11
82
|
* @example
|
|
12
83
|
* parseIdCard('123456789123456');
|
|
13
84
|
* // => null
|
|
@@ -16,33 +87,21 @@ export default parseIdCard;
|
|
|
16
87
|
* parseIdCard('130701199310302288')
|
|
17
88
|
* // =>
|
|
18
89
|
* {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
90
|
+
* birthday: "1993-10-30",
|
|
91
|
+
* gender: "女",
|
|
92
|
+
* origin: { province: "13", city: "07", area: "01", year: "1993", month: "10", day: "30", gender: "8" },
|
|
93
|
+
* province: "河北省"
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
24
96
|
* // 15位身份证号码
|
|
25
97
|
* parseIdCard('130701931030228');
|
|
26
98
|
* // =>
|
|
27
99
|
* {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
100
|
+
* birthday: "93-10-30",
|
|
101
|
+
* gender: "女",
|
|
102
|
+
* origin: { province: "13", city: "07", area: "01", year: "93", month: "10", day: "30", gender: "8" },
|
|
103
|
+
* province: "河北省"
|
|
104
|
+
* }
|
|
33
105
|
*
|
|
34
106
|
*/
|
|
35
|
-
declare function parseIdCard(id: string):
|
|
36
|
-
province: string;
|
|
37
|
-
birthday: string;
|
|
38
|
-
gender: string;
|
|
39
|
-
origin: {
|
|
40
|
-
province: string;
|
|
41
|
-
city: string;
|
|
42
|
-
area: string;
|
|
43
|
-
year: string;
|
|
44
|
-
month: string;
|
|
45
|
-
day: string;
|
|
46
|
-
gender: string;
|
|
47
|
-
};
|
|
48
|
-
} | null;
|
|
107
|
+
declare function parseIdCard(id: string): null | IdCardInfo;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default safeDate;
|
|
2
|
+
/**
|
|
3
|
+
* 创建一个 Date 实例日期对象,同 new Date() 。<br/>
|
|
4
|
+
* 规避了苹果设备浏览器不支持部分格式(YYYY-MM-DD HH-mm 或 YYYY.MM.DD)。
|
|
5
|
+
*
|
|
6
|
+
* @static
|
|
7
|
+
* @alias module:Processor.safeDate
|
|
8
|
+
* @see 参考 {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date|Date}
|
|
9
|
+
* @since 4.4.0
|
|
10
|
+
* @param {string|number|Date} [value] 日期时间字符串、毫秒数、日期对象
|
|
11
|
+
* @param {...number} args 月/日/时/分/秒/毫秒
|
|
12
|
+
* @returns {Date} Date 实例日期对象
|
|
13
|
+
* @example
|
|
14
|
+
* safeDate('2022-1-1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
|
|
15
|
+
* safeDate('2022/1/1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
|
|
16
|
+
* safeDate('2022.1.1'); // Sat Jan 01 2022 00:00:00 GMT+0800 (中国标准时间)
|
|
17
|
+
* safeDate('2022.1.1 11:11'); // Sat Jan 01 2022 11:11:00 GMT+0800 (中国标准时间)
|
|
18
|
+
* safeDate(99, 1); // Mon Feb 01 1999 00:00:00 GMT+0800 (中国标准时间)
|
|
19
|
+
* safeDate(1646711233171); // Tue Mar 08 2022 11:47:13 GMT+0800 (中国标准时间)
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
declare function safeDate(value?: string | number | Date | undefined, ...args: number[]): Date;
|
|
@@ -1,4 +1,60 @@
|
|
|
1
1
|
export default validatePassword;
|
|
2
|
+
/**
|
|
3
|
+
* - 验证密码的包含内容
|
|
4
|
+
*/
|
|
5
|
+
export type PasswordContaines = {
|
|
6
|
+
/**
|
|
7
|
+
* - 包含数字
|
|
8
|
+
*/
|
|
9
|
+
number: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* - 包含小写字母
|
|
12
|
+
*/
|
|
13
|
+
lowerCaseLetter: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* - 包含大写字母
|
|
16
|
+
*/
|
|
17
|
+
upperCaseLetter: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* - 包含特殊字符
|
|
20
|
+
*/
|
|
21
|
+
specialCharacter: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* - 包含非法字符
|
|
24
|
+
*/
|
|
25
|
+
unallowableCharacter: boolean;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* - 验证结果
|
|
29
|
+
*/
|
|
30
|
+
export type ValidatePasswordReturn = {
|
|
31
|
+
/**
|
|
32
|
+
* - 验证结果,根据密码强度、是否包含非法字符得出
|
|
33
|
+
*/
|
|
34
|
+
validated: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* - 强度级别,包含数字/大小写字母/特殊字符
|
|
37
|
+
*/
|
|
38
|
+
level: number;
|
|
39
|
+
/**
|
|
40
|
+
* - 包含内容
|
|
41
|
+
*/
|
|
42
|
+
containes: PasswordContaines;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @typedef {Object} PasswordContaines - 验证密码的包含内容
|
|
46
|
+
* @property {boolean} number - 包含数字
|
|
47
|
+
* @property {boolean} lowerCaseLetter - 包含小写字母
|
|
48
|
+
* @property {boolean} upperCaseLetter - 包含大写字母
|
|
49
|
+
* @property {boolean} specialCharacter - 包含特殊字符
|
|
50
|
+
* @property {boolean} unallowableCharacter - 包含非法字符
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* @typedef {Object} ValidatePasswordReturn - 验证结果
|
|
54
|
+
* @property {boolean} validated - 验证结果,根据密码强度、是否包含非法字符得出
|
|
55
|
+
* @property {number} level - 强度级别,包含数字/大小写字母/特殊字符
|
|
56
|
+
* @property {PasswordContaines} containes - 包含内容
|
|
57
|
+
*/
|
|
2
58
|
/**
|
|
3
59
|
* 验证密码(数字、大小写字母、特殊字符、非法字符)
|
|
4
60
|
*
|
|
@@ -11,7 +67,7 @@ export default validatePassword;
|
|
|
11
67
|
* @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
|
|
12
68
|
* @param {boolean} [options.ignoreCase=false] 是否忽略大小写,为 ture 时,大小写字母视为一种字符
|
|
13
69
|
* @param {string} [options.special="!@#$%^&*()-=_+[]\|{},./?<>~"] 支持的特殊字符
|
|
14
|
-
* @returns 验证结果
|
|
70
|
+
* @returns {ValidatePasswordReturn} 验证结果
|
|
15
71
|
* @example
|
|
16
72
|
*
|
|
17
73
|
* validatePassword('a12345678');
|
|
@@ -75,14 +131,4 @@ declare function validatePassword(value: string, { level, ignoreCase, special }?
|
|
|
75
131
|
level?: number | undefined;
|
|
76
132
|
ignoreCase?: boolean | undefined;
|
|
77
133
|
special?: string | undefined;
|
|
78
|
-
} | undefined):
|
|
79
|
-
validated: boolean;
|
|
80
|
-
level: number;
|
|
81
|
-
containes: {
|
|
82
|
-
number: boolean;
|
|
83
|
-
lowerCaseLetter: boolean;
|
|
84
|
-
upperCaseLetter: boolean;
|
|
85
|
-
specialCharacter: boolean;
|
|
86
|
-
unallowableCharacter: boolean;
|
|
87
|
-
};
|
|
88
|
-
};
|
|
134
|
+
} | undefined): ValidatePasswordReturn;
|