@odinlin/utils 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/index.cjs +231 -0
- package/dist/index.d.ts +393 -0
- package/dist/index.mjs +137 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 odinlin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @odinlin/utils
|
|
2
|
+
|
|
3
|
+
Collection of common JavaScript / TypeScript utils
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- [base](/topazur/utils/blob/main/src/base.ts)
|
|
8
|
+
|
|
9
|
+
- [random](/topazur/utils/blob/main/src/random.ts)
|
|
10
|
+
|
|
11
|
+
- [regexp](/topazur/utils/blob/main/src/regexp.ts) depend on [any-rule](https://github.com/any86/any-rule)
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
[MIT](./LICENSE) License © 2022 [odinlin](https://github.com/topazur)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const assert = (condition, message) => {
|
|
6
|
+
if (!condition) {
|
|
7
|
+
throw new Error(message);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function callString(target, mode) {
|
|
11
|
+
const result = Object.prototype.toString.call(target);
|
|
12
|
+
if (typeof mode === "undefined") {
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
const typeStr = result.slice(8, -1);
|
|
16
|
+
if (mode === 0) {
|
|
17
|
+
return typeStr;
|
|
18
|
+
}
|
|
19
|
+
if (mode === -1) {
|
|
20
|
+
return typeStr.toLowerCase();
|
|
21
|
+
}
|
|
22
|
+
return typeStr.toUpperCase();
|
|
23
|
+
}
|
|
24
|
+
const noop = () => {
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function randomRange(min, max) {
|
|
28
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
29
|
+
}
|
|
30
|
+
function randomRgbColor(raw = false) {
|
|
31
|
+
const [r, g, b] = Array(3).fill(0).map(() => Math.random()).map((item) => raw ? item * 255 : parseInt(`${item * 255}`, 10));
|
|
32
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
33
|
+
}
|
|
34
|
+
function randomHexColor() {
|
|
35
|
+
return `#${(Math.random() * 1048575 * 1e6).toString(16).slice(0, 6)}`;
|
|
36
|
+
}
|
|
37
|
+
function randomDate(start = "1999/01/1", end) {
|
|
38
|
+
const date = new Date();
|
|
39
|
+
const splitTag = start.includes("/") ? "/" : "-";
|
|
40
|
+
const [endY, endM, endD] = (end || "").split(splitTag);
|
|
41
|
+
const y = +endY || date.getFullYear();
|
|
42
|
+
const m = +endM || date.getMonth() + 1;
|
|
43
|
+
const d = +endD || date.getDate();
|
|
44
|
+
const [startY, startM, startD] = start.split("/");
|
|
45
|
+
const startDate = new Date(+startY, +startM, +startD).getTime();
|
|
46
|
+
const endDate = new Date(y, m, d).getTime();
|
|
47
|
+
return new Date(startDate + Math.round(Math.random() * (endDate - startDate)));
|
|
48
|
+
}
|
|
49
|
+
function randomUUID() {
|
|
50
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
51
|
+
const r = Math.random() * 16 | 0;
|
|
52
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
53
|
+
return v.toString(16);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const regUriAndPort = /^((ht|f)tps?:\/\/)?[\w-]+(\.[\w-]+)+:\d{1,5}\/?$/;
|
|
58
|
+
const regUri = /^(((ht|f)tps?):\/\/)?([^!@#$%^&*?.\s-]([^!@#$%^&*?.\s]{0,63}[^!@#$%^&*?.\s])?\.)+[a-z]{2,6}\/?/;
|
|
59
|
+
const regDomain = /^([0-9a-zA-Z-]{1,}\.)+([a-zA-Z]{2,})$/;
|
|
60
|
+
const regIPV4 = /^((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(?::(?:[0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$/;
|
|
61
|
+
const regIPV6 = /(^(?:(?:(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$)|(^\[(?:(?:(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))\](?::(?:[0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$)/i;
|
|
62
|
+
const regJAVAPackageName = /^([a-zA-Z_]\w*)+([.][a-zA-Z_]\w*)+$/;
|
|
63
|
+
const regMacAddr = /^((([a-f0-9]{2}:){5})|(([a-f0-9]{2}-){5}))[a-f0-9]{2}$/i;
|
|
64
|
+
const regThunderEasy = /^thunderx?:\/\/[a-zA-Z\d]+=$/;
|
|
65
|
+
const regEd2kEasy = /^ed2k:\/\/\|file\|.+\|\/$/;
|
|
66
|
+
const regMagnetEasy = /^magnet:\?xt=urn:btih:[0-9a-fA-F]{40,}.*$/;
|
|
67
|
+
const regSubnetMask = /^(254|252|248|240|224|192|128)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(255|254|252|248|240|224|192|128|0)$/;
|
|
68
|
+
const regLinuxHideFilePath = /^\/(?:[^/]+\/)*\.[^/]*/;
|
|
69
|
+
const regLinuxFilePath = /^\/(?:[^/]+\/)*[^/]+$/;
|
|
70
|
+
const regLinuxFolderPath = /^\/(?:[^/]+\/)*$/;
|
|
71
|
+
const regWindowsFilePath = /^[a-zA-Z]:\\(?:\w+\\)*\w+\.\w+$/;
|
|
72
|
+
const regWindowsFolderPath = /^[a-zA-Z]:\\(?:\w+\\?)*$/;
|
|
73
|
+
const regHexadecimalColor = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
|
|
74
|
+
const regHtmlComments = /<!--[\s\S]*?-->/g;
|
|
75
|
+
const regHtmlTags = /<(\w+)[^>]*>(.*?<\/\1>)?/;
|
|
76
|
+
const regMD5 = /^[a-fA-F0-9]{32}$/;
|
|
77
|
+
const regUUID = /^[a-f\d]{4}(?:[a-f\d]{4}-){4}[a-f\d]{12}$/i;
|
|
78
|
+
const regSemVer = /^\d+(?:\.\d+){2}$/;
|
|
79
|
+
const regVideoUri = /^https?:\/\/(.+\/)+.+(\.(swf|avi|flv|mpg|rm|mov|wav|asf|3gp|mkv|rmvb|mp4))$/i;
|
|
80
|
+
const regImageUri = /^https?:\/\/(.+\/)+.+(\.(gif|png|jpg|jpeg|webp|svg|psd|bmp|tif))$/i;
|
|
81
|
+
const regBase64 = /^\s*data:(?:[a-z]+\/[a-z0-9-+.]+(?:;[a-z-]+=[a-z0-9-]+)?)?(?:;base64)?,([a-z0-9!$&',()*+;=\-._~:@/?%\s]*?)\s*$/i;
|
|
82
|
+
const regHHmmss = /^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/;
|
|
83
|
+
const reghhmmss = /^(?:1[0-2]|0?[1-9]):[0-5]\d:[0-5]\d$/;
|
|
84
|
+
const regDateEasy = /^\d{1,4}(-)(1[0-2]|0?[1-9])\1(0?[1-9]|[1-2]\d|30|31)$/;
|
|
85
|
+
const regDate = /^(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$/;
|
|
86
|
+
const regDateMoment = /^\d{4}([/:-\S])(1[0-2]|0?[1-9])\1(0?[1-9]|[1-2]\d|30|31) (?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/;
|
|
87
|
+
const regEmail = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
88
|
+
const regEmailEasy = /^[A-Za-z0-9\u4E00-\u9FA5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
|
|
89
|
+
const regRepeat = /(.)\1+/;
|
|
90
|
+
const regASCII = /[\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]+/;
|
|
91
|
+
const regChineseCharacters = /^(?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])+$/;
|
|
92
|
+
const regChineseCharacterAndPoint = /[\u4E00-\u9FA5|\u3002|\uFF1F|\uFF01|\uFF0C|\u3001|\uFF1B|\uFF1A|\u201C|\u201D|\u2018|\u2019|\uFF08|\uFF09|\u300A|\u300B|\u3008|\u3009|\u3010|\u3011|\u300E|\u300F|\u300C|\u300D|\uFE43|\uFE44|\u3014|\u3015|\u2026|\u2014|\uFF5E|\uFE4F|\uFFE5]/;
|
|
93
|
+
const regChineseAndNumber = /^((?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])|(\d))+$/;
|
|
94
|
+
const regLetterAndNumber = /^(?=.*[a-zA-Z])(?=.*\d).+$/;
|
|
95
|
+
const regLetterOrNumber = /^[A-Za-z0-9]+$/;
|
|
96
|
+
const regOnlyNumber = /^\d+$/;
|
|
97
|
+
const regLetters = /^[a-zA-Z]+$/;
|
|
98
|
+
const regLettersLower = /^[a-z]+$/;
|
|
99
|
+
const regLettersUpper = /^[A-Z]+$/;
|
|
100
|
+
const regNotLetter = /^[^A-Za-z]*$/;
|
|
101
|
+
const regDecimal = /^\d+\.\d+$/;
|
|
102
|
+
const regIntegerPositive = /^\+?[1-9]\d*$/;
|
|
103
|
+
const regIntegerNegative = /^-[1-9]\d*$/;
|
|
104
|
+
const regInteger = /^(?:0|(?:-?[1-9]\d*))$/;
|
|
105
|
+
const regFloatEasy = /^(-?[1-9]\d*\.\d+|-?0\.\d*[1-9]\d*|0\.0+)$/;
|
|
106
|
+
const regFloat = /^(-?[1-9]\d*\.\d+|-?0\.\d*[1-9])$/;
|
|
107
|
+
const regLicensePlateNE = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z](?:((\d{5}[A-HJK])|([A-HJK][A-HJ-NP-Z0-9][0-9]{4}))|[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳])$/;
|
|
108
|
+
const regLicensePlateLegacy = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]$/;
|
|
109
|
+
const regLicensePlateAll = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/;
|
|
110
|
+
const regIdentityCardV1 = /^[1-9]\d{7}(?:0\d|10|11|12)(?:0[1-9]|[1-2][\d]|30|31)\d{3}$/;
|
|
111
|
+
const regIdentityCardV2 = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/;
|
|
112
|
+
const regIdentityCard = /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/;
|
|
113
|
+
const regIdentityCardHK = /^[a-zA-Z]\d{6}\([\dA]\)$/;
|
|
114
|
+
const regIdentityCardMO = /^[1|5|7]\d{6}\(\d\)$/;
|
|
115
|
+
const regIdentityCardTWN = /^[a-zA-Z][0-9]{9}$/;
|
|
116
|
+
const regPassport = /(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/;
|
|
117
|
+
const regBankCardNo = /^[1-9]\d{9,29}$/;
|
|
118
|
+
const regChineseProvince = /^浙江|上海|北京|天津|重庆|黑龙江|吉林|辽宁|内蒙古|河北|新疆|甘肃|青海|陕西|宁夏|河南|山东|山西|安徽|湖北|湖南|江苏|四川|贵州|云南|广西|西藏|江西|广东|福建|台湾|海南|香港|澳门$/;
|
|
119
|
+
const regMobile = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/;
|
|
120
|
+
const regMobileEasy = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/;
|
|
121
|
+
const regMobileEasiest = /^(?:(?:\+|00)86)?1\d{10}$/;
|
|
122
|
+
const regTelephone = /^(?:(?:\d{3}-)?\d{8}|^(?:\d{4}-)?\d{7,8})(?:-\d+)?$/;
|
|
123
|
+
const regTrainNumber = /^[GCDZTSPKXLY1-9]\d{1,4}$/;
|
|
124
|
+
const regStockCodeA = /^(s[hz]|S[HZ])(000[\d]{3}|002[\d]{3}|300[\d]{3}|600[\d]{3}|60[\d]{4})$/;
|
|
125
|
+
const regIMEI = /^\d{15,17}$/;
|
|
126
|
+
const regCreditCode = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
|
|
127
|
+
const regCreditCodeEasy = /^(([0-9A-Za-z]{15})|([0-9A-Za-z]{18})|([0-9A-Za-z]{20}))$/;
|
|
128
|
+
const regPostalCode = /^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/;
|
|
129
|
+
const regAmount = /^-?\d+(,\d{3})*(\.\d{1,2})?$/;
|
|
130
|
+
const regAmountEasy = /(?:^[1-9]([0-9]+)?(?:\.[0-9]{1,2})?$)|(?:^(?:0)$)|(?:^[0-9]\.[0-9](?:[0-9])?$)/;
|
|
131
|
+
const regExamScore = /^150$|^(?:\d|[1-9]\d|1[0-4]\d)(?:\.5)?$/;
|
|
132
|
+
const regChineseName = /^(?:[\u4E00-\u9FA5·]{2,16})$/;
|
|
133
|
+
const regEnglishName = /(^[a-zA-Z][a-zA-Z\s]{0,20}[a-zA-Z]$)/;
|
|
134
|
+
const regValidAccountV1 = /^[a-zA-Z0-9_-]{4,16}$/;
|
|
135
|
+
const regValidAccountV2 = /^[a-zA-Z]\w{4,15}$/;
|
|
136
|
+
const regQQ = /^[1-9][0-9]{4,10}$/;
|
|
137
|
+
const regWechatID = /^[a-zA-Z][-_a-zA-Z0-9]{5,19}$/;
|
|
138
|
+
const regPasswordV1 = /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]/;
|
|
139
|
+
const regPasswordV2 = /^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*? ])\S*$/;
|
|
140
|
+
|
|
141
|
+
exports.assert = assert;
|
|
142
|
+
exports.callString = callString;
|
|
143
|
+
exports.noop = noop;
|
|
144
|
+
exports.randomDate = randomDate;
|
|
145
|
+
exports.randomHexColor = randomHexColor;
|
|
146
|
+
exports.randomRange = randomRange;
|
|
147
|
+
exports.randomRgbColor = randomRgbColor;
|
|
148
|
+
exports.randomUUID = randomUUID;
|
|
149
|
+
exports.regASCII = regASCII;
|
|
150
|
+
exports.regAmount = regAmount;
|
|
151
|
+
exports.regAmountEasy = regAmountEasy;
|
|
152
|
+
exports.regBankCardNo = regBankCardNo;
|
|
153
|
+
exports.regBase64 = regBase64;
|
|
154
|
+
exports.regChineseAndNumber = regChineseAndNumber;
|
|
155
|
+
exports.regChineseCharacterAndPoint = regChineseCharacterAndPoint;
|
|
156
|
+
exports.regChineseCharacters = regChineseCharacters;
|
|
157
|
+
exports.regChineseName = regChineseName;
|
|
158
|
+
exports.regChineseProvince = regChineseProvince;
|
|
159
|
+
exports.regCreditCode = regCreditCode;
|
|
160
|
+
exports.regCreditCodeEasy = regCreditCodeEasy;
|
|
161
|
+
exports.regDate = regDate;
|
|
162
|
+
exports.regDateEasy = regDateEasy;
|
|
163
|
+
exports.regDateMoment = regDateMoment;
|
|
164
|
+
exports.regDecimal = regDecimal;
|
|
165
|
+
exports.regDomain = regDomain;
|
|
166
|
+
exports.regEd2kEasy = regEd2kEasy;
|
|
167
|
+
exports.regEmail = regEmail;
|
|
168
|
+
exports.regEmailEasy = regEmailEasy;
|
|
169
|
+
exports.regEnglishName = regEnglishName;
|
|
170
|
+
exports.regExamScore = regExamScore;
|
|
171
|
+
exports.regFloat = regFloat;
|
|
172
|
+
exports.regFloatEasy = regFloatEasy;
|
|
173
|
+
exports.regHHmmss = regHHmmss;
|
|
174
|
+
exports.regHexadecimalColor = regHexadecimalColor;
|
|
175
|
+
exports.regHtmlComments = regHtmlComments;
|
|
176
|
+
exports.regHtmlTags = regHtmlTags;
|
|
177
|
+
exports.regIMEI = regIMEI;
|
|
178
|
+
exports.regIPV4 = regIPV4;
|
|
179
|
+
exports.regIPV6 = regIPV6;
|
|
180
|
+
exports.regIdentityCard = regIdentityCard;
|
|
181
|
+
exports.regIdentityCardHK = regIdentityCardHK;
|
|
182
|
+
exports.regIdentityCardMO = regIdentityCardMO;
|
|
183
|
+
exports.regIdentityCardTWN = regIdentityCardTWN;
|
|
184
|
+
exports.regIdentityCardV1 = regIdentityCardV1;
|
|
185
|
+
exports.regIdentityCardV2 = regIdentityCardV2;
|
|
186
|
+
exports.regImageUri = regImageUri;
|
|
187
|
+
exports.regInteger = regInteger;
|
|
188
|
+
exports.regIntegerNegative = regIntegerNegative;
|
|
189
|
+
exports.regIntegerPositive = regIntegerPositive;
|
|
190
|
+
exports.regJAVAPackageName = regJAVAPackageName;
|
|
191
|
+
exports.regLetterAndNumber = regLetterAndNumber;
|
|
192
|
+
exports.regLetterOrNumber = regLetterOrNumber;
|
|
193
|
+
exports.regLetters = regLetters;
|
|
194
|
+
exports.regLettersLower = regLettersLower;
|
|
195
|
+
exports.regLettersUpper = regLettersUpper;
|
|
196
|
+
exports.regLicensePlateAll = regLicensePlateAll;
|
|
197
|
+
exports.regLicensePlateLegacy = regLicensePlateLegacy;
|
|
198
|
+
exports.regLicensePlateNE = regLicensePlateNE;
|
|
199
|
+
exports.regLinuxFilePath = regLinuxFilePath;
|
|
200
|
+
exports.regLinuxFolderPath = regLinuxFolderPath;
|
|
201
|
+
exports.regLinuxHideFilePath = regLinuxHideFilePath;
|
|
202
|
+
exports.regMD5 = regMD5;
|
|
203
|
+
exports.regMacAddr = regMacAddr;
|
|
204
|
+
exports.regMagnetEasy = regMagnetEasy;
|
|
205
|
+
exports.regMobile = regMobile;
|
|
206
|
+
exports.regMobileEasiest = regMobileEasiest;
|
|
207
|
+
exports.regMobileEasy = regMobileEasy;
|
|
208
|
+
exports.regNotLetter = regNotLetter;
|
|
209
|
+
exports.regOnlyNumber = regOnlyNumber;
|
|
210
|
+
exports.regPassport = regPassport;
|
|
211
|
+
exports.regPasswordV1 = regPasswordV1;
|
|
212
|
+
exports.regPasswordV2 = regPasswordV2;
|
|
213
|
+
exports.regPostalCode = regPostalCode;
|
|
214
|
+
exports.regQQ = regQQ;
|
|
215
|
+
exports.regRepeat = regRepeat;
|
|
216
|
+
exports.regSemVer = regSemVer;
|
|
217
|
+
exports.regStockCodeA = regStockCodeA;
|
|
218
|
+
exports.regSubnetMask = regSubnetMask;
|
|
219
|
+
exports.regTelephone = regTelephone;
|
|
220
|
+
exports.regThunderEasy = regThunderEasy;
|
|
221
|
+
exports.regTrainNumber = regTrainNumber;
|
|
222
|
+
exports.regUUID = regUUID;
|
|
223
|
+
exports.regUri = regUri;
|
|
224
|
+
exports.regUriAndPort = regUriAndPort;
|
|
225
|
+
exports.regValidAccountV1 = regValidAccountV1;
|
|
226
|
+
exports.regValidAccountV2 = regValidAccountV2;
|
|
227
|
+
exports.regVideoUri = regVideoUri;
|
|
228
|
+
exports.regWechatID = regWechatID;
|
|
229
|
+
exports.regWindowsFilePath = regWindowsFilePath;
|
|
230
|
+
exports.regWindowsFolderPath = regWindowsFolderPath;
|
|
231
|
+
exports.reghhmmss = reghhmmss;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title 若condition为true则什么也不做,否则抛出异常
|
|
3
|
+
* @param { boolean } condition 条件
|
|
4
|
+
* @param { string } message 自定义错误信息
|
|
5
|
+
*/
|
|
6
|
+
declare const assert: (condition: boolean, message: string) => asserts condition;
|
|
7
|
+
/**
|
|
8
|
+
* @title 通过toString判断数据类型
|
|
9
|
+
* @param { unknown } target 需要判断的数据
|
|
10
|
+
* @param mode -1 小写 0 不变 1 大写
|
|
11
|
+
* @returns { string }
|
|
12
|
+
*/
|
|
13
|
+
declare function callString(target: any, mode?: -1 | 0 | 1): string;
|
|
14
|
+
/**
|
|
15
|
+
* @title 空函数 <空操作; 无操作;>
|
|
16
|
+
*/
|
|
17
|
+
declare const noop: () => void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @title 随机生成数字函数
|
|
21
|
+
* @param [start, end] 大小范围
|
|
22
|
+
* @returns {Date} 随机数字结果
|
|
23
|
+
*/
|
|
24
|
+
declare function randomRange(min: number, max: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* @title 随机生成RGB颜色
|
|
27
|
+
* @return { string } 随机RGB颜色
|
|
28
|
+
* @example console.log(randomRgb())// 'rgb(255,0,0)'
|
|
29
|
+
*/
|
|
30
|
+
declare function randomRgbColor(raw?: boolean): string;
|
|
31
|
+
/**
|
|
32
|
+
* @title 随机生成十六进制颜色
|
|
33
|
+
* @return { string } 随机十六进制颜色
|
|
34
|
+
* @example console.log(randomHexColor()) // '#ff0000'
|
|
35
|
+
*/
|
|
36
|
+
declare function randomHexColor(): string;
|
|
37
|
+
/**
|
|
38
|
+
* @title 随机生成时间
|
|
39
|
+
* @param [start, end] 时间范围 (支持/或-分隔, end默认是当前日期)
|
|
40
|
+
* @returns {Date} 随机时间结果
|
|
41
|
+
*/
|
|
42
|
+
declare function randomDate(start?: string, end?: string): Date;
|
|
43
|
+
/**
|
|
44
|
+
* @title 随机生成uuid
|
|
45
|
+
* @returns {string} 32位uuid
|
|
46
|
+
*/
|
|
47
|
+
declare function randomUUID(): string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @title [any-rule](https://github.com/any86/any-rule)
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* @title 必须带端口号的网址(或ip)
|
|
54
|
+
*/
|
|
55
|
+
declare const regUriAndPort: RegExp;
|
|
56
|
+
/**
|
|
57
|
+
* @title 网址(URL)
|
|
58
|
+
* @desc https://baike.baidu.com/item/%E9%A1%B6%E7%BA%A7%E5%9F%9F%E5%90%8D#4_1
|
|
59
|
+
* @desc https://baike.baidu.com/item/%E9%A1%B6%E7%BA%A7%E5%9F%9F%E5%90%8D#7
|
|
60
|
+
* @desc 也参考谷歌浏览器的地址栏, 如果输入非字母不会被识别为域名
|
|
61
|
+
*/
|
|
62
|
+
declare const regUri: RegExp;
|
|
63
|
+
/**
|
|
64
|
+
* @title 域名(非网址, 不包含协议)
|
|
65
|
+
*/
|
|
66
|
+
declare const regDomain: RegExp;
|
|
67
|
+
/**
|
|
68
|
+
* @title ip-v4[:端口]
|
|
69
|
+
*/
|
|
70
|
+
declare const regIPV4: RegExp;
|
|
71
|
+
/**
|
|
72
|
+
* @title ip-v6[:端口]
|
|
73
|
+
*/
|
|
74
|
+
declare const regIPV6: RegExp;
|
|
75
|
+
/**
|
|
76
|
+
* @title java包名
|
|
77
|
+
*/
|
|
78
|
+
declare const regJAVAPackageName: RegExp;
|
|
79
|
+
/**
|
|
80
|
+
* @title mac地址
|
|
81
|
+
*/
|
|
82
|
+
declare const regMacAddr: RegExp;
|
|
83
|
+
/**
|
|
84
|
+
* @title 迅雷链接(宽松匹配)
|
|
85
|
+
*/
|
|
86
|
+
declare const regThunderEasy: RegExp;
|
|
87
|
+
/**
|
|
88
|
+
* @title ed2k链接(宽松匹配)
|
|
89
|
+
*/
|
|
90
|
+
declare const regEd2kEasy: RegExp;
|
|
91
|
+
/**
|
|
92
|
+
* @title 磁力链接(宽松匹配)
|
|
93
|
+
*/
|
|
94
|
+
declare const regMagnetEasy: RegExp;
|
|
95
|
+
/**
|
|
96
|
+
* @title 子网掩码(不包含 0.0.0.0)
|
|
97
|
+
*/
|
|
98
|
+
declare const regSubnetMask: RegExp;
|
|
99
|
+
/**
|
|
100
|
+
* @title linux"隐藏文件"路径
|
|
101
|
+
*/
|
|
102
|
+
declare const regLinuxHideFilePath: RegExp;
|
|
103
|
+
/**
|
|
104
|
+
* @title linux文件路径
|
|
105
|
+
*/
|
|
106
|
+
declare const regLinuxFilePath: RegExp;
|
|
107
|
+
/**
|
|
108
|
+
* @title linux文件夹路径
|
|
109
|
+
*/
|
|
110
|
+
declare const regLinuxFolderPath: RegExp;
|
|
111
|
+
/**
|
|
112
|
+
* @title window下"文件"路径
|
|
113
|
+
*/
|
|
114
|
+
declare const regWindowsFilePath: RegExp;
|
|
115
|
+
/**
|
|
116
|
+
* @title window"文件夹"路径
|
|
117
|
+
*/
|
|
118
|
+
declare const regWindowsFolderPath: RegExp;
|
|
119
|
+
/**
|
|
120
|
+
* @title 16进制颜色
|
|
121
|
+
*/
|
|
122
|
+
declare const regHexadecimalColor: RegExp;
|
|
123
|
+
/**
|
|
124
|
+
* @title html注释
|
|
125
|
+
*/
|
|
126
|
+
declare const regHtmlComments: RegExp;
|
|
127
|
+
/**
|
|
128
|
+
* @title html标签(宽松匹配)
|
|
129
|
+
*/
|
|
130
|
+
declare const regHtmlTags: RegExp;
|
|
131
|
+
/**
|
|
132
|
+
* @title md5格式(32位)
|
|
133
|
+
*/
|
|
134
|
+
declare const regMD5: RegExp;
|
|
135
|
+
/**
|
|
136
|
+
* @title GUID/UUID
|
|
137
|
+
*/
|
|
138
|
+
declare const regUUID: RegExp;
|
|
139
|
+
/**
|
|
140
|
+
* @title 版本号(version)格式必须为X.Y.Z
|
|
141
|
+
* @desc https://semver.org/lang/zh-CN/
|
|
142
|
+
*/
|
|
143
|
+
declare const regSemVer: RegExp;
|
|
144
|
+
/**
|
|
145
|
+
* @title 视频(video)链接地址(视频格式可按需增删)
|
|
146
|
+
*/
|
|
147
|
+
declare const regVideoUri: RegExp;
|
|
148
|
+
/**
|
|
149
|
+
* @title 图片(image)链接地址(图片格式可按需增删)
|
|
150
|
+
*/
|
|
151
|
+
declare const regImageUri: RegExp;
|
|
152
|
+
/**
|
|
153
|
+
* @title base64格式
|
|
154
|
+
*/
|
|
155
|
+
declare const regBase64: RegExp;
|
|
156
|
+
/**
|
|
157
|
+
* @title 24小时制时间(HH:mm:ss)
|
|
158
|
+
*/
|
|
159
|
+
declare const regHHmmss: RegExp;
|
|
160
|
+
/**
|
|
161
|
+
* @title 12小时制时间(hh:mm:ss)
|
|
162
|
+
*/
|
|
163
|
+
declare const reghhmmss: RegExp;
|
|
164
|
+
/**
|
|
165
|
+
* @title 日期(宽松)
|
|
166
|
+
*/
|
|
167
|
+
declare const regDateEasy: RegExp;
|
|
168
|
+
/**
|
|
169
|
+
* @title 日期(严谨, 支持闰年判断)
|
|
170
|
+
*/
|
|
171
|
+
declare const regDate: RegExp;
|
|
172
|
+
/**
|
|
173
|
+
* @title 可以被moment转化成功的时间 YYYYMMDD HH:mm:ss
|
|
174
|
+
*/
|
|
175
|
+
declare const regDateMoment: RegExp;
|
|
176
|
+
/**
|
|
177
|
+
* @title email(邮箱)
|
|
178
|
+
*/
|
|
179
|
+
declare const regEmail: RegExp;
|
|
180
|
+
/**
|
|
181
|
+
* @title email(支持中文邮箱)
|
|
182
|
+
*/
|
|
183
|
+
declare const regEmailEasy: RegExp;
|
|
184
|
+
/**
|
|
185
|
+
* @title 匹配连续重复的字符
|
|
186
|
+
*/
|
|
187
|
+
declare const regRepeat: RegExp;
|
|
188
|
+
/**
|
|
189
|
+
* @title ASCII码表中的全部的特殊字符
|
|
190
|
+
*/
|
|
191
|
+
declare const regASCII: RegExp;
|
|
192
|
+
/**
|
|
193
|
+
* @title 中文/汉字
|
|
194
|
+
* // rule: /^[\u4E00-\u9FA5]+$/
|
|
195
|
+
*/
|
|
196
|
+
declare const regChineseCharacters: RegExp;
|
|
197
|
+
/**
|
|
198
|
+
* @title 匹配中文汉字和中文标点
|
|
199
|
+
*/
|
|
200
|
+
declare const regChineseCharacterAndPoint: RegExp;
|
|
201
|
+
/**
|
|
202
|
+
* @title 中文和数字
|
|
203
|
+
*/
|
|
204
|
+
declare const regChineseAndNumber: RegExp;
|
|
205
|
+
/**
|
|
206
|
+
* @title 数字和英文字母组成,并且同时含有数字和英文字母
|
|
207
|
+
*/
|
|
208
|
+
declare const regLetterAndNumber: RegExp;
|
|
209
|
+
/**
|
|
210
|
+
* @title 数字和字母组成
|
|
211
|
+
*/
|
|
212
|
+
declare const regLetterOrNumber: RegExp;
|
|
213
|
+
/**
|
|
214
|
+
* @title 只包含数字
|
|
215
|
+
*/
|
|
216
|
+
declare const regOnlyNumber: RegExp;
|
|
217
|
+
/**
|
|
218
|
+
* @title 英文字母
|
|
219
|
+
*/
|
|
220
|
+
declare const regLetters: RegExp;
|
|
221
|
+
/**
|
|
222
|
+
* @title 小写英文字母组成
|
|
223
|
+
*/
|
|
224
|
+
declare const regLettersLower: RegExp;
|
|
225
|
+
/**
|
|
226
|
+
* @title 大写英文字母
|
|
227
|
+
*/
|
|
228
|
+
declare const regLettersUpper: RegExp;
|
|
229
|
+
/**
|
|
230
|
+
* @title 不能包含字母
|
|
231
|
+
*/
|
|
232
|
+
declare const regNotLetter: RegExp;
|
|
233
|
+
/**
|
|
234
|
+
* @title 小数
|
|
235
|
+
*/
|
|
236
|
+
declare const regDecimal: RegExp;
|
|
237
|
+
/**
|
|
238
|
+
* @title 正整数,不包含0
|
|
239
|
+
*/
|
|
240
|
+
declare const regIntegerPositive: RegExp;
|
|
241
|
+
/**
|
|
242
|
+
* @title 负整数,不包含0
|
|
243
|
+
*/
|
|
244
|
+
declare const regIntegerNegative: RegExp;
|
|
245
|
+
/**
|
|
246
|
+
* @title 整数
|
|
247
|
+
*/
|
|
248
|
+
declare const regInteger: RegExp;
|
|
249
|
+
/**
|
|
250
|
+
* @title 浮点数
|
|
251
|
+
* // allow "1.23", allow "-0.1", allow "0.00", ban "-0.00", ban "2.", allow "2.0"
|
|
252
|
+
*/
|
|
253
|
+
declare const regFloatEasy: RegExp;
|
|
254
|
+
/**
|
|
255
|
+
* @title 浮点数(严格)
|
|
256
|
+
* // allow "1.23", allow "-0.1", ban "2.", ban "2.0"
|
|
257
|
+
*/
|
|
258
|
+
declare const regFloat: RegExp;
|
|
259
|
+
/**
|
|
260
|
+
* @title 车牌号(新能源)
|
|
261
|
+
*/
|
|
262
|
+
declare const regLicensePlateNE: RegExp;
|
|
263
|
+
/**
|
|
264
|
+
* @title 车牌号(非新能源)
|
|
265
|
+
*/
|
|
266
|
+
declare const regLicensePlateLegacy: RegExp;
|
|
267
|
+
/**
|
|
268
|
+
* @title 车牌号(新能源+非新能源)
|
|
269
|
+
*/
|
|
270
|
+
declare const regLicensePlateAll: RegExp;
|
|
271
|
+
/**
|
|
272
|
+
* @title 身份证号(1代,15位数字)
|
|
273
|
+
*/
|
|
274
|
+
declare const regIdentityCardV1: RegExp;
|
|
275
|
+
/**
|
|
276
|
+
* @title 身份证号(2代,18位数字),最后一位是校验位,可能为数字或字符X
|
|
277
|
+
*/
|
|
278
|
+
declare const regIdentityCardV2: RegExp;
|
|
279
|
+
/**
|
|
280
|
+
* @title 身份证号, 支持1/2代(15位/18位数字)
|
|
281
|
+
*/
|
|
282
|
+
declare const regIdentityCard: RegExp;
|
|
283
|
+
/**
|
|
284
|
+
* @title 香港身份证
|
|
285
|
+
*/
|
|
286
|
+
declare const regIdentityCardHK: RegExp;
|
|
287
|
+
/**
|
|
288
|
+
* @title 澳门身份证
|
|
289
|
+
* @desc https://baike.baidu.com/item/%E6%BE%B3%E9%97%A8%E5%B1%85%E6%B0%91%E8%BA%AB%E4%BB%BD%E8%AF%81/12509098?fr=aladdin#5
|
|
290
|
+
*/
|
|
291
|
+
declare const regIdentityCardMO: RegExp;
|
|
292
|
+
/**
|
|
293
|
+
* @title 台湾身份证
|
|
294
|
+
*/
|
|
295
|
+
declare const regIdentityCardTWN: RegExp;
|
|
296
|
+
/**
|
|
297
|
+
* @title 护照(包含香港、澳门)
|
|
298
|
+
*/
|
|
299
|
+
declare const regPassport: RegExp;
|
|
300
|
+
/**
|
|
301
|
+
* @title 银行卡号(10到30位, 覆盖对公/私账户, 参考[微信支付](https://pay.weixin.qq.com/wiki/doc/api/xiaowei.php?chapter=22_1))
|
|
302
|
+
*/
|
|
303
|
+
declare const regBankCardNo: RegExp;
|
|
304
|
+
/**
|
|
305
|
+
* @title 中国的所有省
|
|
306
|
+
*/
|
|
307
|
+
declare const regChineseProvince: RegExp;
|
|
308
|
+
/**
|
|
309
|
+
* @title 手机号(mobile phone)中国(严谨), 根据工信部2019年最新公布的手机号段
|
|
310
|
+
*/
|
|
311
|
+
declare const regMobile: RegExp;
|
|
312
|
+
/**
|
|
313
|
+
* @title 手机号(mobile phone)中国(宽松), 只要是13,14,15,16,17,18,19开头即可
|
|
314
|
+
*/
|
|
315
|
+
declare const regMobileEasy: RegExp;
|
|
316
|
+
/**
|
|
317
|
+
* @title 手机号(mobile phone)中国(最宽松), 只要是1开头即可, 如果你的手机号是用来接收短信, 优先建议选择这一条
|
|
318
|
+
*/
|
|
319
|
+
declare const regMobileEasiest: RegExp;
|
|
320
|
+
/**
|
|
321
|
+
* @title 座机(tel phone)电话(国内),如: 0341-86091234
|
|
322
|
+
*/
|
|
323
|
+
declare const regTelephone: RegExp;
|
|
324
|
+
/**
|
|
325
|
+
* @title 火车车次
|
|
326
|
+
*/
|
|
327
|
+
declare const regTrainNumber: RegExp;
|
|
328
|
+
/**
|
|
329
|
+
* @title 股票代码(A股)
|
|
330
|
+
*/
|
|
331
|
+
declare const regStockCodeA: RegExp;
|
|
332
|
+
/**
|
|
333
|
+
* @title 手机机身码(IMEI)
|
|
334
|
+
*/
|
|
335
|
+
declare const regIMEI: RegExp;
|
|
336
|
+
/**
|
|
337
|
+
* @title 统一社会信用代码
|
|
338
|
+
*/
|
|
339
|
+
declare const regCreditCode: RegExp;
|
|
340
|
+
/**
|
|
341
|
+
* @title 统一社会信用代码(宽松匹配)(15位/18位/20位数字/字母)
|
|
342
|
+
*/
|
|
343
|
+
declare const regCreditCodeEasy: RegExp;
|
|
344
|
+
/**
|
|
345
|
+
* @title 邮政编码(中国)
|
|
346
|
+
*/
|
|
347
|
+
declare const regPostalCode: RegExp;
|
|
348
|
+
/**
|
|
349
|
+
* @title 数字/货币金额(支持负数、千分位分隔符)
|
|
350
|
+
*/
|
|
351
|
+
declare const regAmount: RegExp;
|
|
352
|
+
/**
|
|
353
|
+
* @title 数字/货币金额 (只支持正数、不支持校验千分位分隔符)
|
|
354
|
+
*/
|
|
355
|
+
declare const regAmountEasy: RegExp;
|
|
356
|
+
/**
|
|
357
|
+
* @title 大于等于0, 小于等于150, 支持小数位出现5, 如145.5, 用于判断考卷分数
|
|
358
|
+
*/
|
|
359
|
+
declare const regExamScore: RegExp;
|
|
360
|
+
/**
|
|
361
|
+
* @title 中文姓名
|
|
362
|
+
*/
|
|
363
|
+
declare const regChineseName: RegExp;
|
|
364
|
+
/**
|
|
365
|
+
* @title 英文姓名
|
|
366
|
+
*/
|
|
367
|
+
declare const regEnglishName: RegExp;
|
|
368
|
+
/**
|
|
369
|
+
* @title 用户名校验,4到16位(字母,数字,下划线,减号)
|
|
370
|
+
*/
|
|
371
|
+
declare const regValidAccountV1: RegExp;
|
|
372
|
+
/**
|
|
373
|
+
* @title 帐号是否合法 (字母开头,允许5-16字节,允许字母数字下划线组合)
|
|
374
|
+
*/
|
|
375
|
+
declare const regValidAccountV2: RegExp;
|
|
376
|
+
/**
|
|
377
|
+
* @title qq号格式正确
|
|
378
|
+
*/
|
|
379
|
+
declare const regQQ: RegExp;
|
|
380
|
+
/**
|
|
381
|
+
* @title 微信号(wx),6至20位,以字母开头,字母,数字,减号,下划线
|
|
382
|
+
*/
|
|
383
|
+
declare const regWechatID: RegExp;
|
|
384
|
+
/**
|
|
385
|
+
* @title 大写字母,小写字母,数字,特殊符号 `@#$%^&*`~()-+=` 中任意3项密码
|
|
386
|
+
*/
|
|
387
|
+
declare const regPasswordV1: RegExp;
|
|
388
|
+
/**
|
|
389
|
+
* @title 密码强度校验,最少6位,包括至少1个大写字母,1个小写字母,1个数字,1个特殊字符
|
|
390
|
+
*/
|
|
391
|
+
declare const regPasswordV2: RegExp;
|
|
392
|
+
|
|
393
|
+
export { assert, callString, noop, randomDate, randomHexColor, randomRange, randomRgbColor, randomUUID, regASCII, regAmount, regAmountEasy, regBankCardNo, regBase64, regChineseAndNumber, regChineseCharacterAndPoint, regChineseCharacters, regChineseName, regChineseProvince, regCreditCode, regCreditCodeEasy, regDate, regDateEasy, regDateMoment, regDecimal, regDomain, regEd2kEasy, regEmail, regEmailEasy, regEnglishName, regExamScore, regFloat, regFloatEasy, regHHmmss, regHexadecimalColor, regHtmlComments, regHtmlTags, regIMEI, regIPV4, regIPV6, regIdentityCard, regIdentityCardHK, regIdentityCardMO, regIdentityCardTWN, regIdentityCardV1, regIdentityCardV2, regImageUri, regInteger, regIntegerNegative, regIntegerPositive, regJAVAPackageName, regLetterAndNumber, regLetterOrNumber, regLetters, regLettersLower, regLettersUpper, regLicensePlateAll, regLicensePlateLegacy, regLicensePlateNE, regLinuxFilePath, regLinuxFolderPath, regLinuxHideFilePath, regMD5, regMacAddr, regMagnetEasy, regMobile, regMobileEasiest, regMobileEasy, regNotLetter, regOnlyNumber, regPassport, regPasswordV1, regPasswordV2, regPostalCode, regQQ, regRepeat, regSemVer, regStockCodeA, regSubnetMask, regTelephone, regThunderEasy, regTrainNumber, regUUID, regUri, regUriAndPort, regValidAccountV1, regValidAccountV2, regVideoUri, regWechatID, regWindowsFilePath, regWindowsFolderPath, reghhmmss };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const assert = (condition, message) => {
|
|
2
|
+
if (!condition) {
|
|
3
|
+
throw new Error(message);
|
|
4
|
+
}
|
|
5
|
+
};
|
|
6
|
+
function callString(target, mode) {
|
|
7
|
+
const result = Object.prototype.toString.call(target);
|
|
8
|
+
if (typeof mode === "undefined") {
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
const typeStr = result.slice(8, -1);
|
|
12
|
+
if (mode === 0) {
|
|
13
|
+
return typeStr;
|
|
14
|
+
}
|
|
15
|
+
if (mode === -1) {
|
|
16
|
+
return typeStr.toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
return typeStr.toUpperCase();
|
|
19
|
+
}
|
|
20
|
+
const noop = () => {
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function randomRange(min, max) {
|
|
24
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
25
|
+
}
|
|
26
|
+
function randomRgbColor(raw = false) {
|
|
27
|
+
const [r, g, b] = Array(3).fill(0).map(() => Math.random()).map((item) => raw ? item * 255 : parseInt(`${item * 255}`, 10));
|
|
28
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
29
|
+
}
|
|
30
|
+
function randomHexColor() {
|
|
31
|
+
return `#${(Math.random() * 1048575 * 1e6).toString(16).slice(0, 6)}`;
|
|
32
|
+
}
|
|
33
|
+
function randomDate(start = "1999/01/1", end) {
|
|
34
|
+
const date = new Date();
|
|
35
|
+
const splitTag = start.includes("/") ? "/" : "-";
|
|
36
|
+
const [endY, endM, endD] = (end || "").split(splitTag);
|
|
37
|
+
const y = +endY || date.getFullYear();
|
|
38
|
+
const m = +endM || date.getMonth() + 1;
|
|
39
|
+
const d = +endD || date.getDate();
|
|
40
|
+
const [startY, startM, startD] = start.split("/");
|
|
41
|
+
const startDate = new Date(+startY, +startM, +startD).getTime();
|
|
42
|
+
const endDate = new Date(y, m, d).getTime();
|
|
43
|
+
return new Date(startDate + Math.round(Math.random() * (endDate - startDate)));
|
|
44
|
+
}
|
|
45
|
+
function randomUUID() {
|
|
46
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
47
|
+
const r = Math.random() * 16 | 0;
|
|
48
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
49
|
+
return v.toString(16);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const regUriAndPort = /^((ht|f)tps?:\/\/)?[\w-]+(\.[\w-]+)+:\d{1,5}\/?$/;
|
|
54
|
+
const regUri = /^(((ht|f)tps?):\/\/)?([^!@#$%^&*?.\s-]([^!@#$%^&*?.\s]{0,63}[^!@#$%^&*?.\s])?\.)+[a-z]{2,6}\/?/;
|
|
55
|
+
const regDomain = /^([0-9a-zA-Z-]{1,}\.)+([a-zA-Z]{2,})$/;
|
|
56
|
+
const regIPV4 = /^((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(?::(?:[0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$/;
|
|
57
|
+
const regIPV6 = /(^(?:(?:(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$)|(^\[(?:(?:(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))\](?::(?:[0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$)/i;
|
|
58
|
+
const regJAVAPackageName = /^([a-zA-Z_]\w*)+([.][a-zA-Z_]\w*)+$/;
|
|
59
|
+
const regMacAddr = /^((([a-f0-9]{2}:){5})|(([a-f0-9]{2}-){5}))[a-f0-9]{2}$/i;
|
|
60
|
+
const regThunderEasy = /^thunderx?:\/\/[a-zA-Z\d]+=$/;
|
|
61
|
+
const regEd2kEasy = /^ed2k:\/\/\|file\|.+\|\/$/;
|
|
62
|
+
const regMagnetEasy = /^magnet:\?xt=urn:btih:[0-9a-fA-F]{40,}.*$/;
|
|
63
|
+
const regSubnetMask = /^(254|252|248|240|224|192|128)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(255|254|252|248|240|224|192|128|0)$/;
|
|
64
|
+
const regLinuxHideFilePath = /^\/(?:[^/]+\/)*\.[^/]*/;
|
|
65
|
+
const regLinuxFilePath = /^\/(?:[^/]+\/)*[^/]+$/;
|
|
66
|
+
const regLinuxFolderPath = /^\/(?:[^/]+\/)*$/;
|
|
67
|
+
const regWindowsFilePath = /^[a-zA-Z]:\\(?:\w+\\)*\w+\.\w+$/;
|
|
68
|
+
const regWindowsFolderPath = /^[a-zA-Z]:\\(?:\w+\\?)*$/;
|
|
69
|
+
const regHexadecimalColor = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
|
|
70
|
+
const regHtmlComments = /<!--[\s\S]*?-->/g;
|
|
71
|
+
const regHtmlTags = /<(\w+)[^>]*>(.*?<\/\1>)?/;
|
|
72
|
+
const regMD5 = /^[a-fA-F0-9]{32}$/;
|
|
73
|
+
const regUUID = /^[a-f\d]{4}(?:[a-f\d]{4}-){4}[a-f\d]{12}$/i;
|
|
74
|
+
const regSemVer = /^\d+(?:\.\d+){2}$/;
|
|
75
|
+
const regVideoUri = /^https?:\/\/(.+\/)+.+(\.(swf|avi|flv|mpg|rm|mov|wav|asf|3gp|mkv|rmvb|mp4))$/i;
|
|
76
|
+
const regImageUri = /^https?:\/\/(.+\/)+.+(\.(gif|png|jpg|jpeg|webp|svg|psd|bmp|tif))$/i;
|
|
77
|
+
const regBase64 = /^\s*data:(?:[a-z]+\/[a-z0-9-+.]+(?:;[a-z-]+=[a-z0-9-]+)?)?(?:;base64)?,([a-z0-9!$&',()*+;=\-._~:@/?%\s]*?)\s*$/i;
|
|
78
|
+
const regHHmmss = /^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/;
|
|
79
|
+
const reghhmmss = /^(?:1[0-2]|0?[1-9]):[0-5]\d:[0-5]\d$/;
|
|
80
|
+
const regDateEasy = /^\d{1,4}(-)(1[0-2]|0?[1-9])\1(0?[1-9]|[1-2]\d|30|31)$/;
|
|
81
|
+
const regDate = /^(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$/;
|
|
82
|
+
const regDateMoment = /^\d{4}([/:-\S])(1[0-2]|0?[1-9])\1(0?[1-9]|[1-2]\d|30|31) (?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/;
|
|
83
|
+
const regEmail = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
84
|
+
const regEmailEasy = /^[A-Za-z0-9\u4E00-\u9FA5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
|
|
85
|
+
const regRepeat = /(.)\1+/;
|
|
86
|
+
const regASCII = /[\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]+/;
|
|
87
|
+
const regChineseCharacters = /^(?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])+$/;
|
|
88
|
+
const regChineseCharacterAndPoint = /[\u4E00-\u9FA5|\u3002|\uFF1F|\uFF01|\uFF0C|\u3001|\uFF1B|\uFF1A|\u201C|\u201D|\u2018|\u2019|\uFF08|\uFF09|\u300A|\u300B|\u3008|\u3009|\u3010|\u3011|\u300E|\u300F|\u300C|\u300D|\uFE43|\uFE44|\u3014|\u3015|\u2026|\u2014|\uFF5E|\uFE4F|\uFFE5]/;
|
|
89
|
+
const regChineseAndNumber = /^((?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])|(\d))+$/;
|
|
90
|
+
const regLetterAndNumber = /^(?=.*[a-zA-Z])(?=.*\d).+$/;
|
|
91
|
+
const regLetterOrNumber = /^[A-Za-z0-9]+$/;
|
|
92
|
+
const regOnlyNumber = /^\d+$/;
|
|
93
|
+
const regLetters = /^[a-zA-Z]+$/;
|
|
94
|
+
const regLettersLower = /^[a-z]+$/;
|
|
95
|
+
const regLettersUpper = /^[A-Z]+$/;
|
|
96
|
+
const regNotLetter = /^[^A-Za-z]*$/;
|
|
97
|
+
const regDecimal = /^\d+\.\d+$/;
|
|
98
|
+
const regIntegerPositive = /^\+?[1-9]\d*$/;
|
|
99
|
+
const regIntegerNegative = /^-[1-9]\d*$/;
|
|
100
|
+
const regInteger = /^(?:0|(?:-?[1-9]\d*))$/;
|
|
101
|
+
const regFloatEasy = /^(-?[1-9]\d*\.\d+|-?0\.\d*[1-9]\d*|0\.0+)$/;
|
|
102
|
+
const regFloat = /^(-?[1-9]\d*\.\d+|-?0\.\d*[1-9])$/;
|
|
103
|
+
const regLicensePlateNE = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z](?:((\d{5}[A-HJK])|([A-HJK][A-HJ-NP-Z0-9][0-9]{4}))|[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳])$/;
|
|
104
|
+
const regLicensePlateLegacy = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]$/;
|
|
105
|
+
const regLicensePlateAll = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/;
|
|
106
|
+
const regIdentityCardV1 = /^[1-9]\d{7}(?:0\d|10|11|12)(?:0[1-9]|[1-2][\d]|30|31)\d{3}$/;
|
|
107
|
+
const regIdentityCardV2 = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/;
|
|
108
|
+
const regIdentityCard = /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/;
|
|
109
|
+
const regIdentityCardHK = /^[a-zA-Z]\d{6}\([\dA]\)$/;
|
|
110
|
+
const regIdentityCardMO = /^[1|5|7]\d{6}\(\d\)$/;
|
|
111
|
+
const regIdentityCardTWN = /^[a-zA-Z][0-9]{9}$/;
|
|
112
|
+
const regPassport = /(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/;
|
|
113
|
+
const regBankCardNo = /^[1-9]\d{9,29}$/;
|
|
114
|
+
const regChineseProvince = /^浙江|上海|北京|天津|重庆|黑龙江|吉林|辽宁|内蒙古|河北|新疆|甘肃|青海|陕西|宁夏|河南|山东|山西|安徽|湖北|湖南|江苏|四川|贵州|云南|广西|西藏|江西|广东|福建|台湾|海南|香港|澳门$/;
|
|
115
|
+
const regMobile = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/;
|
|
116
|
+
const regMobileEasy = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/;
|
|
117
|
+
const regMobileEasiest = /^(?:(?:\+|00)86)?1\d{10}$/;
|
|
118
|
+
const regTelephone = /^(?:(?:\d{3}-)?\d{8}|^(?:\d{4}-)?\d{7,8})(?:-\d+)?$/;
|
|
119
|
+
const regTrainNumber = /^[GCDZTSPKXLY1-9]\d{1,4}$/;
|
|
120
|
+
const regStockCodeA = /^(s[hz]|S[HZ])(000[\d]{3}|002[\d]{3}|300[\d]{3}|600[\d]{3}|60[\d]{4})$/;
|
|
121
|
+
const regIMEI = /^\d{15,17}$/;
|
|
122
|
+
const regCreditCode = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
|
|
123
|
+
const regCreditCodeEasy = /^(([0-9A-Za-z]{15})|([0-9A-Za-z]{18})|([0-9A-Za-z]{20}))$/;
|
|
124
|
+
const regPostalCode = /^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/;
|
|
125
|
+
const regAmount = /^-?\d+(,\d{3})*(\.\d{1,2})?$/;
|
|
126
|
+
const regAmountEasy = /(?:^[1-9]([0-9]+)?(?:\.[0-9]{1,2})?$)|(?:^(?:0)$)|(?:^[0-9]\.[0-9](?:[0-9])?$)/;
|
|
127
|
+
const regExamScore = /^150$|^(?:\d|[1-9]\d|1[0-4]\d)(?:\.5)?$/;
|
|
128
|
+
const regChineseName = /^(?:[\u4E00-\u9FA5·]{2,16})$/;
|
|
129
|
+
const regEnglishName = /(^[a-zA-Z][a-zA-Z\s]{0,20}[a-zA-Z]$)/;
|
|
130
|
+
const regValidAccountV1 = /^[a-zA-Z0-9_-]{4,16}$/;
|
|
131
|
+
const regValidAccountV2 = /^[a-zA-Z]\w{4,15}$/;
|
|
132
|
+
const regQQ = /^[1-9][0-9]{4,10}$/;
|
|
133
|
+
const regWechatID = /^[a-zA-Z][-_a-zA-Z0-9]{5,19}$/;
|
|
134
|
+
const regPasswordV1 = /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]/;
|
|
135
|
+
const regPasswordV2 = /^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*? ])\S*$/;
|
|
136
|
+
|
|
137
|
+
export { assert, callString, noop, randomDate, randomHexColor, randomRange, randomRgbColor, randomUUID, regASCII, regAmount, regAmountEasy, regBankCardNo, regBase64, regChineseAndNumber, regChineseCharacterAndPoint, regChineseCharacters, regChineseName, regChineseProvince, regCreditCode, regCreditCodeEasy, regDate, regDateEasy, regDateMoment, regDecimal, regDomain, regEd2kEasy, regEmail, regEmailEasy, regEnglishName, regExamScore, regFloat, regFloatEasy, regHHmmss, regHexadecimalColor, regHtmlComments, regHtmlTags, regIMEI, regIPV4, regIPV6, regIdentityCard, regIdentityCardHK, regIdentityCardMO, regIdentityCardTWN, regIdentityCardV1, regIdentityCardV2, regImageUri, regInteger, regIntegerNegative, regIntegerPositive, regJAVAPackageName, regLetterAndNumber, regLetterOrNumber, regLetters, regLettersLower, regLettersUpper, regLicensePlateAll, regLicensePlateLegacy, regLicensePlateNE, regLinuxFilePath, regLinuxFolderPath, regLinuxHideFilePath, regMD5, regMacAddr, regMagnetEasy, regMobile, regMobileEasiest, regMobileEasy, regNotLetter, regOnlyNumber, regPassport, regPasswordV1, regPasswordV2, regPostalCode, regQQ, regRepeat, regSemVer, regStockCodeA, regSubnetMask, regTelephone, regThunderEasy, regTrainNumber, regUUID, regUri, regUriAndPort, regValidAccountV1, regValidAccountV2, regVideoUri, regWechatID, regWindowsFilePath, regWindowsFolderPath, reghhmmss };
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@odinlin/utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Opinionated collection of common JavaScript / TypeScript utils by @odinlin",
|
|
5
|
+
"author": "odinlin <topazur@163.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/topazur/utils#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/topazur/utils.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/topazur/utils/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"utils"
|
|
17
|
+
],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"require": "./dist/index.cjs",
|
|
23
|
+
"import": "./dist/index.mjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"main": "dist/index.cjs",
|
|
27
|
+
"module": "dist/index.mjs",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"*.d.ts"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"prepublishOnly": "nr build",
|
|
35
|
+
"start": "esno src/index.ts",
|
|
36
|
+
"build": "rollup -c",
|
|
37
|
+
"dev": "nr build --watch",
|
|
38
|
+
"build:pkgroll": "pkgroll --minify",
|
|
39
|
+
"dev:pkgroll": "pkgroll --watch",
|
|
40
|
+
"release": "bumpp --commit --push --tag && npm publish",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"test": "vitest",
|
|
43
|
+
"lint": "eslint --fix --ext .ts ."
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@antfu/eslint-config": "^0.27.0",
|
|
47
|
+
"@rollup/plugin-alias": "^3.1.9",
|
|
48
|
+
"@rollup/plugin-commonjs": "^22.0.2",
|
|
49
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
50
|
+
"@rollup/plugin-node-resolve": "^14.1.0",
|
|
51
|
+
"@types/node": "^18.7.18",
|
|
52
|
+
"bumpp": "^8.2.1",
|
|
53
|
+
"eslint": "^8.23.1",
|
|
54
|
+
"esno": "^0.16.3",
|
|
55
|
+
"pkgroll": "^1.4.0",
|
|
56
|
+
"rollup": "^2.79.0",
|
|
57
|
+
"rollup-plugin-dts": "^4.2.2",
|
|
58
|
+
"rollup-plugin-esbuild": "^4.10.1",
|
|
59
|
+
"typescript": "^4.8.3",
|
|
60
|
+
"vitest": "^0.23.4"
|
|
61
|
+
},
|
|
62
|
+
"eslintIgnore": [
|
|
63
|
+
"dist",
|
|
64
|
+
"node_modules",
|
|
65
|
+
"*.d.ts"
|
|
66
|
+
],
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public",
|
|
69
|
+
"registry": "https://registry.npmjs.org/"
|
|
70
|
+
}
|
|
71
|
+
}
|