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
package/es/lib/alpha.js
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
export var alpha = {
|
2
|
+
'en-US': /^[A-Z]+$/i,
|
3
|
+
'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i,
|
4
|
+
'bg-BG': /^[А-Я]+$/i,
|
5
|
+
'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
|
6
|
+
'da-DK': /^[A-ZÆØÅ]+$/i,
|
7
|
+
'de-DE': /^[A-ZÄÖÜß]+$/i,
|
8
|
+
'el-GR': /^[Α-ώ]+$/i,
|
9
|
+
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
|
10
|
+
'fa-IR': /^[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی]+$/i,
|
11
|
+
'fi-FI': /^[A-ZÅÄÖ]+$/i,
|
12
|
+
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
|
13
|
+
'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
|
14
|
+
'ja-JP': /^[ぁ-んァ-ヶヲ-゚一-龠ー・。、]+$/i,
|
15
|
+
'nb-NO': /^[A-ZÆØÅ]+$/i,
|
16
|
+
'nl-NL': /^[A-ZÁÉËÏÓÖÜÚ]+$/i,
|
17
|
+
'nn-NO': /^[A-ZÆØÅ]+$/i,
|
18
|
+
'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
|
19
|
+
'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
|
20
|
+
'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
|
21
|
+
'ru-RU': /^[А-ЯЁ]+$/i,
|
22
|
+
'kk-KZ': /^[А-ЯЁ\u04D8\u04B0\u0406\u04A2\u0492\u04AE\u049A\u04E8\u04BA]+$/i,
|
23
|
+
'sl-SI': /^[A-ZČĆĐŠŽ]+$/i,
|
24
|
+
'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
|
25
|
+
'sr-RS@latin': /^[A-ZČĆŽŠĐ]+$/i,
|
26
|
+
'sr-RS': /^[А-ЯЂЈЉЊЋЏ]+$/i,
|
27
|
+
'sv-SE': /^[A-ZÅÄÖ]+$/i,
|
28
|
+
'th-TH': /^[ก-๐\s]+$/i,
|
29
|
+
'tr-TR': /^[A-ZÇĞİıÖŞÜ]+$/i,
|
30
|
+
'uk-UA': /^[А-ЩЬЮЯЄIЇҐі]+$/i,
|
31
|
+
'vi-VN': /^[A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
|
32
|
+
'ko-KR': /^[ㄱ-ㅎㅏ-ㅣ가-힣]*$/,
|
33
|
+
'ku-IQ': /^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
|
34
|
+
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
|
35
|
+
he: /^[א-ת]+$/,
|
36
|
+
fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i,
|
37
|
+
bn: /^['ঀঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ঽািীুূৃৄেৈোৌ্ৎৗড়ঢ়য়ৠৡৢৣৰৱ৲৳৴৵৶৷৸৹৺৻']+$/,
|
38
|
+
eo: /^[ABCĈD-GĜHĤIJĴK-PRSŜTUŬVZ]+$/i,
|
39
|
+
'hi-IN': /^[\u0900-\u0961]+[\u0972-\u097F]*$/i,
|
40
|
+
'si-LK': /^[\u0D80-\u0DFF]+$/
|
41
|
+
};
|
42
|
+
export var alphanumeric = {
|
43
|
+
'en-US': /^[0-9A-Z]+$/i,
|
44
|
+
'az-AZ': /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i,
|
45
|
+
'bg-BG': /^[0-9А-Я]+$/i,
|
46
|
+
'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
|
47
|
+
'da-DK': /^[0-9A-ZÆØÅ]+$/i,
|
48
|
+
'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
|
49
|
+
'el-GR': /^[0-9Α-ω]+$/i,
|
50
|
+
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
|
51
|
+
'fi-FI': /^[0-9A-ZÅÄÖ]+$/i,
|
52
|
+
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
|
53
|
+
'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
|
54
|
+
'ja-JP': /^[0-90-9ぁ-んァ-ヶヲ-゚一-龠ー・。、]+$/i,
|
55
|
+
'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
|
56
|
+
'nb-NO': /^[0-9A-ZÆØÅ]+$/i,
|
57
|
+
'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i,
|
58
|
+
'nn-NO': /^[0-9A-ZÆØÅ]+$/i,
|
59
|
+
'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
|
60
|
+
'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
|
61
|
+
'ru-RU': /^[0-9А-ЯЁ]+$/i,
|
62
|
+
'kk-KZ': /^[0-9А-ЯЁ\u04D8\u04B0\u0406\u04A2\u0492\u04AE\u049A\u04E8\u04BA]+$/i,
|
63
|
+
'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i,
|
64
|
+
'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
|
65
|
+
'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i,
|
66
|
+
'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i,
|
67
|
+
'sv-SE': /^[0-9A-ZÅÄÖ]+$/i,
|
68
|
+
'th-TH': /^[ก-๙\s]+$/i,
|
69
|
+
'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i,
|
70
|
+
'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i,
|
71
|
+
'ko-KR': /^[0-9ㄱ-ㅎㅏ-ㅣ가-힣]*$/,
|
72
|
+
'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
|
73
|
+
'vi-VN': /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
|
74
|
+
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
|
75
|
+
he: /^[0-9א-ת]+$/,
|
76
|
+
fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i,
|
77
|
+
bn: /^['ঀঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ঽািীুূৃৄেৈোৌ্ৎৗড়ঢ়য়ৠৡৢৣ০১২৩৪৫৬৭৮৯ৰৱ৲৳৴৵৶৷৸৹৺৻']+$/,
|
78
|
+
eo: /^[0-9ABCĈD-GĜHĤIJĴK-PRSŜTUŬVZ]+$/i,
|
79
|
+
'hi-IN': /^[\u0900-\u0963]+[\u0966-\u097F]*$/i,
|
80
|
+
'si-LK': /^[0-9\u0D80-\u0DFF]+$/
|
81
|
+
};
|
82
|
+
export var decimal = {
|
83
|
+
'en-US': '.',
|
84
|
+
ar: '٫'
|
85
|
+
};
|
86
|
+
export var englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM'];
|
87
|
+
for (var locale, i = 0; i < englishLocales.length; i++) {
|
88
|
+
locale = "en-".concat(englishLocales[i]);
|
89
|
+
alpha[locale] = alpha['en-US'];
|
90
|
+
alphanumeric[locale] = alphanumeric['en-US'];
|
91
|
+
decimal[locale] = decimal['en-US'];
|
92
|
+
}
|
93
|
+
|
94
|
+
// Source: http://www.localeplanet.com/java/
|
95
|
+
export var arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', 'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE'];
|
96
|
+
for (var _locale, _i = 0; _i < arabicLocales.length; _i++) {
|
97
|
+
_locale = "ar-".concat(arabicLocales[_i]);
|
98
|
+
alpha[_locale] = alpha.ar;
|
99
|
+
alphanumeric[_locale] = alphanumeric.ar;
|
100
|
+
decimal[_locale] = decimal.ar;
|
101
|
+
}
|
102
|
+
export var farsiLocales = ['IR', 'AF'];
|
103
|
+
for (var _locale2, _i2 = 0; _i2 < farsiLocales.length; _i2++) {
|
104
|
+
_locale2 = "fa-".concat(farsiLocales[_i2]);
|
105
|
+
alphanumeric[_locale2] = alphanumeric.fa;
|
106
|
+
decimal[_locale2] = decimal.ar;
|
107
|
+
}
|
108
|
+
export var bengaliLocales = ['BD', 'IN'];
|
109
|
+
for (var _locale3, _i3 = 0; _i3 < bengaliLocales.length; _i3++) {
|
110
|
+
_locale3 = "bn-".concat(bengaliLocales[_i3]);
|
111
|
+
alpha[_locale3] = alpha.bn;
|
112
|
+
alphanumeric[_locale3] = alphanumeric.bn;
|
113
|
+
decimal[_locale3] = decimal['en-US'];
|
114
|
+
}
|
115
|
+
|
116
|
+
// Source: https://en.wikipedia.org/wiki/Decimal_mark
|
117
|
+
export var dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY'];
|
118
|
+
export var commaDecimal = ['bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'eo', 'es-ES', 'fr-CA', 'fr-FR', 'id-ID', 'it-IT', 'ku-IQ', 'hi-IN', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'kk-KZ', 'si-LK', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN'];
|
119
|
+
for (var _i4 = 0; _i4 < dotDecimal.length; _i4++) {
|
120
|
+
decimal[dotDecimal[_i4]] = decimal['en-US'];
|
121
|
+
}
|
122
|
+
for (var _i5 = 0; _i5 < commaDecimal.length; _i5++) {
|
123
|
+
decimal[commaDecimal[_i5]] = ',';
|
124
|
+
}
|
125
|
+
alpha['fr-CA'] = alpha['fr-FR'];
|
126
|
+
alphanumeric['fr-CA'] = alphanumeric['fr-FR'];
|
127
|
+
alpha['pt-BR'] = alpha['pt-PT'];
|
128
|
+
alphanumeric['pt-BR'] = alphanumeric['pt-PT'];
|
129
|
+
decimal['pt-BR'] = decimal['pt-PT'];
|
130
|
+
|
131
|
+
// see #862
|
132
|
+
alpha['pl-Pl'] = alpha['pl-PL'];
|
133
|
+
alphanumeric['pl-Pl'] = alphanumeric['pl-PL'];
|
134
|
+
decimal['pl-Pl'] = decimal['pl-PL'];
|
135
|
+
|
136
|
+
// see #1455
|
137
|
+
alpha['fa-AF'] = alpha.fa;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
import toString from './util/toString';
|
3
|
+
import merge from './util/merge';
|
4
|
+
var defaulContainsOptions = {
|
5
|
+
ignoreCase: false,
|
6
|
+
minOccurrences: 1
|
7
|
+
};
|
8
|
+
export default function contains(str, elem, options) {
|
9
|
+
assertString(str);
|
10
|
+
options = merge(options, defaulContainsOptions);
|
11
|
+
if (options.ignoreCase) {
|
12
|
+
return str.toLowerCase().split(toString(elem).toLowerCase()).length > options.minOccurrences;
|
13
|
+
}
|
14
|
+
return str.split(toString(elem)).length > options.minOccurrences;
|
15
|
+
}
|
package/es/lib/equals.js
ADDED
package/es/lib/escape.js
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
export default function escape(str) {
|
3
|
+
assertString(str);
|
4
|
+
return str.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>').replace(/\//g, '/').replace(/\\/g, '\').replace(/`/g, '`');
|
5
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
|
3
|
+
// http://www.brainjar.com/js/validation/
|
4
|
+
// https://www.aba.com/news-research/research-analysis/routing-number-policy-procedures
|
5
|
+
// series reserved for future use are excluded
|
6
|
+
var isRoutingReg = /^(?!(1[3-9])|(20)|(3[3-9])|(4[0-9])|(5[0-9])|(60)|(7[3-9])|(8[1-9])|(9[0-2])|(9[3-9]))[0-9]{9}$/;
|
7
|
+
export default function isAbaRouting(str) {
|
8
|
+
assertString(str);
|
9
|
+
if (!isRoutingReg.test(str)) return false;
|
10
|
+
var checkSumVal = 0;
|
11
|
+
for (var i = 0; i < str.length; i++) {
|
12
|
+
if (i % 3 === 0) checkSumVal += str[i] * 3;else if (i % 3 === 1) checkSumVal += str[i] * 7;else checkSumVal += str[i] * 1;
|
13
|
+
}
|
14
|
+
return checkSumVal % 10 === 0;
|
15
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import toDate from './toDate';
|
2
|
+
export default function isAfter(date, options) {
|
3
|
+
// For backwards compatibility:
|
4
|
+
// isAfter(str [, date]), i.e. `options` could be used as argument for the legacy `date`
|
5
|
+
var comparisonDate = (options === null || options === void 0 ? void 0 : options.comparisonDate) || options || Date().toString();
|
6
|
+
var comparison = toDate(comparisonDate);
|
7
|
+
var original = toDate(date);
|
8
|
+
return !!(original && comparison && original > comparison);
|
9
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
import { alpha } from './alpha';
|
3
|
+
export default function isAlpha(_str) {
|
4
|
+
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
|
5
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
6
|
+
assertString(_str);
|
7
|
+
var str = _str;
|
8
|
+
var ignore = options.ignore;
|
9
|
+
if (ignore) {
|
10
|
+
if (ignore instanceof RegExp) {
|
11
|
+
str = str.replace(ignore, '');
|
12
|
+
} else if (typeof ignore === 'string') {
|
13
|
+
str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
|
14
|
+
} else {
|
15
|
+
throw new Error('ignore should be instance of a String or RegExp');
|
16
|
+
}
|
17
|
+
}
|
18
|
+
if (locale in alpha) {
|
19
|
+
return alpha[locale].test(str);
|
20
|
+
}
|
21
|
+
throw new Error("Invalid locale '".concat(locale, "'"));
|
22
|
+
}
|
23
|
+
export var locales = Object.keys(alpha);
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
import { alphanumeric } from './alpha';
|
3
|
+
export default function isAlphanumeric(_str) {
|
4
|
+
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
|
5
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
6
|
+
assertString(_str);
|
7
|
+
var str = _str;
|
8
|
+
var ignore = options.ignore;
|
9
|
+
if (ignore) {
|
10
|
+
if (ignore instanceof RegExp) {
|
11
|
+
str = str.replace(ignore, '');
|
12
|
+
} else if (typeof ignore === 'string') {
|
13
|
+
str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
|
14
|
+
} else {
|
15
|
+
throw new Error('ignore should be instance of a String or RegExp');
|
16
|
+
}
|
17
|
+
}
|
18
|
+
if (locale in alphanumeric) {
|
19
|
+
return alphanumeric[locale].test(str);
|
20
|
+
}
|
21
|
+
throw new Error("Invalid locale '".concat(locale, "'"));
|
22
|
+
}
|
23
|
+
export var locales = Object.keys(alphanumeric);
|
package/es/lib/isBIC.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
import { CountryCodes } from './isISO31661Alpha2';
|
3
|
+
|
4
|
+
// https://en.wikipedia.org/wiki/ISO_9362
|
5
|
+
var isBICReg = /^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/;
|
6
|
+
export default function isBIC(str) {
|
7
|
+
assertString(str);
|
8
|
+
|
9
|
+
// toUpperCase() should be removed when a new major version goes out that changes
|
10
|
+
// the regex to [A-Z] (per the spec).
|
11
|
+
var countryCode = str.slice(4, 6).toUpperCase();
|
12
|
+
if (!CountryCodes.has(countryCode) && countryCode !== 'XK') {
|
13
|
+
return false;
|
14
|
+
}
|
15
|
+
return isBICReg.test(str);
|
16
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
import merge from './util/merge';
|
3
|
+
var base32 = /^[A-Z2-7]+=*$/;
|
4
|
+
var crockfordBase32 = /^[A-HJKMNP-TV-Z0-9]+$/;
|
5
|
+
var defaultBase32Options = {
|
6
|
+
crockford: false
|
7
|
+
};
|
8
|
+
export default function isBase32(str, options) {
|
9
|
+
assertString(str);
|
10
|
+
options = merge(options, defaultBase32Options);
|
11
|
+
if (options.crockford) {
|
12
|
+
return crockfordBase32.test(str);
|
13
|
+
}
|
14
|
+
var len = str.length;
|
15
|
+
if (len % 8 === 0 && base32.test(str)) {
|
16
|
+
return true;
|
17
|
+
}
|
18
|
+
return false;
|
19
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
|
3
|
+
// Accepted chars - 123456789ABCDEFGH JKLMN PQRSTUVWXYZabcdefghijk mnopqrstuvwxyz
|
4
|
+
var base58Reg = /^[A-HJ-NP-Za-km-z1-9]*$/;
|
5
|
+
export default function isBase58(str) {
|
6
|
+
assertString(str);
|
7
|
+
if (base58Reg.test(str)) {
|
8
|
+
return true;
|
9
|
+
}
|
10
|
+
return false;
|
11
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
import merge from './util/merge';
|
3
|
+
var notBase64 = /[^A-Z0-9+\/=]/i;
|
4
|
+
var urlSafeBase64 = /^[A-Z0-9_\-]*$/i;
|
5
|
+
var defaultBase64Options = {
|
6
|
+
urlSafe: false
|
7
|
+
};
|
8
|
+
export default function isBase64(str, options) {
|
9
|
+
assertString(str);
|
10
|
+
options = merge(options, defaultBase64Options);
|
11
|
+
var len = str.length;
|
12
|
+
if (options.urlSafe) {
|
13
|
+
return urlSafeBase64.test(str);
|
14
|
+
}
|
15
|
+
if (len % 4 !== 0 || notBase64.test(str)) {
|
16
|
+
return false;
|
17
|
+
}
|
18
|
+
var firstPaddingChar = str.indexOf('=');
|
19
|
+
return firstPaddingChar === -1 || firstPaddingChar === len - 1 || firstPaddingChar === len - 2 && str[len - 1] === '=';
|
20
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
import toDate from './toDate';
|
3
|
+
export default function isBefore(str) {
|
4
|
+
var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String(new Date());
|
5
|
+
assertString(str);
|
6
|
+
var comparison = toDate(date);
|
7
|
+
var original = toDate(str);
|
8
|
+
return !!(original && comparison && original < comparison);
|
9
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
var defaultOptions = {
|
3
|
+
loose: false
|
4
|
+
};
|
5
|
+
var strictBooleans = ['true', 'false', '1', '0'];
|
6
|
+
var looseBooleans = [].concat(strictBooleans, ['yes', 'no']);
|
7
|
+
export default function isBoolean(str) {
|
8
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
|
9
|
+
assertString(str);
|
10
|
+
if (options.loose) {
|
11
|
+
return looseBooleans.includes(str.toLowerCase());
|
12
|
+
}
|
13
|
+
return strictBooleans.includes(str);
|
14
|
+
}
|
@@ -0,0 +1,19 @@
|
|
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
|
+
import assertString from './util/assertString';
|
3
|
+
|
4
|
+
/* eslint-disable prefer-rest-params */
|
5
|
+
export default function isByteLength(str, options) {
|
6
|
+
assertString(str);
|
7
|
+
var min;
|
8
|
+
var max;
|
9
|
+
if (_typeof(options) === 'object') {
|
10
|
+
min = options.min || 0;
|
11
|
+
max = options.max;
|
12
|
+
} else {
|
13
|
+
// backwards compatibility: isByteLength(str, min [, max])
|
14
|
+
min = arguments[1];
|
15
|
+
max = arguments[2];
|
16
|
+
}
|
17
|
+
var len = encodeURI(str).split(/%..|./).length - 1;
|
18
|
+
return len >= min && (typeof max === 'undefined' || len <= max);
|
19
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
import isLuhnValid from './isLuhnNumber';
|
3
|
+
var cards = {
|
4
|
+
amex: /^3[47][0-9]{13}$/,
|
5
|
+
dinersclub: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
|
6
|
+
discover: /^6(?:011|5[0-9][0-9])[0-9]{12,15}$/,
|
7
|
+
jcb: /^(?:2131|1800|35\d{3})\d{11}$/,
|
8
|
+
mastercard: /^5[1-5][0-9]{2}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$/,
|
9
|
+
// /^[25][1-7][0-9]{14}$/;
|
10
|
+
unionpay: /^(6[27][0-9]{14}|^(81[0-9]{14,17}))$/,
|
11
|
+
visa: /^(?:4[0-9]{12})(?:[0-9]{3,6})?$/
|
12
|
+
};
|
13
|
+
var allCards = function () {
|
14
|
+
var tmpCardsArray = [];
|
15
|
+
for (var cardProvider in cards) {
|
16
|
+
// istanbul ignore else
|
17
|
+
if (cards.hasOwnProperty(cardProvider)) {
|
18
|
+
tmpCardsArray.push(cards[cardProvider]);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
return tmpCardsArray;
|
22
|
+
}();
|
23
|
+
export default function isCreditCard(card) {
|
24
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
25
|
+
assertString(card);
|
26
|
+
var provider = options.provider;
|
27
|
+
var sanitized = card.replace(/[- ]+/g, '');
|
28
|
+
if (provider && provider.toLowerCase() in cards) {
|
29
|
+
// specific provider in the list
|
30
|
+
if (!cards[provider.toLowerCase()].test(sanitized)) {
|
31
|
+
return false;
|
32
|
+
}
|
33
|
+
} else if (provider && !(provider.toLowerCase() in cards)) {
|
34
|
+
/* specific provider not in the list */
|
35
|
+
throw new Error("".concat(provider, " is not a valid credit card provider."));
|
36
|
+
} else if (!allCards.some(function (cardProvider) {
|
37
|
+
return cardProvider.test(sanitized);
|
38
|
+
})) {
|
39
|
+
// no specific provider
|
40
|
+
return false;
|
41
|
+
}
|
42
|
+
return isLuhnValid(card);
|
43
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import merge from './util/merge';
|
2
|
+
import assertString from './util/assertString';
|
3
|
+
function currencyRegex(options) {
|
4
|
+
var decimal_digits = "\\d{".concat(options.digits_after_decimal[0], "}");
|
5
|
+
options.digits_after_decimal.forEach(function (digit, index) {
|
6
|
+
if (index !== 0) decimal_digits = "".concat(decimal_digits, "|\\d{").concat(digit, "}");
|
7
|
+
});
|
8
|
+
var symbol = "(".concat(options.symbol.replace(/\W/, function (m) {
|
9
|
+
return "\\".concat(m);
|
10
|
+
}), ")").concat(options.require_symbol ? '' : '?'),
|
11
|
+
negative = '-?',
|
12
|
+
whole_dollar_amount_without_sep = '[1-9]\\d*',
|
13
|
+
whole_dollar_amount_with_sep = "[1-9]\\d{0,2}(\\".concat(options.thousands_separator, "\\d{3})*"),
|
14
|
+
valid_whole_dollar_amounts = ['0', whole_dollar_amount_without_sep, whole_dollar_amount_with_sep],
|
15
|
+
whole_dollar_amount = "(".concat(valid_whole_dollar_amounts.join('|'), ")?"),
|
16
|
+
decimal_amount = "(\\".concat(options.decimal_separator, "(").concat(decimal_digits, "))").concat(options.require_decimal ? '' : '?');
|
17
|
+
var pattern = whole_dollar_amount + (options.allow_decimal || options.require_decimal ? decimal_amount : '');
|
18
|
+
|
19
|
+
// default is negative sign before symbol, but there are two other options (besides parens)
|
20
|
+
if (options.allow_negatives && !options.parens_for_negatives) {
|
21
|
+
if (options.negative_sign_after_digits) {
|
22
|
+
pattern += negative;
|
23
|
+
} else if (options.negative_sign_before_digits) {
|
24
|
+
pattern = negative + pattern;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
// South African Rand, for example, uses R 123 (space) and R-123 (no space)
|
29
|
+
if (options.allow_negative_sign_placeholder) {
|
30
|
+
pattern = "( (?!\\-))?".concat(pattern);
|
31
|
+
} else if (options.allow_space_after_symbol) {
|
32
|
+
pattern = " ?".concat(pattern);
|
33
|
+
} else if (options.allow_space_after_digits) {
|
34
|
+
pattern += '( (?!$))?';
|
35
|
+
}
|
36
|
+
if (options.symbol_after_digits) {
|
37
|
+
pattern += symbol;
|
38
|
+
} else {
|
39
|
+
pattern = symbol + pattern;
|
40
|
+
}
|
41
|
+
if (options.allow_negatives) {
|
42
|
+
if (options.parens_for_negatives) {
|
43
|
+
pattern = "(\\(".concat(pattern, "\\)|").concat(pattern, ")");
|
44
|
+
} else if (!(options.negative_sign_before_digits || options.negative_sign_after_digits)) {
|
45
|
+
pattern = negative + pattern;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
// ensure there's a dollar and/or decimal amount, and that
|
50
|
+
// it doesn't start with a space or a negative sign followed by a space
|
51
|
+
return new RegExp("^(?!-? )(?=.*\\d)".concat(pattern, "$"));
|
52
|
+
}
|
53
|
+
var default_currency_options = {
|
54
|
+
symbol: '$',
|
55
|
+
require_symbol: false,
|
56
|
+
allow_space_after_symbol: false,
|
57
|
+
symbol_after_digits: false,
|
58
|
+
allow_negatives: true,
|
59
|
+
parens_for_negatives: false,
|
60
|
+
negative_sign_before_digits: false,
|
61
|
+
negative_sign_after_digits: false,
|
62
|
+
allow_negative_sign_placeholder: false,
|
63
|
+
thousands_separator: ',',
|
64
|
+
decimal_separator: '.',
|
65
|
+
allow_decimal: true,
|
66
|
+
require_decimal: false,
|
67
|
+
digits_after_decimal: [2],
|
68
|
+
allow_space_after_digits: false
|
69
|
+
};
|
70
|
+
export default function isCurrency(str, options) {
|
71
|
+
assertString(str);
|
72
|
+
options = merge(options, default_currency_options);
|
73
|
+
return currencyRegex(options).test(str);
|
74
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
var validMediaType = /^[a-z]+\/[a-z0-9\-\+\._]+$/i;
|
3
|
+
var validAttribute = /^[a-z\-]+=[a-z0-9\-]+$/i;
|
4
|
+
var validData = /^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i;
|
5
|
+
export default function isDataURI(str) {
|
6
|
+
assertString(str);
|
7
|
+
var data = str.split(',');
|
8
|
+
if (data.length < 2) {
|
9
|
+
return false;
|
10
|
+
}
|
11
|
+
var attributes = data.shift().trim().split(';');
|
12
|
+
var schemeAndMediaType = attributes.shift();
|
13
|
+
if (schemeAndMediaType.slice(0, 5) !== 'data:') {
|
14
|
+
return false;
|
15
|
+
}
|
16
|
+
var mediaType = schemeAndMediaType.slice(5);
|
17
|
+
if (mediaType !== '' && !validMediaType.test(mediaType)) {
|
18
|
+
return false;
|
19
|
+
}
|
20
|
+
for (var i = 0; i < attributes.length; i++) {
|
21
|
+
if (!(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') && !validAttribute.test(attributes[i])) {
|
22
|
+
return false;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
for (var _i = 0; _i < data.length; _i++) {
|
26
|
+
if (!validData.test(data[_i])) {
|
27
|
+
return false;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
return true;
|
31
|
+
}
|
package/es/lib/isDate.js
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
3
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
4
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
5
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
6
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
8
|
+
import merge from './util/merge';
|
9
|
+
var default_date_options = {
|
10
|
+
format: 'YYYY/MM/DD',
|
11
|
+
delimiters: ['/', '-'],
|
12
|
+
strictMode: false
|
13
|
+
};
|
14
|
+
function isValidFormat(format) {
|
15
|
+
return /(^(y{4}|y{2})[.\/-](m{1,2})[.\/-](d{1,2})$)|(^(m{1,2})[.\/-](d{1,2})[.\/-]((y{4}|y{2})$))|(^(d{1,2})[.\/-](m{1,2})[.\/-]((y{4}|y{2})$))/gi.test(format);
|
16
|
+
}
|
17
|
+
function zip(date, format) {
|
18
|
+
var zippedArr = [],
|
19
|
+
len = Math.min(date.length, format.length);
|
20
|
+
for (var i = 0; i < len; i++) {
|
21
|
+
zippedArr.push([date[i], format[i]]);
|
22
|
+
}
|
23
|
+
return zippedArr;
|
24
|
+
}
|
25
|
+
export default function isDate(input, options) {
|
26
|
+
if (typeof options === 'string') {
|
27
|
+
// Allow backward compatibility for old format isDate(input [, format])
|
28
|
+
options = merge({
|
29
|
+
format: options
|
30
|
+
}, default_date_options);
|
31
|
+
} else {
|
32
|
+
options = merge(options, default_date_options);
|
33
|
+
}
|
34
|
+
if (typeof input === 'string' && isValidFormat(options.format)) {
|
35
|
+
var formatDelimiter = options.delimiters.find(function (delimiter) {
|
36
|
+
return options.format.indexOf(delimiter) !== -1;
|
37
|
+
});
|
38
|
+
var dateDelimiter = options.strictMode ? formatDelimiter : options.delimiters.find(function (delimiter) {
|
39
|
+
return input.indexOf(delimiter) !== -1;
|
40
|
+
});
|
41
|
+
var dateAndFormat = zip(input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter));
|
42
|
+
var dateObj = {};
|
43
|
+
var _iterator = _createForOfIteratorHelper(dateAndFormat),
|
44
|
+
_step;
|
45
|
+
try {
|
46
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
47
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
48
|
+
dateWord = _step$value[0],
|
49
|
+
formatWord = _step$value[1];
|
50
|
+
if (dateWord.length !== formatWord.length) {
|
51
|
+
return false;
|
52
|
+
}
|
53
|
+
dateObj[formatWord.charAt(0)] = dateWord;
|
54
|
+
}
|
55
|
+
} catch (err) {
|
56
|
+
_iterator.e(err);
|
57
|
+
} finally {
|
58
|
+
_iterator.f();
|
59
|
+
}
|
60
|
+
var fullYear = dateObj.y;
|
61
|
+
|
62
|
+
// Check if the year starts with a hyphen
|
63
|
+
if (fullYear.startsWith('-')) {
|
64
|
+
return false; // Hyphen before year is not allowed
|
65
|
+
}
|
66
|
+
if (dateObj.y.length === 2) {
|
67
|
+
var parsedYear = parseInt(dateObj.y, 10);
|
68
|
+
if (isNaN(parsedYear)) {
|
69
|
+
return false;
|
70
|
+
}
|
71
|
+
var currentYearLastTwoDigits = new Date().getFullYear() % 100;
|
72
|
+
if (parsedYear < currentYearLastTwoDigits) {
|
73
|
+
fullYear = "20".concat(dateObj.y);
|
74
|
+
} else {
|
75
|
+
fullYear = "19".concat(dateObj.y);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
var month = dateObj.m;
|
79
|
+
if (dateObj.m.length === 1) {
|
80
|
+
month = "0".concat(dateObj.m);
|
81
|
+
}
|
82
|
+
var day = dateObj.d;
|
83
|
+
if (dateObj.d.length === 1) {
|
84
|
+
day = "0".concat(dateObj.d);
|
85
|
+
}
|
86
|
+
return new Date("".concat(fullYear, "-").concat(month, "-").concat(day, "T00:00:00.000Z")).getUTCDate() === +dateObj.d;
|
87
|
+
}
|
88
|
+
if (!options.strictMode) {
|
89
|
+
return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
|
90
|
+
}
|
91
|
+
return false;
|
92
|
+
}
|