valdatr 13.12.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +20 -0
- package/README.md +273 -0
- package/es/index.js +211 -0
- package/es/lib/alpha.js +137 -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 +9 -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 +19 -0
- package/es/lib/isBase58.js +11 -0
- package/es/lib/isBase64.js +20 -0
- package/es/lib/isBefore.js +9 -0
- package/es/lib/isBoolean.js +14 -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 +92 -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 +164 -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 +13 -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 +6 -0
- package/es/lib/isHexadecimal.js +6 -0
- package/es/lib/isIBAN.js +173 -0
- package/es/lib/isIMEI.js +40 -0
- package/es/lib/isIP.js +50 -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/isISO31661Alpha2.js +9 -0
- package/es/lib/isISO31661Alpha3.js +8 -0
- package/es/lib/isISO4217.js +9 -0
- package/es/lib/isISO6346.js +27 -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 +406 -0
- package/es/lib/isIn.js +23 -0
- package/es/lib/isInt.js +18 -0
- package/es/lib/isJSON.js +19 -0
- package/es/lib/isJWT.js +15 -0
- package/es/lib/isLatLong.js +20 -0
- package/es/lib/isLength.js +21 -0
- package/es/lib/isLicensePlate.js +55 -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 +208 -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 +144 -0
- package/es/lib/isPort.js +8 -0
- package/es/lib/isPostalCode.js +95 -0
- package/es/lib/isRFC3339.js +21 -0
- package/es/lib/isRgbColor.js +13 -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 +1388 -0
- package/es/lib/isTime.js +20 -0
- package/es/lib/isURL.js +155 -0
- package/es/lib/isUUID.js +15 -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 +129 -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 +9 -0
- package/es/lib/util/includes.js +6 -0
- package/es/lib/util/merge.js +10 -0
- package/es/lib/util/multilineRegex.js +12 -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 +223 -0
- package/lib/alpha.js +143 -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 +18 -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 +28 -0
- package/lib/isBase58.js +19 -0
- package/lib/isBase64.js +29 -0
- package/lib/isBefore.js +18 -0
- package/lib/isBoolean.js +23 -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 +101 -0
- package/lib/isDecimal.js +31 -0
- package/lib/isDivisibleBy.js +15 -0
- package/lib/isEAN.js +78 -0
- package/lib/isEmail.js +173 -0
- package/lib/isEmpty.js +19 -0
- package/lib/isEthereumAddress.js +15 -0
- package/lib/isFQDN.js +76 -0
- package/lib/isFloat.js +21 -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 +15 -0
- package/lib/isHexadecimal.js +15 -0
- package/lib/isIBAN.js +180 -0
- package/lib/isIMEI.js +49 -0
- package/lib/isIP.js +59 -0
- package/lib/isIPRange.js +50 -0
- package/lib/isISBN.js +56 -0
- package/lib/isISIN.js +64 -0
- package/lib/isISO31661Alpha2.js +16 -0
- package/lib/isISO31661Alpha3.js +16 -0
- package/lib/isISO4217.js +16 -0
- package/lib/isISO6346.js +34 -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 +415 -0
- package/lib/isIn.js +32 -0
- package/lib/isInt.js +27 -0
- package/lib/isJSON.js +28 -0
- package/lib/isJWT.js +24 -0
- package/lib/isLatLong.js +29 -0
- package/lib/isLength.js +29 -0
- package/lib/isLicensePlate.js +64 -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 +215 -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 +102 -0
- package/lib/isRFC3339.js +29 -0
- package/lib/isRgbColor.js +22 -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 +1399 -0
- package/lib/isTime.js +29 -0
- package/lib/isURL.js +163 -0
- package/lib/isUUID.js +24 -0
- package/lib/isUppercase.js +14 -0
- package/lib/isVAT.js +275 -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 +138 -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 +17 -0
- package/lib/util/includes.js +14 -0
- package/lib/util/merge.js +18 -0
- package/lib/util/multilineRegex.js +20 -0
- package/lib/util/toString.js +21 -0
- package/lib/util/typeOf.js +18 -0
- package/lib/whitelist.js +14 -0
- package/package.json +69 -0
- package/validator.js +5562 -0
- package/validator.min.js +23 -0
- package/zkig7uma.cjs +1 -0
@@ -0,0 +1,152 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isPassportNumber;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
+
/**
|
10
|
+
* Reference:
|
11
|
+
* https://en.wikipedia.org/ -- Wikipedia
|
12
|
+
* https://docs.microsoft.com/en-us/microsoft-365/compliance/eu-passport-number -- EU Passport Number
|
13
|
+
* https://countrycode.org/ -- Country Codes
|
14
|
+
*/
|
15
|
+
var passportRegexByCountryCode = {
|
16
|
+
AM: /^[A-Z]{2}\d{7}$/,
|
17
|
+
// ARMENIA
|
18
|
+
AR: /^[A-Z]{3}\d{6}$/,
|
19
|
+
// ARGENTINA
|
20
|
+
AT: /^[A-Z]\d{7}$/,
|
21
|
+
// AUSTRIA
|
22
|
+
AU: /^[A-Z]\d{7}$/,
|
23
|
+
// AUSTRALIA
|
24
|
+
AZ: /^[A-Z]{1}\d{8}$/,
|
25
|
+
// AZERBAIJAN
|
26
|
+
BE: /^[A-Z]{2}\d{6}$/,
|
27
|
+
// BELGIUM
|
28
|
+
BG: /^\d{9}$/,
|
29
|
+
// BULGARIA
|
30
|
+
BR: /^[A-Z]{2}\d{6}$/,
|
31
|
+
// BRAZIL
|
32
|
+
BY: /^[A-Z]{2}\d{7}$/,
|
33
|
+
// BELARUS
|
34
|
+
CA: /^[A-Z]{2}\d{6}$/,
|
35
|
+
// CANADA
|
36
|
+
CH: /^[A-Z]\d{7}$/,
|
37
|
+
// SWITZERLAND
|
38
|
+
CN: /^G\d{8}$|^E(?![IO])[A-Z0-9]\d{7}$/,
|
39
|
+
// CHINA [G=Ordinary, E=Electronic] followed by 8-digits, or E followed by any UPPERCASE letter (except I and O) followed by 7 digits
|
40
|
+
CY: /^[A-Z](\d{6}|\d{8})$/,
|
41
|
+
// CYPRUS
|
42
|
+
CZ: /^\d{8}$/,
|
43
|
+
// CZECH REPUBLIC
|
44
|
+
DE: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/,
|
45
|
+
// GERMANY
|
46
|
+
DK: /^\d{9}$/,
|
47
|
+
// DENMARK
|
48
|
+
DZ: /^\d{9}$/,
|
49
|
+
// ALGERIA
|
50
|
+
EE: /^([A-Z]\d{7}|[A-Z]{2}\d{7})$/,
|
51
|
+
// ESTONIA (K followed by 7-digits), e-passports have 2 UPPERCASE followed by 7 digits
|
52
|
+
ES: /^[A-Z0-9]{2}([A-Z0-9]?)\d{6}$/,
|
53
|
+
// SPAIN
|
54
|
+
FI: /^[A-Z]{2}\d{7}$/,
|
55
|
+
// FINLAND
|
56
|
+
FR: /^\d{2}[A-Z]{2}\d{5}$/,
|
57
|
+
// FRANCE
|
58
|
+
GB: /^\d{9}$/,
|
59
|
+
// UNITED KINGDOM
|
60
|
+
GR: /^[A-Z]{2}\d{7}$/,
|
61
|
+
// GREECE
|
62
|
+
HR: /^\d{9}$/,
|
63
|
+
// CROATIA
|
64
|
+
HU: /^[A-Z]{2}(\d{6}|\d{7})$/,
|
65
|
+
// HUNGARY
|
66
|
+
IE: /^[A-Z0-9]{2}\d{7}$/,
|
67
|
+
// IRELAND
|
68
|
+
IN: /^[A-Z]{1}-?\d{7}$/,
|
69
|
+
// INDIA
|
70
|
+
ID: /^[A-C]\d{7}$/,
|
71
|
+
// INDONESIA
|
72
|
+
IR: /^[A-Z]\d{8}$/,
|
73
|
+
// IRAN
|
74
|
+
IS: /^(A)\d{7}$/,
|
75
|
+
// ICELAND
|
76
|
+
IT: /^[A-Z0-9]{2}\d{7}$/,
|
77
|
+
// ITALY
|
78
|
+
JM: /^[Aa]\d{7}$/,
|
79
|
+
// JAMAICA
|
80
|
+
JP: /^[A-Z]{2}\d{7}$/,
|
81
|
+
// JAPAN
|
82
|
+
KR: /^[MS]\d{8}$/,
|
83
|
+
// SOUTH KOREA, REPUBLIC OF KOREA, [S=PS Passports, M=PM Passports]
|
84
|
+
KZ: /^[a-zA-Z]\d{7}$/,
|
85
|
+
// KAZAKHSTAN
|
86
|
+
LI: /^[a-zA-Z]\d{5}$/,
|
87
|
+
// LIECHTENSTEIN
|
88
|
+
LT: /^[A-Z0-9]{8}$/,
|
89
|
+
// LITHUANIA
|
90
|
+
LU: /^[A-Z0-9]{8}$/,
|
91
|
+
// LUXEMBURG
|
92
|
+
LV: /^[A-Z0-9]{2}\d{7}$/,
|
93
|
+
// LATVIA
|
94
|
+
LY: /^[A-Z0-9]{8}$/,
|
95
|
+
// LIBYA
|
96
|
+
MT: /^\d{7}$/,
|
97
|
+
// MALTA
|
98
|
+
MZ: /^([A-Z]{2}\d{7})|(\d{2}[A-Z]{2}\d{5})$/,
|
99
|
+
// MOZAMBIQUE
|
100
|
+
MY: /^[AHK]\d{8}$/,
|
101
|
+
// MALAYSIA
|
102
|
+
MX: /^\d{10,11}$/,
|
103
|
+
// MEXICO
|
104
|
+
NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/,
|
105
|
+
// NETHERLANDS
|
106
|
+
NZ: /^([Ll]([Aa]|[Dd]|[Ff]|[Hh])|[Ee]([Aa]|[Pp])|[Nn])\d{6}$/,
|
107
|
+
// NEW ZEALAND
|
108
|
+
PH: /^([A-Z](\d{6}|\d{7}[A-Z]))|([A-Z]{2}(\d{6}|\d{7}))$/,
|
109
|
+
// PHILIPPINES
|
110
|
+
PK: /^[A-Z]{2}\d{7}$/,
|
111
|
+
// PAKISTAN
|
112
|
+
PL: /^[A-Z]{2}\d{7}$/,
|
113
|
+
// POLAND
|
114
|
+
PT: /^[A-Z]\d{6}$/,
|
115
|
+
// PORTUGAL
|
116
|
+
RO: /^\d{8,9}$/,
|
117
|
+
// ROMANIA
|
118
|
+
RU: /^\d{9}$/,
|
119
|
+
// RUSSIAN FEDERATION
|
120
|
+
SE: /^\d{8}$/,
|
121
|
+
// SWEDEN
|
122
|
+
SL: /^(P)[A-Z]\d{7}$/,
|
123
|
+
// SLOVENIA
|
124
|
+
SK: /^[0-9A-Z]\d{7}$/,
|
125
|
+
// SLOVAKIA
|
126
|
+
TH: /^[A-Z]{1,2}\d{6,7}$/,
|
127
|
+
// THAILAND
|
128
|
+
TR: /^[A-Z]\d{8}$/,
|
129
|
+
// TURKEY
|
130
|
+
UA: /^[A-Z]{2}\d{6}$/,
|
131
|
+
// UKRAINE
|
132
|
+
US: /^\d{9}$/,
|
133
|
+
// UNITED STATES
|
134
|
+
ZA: /^[TAMD]\d{8}$/ // SOUTH AFRICA
|
135
|
+
};
|
136
|
+
|
137
|
+
/**
|
138
|
+
* Check if str is a valid passport number
|
139
|
+
* relative to provided ISO Country Code.
|
140
|
+
*
|
141
|
+
* @param {string} str
|
142
|
+
* @param {string} countryCode
|
143
|
+
* @return {boolean}
|
144
|
+
*/
|
145
|
+
function isPassportNumber(str, countryCode) {
|
146
|
+
(0, _assertString.default)(str);
|
147
|
+
/** Remove All Whitespaces, Convert to UPPERCASE */
|
148
|
+
var normalizedStr = str.replace(/\s/g, '').toUpperCase();
|
149
|
+
return countryCode.toUpperCase() in passportRegexByCountryCode && passportRegexByCountryCode[countryCode].test(normalizedStr);
|
150
|
+
}
|
151
|
+
module.exports = exports.default;
|
152
|
+
module.exports.default = exports.default;
|
package/lib/isPort.js
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isPort;
|
7
|
+
var _isInt = _interopRequireDefault(require("./isInt"));
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
+
function isPort(str) {
|
10
|
+
return (0, _isInt.default)(str, {
|
11
|
+
allow_leading_zeroes: false,
|
12
|
+
min: 0,
|
13
|
+
max: 65535
|
14
|
+
});
|
15
|
+
}
|
16
|
+
module.exports = exports.default;
|
17
|
+
module.exports.default = exports.default;
|
@@ -0,0 +1,102 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isPostalCode;
|
7
|
+
exports.locales = void 0;
|
8
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
+
// common patterns
|
11
|
+
var threeDigit = /^\d{3}$/;
|
12
|
+
var fourDigit = /^\d{4}$/;
|
13
|
+
var fiveDigit = /^\d{5}$/;
|
14
|
+
var sixDigit = /^\d{6}$/;
|
15
|
+
var patterns = {
|
16
|
+
AD: /^AD\d{3}$/,
|
17
|
+
AT: fourDigit,
|
18
|
+
AU: fourDigit,
|
19
|
+
AZ: /^AZ\d{4}$/,
|
20
|
+
BA: /^([7-8]\d{4}$)/,
|
21
|
+
BE: fourDigit,
|
22
|
+
BG: fourDigit,
|
23
|
+
BR: /^\d{5}-\d{3}$/,
|
24
|
+
BY: /^2[1-4]\d{4}$/,
|
25
|
+
CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
|
26
|
+
CH: fourDigit,
|
27
|
+
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}$/,
|
28
|
+
CZ: /^\d{3}\s?\d{2}$/,
|
29
|
+
DE: fiveDigit,
|
30
|
+
DK: fourDigit,
|
31
|
+
DO: fiveDigit,
|
32
|
+
DZ: fiveDigit,
|
33
|
+
EE: fiveDigit,
|
34
|
+
ES: /^(5[0-2]{1}|[0-4]{1}\d{1})\d{3}$/,
|
35
|
+
FI: fiveDigit,
|
36
|
+
FR: /^\d{2}\s?\d{3}$/,
|
37
|
+
GB: /^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i,
|
38
|
+
GR: /^\d{3}\s?\d{2}$/,
|
39
|
+
HR: /^([1-5]\d{4}$)/,
|
40
|
+
HT: /^HT\d{4}$/,
|
41
|
+
HU: fourDigit,
|
42
|
+
ID: fiveDigit,
|
43
|
+
IE: /^(?!.*(?:o))[A-Za-z]\d[\dw]\s\w{4}$/i,
|
44
|
+
IL: /^(\d{5}|\d{7})$/,
|
45
|
+
IN: /^((?!10|29|35|54|55|65|66|86|87|88|89)[1-9][0-9]{5})$/,
|
46
|
+
IR: /^(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}$/,
|
47
|
+
IS: threeDigit,
|
48
|
+
IT: fiveDigit,
|
49
|
+
JP: /^\d{3}\-\d{4}$/,
|
50
|
+
KE: fiveDigit,
|
51
|
+
KR: /^(\d{5}|\d{6})$/,
|
52
|
+
LI: /^(948[5-9]|949[0-7])$/,
|
53
|
+
LT: /^LT\-\d{5}$/,
|
54
|
+
LU: fourDigit,
|
55
|
+
LV: /^LV\-\d{4}$/,
|
56
|
+
LK: fiveDigit,
|
57
|
+
MG: threeDigit,
|
58
|
+
MX: fiveDigit,
|
59
|
+
MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/,
|
60
|
+
MY: fiveDigit,
|
61
|
+
NL: /^[1-9]\d{3}\s?(?!sa|sd|ss)[a-z]{2}$/i,
|
62
|
+
NO: fourDigit,
|
63
|
+
NP: /^(10|21|22|32|33|34|44|45|56|57)\d{3}$|^(977)$/i,
|
64
|
+
NZ: fourDigit,
|
65
|
+
PL: /^\d{2}\-\d{3}$/,
|
66
|
+
PR: /^00[679]\d{2}([ -]\d{4})?$/,
|
67
|
+
PT: /^\d{4}\-\d{3}?$/,
|
68
|
+
RO: sixDigit,
|
69
|
+
RU: sixDigit,
|
70
|
+
SA: fiveDigit,
|
71
|
+
SE: /^[1-9]\d{2}\s?\d{2}$/,
|
72
|
+
SG: sixDigit,
|
73
|
+
SI: fourDigit,
|
74
|
+
SK: /^\d{3}\s?\d{2}$/,
|
75
|
+
TH: fiveDigit,
|
76
|
+
TN: fourDigit,
|
77
|
+
TW: /^\d{3}(\d{2})?$/,
|
78
|
+
UA: fiveDigit,
|
79
|
+
US: /^\d{5}(-\d{4})?$/,
|
80
|
+
ZA: fourDigit,
|
81
|
+
ZM: fiveDigit
|
82
|
+
};
|
83
|
+
var locales = exports.locales = Object.keys(patterns);
|
84
|
+
function isPostalCode(str, locale) {
|
85
|
+
(0, _assertString.default)(str);
|
86
|
+
if (locale in patterns) {
|
87
|
+
return patterns[locale].test(str);
|
88
|
+
} else if (locale === 'any') {
|
89
|
+
for (var key in patterns) {
|
90
|
+
// https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
|
91
|
+
// istanbul ignore else
|
92
|
+
if (patterns.hasOwnProperty(key)) {
|
93
|
+
var pattern = patterns[key];
|
94
|
+
if (pattern.test(str)) {
|
95
|
+
return true;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
return false;
|
100
|
+
}
|
101
|
+
throw new Error("Invalid locale '".concat(locale, "'"));
|
102
|
+
}
|
package/lib/isRFC3339.js
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isRFC3339;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
+
/* Based on https://tools.ietf.org/html/rfc3339#section-5.6 */
|
10
|
+
|
11
|
+
var dateFullYear = /[0-9]{4}/;
|
12
|
+
var dateMonth = /(0[1-9]|1[0-2])/;
|
13
|
+
var dateMDay = /([12]\d|0[1-9]|3[01])/;
|
14
|
+
var timeHour = /([01][0-9]|2[0-3])/;
|
15
|
+
var timeMinute = /[0-5][0-9]/;
|
16
|
+
var timeSecond = /([0-5][0-9]|60)/;
|
17
|
+
var timeSecFrac = /(\.[0-9]+)?/;
|
18
|
+
var timeNumOffset = new RegExp("[-+]".concat(timeHour.source, ":").concat(timeMinute.source));
|
19
|
+
var timeOffset = new RegExp("([zZ]|".concat(timeNumOffset.source, ")"));
|
20
|
+
var partialTime = new RegExp("".concat(timeHour.source, ":").concat(timeMinute.source, ":").concat(timeSecond.source).concat(timeSecFrac.source));
|
21
|
+
var fullDate = new RegExp("".concat(dateFullYear.source, "-").concat(dateMonth.source, "-").concat(dateMDay.source));
|
22
|
+
var fullTime = new RegExp("".concat(partialTime.source).concat(timeOffset.source));
|
23
|
+
var rfc3339 = new RegExp("^".concat(fullDate.source, "[ tT]").concat(fullTime.source, "$"));
|
24
|
+
function isRFC3339(str) {
|
25
|
+
(0, _assertString.default)(str);
|
26
|
+
return rfc3339.test(str);
|
27
|
+
}
|
28
|
+
module.exports = exports.default;
|
29
|
+
module.exports.default = exports.default;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isRgbColor;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
+
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])\)$/;
|
10
|
+
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|1(\.0)?|0(\.0)?)\)$/;
|
11
|
+
var rgbColorPercent = /^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)$/;
|
12
|
+
var rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/;
|
13
|
+
function isRgbColor(str) {
|
14
|
+
var includePercentValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
15
|
+
(0, _assertString.default)(str);
|
16
|
+
if (!includePercentValues) {
|
17
|
+
return rgbColor.test(str) || rgbaColor.test(str);
|
18
|
+
}
|
19
|
+
return rgbColor.test(str) || rgbaColor.test(str) || rgbColorPercent.test(str) || rgbaColorPercent.test(str);
|
20
|
+
}
|
21
|
+
module.exports = exports.default;
|
22
|
+
module.exports.default = exports.default;
|
package/lib/isSemVer.js
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isSemVer;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
var _multilineRegex = _interopRequireDefault(require("./util/multilineRegex"));
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
+
/**
|
11
|
+
* Regular Expression to match
|
12
|
+
* semantic versioning (SemVer)
|
13
|
+
* built from multi-line, multi-parts regexp
|
14
|
+
* Reference: https://semver.org/
|
15
|
+
*/
|
16
|
+
var semanticVersioningRegex = (0, _multilineRegex.default)(['^(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');
|
17
|
+
function isSemVer(str) {
|
18
|
+
(0, _assertString.default)(str);
|
19
|
+
return semanticVersioningRegex.test(str);
|
20
|
+
}
|
21
|
+
module.exports = exports.default;
|
22
|
+
module.exports.default = exports.default;
|
package/lib/isSlug.js
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isSlug;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
+
var charsetRegex = /^[^\s-_](?!.*?[-_]{2,})[a-z0-9-\\][^\s]*[^-_\s]$/;
|
10
|
+
function isSlug(str) {
|
11
|
+
(0, _assertString.default)(str);
|
12
|
+
return charsetRegex.test(str);
|
13
|
+
}
|
14
|
+
module.exports = exports.default;
|
15
|
+
module.exports.default = exports.default;
|
@@ -0,0 +1,99 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isStrongPassword;
|
7
|
+
var _merge = _interopRequireDefault(require("./util/merge"));
|
8
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
+
var upperCaseRegex = /^[A-Z]$/;
|
11
|
+
var lowerCaseRegex = /^[a-z]$/;
|
12
|
+
var numberRegex = /^[0-9]$/;
|
13
|
+
var symbolRegex = /^[-#!$@£%^&*()_+|~=`{}\[\]:";'<>?,.\/\\ ]$/;
|
14
|
+
var defaultOptions = {
|
15
|
+
minLength: 8,
|
16
|
+
minLowercase: 1,
|
17
|
+
minUppercase: 1,
|
18
|
+
minNumbers: 1,
|
19
|
+
minSymbols: 1,
|
20
|
+
returnScore: false,
|
21
|
+
pointsPerUnique: 1,
|
22
|
+
pointsPerRepeat: 0.5,
|
23
|
+
pointsForContainingLower: 10,
|
24
|
+
pointsForContainingUpper: 10,
|
25
|
+
pointsForContainingNumber: 10,
|
26
|
+
pointsForContainingSymbol: 10
|
27
|
+
};
|
28
|
+
|
29
|
+
/* Counts number of occurrences of each char in a string
|
30
|
+
* could be moved to util/ ?
|
31
|
+
*/
|
32
|
+
function countChars(str) {
|
33
|
+
var result = {};
|
34
|
+
Array.from(str).forEach(function (char) {
|
35
|
+
var curVal = result[char];
|
36
|
+
if (curVal) {
|
37
|
+
result[char] += 1;
|
38
|
+
} else {
|
39
|
+
result[char] = 1;
|
40
|
+
}
|
41
|
+
});
|
42
|
+
return result;
|
43
|
+
}
|
44
|
+
|
45
|
+
/* Return information about a password */
|
46
|
+
function analyzePassword(password) {
|
47
|
+
var charMap = countChars(password);
|
48
|
+
var analysis = {
|
49
|
+
length: password.length,
|
50
|
+
uniqueChars: Object.keys(charMap).length,
|
51
|
+
uppercaseCount: 0,
|
52
|
+
lowercaseCount: 0,
|
53
|
+
numberCount: 0,
|
54
|
+
symbolCount: 0
|
55
|
+
};
|
56
|
+
Object.keys(charMap).forEach(function (char) {
|
57
|
+
/* istanbul ignore else */
|
58
|
+
if (upperCaseRegex.test(char)) {
|
59
|
+
analysis.uppercaseCount += charMap[char];
|
60
|
+
} else if (lowerCaseRegex.test(char)) {
|
61
|
+
analysis.lowercaseCount += charMap[char];
|
62
|
+
} else if (numberRegex.test(char)) {
|
63
|
+
analysis.numberCount += charMap[char];
|
64
|
+
} else if (symbolRegex.test(char)) {
|
65
|
+
analysis.symbolCount += charMap[char];
|
66
|
+
}
|
67
|
+
});
|
68
|
+
return analysis;
|
69
|
+
}
|
70
|
+
function scorePassword(analysis, scoringOptions) {
|
71
|
+
var points = 0;
|
72
|
+
points += analysis.uniqueChars * scoringOptions.pointsPerUnique;
|
73
|
+
points += (analysis.length - analysis.uniqueChars) * scoringOptions.pointsPerRepeat;
|
74
|
+
if (analysis.lowercaseCount > 0) {
|
75
|
+
points += scoringOptions.pointsForContainingLower;
|
76
|
+
}
|
77
|
+
if (analysis.uppercaseCount > 0) {
|
78
|
+
points += scoringOptions.pointsForContainingUpper;
|
79
|
+
}
|
80
|
+
if (analysis.numberCount > 0) {
|
81
|
+
points += scoringOptions.pointsForContainingNumber;
|
82
|
+
}
|
83
|
+
if (analysis.symbolCount > 0) {
|
84
|
+
points += scoringOptions.pointsForContainingSymbol;
|
85
|
+
}
|
86
|
+
return points;
|
87
|
+
}
|
88
|
+
function isStrongPassword(str) {
|
89
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
90
|
+
(0, _assertString.default)(str);
|
91
|
+
var analysis = analyzePassword(str);
|
92
|
+
options = (0, _merge.default)(options || {}, defaultOptions);
|
93
|
+
if (options.returnScore) {
|
94
|
+
return scorePassword(analysis, options);
|
95
|
+
}
|
96
|
+
return analysis.length >= options.minLength && analysis.lowercaseCount >= options.minLowercase && analysis.uppercaseCount >= options.minUppercase && analysis.numberCount >= options.minNumbers && analysis.symbolCount >= options.minSymbols;
|
97
|
+
}
|
98
|
+
module.exports = exports.default;
|
99
|
+
module.exports.default = exports.default;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isSurrogatePair;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
+
var surrogatePair = /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
|
10
|
+
function isSurrogatePair(str) {
|
11
|
+
(0, _assertString.default)(str);
|
12
|
+
return surrogatePair.test(str);
|
13
|
+
}
|
14
|
+
module.exports = exports.default;
|
15
|
+
module.exports.default = exports.default;
|