validator-string 13.15.36
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 +20 -0
- package/README.md +269 -0
- package/es/index.js +218 -0
- package/es/lib/alpha.js +151 -0
- package/es/lib/blacklist.js +5 -0
- package/es/lib/contains.js +15 -0
- package/es/lib/equals.js +5 -0
- package/es/lib/escape.js +5 -0
- package/es/lib/isAbaRouting.js +15 -0
- package/es/lib/isAfter.js +10 -0
- package/es/lib/isAlpha.js +23 -0
- package/es/lib/isAlphanumeric.js +23 -0
- package/es/lib/isAscii.js +10 -0
- package/es/lib/isBIC.js +16 -0
- package/es/lib/isBase32.js +15 -0
- package/es/lib/isBase58.js +8 -0
- package/es/lib/isBase64.js +23 -0
- package/es/lib/isBefore.js +10 -0
- package/es/lib/isBoolean.js +15 -0
- package/es/lib/isBtcAddress.js +7 -0
- package/es/lib/isByteLength.js +19 -0
- package/es/lib/isCreditCard.js +43 -0
- package/es/lib/isCurrency.js +74 -0
- package/es/lib/isDataURI.js +31 -0
- package/es/lib/isDate.js +93 -0
- package/es/lib/isDecimal.js +22 -0
- package/es/lib/isDivisibleBy.js +6 -0
- package/es/lib/isEAN.js +70 -0
- package/es/lib/isEmail.js +165 -0
- package/es/lib/isEmpty.js +10 -0
- package/es/lib/isEthereumAddress.js +6 -0
- package/es/lib/isFQDN.js +67 -0
- package/es/lib/isFloat.js +14 -0
- package/es/lib/isFullWidth.js +6 -0
- package/es/lib/isHSL.js +13 -0
- package/es/lib/isHalfWidth.js +6 -0
- package/es/lib/isHash.js +21 -0
- package/es/lib/isHexColor.js +13 -0
- package/es/lib/isHexadecimal.js +6 -0
- package/es/lib/isIBAN.js +171 -0
- package/es/lib/isIMEI.js +40 -0
- package/es/lib/isIP.js +58 -0
- package/es/lib/isIPRange.js +41 -0
- package/es/lib/isISBN.js +47 -0
- package/es/lib/isISIN.js +55 -0
- package/es/lib/isISO15924.js +9 -0
- package/es/lib/isISO31661Alpha2.js +21 -0
- package/es/lib/isISO31661Alpha3.js +20 -0
- package/es/lib/isISO31661Numeric.js +8 -0
- package/es/lib/isISO4217.js +9 -0
- package/es/lib/isISO6346.js +28 -0
- package/es/lib/isISO6391.js +6 -0
- package/es/lib/isISO8601.js +42 -0
- package/es/lib/isISRC.js +8 -0
- package/es/lib/isISSN.js +19 -0
- package/es/lib/isIdentityCard.js +407 -0
- package/es/lib/isIn.js +23 -0
- package/es/lib/isInt.js +19 -0
- package/es/lib/isJSON.js +26 -0
- package/es/lib/isJWT.js +15 -0
- package/es/lib/isLatLong.js +21 -0
- package/es/lib/isLength.js +27 -0
- package/es/lib/isLicensePlate.js +58 -0
- package/es/lib/isLocale.js +107 -0
- package/es/lib/isLowercase.js +5 -0
- package/es/lib/isLuhnNumber.js +25 -0
- package/es/lib/isMACAddress.js +36 -0
- package/es/lib/isMD5.js +6 -0
- package/es/lib/isMagnetURI.js +9 -0
- package/es/lib/isMailtoURI.js +75 -0
- package/es/lib/isMimeType.js +40 -0
- package/es/lib/isMobilePhone.js +212 -0
- package/es/lib/isMongoId.js +6 -0
- package/es/lib/isMultibyte.js +10 -0
- package/es/lib/isNumeric.js +10 -0
- package/es/lib/isOctal.js +6 -0
- package/es/lib/isPassportNumber.js +145 -0
- package/es/lib/isPort.js +8 -0
- package/es/lib/isPostalCode.js +100 -0
- package/es/lib/isRFC3339.js +21 -0
- package/es/lib/isRgbColor.js +34 -0
- package/es/lib/isSemVer.js +14 -0
- package/es/lib/isSlug.js +6 -0
- package/es/lib/isStrongPassword.js +90 -0
- package/es/lib/isSurrogatePair.js +6 -0
- package/es/lib/isTaxID.js +1407 -0
- package/es/lib/isTime.js +22 -0
- package/es/lib/isULID.js +5 -0
- package/es/lib/isURL.js +241 -0
- package/es/lib/isUUID.js +23 -0
- package/es/lib/isUppercase.js +5 -0
- package/es/lib/isVAT.js +264 -0
- package/es/lib/isVariableWidth.js +7 -0
- package/es/lib/isWhitelisted.js +10 -0
- package/es/lib/ltrim.js +7 -0
- package/es/lib/matches.js +8 -0
- package/es/lib/normalizeEmail.js +131 -0
- package/es/lib/rtrim.js +15 -0
- package/es/lib/stripLow.js +7 -0
- package/es/lib/toBoolean.js +8 -0
- package/es/lib/toDate.js +6 -0
- package/es/lib/toFloat.js +5 -0
- package/es/lib/toInt.js +5 -0
- package/es/lib/trim.js +5 -0
- package/es/lib/unescape.js +8 -0
- package/es/lib/util/algorithms.js +79 -0
- package/es/lib/util/assertString.js +4 -0
- package/es/lib/util/checkHost.js +12 -0
- package/es/lib/util/includesArray.js +6 -0
- package/es/lib/util/includesString.js +4 -0
- package/es/lib/util/merge.js +14 -0
- package/es/lib/util/multilineRegex.js +12 -0
- package/es/lib/util/nullUndefinedCheck.js +3 -0
- package/es/lib/util/toString.js +13 -0
- package/es/lib/util/typeOf.js +10 -0
- package/es/lib/whitelist.js +5 -0
- package/index.js +229 -0
- package/lib/alpha.js +157 -0
- package/lib/blacklist.js +14 -0
- package/lib/contains.js +24 -0
- package/lib/equals.js +14 -0
- package/lib/escape.js +14 -0
- package/lib/isAbaRouting.js +23 -0
- package/lib/isAfter.js +19 -0
- package/lib/isAlpha.js +31 -0
- package/lib/isAlphanumeric.js +31 -0
- package/lib/isAscii.js +18 -0
- package/lib/isBIC.js +24 -0
- package/lib/isBase32.js +24 -0
- package/lib/isBase58.js +16 -0
- package/lib/isBase64.js +32 -0
- package/lib/isBefore.js +19 -0
- package/lib/isBoolean.js +24 -0
- package/lib/isBtcAddress.js +16 -0
- package/lib/isByteLength.js +27 -0
- package/lib/isCreditCard.js +52 -0
- package/lib/isCurrency.js +83 -0
- package/lib/isDataURI.js +40 -0
- package/lib/isDate.js +102 -0
- package/lib/isDecimal.js +31 -0
- package/lib/isDivisibleBy.js +15 -0
- package/lib/isEAN.js +78 -0
- package/lib/isEmail.js +174 -0
- package/lib/isEmpty.js +19 -0
- package/lib/isEthereumAddress.js +15 -0
- package/lib/isFQDN.js +76 -0
- package/lib/isFloat.js +22 -0
- package/lib/isFullWidth.js +14 -0
- package/lib/isHSL.js +22 -0
- package/lib/isHalfWidth.js +14 -0
- package/lib/isHash.js +30 -0
- package/lib/isHexColor.js +22 -0
- package/lib/isHexadecimal.js +15 -0
- package/lib/isIBAN.js +178 -0
- package/lib/isIMEI.js +49 -0
- package/lib/isIP.js +67 -0
- package/lib/isIPRange.js +50 -0
- package/lib/isISBN.js +56 -0
- package/lib/isISIN.js +64 -0
- package/lib/isISO15924.js +16 -0
- package/lib/isISO31661Alpha2.js +28 -0
- package/lib/isISO31661Alpha3.js +28 -0
- package/lib/isISO31661Numeric.js +16 -0
- package/lib/isISO4217.js +16 -0
- package/lib/isISO6346.js +35 -0
- package/lib/isISO6391.js +15 -0
- package/lib/isISO8601.js +50 -0
- package/lib/isISRC.js +16 -0
- package/lib/isISSN.js +28 -0
- package/lib/isIdentityCard.js +416 -0
- package/lib/isIn.js +32 -0
- package/lib/isInt.js +28 -0
- package/lib/isJSON.js +35 -0
- package/lib/isJWT.js +24 -0
- package/lib/isLatLong.js +30 -0
- package/lib/isLength.js +35 -0
- package/lib/isLicensePlate.js +67 -0
- package/lib/isLocale.js +115 -0
- package/lib/isLowercase.js +14 -0
- package/lib/isLuhnNumber.js +34 -0
- package/lib/isMACAddress.js +45 -0
- package/lib/isMD5.js +15 -0
- package/lib/isMagnetURI.js +18 -0
- package/lib/isMailtoURI.js +84 -0
- package/lib/isMimeType.js +48 -0
- package/lib/isMobilePhone.js +219 -0
- package/lib/isMongoId.js +15 -0
- package/lib/isMultibyte.js +18 -0
- package/lib/isNumeric.js +19 -0
- package/lib/isOctal.js +15 -0
- package/lib/isPassportNumber.js +152 -0
- package/lib/isPort.js +17 -0
- package/lib/isPostalCode.js +107 -0
- package/lib/isRFC3339.js +29 -0
- package/lib/isRgbColor.js +42 -0
- package/lib/isSemVer.js +22 -0
- package/lib/isSlug.js +15 -0
- package/lib/isStrongPassword.js +99 -0
- package/lib/isSurrogatePair.js +15 -0
- package/lib/isTaxID.js +1417 -0
- package/lib/isTime.js +31 -0
- package/lib/isULID.js +14 -0
- package/lib/isURL.js +249 -0
- package/lib/isUUID.js +32 -0
- package/lib/isUppercase.js +14 -0
- package/lib/isVAT.js +274 -0
- package/lib/isVariableWidth.js +16 -0
- package/lib/isWhitelisted.js +19 -0
- package/lib/ltrim.js +16 -0
- package/lib/matches.js +17 -0
- package/lib/normalizeEmail.js +140 -0
- package/lib/rtrim.js +24 -0
- package/lib/stripLow.js +16 -0
- package/lib/toBoolean.js +17 -0
- package/lib/toDate.js +15 -0
- package/lib/toFloat.js +14 -0
- package/lib/toInt.js +14 -0
- package/lib/trim.js +14 -0
- package/lib/unescape.js +17 -0
- package/lib/util/algorithms.js +88 -0
- package/lib/util/assertString.js +12 -0
- package/lib/util/checkHost.js +20 -0
- package/lib/util/includesArray.js +14 -0
- package/lib/util/includesString.js +12 -0
- package/lib/util/merge.js +22 -0
- package/lib/util/multilineRegex.js +20 -0
- package/lib/util/nullUndefinedCheck.js +11 -0
- package/lib/util/toString.js +21 -0
- package/lib/util/typeOf.js +18 -0
- package/lib/whitelist.js +14 -0
- package/package.json +83 -0
- package/validator.js +5808 -0
- package/validator.min.js +23 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import assertString from './util/assertString';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reference:
|
|
5
|
+
* https://en.wikipedia.org/ -- Wikipedia
|
|
6
|
+
* https://docs.microsoft.com/en-us/microsoft-365/compliance/eu-passport-number -- EU Passport Number
|
|
7
|
+
* https://countrycode.org/ -- Country Codes
|
|
8
|
+
*/
|
|
9
|
+
var passportRegexByCountryCode = {
|
|
10
|
+
AM: /^[A-Z]{2}\d{7}$/,
|
|
11
|
+
// ARMENIA
|
|
12
|
+
AR: /^[A-Z]{3}\d{6}$/,
|
|
13
|
+
// ARGENTINA
|
|
14
|
+
AT: /^[A-Z]\d{7}$/,
|
|
15
|
+
// AUSTRIA
|
|
16
|
+
AU: /^[A-Z]\d{7}$/,
|
|
17
|
+
// AUSTRALIA
|
|
18
|
+
AZ: /^[A-Z]{1}\d{8}$/,
|
|
19
|
+
// AZERBAIJAN
|
|
20
|
+
BE: /^[A-Z]{2}\d{6}$/,
|
|
21
|
+
// BELGIUM
|
|
22
|
+
BG: /^\d{9}$/,
|
|
23
|
+
// BULGARIA
|
|
24
|
+
BR: /^[A-Z]{2}\d{6}$/,
|
|
25
|
+
// BRAZIL
|
|
26
|
+
BY: /^[A-Z]{2}\d{7}$/,
|
|
27
|
+
// BELARUS
|
|
28
|
+
CA: /^[A-Z]{2}\d{6}$|^[A-Z]\d{6}[A-Z]{2}$/,
|
|
29
|
+
// CANADA
|
|
30
|
+
CH: /^[A-Z]\d{7}$/,
|
|
31
|
+
// SWITZERLAND
|
|
32
|
+
CN: /^G\d{8}$|^E(?![IO])[A-Z0-9]\d{7}$/,
|
|
33
|
+
// CHINA [G=Ordinary, E=Electronic] followed by 8-digits, or E followed by any UPPERCASE letter (except I and O) followed by 7 digits
|
|
34
|
+
CY: /^[A-Z](\d{6}|\d{8})$/,
|
|
35
|
+
// CYPRUS
|
|
36
|
+
CZ: /^\d{8}$/,
|
|
37
|
+
// CZECH REPUBLIC
|
|
38
|
+
DE: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/,
|
|
39
|
+
// GERMANY
|
|
40
|
+
DK: /^\d{9}$/,
|
|
41
|
+
// DENMARK
|
|
42
|
+
DZ: /^\d{9}$/,
|
|
43
|
+
// ALGERIA
|
|
44
|
+
EE: /^([A-Z]\d{7}|[A-Z]{2}\d{7})$/,
|
|
45
|
+
// ESTONIA (K followed by 7-digits), e-passports have 2 UPPERCASE followed by 7 digits
|
|
46
|
+
ES: /^[A-Z0-9]{2}([A-Z0-9]?)\d{6}$/,
|
|
47
|
+
// SPAIN
|
|
48
|
+
FI: /^[A-Z]{2}\d{7}$/,
|
|
49
|
+
// FINLAND
|
|
50
|
+
FR: /^\d{2}[A-Z]{2}\d{5}$/,
|
|
51
|
+
// FRANCE
|
|
52
|
+
GB: /^\d{9}$/,
|
|
53
|
+
// UNITED KINGDOM
|
|
54
|
+
GR: /^[A-Z]{2}\d{7}$/,
|
|
55
|
+
// GREECE
|
|
56
|
+
HR: /^\d{9}$/,
|
|
57
|
+
// CROATIA
|
|
58
|
+
HU: /^[A-Z]{2}(\d{6}|\d{7})$/,
|
|
59
|
+
// HUNGARY
|
|
60
|
+
IE: /^[A-Z0-9]{2}\d{7}$/,
|
|
61
|
+
// IRELAND
|
|
62
|
+
IN: /^[A-Z]{1}-?\d{7}$/,
|
|
63
|
+
// INDIA
|
|
64
|
+
ID: /^[A-C]\d{7}$/,
|
|
65
|
+
// INDONESIA
|
|
66
|
+
IR: /^[A-Z]\d{8}$/,
|
|
67
|
+
// IRAN
|
|
68
|
+
IS: /^(A)\d{7}$/,
|
|
69
|
+
// ICELAND
|
|
70
|
+
IT: /^[A-Z0-9]{2}\d{7}$/,
|
|
71
|
+
// ITALY
|
|
72
|
+
JM: /^[Aa]\d{7}$/,
|
|
73
|
+
// JAMAICA
|
|
74
|
+
JP: /^[A-Z]{2}\d{7}$/,
|
|
75
|
+
// JAPAN
|
|
76
|
+
KR: /^[MS]\d{8}$/,
|
|
77
|
+
// SOUTH KOREA, REPUBLIC OF KOREA, [S=PS Passports, M=PM Passports]
|
|
78
|
+
KZ: /^[a-zA-Z]\d{7}$/,
|
|
79
|
+
// KAZAKHSTAN
|
|
80
|
+
LI: /^[a-zA-Z]\d{5}$/,
|
|
81
|
+
// LIECHTENSTEIN
|
|
82
|
+
LT: /^[A-Z0-9]{8}$/,
|
|
83
|
+
// LITHUANIA
|
|
84
|
+
LU: /^[A-Z0-9]{8}$/,
|
|
85
|
+
// LUXEMBURG
|
|
86
|
+
LV: /^[A-Z0-9]{2}\d{7}$/,
|
|
87
|
+
// LATVIA
|
|
88
|
+
LY: /^[A-Z0-9]{8}$/,
|
|
89
|
+
// LIBYA
|
|
90
|
+
MT: /^\d{7}$/,
|
|
91
|
+
// MALTA
|
|
92
|
+
MZ: /^([A-Z]{2}\d{7})|(\d{2}[A-Z]{2}\d{5})$/,
|
|
93
|
+
// MOZAMBIQUE
|
|
94
|
+
MY: /^[AHK]\d{8}$/,
|
|
95
|
+
// MALAYSIA
|
|
96
|
+
MX: /^[A-Z]\d{8}$/,
|
|
97
|
+
// MEXICO
|
|
98
|
+
NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/,
|
|
99
|
+
// NETHERLANDS
|
|
100
|
+
NZ: /^([Ll]([Aa]|[Dd]|[Ff]|[Hh])|[Ee]([Aa]|[Pp])|[Nn])\d{6}$/,
|
|
101
|
+
// NEW ZEALAND
|
|
102
|
+
PH: /^([A-Z](\d{6}|\d{7}[A-Z]))|([A-Z]{2}(\d{6}|\d{7}))$/,
|
|
103
|
+
// PHILIPPINES
|
|
104
|
+
PK: /^[A-Z]{2}\d{7}$/,
|
|
105
|
+
// PAKISTAN
|
|
106
|
+
PL: /^[A-Z]{2}\d{7}$/,
|
|
107
|
+
// POLAND
|
|
108
|
+
PT: /^[A-Z]\d{6}$/,
|
|
109
|
+
// PORTUGAL
|
|
110
|
+
RO: /^\d{8,9}$/,
|
|
111
|
+
// ROMANIA
|
|
112
|
+
RU: /^\d{9}$/,
|
|
113
|
+
// RUSSIAN FEDERATION
|
|
114
|
+
SE: /^\d{8}$/,
|
|
115
|
+
// SWEDEN
|
|
116
|
+
SL: /^(P)[A-Z]\d{7}$/,
|
|
117
|
+
// SLOVENIA
|
|
118
|
+
SK: /^[0-9A-Z]\d{7}$/,
|
|
119
|
+
// SLOVAKIA
|
|
120
|
+
TH: /^[A-Z]{1,2}\d{6,7}$/,
|
|
121
|
+
// THAILAND
|
|
122
|
+
TR: /^[A-Z]\d{8}$/,
|
|
123
|
+
// TURKEY
|
|
124
|
+
UA: /^[A-Z]{2}\d{6}$/,
|
|
125
|
+
// UKRAINE
|
|
126
|
+
US: /^\d{9}$|^[A-Z]\d{8}$/,
|
|
127
|
+
// UNITED STATES
|
|
128
|
+
ZA: /^[TAMD]\d{8}$/ // SOUTH AFRICA
|
|
129
|
+
};
|
|
130
|
+
export var locales = Object.keys(passportRegexByCountryCode);
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Check if str is a valid passport number
|
|
134
|
+
* relative to provided ISO Country Code.
|
|
135
|
+
*
|
|
136
|
+
* @param {string} str
|
|
137
|
+
* @param {string} countryCode
|
|
138
|
+
* @return {boolean}
|
|
139
|
+
*/
|
|
140
|
+
export default function isPassportNumber(str, countryCode) {
|
|
141
|
+
assertString(str);
|
|
142
|
+
/** Remove All Whitespaces, Convert to UPPERCASE */
|
|
143
|
+
var normalizedStr = str.replace(/\s/g, '').toUpperCase();
|
|
144
|
+
return countryCode.toUpperCase() in passportRegexByCountryCode && passportRegexByCountryCode[countryCode].test(normalizedStr);
|
|
145
|
+
}
|
package/es/lib/isPort.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import assertString from './util/assertString';
|
|
2
|
+
|
|
3
|
+
// common patterns
|
|
4
|
+
var threeDigit = /^\d{3}$/;
|
|
5
|
+
var fourDigit = /^\d{4}$/;
|
|
6
|
+
var fiveDigit = /^\d{5}$/;
|
|
7
|
+
var sixDigit = /^\d{6}$/;
|
|
8
|
+
var patterns = {
|
|
9
|
+
AD: /^AD\d{3}$/,
|
|
10
|
+
AT: fourDigit,
|
|
11
|
+
AU: fourDigit,
|
|
12
|
+
AZ: /^AZ\d{4}$/,
|
|
13
|
+
BA: /^([7-8]\d{4}$)/,
|
|
14
|
+
BD: /^([1-8][0-9]{3}|9[0-4][0-9]{2})$/,
|
|
15
|
+
BE: fourDigit,
|
|
16
|
+
BG: fourDigit,
|
|
17
|
+
BR: /^\d{5}-?\d{3}$/,
|
|
18
|
+
BY: /^2[1-4]\d{4}$/,
|
|
19
|
+
CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
|
|
20
|
+
CH: fourDigit,
|
|
21
|
+
CN: /^(0[1-7]|1[012356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[1-5]|8[1345]|9[09])\d{4}$/,
|
|
22
|
+
CO: /^(05|08|11|13|15|17|18|19|20|23|25|27|41|44|47|50|52|54|63|66|68|70|73|76|81|85|86|88|91|94|95|97|99)(\d{4})$/,
|
|
23
|
+
CZ: /^\d{3}\s?\d{2}$/,
|
|
24
|
+
DE: fiveDigit,
|
|
25
|
+
DK: fourDigit,
|
|
26
|
+
DO: fiveDigit,
|
|
27
|
+
DZ: fiveDigit,
|
|
28
|
+
EE: fiveDigit,
|
|
29
|
+
ES: /^(5[0-2]{1}|[0-4]{1}\d{1})\d{3}$/,
|
|
30
|
+
FI: fiveDigit,
|
|
31
|
+
FR: /^(?:(?:0[1-9]|[1-8]\d|9[0-5])\d{3}|97[1-46]\d{2})$/,
|
|
32
|
+
GB: /^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i,
|
|
33
|
+
GR: /^\d{3}\s?\d{2}$/,
|
|
34
|
+
HR: /^([1-5]\d{4}$)/,
|
|
35
|
+
HT: /^HT\d{4}$/,
|
|
36
|
+
HU: fourDigit,
|
|
37
|
+
ID: fiveDigit,
|
|
38
|
+
IE: /^(?!.*(?:o))[A-Za-z]\d[\dw]\s\w{4}$/i,
|
|
39
|
+
IL: /^(\d{5}|\d{7})$/,
|
|
40
|
+
IN: /^((?!10|29|35|54|55|65|66|86|87|88|89)[1-9][0-9]{5})$/,
|
|
41
|
+
IR: /^(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}$/,
|
|
42
|
+
IS: threeDigit,
|
|
43
|
+
IT: fiveDigit,
|
|
44
|
+
JP: /^\d{3}\-\d{4}$/,
|
|
45
|
+
KE: fiveDigit,
|
|
46
|
+
KR: /^(\d{5}|\d{6})$/,
|
|
47
|
+
LI: /^(948[5-9]|949[0-7])$/,
|
|
48
|
+
LT: /^LT\-\d{5}$/,
|
|
49
|
+
LU: fourDigit,
|
|
50
|
+
LV: /^LV\-\d{4}$/,
|
|
51
|
+
LK: fiveDigit,
|
|
52
|
+
MC: /^980\d{2}$/,
|
|
53
|
+
MG: threeDigit,
|
|
54
|
+
MX: fiveDigit,
|
|
55
|
+
MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/,
|
|
56
|
+
MY: fiveDigit,
|
|
57
|
+
NL: /^[1-9]\d{3}\s?(?!sa|sd|ss)[a-z]{2}$/i,
|
|
58
|
+
NO: fourDigit,
|
|
59
|
+
NP: /^(10|21|22|32|33|34|44|45|56|57)\d{3}$|^(977)$/i,
|
|
60
|
+
NZ: fourDigit,
|
|
61
|
+
// https://www.pakpost.gov.pk/postcodes.php
|
|
62
|
+
PK: fiveDigit,
|
|
63
|
+
PL: /^\d{2}\-\d{3}$/,
|
|
64
|
+
PR: /^00[679]\d{2}([ -]\d{4})?$/,
|
|
65
|
+
PT: /^\d{4}\-\d{3}?$/,
|
|
66
|
+
RO: sixDigit,
|
|
67
|
+
RU: sixDigit,
|
|
68
|
+
SA: fiveDigit,
|
|
69
|
+
SE: /^[1-9]\d{2}\s?\d{2}$/,
|
|
70
|
+
SG: sixDigit,
|
|
71
|
+
SI: fourDigit,
|
|
72
|
+
SK: /^\d{3}\s?\d{2}$/,
|
|
73
|
+
TH: fiveDigit,
|
|
74
|
+
TN: fourDigit,
|
|
75
|
+
TW: /^\d{3}(\d{2,3})?$/,
|
|
76
|
+
UA: fiveDigit,
|
|
77
|
+
US: /^\d{5}(-\d{4})?$/,
|
|
78
|
+
ZA: fourDigit,
|
|
79
|
+
ZM: fiveDigit
|
|
80
|
+
};
|
|
81
|
+
export var locales = Object.keys(patterns);
|
|
82
|
+
export default function isPostalCode(str, locale) {
|
|
83
|
+
assertString(str);
|
|
84
|
+
if (locale in patterns) {
|
|
85
|
+
return patterns[locale].test(str);
|
|
86
|
+
} else if (locale === 'any') {
|
|
87
|
+
for (var key in patterns) {
|
|
88
|
+
// https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
|
|
89
|
+
// istanbul ignore else
|
|
90
|
+
if (patterns.hasOwnProperty(key)) {
|
|
91
|
+
var pattern = patterns[key];
|
|
92
|
+
if (pattern.test(str)) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
throw new Error("Invalid locale '".concat(locale, "'"));
|
|
100
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import assertString from './util/assertString';
|
|
2
|
+
|
|
3
|
+
/* Based on https://tools.ietf.org/html/rfc3339#section-5.6 */
|
|
4
|
+
|
|
5
|
+
var dateFullYear = /[0-9]{4}/;
|
|
6
|
+
var dateMonth = /(0[1-9]|1[0-2])/;
|
|
7
|
+
var dateMDay = /([12]\d|0[1-9]|3[01])/;
|
|
8
|
+
var timeHour = /([01][0-9]|2[0-3])/;
|
|
9
|
+
var timeMinute = /[0-5][0-9]/;
|
|
10
|
+
var timeSecond = /([0-5][0-9]|60)/;
|
|
11
|
+
var timeSecFrac = /(\.[0-9]+)?/;
|
|
12
|
+
var timeNumOffset = new RegExp("[-+]".concat(timeHour.source, ":").concat(timeMinute.source));
|
|
13
|
+
var timeOffset = new RegExp("([zZ]|".concat(timeNumOffset.source, ")"));
|
|
14
|
+
var partialTime = new RegExp("".concat(timeHour.source, ":").concat(timeMinute.source, ":").concat(timeSecond.source).concat(timeSecFrac.source));
|
|
15
|
+
var fullDate = new RegExp("".concat(dateFullYear.source, "-").concat(dateMonth.source, "-").concat(dateMDay.source));
|
|
16
|
+
var fullTime = new RegExp("".concat(partialTime.source).concat(timeOffset.source));
|
|
17
|
+
var rfc3339 = new RegExp("^".concat(fullDate.source, "[ tT]").concat(fullTime.source, "$"));
|
|
18
|
+
export default function isRFC3339(str) {
|
|
19
|
+
assertString(str);
|
|
20
|
+
return rfc3339.test(str);
|
|
21
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
/* eslint-disable prefer-rest-params */
|
|
3
|
+
import assertString from './util/assertString';
|
|
4
|
+
var rgbColor = /^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/;
|
|
5
|
+
var rgbaColor = /^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d\d?|1(\.0)?|0(\.0)?)\)$/;
|
|
6
|
+
var rgbColorPercent = /^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)$/;
|
|
7
|
+
var rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d\d?|1(\.0)?|0(\.0)?)\)$/;
|
|
8
|
+
var startsWithRgb = /^rgba?/;
|
|
9
|
+
export default function isRgbColor(str, options) {
|
|
10
|
+
assertString(str);
|
|
11
|
+
// default options to true for percent and false for spaces
|
|
12
|
+
var allowSpaces = false;
|
|
13
|
+
var includePercentValues = true;
|
|
14
|
+
if (_typeof(options) !== 'object') {
|
|
15
|
+
if (arguments.length >= 2) {
|
|
16
|
+
includePercentValues = arguments[1];
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
allowSpaces = options.allowSpaces !== undefined ? options.allowSpaces : allowSpaces;
|
|
20
|
+
includePercentValues = options.includePercentValues !== undefined ? options.includePercentValues : includePercentValues;
|
|
21
|
+
}
|
|
22
|
+
if (allowSpaces) {
|
|
23
|
+
// make sure it starts with continuous rgba? without spaces before stripping
|
|
24
|
+
if (!startsWithRgb.test(str)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
// strip all whitespace
|
|
28
|
+
str = str.replace(/\s/g, '');
|
|
29
|
+
}
|
|
30
|
+
if (!includePercentValues) {
|
|
31
|
+
return rgbColor.test(str) || rgbaColor.test(str);
|
|
32
|
+
}
|
|
33
|
+
return rgbColor.test(str) || rgbaColor.test(str) || rgbColorPercent.test(str) || rgbaColorPercent.test(str);
|
|
34
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import assertString from './util/assertString';
|
|
2
|
+
import multilineRegexp from './util/multilineRegex';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Regular Expression to match
|
|
6
|
+
* semantic versioning (SemVer)
|
|
7
|
+
* built from multi-line, multi-parts regexp
|
|
8
|
+
* Reference: https://semver.org/
|
|
9
|
+
*/
|
|
10
|
+
var semanticVersioningRegex = multilineRegexp(['^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)', '(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))', '?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$'], 'i');
|
|
11
|
+
export default function isSemVer(str) {
|
|
12
|
+
assertString(str);
|
|
13
|
+
return semanticVersioningRegex.test(str);
|
|
14
|
+
}
|
package/es/lib/isSlug.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import merge from './util/merge';
|
|
2
|
+
import assertString from './util/assertString';
|
|
3
|
+
var upperCaseRegex = /^[A-Z]$/;
|
|
4
|
+
var lowerCaseRegex = /^[a-z]$/;
|
|
5
|
+
var numberRegex = /^[0-9]$/;
|
|
6
|
+
var symbolRegex = /^[-#!$@£%^&*()_+|~=`{}\[\]:";'<>?,.\/\\ ]$/;
|
|
7
|
+
var defaultOptions = {
|
|
8
|
+
minLength: 8,
|
|
9
|
+
minLowercase: 1,
|
|
10
|
+
minUppercase: 1,
|
|
11
|
+
minNumbers: 1,
|
|
12
|
+
minSymbols: 1,
|
|
13
|
+
returnScore: false,
|
|
14
|
+
pointsPerUnique: 1,
|
|
15
|
+
pointsPerRepeat: 0.5,
|
|
16
|
+
pointsForContainingLower: 10,
|
|
17
|
+
pointsForContainingUpper: 10,
|
|
18
|
+
pointsForContainingNumber: 10,
|
|
19
|
+
pointsForContainingSymbol: 10
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/* Counts number of occurrences of each char in a string
|
|
23
|
+
* could be moved to util/ ?
|
|
24
|
+
*/
|
|
25
|
+
function countChars(str) {
|
|
26
|
+
var result = {};
|
|
27
|
+
Array.from(str).forEach(function (_char) {
|
|
28
|
+
var curVal = result[_char];
|
|
29
|
+
if (curVal) {
|
|
30
|
+
result[_char] += 1;
|
|
31
|
+
} else {
|
|
32
|
+
result[_char] = 1;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* Return information about a password */
|
|
39
|
+
function analyzePassword(password) {
|
|
40
|
+
var charMap = countChars(password);
|
|
41
|
+
var analysis = {
|
|
42
|
+
length: password.length,
|
|
43
|
+
uniqueChars: Object.keys(charMap).length,
|
|
44
|
+
uppercaseCount: 0,
|
|
45
|
+
lowercaseCount: 0,
|
|
46
|
+
numberCount: 0,
|
|
47
|
+
symbolCount: 0
|
|
48
|
+
};
|
|
49
|
+
Object.keys(charMap).forEach(function (_char2) {
|
|
50
|
+
/* istanbul ignore else */
|
|
51
|
+
if (upperCaseRegex.test(_char2)) {
|
|
52
|
+
analysis.uppercaseCount += charMap[_char2];
|
|
53
|
+
} else if (lowerCaseRegex.test(_char2)) {
|
|
54
|
+
analysis.lowercaseCount += charMap[_char2];
|
|
55
|
+
} else if (numberRegex.test(_char2)) {
|
|
56
|
+
analysis.numberCount += charMap[_char2];
|
|
57
|
+
} else if (symbolRegex.test(_char2)) {
|
|
58
|
+
analysis.symbolCount += charMap[_char2];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return analysis;
|
|
62
|
+
}
|
|
63
|
+
function scorePassword(analysis, scoringOptions) {
|
|
64
|
+
var points = 0;
|
|
65
|
+
points += analysis.uniqueChars * scoringOptions.pointsPerUnique;
|
|
66
|
+
points += (analysis.length - analysis.uniqueChars) * scoringOptions.pointsPerRepeat;
|
|
67
|
+
if (analysis.lowercaseCount > 0) {
|
|
68
|
+
points += scoringOptions.pointsForContainingLower;
|
|
69
|
+
}
|
|
70
|
+
if (analysis.uppercaseCount > 0) {
|
|
71
|
+
points += scoringOptions.pointsForContainingUpper;
|
|
72
|
+
}
|
|
73
|
+
if (analysis.numberCount > 0) {
|
|
74
|
+
points += scoringOptions.pointsForContainingNumber;
|
|
75
|
+
}
|
|
76
|
+
if (analysis.symbolCount > 0) {
|
|
77
|
+
points += scoringOptions.pointsForContainingSymbol;
|
|
78
|
+
}
|
|
79
|
+
return points;
|
|
80
|
+
}
|
|
81
|
+
export default function isStrongPassword(str) {
|
|
82
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
83
|
+
assertString(str);
|
|
84
|
+
var analysis = analyzePassword(str);
|
|
85
|
+
options = merge(options || {}, defaultOptions);
|
|
86
|
+
if (options.returnScore) {
|
|
87
|
+
return scorePassword(analysis, options);
|
|
88
|
+
}
|
|
89
|
+
return analysis.length >= options.minLength && analysis.lowercaseCount >= options.minLowercase && analysis.uppercaseCount >= options.minUppercase && analysis.numberCount >= options.minNumbers && analysis.symbolCount >= options.minSymbols;
|
|
90
|
+
}
|