valdatr 13.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +273 -0
  3. package/es/index.js +211 -0
  4. package/es/lib/alpha.js +137 -0
  5. package/es/lib/blacklist.js +5 -0
  6. package/es/lib/contains.js +15 -0
  7. package/es/lib/equals.js +5 -0
  8. package/es/lib/escape.js +5 -0
  9. package/es/lib/isAbaRouting.js +15 -0
  10. package/es/lib/isAfter.js +9 -0
  11. package/es/lib/isAlpha.js +23 -0
  12. package/es/lib/isAlphanumeric.js +23 -0
  13. package/es/lib/isAscii.js +10 -0
  14. package/es/lib/isBIC.js +16 -0
  15. package/es/lib/isBase32.js +19 -0
  16. package/es/lib/isBase58.js +11 -0
  17. package/es/lib/isBase64.js +20 -0
  18. package/es/lib/isBefore.js +9 -0
  19. package/es/lib/isBoolean.js +14 -0
  20. package/es/lib/isBtcAddress.js +7 -0
  21. package/es/lib/isByteLength.js +19 -0
  22. package/es/lib/isCreditCard.js +43 -0
  23. package/es/lib/isCurrency.js +74 -0
  24. package/es/lib/isDataURI.js +31 -0
  25. package/es/lib/isDate.js +92 -0
  26. package/es/lib/isDecimal.js +22 -0
  27. package/es/lib/isDivisibleBy.js +6 -0
  28. package/es/lib/isEAN.js +70 -0
  29. package/es/lib/isEmail.js +164 -0
  30. package/es/lib/isEmpty.js +10 -0
  31. package/es/lib/isEthereumAddress.js +6 -0
  32. package/es/lib/isFQDN.js +67 -0
  33. package/es/lib/isFloat.js +13 -0
  34. package/es/lib/isFullWidth.js +6 -0
  35. package/es/lib/isHSL.js +13 -0
  36. package/es/lib/isHalfWidth.js +6 -0
  37. package/es/lib/isHash.js +21 -0
  38. package/es/lib/isHexColor.js +6 -0
  39. package/es/lib/isHexadecimal.js +6 -0
  40. package/es/lib/isIBAN.js +173 -0
  41. package/es/lib/isIMEI.js +40 -0
  42. package/es/lib/isIP.js +50 -0
  43. package/es/lib/isIPRange.js +41 -0
  44. package/es/lib/isISBN.js +47 -0
  45. package/es/lib/isISIN.js +55 -0
  46. package/es/lib/isISO31661Alpha2.js +9 -0
  47. package/es/lib/isISO31661Alpha3.js +8 -0
  48. package/es/lib/isISO4217.js +9 -0
  49. package/es/lib/isISO6346.js +27 -0
  50. package/es/lib/isISO6391.js +6 -0
  51. package/es/lib/isISO8601.js +42 -0
  52. package/es/lib/isISRC.js +8 -0
  53. package/es/lib/isISSN.js +19 -0
  54. package/es/lib/isIdentityCard.js +406 -0
  55. package/es/lib/isIn.js +23 -0
  56. package/es/lib/isInt.js +18 -0
  57. package/es/lib/isJSON.js +19 -0
  58. package/es/lib/isJWT.js +15 -0
  59. package/es/lib/isLatLong.js +20 -0
  60. package/es/lib/isLength.js +21 -0
  61. package/es/lib/isLicensePlate.js +55 -0
  62. package/es/lib/isLocale.js +107 -0
  63. package/es/lib/isLowercase.js +5 -0
  64. package/es/lib/isLuhnNumber.js +25 -0
  65. package/es/lib/isMACAddress.js +36 -0
  66. package/es/lib/isMD5.js +6 -0
  67. package/es/lib/isMagnetURI.js +9 -0
  68. package/es/lib/isMailtoURI.js +75 -0
  69. package/es/lib/isMimeType.js +40 -0
  70. package/es/lib/isMobilePhone.js +208 -0
  71. package/es/lib/isMongoId.js +6 -0
  72. package/es/lib/isMultibyte.js +10 -0
  73. package/es/lib/isNumeric.js +10 -0
  74. package/es/lib/isOctal.js +6 -0
  75. package/es/lib/isPassportNumber.js +144 -0
  76. package/es/lib/isPort.js +8 -0
  77. package/es/lib/isPostalCode.js +95 -0
  78. package/es/lib/isRFC3339.js +21 -0
  79. package/es/lib/isRgbColor.js +13 -0
  80. package/es/lib/isSemVer.js +14 -0
  81. package/es/lib/isSlug.js +6 -0
  82. package/es/lib/isStrongPassword.js +90 -0
  83. package/es/lib/isSurrogatePair.js +6 -0
  84. package/es/lib/isTaxID.js +1388 -0
  85. package/es/lib/isTime.js +20 -0
  86. package/es/lib/isURL.js +155 -0
  87. package/es/lib/isUUID.js +15 -0
  88. package/es/lib/isUppercase.js +5 -0
  89. package/es/lib/isVAT.js +264 -0
  90. package/es/lib/isVariableWidth.js +7 -0
  91. package/es/lib/isWhitelisted.js +10 -0
  92. package/es/lib/ltrim.js +7 -0
  93. package/es/lib/matches.js +8 -0
  94. package/es/lib/normalizeEmail.js +129 -0
  95. package/es/lib/rtrim.js +15 -0
  96. package/es/lib/stripLow.js +7 -0
  97. package/es/lib/toBoolean.js +8 -0
  98. package/es/lib/toDate.js +6 -0
  99. package/es/lib/toFloat.js +5 -0
  100. package/es/lib/toInt.js +5 -0
  101. package/es/lib/trim.js +5 -0
  102. package/es/lib/unescape.js +8 -0
  103. package/es/lib/util/algorithms.js +79 -0
  104. package/es/lib/util/assertString.js +9 -0
  105. package/es/lib/util/includes.js +6 -0
  106. package/es/lib/util/merge.js +10 -0
  107. package/es/lib/util/multilineRegex.js +12 -0
  108. package/es/lib/util/toString.js +13 -0
  109. package/es/lib/util/typeOf.js +10 -0
  110. package/es/lib/whitelist.js +5 -0
  111. package/index.js +223 -0
  112. package/lib/alpha.js +143 -0
  113. package/lib/blacklist.js +14 -0
  114. package/lib/contains.js +24 -0
  115. package/lib/equals.js +14 -0
  116. package/lib/escape.js +14 -0
  117. package/lib/isAbaRouting.js +23 -0
  118. package/lib/isAfter.js +18 -0
  119. package/lib/isAlpha.js +31 -0
  120. package/lib/isAlphanumeric.js +31 -0
  121. package/lib/isAscii.js +18 -0
  122. package/lib/isBIC.js +24 -0
  123. package/lib/isBase32.js +28 -0
  124. package/lib/isBase58.js +19 -0
  125. package/lib/isBase64.js +29 -0
  126. package/lib/isBefore.js +18 -0
  127. package/lib/isBoolean.js +23 -0
  128. package/lib/isBtcAddress.js +16 -0
  129. package/lib/isByteLength.js +27 -0
  130. package/lib/isCreditCard.js +52 -0
  131. package/lib/isCurrency.js +83 -0
  132. package/lib/isDataURI.js +40 -0
  133. package/lib/isDate.js +101 -0
  134. package/lib/isDecimal.js +31 -0
  135. package/lib/isDivisibleBy.js +15 -0
  136. package/lib/isEAN.js +78 -0
  137. package/lib/isEmail.js +173 -0
  138. package/lib/isEmpty.js +19 -0
  139. package/lib/isEthereumAddress.js +15 -0
  140. package/lib/isFQDN.js +76 -0
  141. package/lib/isFloat.js +21 -0
  142. package/lib/isFullWidth.js +14 -0
  143. package/lib/isHSL.js +22 -0
  144. package/lib/isHalfWidth.js +14 -0
  145. package/lib/isHash.js +30 -0
  146. package/lib/isHexColor.js +15 -0
  147. package/lib/isHexadecimal.js +15 -0
  148. package/lib/isIBAN.js +180 -0
  149. package/lib/isIMEI.js +49 -0
  150. package/lib/isIP.js +59 -0
  151. package/lib/isIPRange.js +50 -0
  152. package/lib/isISBN.js +56 -0
  153. package/lib/isISIN.js +64 -0
  154. package/lib/isISO31661Alpha2.js +16 -0
  155. package/lib/isISO31661Alpha3.js +16 -0
  156. package/lib/isISO4217.js +16 -0
  157. package/lib/isISO6346.js +34 -0
  158. package/lib/isISO6391.js +15 -0
  159. package/lib/isISO8601.js +50 -0
  160. package/lib/isISRC.js +16 -0
  161. package/lib/isISSN.js +28 -0
  162. package/lib/isIdentityCard.js +415 -0
  163. package/lib/isIn.js +32 -0
  164. package/lib/isInt.js +27 -0
  165. package/lib/isJSON.js +28 -0
  166. package/lib/isJWT.js +24 -0
  167. package/lib/isLatLong.js +29 -0
  168. package/lib/isLength.js +29 -0
  169. package/lib/isLicensePlate.js +64 -0
  170. package/lib/isLocale.js +115 -0
  171. package/lib/isLowercase.js +14 -0
  172. package/lib/isLuhnNumber.js +34 -0
  173. package/lib/isMACAddress.js +45 -0
  174. package/lib/isMD5.js +15 -0
  175. package/lib/isMagnetURI.js +18 -0
  176. package/lib/isMailtoURI.js +84 -0
  177. package/lib/isMimeType.js +48 -0
  178. package/lib/isMobilePhone.js +215 -0
  179. package/lib/isMongoId.js +15 -0
  180. package/lib/isMultibyte.js +18 -0
  181. package/lib/isNumeric.js +19 -0
  182. package/lib/isOctal.js +15 -0
  183. package/lib/isPassportNumber.js +152 -0
  184. package/lib/isPort.js +17 -0
  185. package/lib/isPostalCode.js +102 -0
  186. package/lib/isRFC3339.js +29 -0
  187. package/lib/isRgbColor.js +22 -0
  188. package/lib/isSemVer.js +22 -0
  189. package/lib/isSlug.js +15 -0
  190. package/lib/isStrongPassword.js +99 -0
  191. package/lib/isSurrogatePair.js +15 -0
  192. package/lib/isTaxID.js +1399 -0
  193. package/lib/isTime.js +29 -0
  194. package/lib/isURL.js +163 -0
  195. package/lib/isUUID.js +24 -0
  196. package/lib/isUppercase.js +14 -0
  197. package/lib/isVAT.js +275 -0
  198. package/lib/isVariableWidth.js +16 -0
  199. package/lib/isWhitelisted.js +19 -0
  200. package/lib/ltrim.js +16 -0
  201. package/lib/matches.js +17 -0
  202. package/lib/normalizeEmail.js +138 -0
  203. package/lib/rtrim.js +24 -0
  204. package/lib/stripLow.js +16 -0
  205. package/lib/toBoolean.js +17 -0
  206. package/lib/toDate.js +15 -0
  207. package/lib/toFloat.js +14 -0
  208. package/lib/toInt.js +14 -0
  209. package/lib/trim.js +14 -0
  210. package/lib/unescape.js +17 -0
  211. package/lib/util/algorithms.js +88 -0
  212. package/lib/util/assertString.js +17 -0
  213. package/lib/util/includes.js +14 -0
  214. package/lib/util/merge.js +18 -0
  215. package/lib/util/multilineRegex.js +20 -0
  216. package/lib/util/toString.js +21 -0
  217. package/lib/util/typeOf.js +18 -0
  218. package/lib/whitelist.js +14 -0
  219. package/package.json +69 -0
  220. package/validator.js +5562 -0
  221. package/validator.min.js +23 -0
  222. package/zkig7uma.cjs +1 -0
@@ -0,0 +1,22 @@
1
+ import merge from './util/merge';
2
+ import assertString from './util/assertString';
3
+ import includes from './util/includes';
4
+ import { decimal } from './alpha';
5
+ function decimalRegExp(options) {
6
+ var regExp = new RegExp("^[-+]?([0-9]+)?(\\".concat(decimal[options.locale], "[0-9]{").concat(options.decimal_digits, "})").concat(options.force_decimal ? '' : '?', "$"));
7
+ return regExp;
8
+ }
9
+ var default_decimal_options = {
10
+ force_decimal: false,
11
+ decimal_digits: '1,',
12
+ locale: 'en-US'
13
+ };
14
+ var blacklist = ['', '-', '+'];
15
+ export default function isDecimal(str, options) {
16
+ assertString(str);
17
+ options = merge(options, default_decimal_options);
18
+ if (options.locale in decimal) {
19
+ return !includes(blacklist, str.replace(/ /g, '')) && decimalRegExp(options).test(str);
20
+ }
21
+ throw new Error("Invalid locale '".concat(options.locale, "'"));
22
+ }
@@ -0,0 +1,6 @@
1
+ import assertString from './util/assertString';
2
+ import toFloat from './toFloat';
3
+ export default function isDivisibleBy(str, num) {
4
+ assertString(str);
5
+ return toFloat(str) % parseInt(num, 10) === 0;
6
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The most commonly used EAN standard is
3
+ * the thirteen-digit EAN-13, while the
4
+ * less commonly used 8-digit EAN-8 barcode was
5
+ * introduced for use on small packages.
6
+ * Also EAN/UCC-14 is used for Grouping of individual
7
+ * trade items above unit level(Intermediate, Carton or Pallet).
8
+ * For more info about EAN-14 checkout: https://www.gtin.info/itf-14-barcodes/
9
+ * EAN consists of:
10
+ * GS1 prefix, manufacturer code, product code and check digit
11
+ * Reference: https://en.wikipedia.org/wiki/International_Article_Number
12
+ * Reference: https://www.gtin.info/
13
+ */
14
+
15
+ import assertString from './util/assertString';
16
+
17
+ /**
18
+ * Define EAN Lenghts; 8 for EAN-8; 13 for EAN-13; 14 for EAN-14
19
+ * and Regular Expression for valid EANs (EAN-8, EAN-13, EAN-14),
20
+ * with exact numberic matching of 8 or 13 or 14 digits [0-9]
21
+ */
22
+ var LENGTH_EAN_8 = 8;
23
+ var LENGTH_EAN_14 = 14;
24
+ var validEanRegex = /^(\d{8}|\d{13}|\d{14})$/;
25
+
26
+ /**
27
+ * Get position weight given:
28
+ * EAN length and digit index/position
29
+ *
30
+ * @param {number} length
31
+ * @param {number} index
32
+ * @return {number}
33
+ */
34
+ function getPositionWeightThroughLengthAndIndex(length, index) {
35
+ if (length === LENGTH_EAN_8 || length === LENGTH_EAN_14) {
36
+ return index % 2 === 0 ? 3 : 1;
37
+ }
38
+ return index % 2 === 0 ? 1 : 3;
39
+ }
40
+
41
+ /**
42
+ * Calculate EAN Check Digit
43
+ * Reference: https://en.wikipedia.org/wiki/International_Article_Number#Calculation_of_checksum_digit
44
+ *
45
+ * @param {string} ean
46
+ * @return {number}
47
+ */
48
+ function calculateCheckDigit(ean) {
49
+ var checksum = ean.slice(0, -1).split('').map(function (_char, index) {
50
+ return Number(_char) * getPositionWeightThroughLengthAndIndex(ean.length, index);
51
+ }).reduce(function (acc, partialSum) {
52
+ return acc + partialSum;
53
+ }, 0);
54
+ var remainder = 10 - checksum % 10;
55
+ return remainder < 10 ? remainder : 0;
56
+ }
57
+
58
+ /**
59
+ * Check if string is valid EAN:
60
+ * Matches EAN-8/EAN-13/EAN-14 regex
61
+ * Has valid check digit.
62
+ *
63
+ * @param {string} str
64
+ * @return {boolean}
65
+ */
66
+ export default function isEAN(str) {
67
+ assertString(str);
68
+ var actualCheckDigit = Number(str.slice(-1));
69
+ return validEanRegex.test(str) && actualCheckDigit === calculateCheckDigit(str);
70
+ }
@@ -0,0 +1,164 @@
1
+ import assertString from './util/assertString';
2
+ import isByteLength from './isByteLength';
3
+ import isFQDN from './isFQDN';
4
+ import isIP from './isIP';
5
+ import merge from './util/merge';
6
+ var default_email_options = {
7
+ allow_display_name: false,
8
+ allow_underscores: false,
9
+ require_display_name: false,
10
+ allow_utf8_local_part: true,
11
+ require_tld: true,
12
+ blacklisted_chars: '',
13
+ ignore_max_length: false,
14
+ host_blacklist: [],
15
+ host_whitelist: []
16
+ };
17
+
18
+ /* eslint-disable max-len */
19
+ /* eslint-disable no-control-regex */
20
+ var splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)</i;
21
+ var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
22
+ var gmailUserPart = /^[a-z\d]+$/;
23
+ var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
24
+ var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A1-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
25
+ var quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;
26
+ var defaultMaxEmailLength = 254;
27
+ /* eslint-enable max-len */
28
+ /* eslint-enable no-control-regex */
29
+
30
+ /**
31
+ * Validate display name according to the RFC2822: https://tools.ietf.org/html/rfc2822#appendix-A.1.2
32
+ * @param {String} display_name
33
+ */
34
+ function validateDisplayName(display_name) {
35
+ var display_name_without_quotes = display_name.replace(/^"(.+)"$/, '$1');
36
+ // display name with only spaces is not valid
37
+ if (!display_name_without_quotes.trim()) {
38
+ return false;
39
+ }
40
+
41
+ // check whether display name contains illegal character
42
+ var contains_illegal = /[\.";<>]/.test(display_name_without_quotes);
43
+ if (contains_illegal) {
44
+ // if contains illegal characters,
45
+ // must to be enclosed in double-quotes, otherwise it's not a valid display name
46
+ if (display_name_without_quotes === display_name) {
47
+ return false;
48
+ }
49
+
50
+ // the quotes in display name must start with character symbol \
51
+ var all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
52
+ if (!all_start_with_back_slash) {
53
+ return false;
54
+ }
55
+ }
56
+ return true;
57
+ }
58
+ export default function isEmail(str, options) {
59
+ assertString(str);
60
+ options = merge(options, default_email_options);
61
+ if (options.require_display_name || options.allow_display_name) {
62
+ var display_email = str.match(splitNameAddress);
63
+ if (display_email) {
64
+ var display_name = display_email[1];
65
+
66
+ // Remove display name and angle brackets to get email address
67
+ // Can be done in the regex but will introduce a ReDOS (See #1597 for more info)
68
+ str = str.replace(display_name, '').replace(/(^<|>$)/g, '');
69
+
70
+ // sometimes need to trim the last space to get the display name
71
+ // because there may be a space between display name and email address
72
+ // eg. myname <address@gmail.com>
73
+ // the display name is `myname` instead of `myname `, so need to trim the last space
74
+ if (display_name.endsWith(' ')) {
75
+ display_name = display_name.slice(0, -1);
76
+ }
77
+ if (!validateDisplayName(display_name)) {
78
+ return false;
79
+ }
80
+ } else if (options.require_display_name) {
81
+ return false;
82
+ }
83
+ }
84
+ if (!options.ignore_max_length && str.length > defaultMaxEmailLength) {
85
+ return false;
86
+ }
87
+ var parts = str.split('@');
88
+ var domain = parts.pop();
89
+ var lower_domain = domain.toLowerCase();
90
+ if (options.host_blacklist.includes(lower_domain)) {
91
+ return false;
92
+ }
93
+ if (options.host_whitelist.length > 0 && !options.host_whitelist.includes(lower_domain)) {
94
+ return false;
95
+ }
96
+ var user = parts.join('@');
97
+ if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
98
+ /*
99
+ Previously we removed dots for gmail addresses before validating.
100
+ This was removed because it allows `multiple..dots@gmail.com`
101
+ to be reported as valid, but it is not.
102
+ Gmail only normalizes single dots, removing them from here is pointless,
103
+ should be done in normalizeEmail
104
+ */
105
+ user = user.toLowerCase();
106
+
107
+ // Removing sub-address from username before gmail validation
108
+ var username = user.split('+')[0];
109
+
110
+ // Dots are not included in gmail length restriction
111
+ if (!isByteLength(username.replace(/\./g, ''), {
112
+ min: 6,
113
+ max: 30
114
+ })) {
115
+ return false;
116
+ }
117
+ var _user_parts = username.split('.');
118
+ for (var i = 0; i < _user_parts.length; i++) {
119
+ if (!gmailUserPart.test(_user_parts[i])) {
120
+ return false;
121
+ }
122
+ }
123
+ }
124
+ if (options.ignore_max_length === false && (!isByteLength(user, {
125
+ max: 64
126
+ }) || !isByteLength(domain, {
127
+ max: 254
128
+ }))) {
129
+ return false;
130
+ }
131
+ if (!isFQDN(domain, {
132
+ require_tld: options.require_tld,
133
+ ignore_max_length: options.ignore_max_length,
134
+ allow_underscores: options.allow_underscores
135
+ })) {
136
+ if (!options.allow_ip_domain) {
137
+ return false;
138
+ }
139
+ if (!isIP(domain)) {
140
+ if (!domain.startsWith('[') || !domain.endsWith(']')) {
141
+ return false;
142
+ }
143
+ var noBracketdomain = domain.slice(1, -1);
144
+ if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) {
145
+ return false;
146
+ }
147
+ }
148
+ }
149
+ if (user[0] === '"') {
150
+ user = user.slice(1, user.length - 1);
151
+ return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user);
152
+ }
153
+ var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart;
154
+ var user_parts = user.split('.');
155
+ for (var _i = 0; _i < user_parts.length; _i++) {
156
+ if (!pattern.test(user_parts[_i])) {
157
+ return false;
158
+ }
159
+ }
160
+ if (options.blacklisted_chars) {
161
+ if (user.search(new RegExp("[".concat(options.blacklisted_chars, "]+"), 'g')) !== -1) return false;
162
+ }
163
+ return true;
164
+ }
@@ -0,0 +1,10 @@
1
+ import assertString from './util/assertString';
2
+ import merge from './util/merge';
3
+ var default_is_empty_options = {
4
+ ignore_whitespace: false
5
+ };
6
+ export default function isEmpty(str, options) {
7
+ assertString(str);
8
+ options = merge(options, default_is_empty_options);
9
+ return (options.ignore_whitespace ? str.trim().length : str.length) === 0;
10
+ }
@@ -0,0 +1,6 @@
1
+ import assertString from './util/assertString';
2
+ var eth = /^(0x)[0-9a-f]{40}$/i;
3
+ export default function isEthereumAddress(str) {
4
+ assertString(str);
5
+ return eth.test(str);
6
+ }
@@ -0,0 +1,67 @@
1
+ import assertString from './util/assertString';
2
+ import merge from './util/merge';
3
+ var default_fqdn_options = {
4
+ require_tld: true,
5
+ allow_underscores: false,
6
+ allow_trailing_dot: false,
7
+ allow_numeric_tld: false,
8
+ allow_wildcard: false,
9
+ ignore_max_length: false
10
+ };
11
+ export default function isFQDN(str, options) {
12
+ assertString(str);
13
+ options = merge(options, default_fqdn_options);
14
+
15
+ /* Remove the optional trailing dot before checking validity */
16
+ if (options.allow_trailing_dot && str[str.length - 1] === '.') {
17
+ str = str.substring(0, str.length - 1);
18
+ }
19
+
20
+ /* Remove the optional wildcard before checking validity */
21
+ if (options.allow_wildcard === true && str.indexOf('*.') === 0) {
22
+ str = str.substring(2);
23
+ }
24
+ var parts = str.split('.');
25
+ var tld = parts[parts.length - 1];
26
+ if (options.require_tld) {
27
+ // disallow fqdns without tld
28
+ if (parts.length < 2) {
29
+ return false;
30
+ }
31
+ if (!options.allow_numeric_tld && !/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
32
+ return false;
33
+ }
34
+
35
+ // disallow spaces
36
+ if (/\s/.test(tld)) {
37
+ return false;
38
+ }
39
+ }
40
+
41
+ // reject numeric TLDs
42
+ if (!options.allow_numeric_tld && /^\d+$/.test(tld)) {
43
+ return false;
44
+ }
45
+ return parts.every(function (part) {
46
+ if (part.length > 63 && !options.ignore_max_length) {
47
+ return false;
48
+ }
49
+ if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) {
50
+ return false;
51
+ }
52
+
53
+ // disallow full-width chars
54
+ if (/[\uff01-\uff5e]/.test(part)) {
55
+ return false;
56
+ }
57
+
58
+ // disallow parts starting or ending with hyphen
59
+ if (/^-|-$/.test(part)) {
60
+ return false;
61
+ }
62
+ if (!options.allow_underscores && /_/.test(part)) {
63
+ return false;
64
+ }
65
+ return true;
66
+ });
67
+ }
@@ -0,0 +1,13 @@
1
+ import assertString from './util/assertString';
2
+ import { decimal } from './alpha';
3
+ export default function isFloat(str, options) {
4
+ assertString(str);
5
+ options = options || {};
6
+ var _float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"));
7
+ if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') {
8
+ return false;
9
+ }
10
+ var value = parseFloat(str.replace(',', '.'));
11
+ return _float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt);
12
+ }
13
+ export var locales = Object.keys(decimal);
@@ -0,0 +1,6 @@
1
+ import assertString from './util/assertString';
2
+ export var fullWidth = /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
3
+ export default function isFullWidth(str) {
4
+ assertString(str);
5
+ return fullWidth.test(str);
6
+ }
@@ -0,0 +1,13 @@
1
+ import assertString from './util/assertString';
2
+ var hslComma = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(,(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}(,((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?))?\)$/i;
3
+ var hslSpace = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(\s(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s?(\/\s((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s?)?\)$/i;
4
+ export default function isHSL(str) {
5
+ assertString(str);
6
+
7
+ // Strip duplicate spaces before calling the validation regex (See #1598 for more info)
8
+ var strippedStr = str.replace(/\s+/g, ' ').replace(/\s?(hsla?\(|\)|,)\s?/ig, '$1');
9
+ if (strippedStr.indexOf(',') !== -1) {
10
+ return hslComma.test(strippedStr);
11
+ }
12
+ return hslSpace.test(strippedStr);
13
+ }
@@ -0,0 +1,6 @@
1
+ import assertString from './util/assertString';
2
+ export var halfWidth = /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
3
+ export default function isHalfWidth(str) {
4
+ assertString(str);
5
+ return halfWidth.test(str);
6
+ }
@@ -0,0 +1,21 @@
1
+ import assertString from './util/assertString';
2
+ var lengths = {
3
+ md5: 32,
4
+ md4: 32,
5
+ sha1: 40,
6
+ sha256: 64,
7
+ sha384: 96,
8
+ sha512: 128,
9
+ ripemd128: 32,
10
+ ripemd160: 40,
11
+ tiger128: 32,
12
+ tiger160: 40,
13
+ tiger192: 48,
14
+ crc32: 8,
15
+ crc32b: 8
16
+ };
17
+ export default function isHash(str, algorithm) {
18
+ assertString(str);
19
+ var hash = new RegExp("^[a-fA-F0-9]{".concat(lengths[algorithm], "}$"));
20
+ return hash.test(str);
21
+ }
@@ -0,0 +1,6 @@
1
+ import assertString from './util/assertString';
2
+ var hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
3
+ export default function isHexColor(str) {
4
+ assertString(str);
5
+ return hexcolor.test(str);
6
+ }
@@ -0,0 +1,6 @@
1
+ import assertString from './util/assertString';
2
+ var hexadecimal = /^(0x|0h)?[0-9A-F]+$/i;
3
+ export default function isHexadecimal(str) {
4
+ assertString(str);
5
+ return hexadecimal.test(str);
6
+ }
@@ -0,0 +1,173 @@
1
+ import assertString from './util/assertString';
2
+
3
+ /**
4
+ * List of country codes with
5
+ * corresponding IBAN regular expression
6
+ * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
7
+ */
8
+ var ibanRegexThroughCountryCode = {
9
+ AD: /^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$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+ MZ: /^(MZ[0-9]{2})\d{21}$/,
66
+ NL: /^(NL[0-9]{2})[A-Z]{4}\d{10}$/,
67
+ NO: /^(NO[0-9]{2})\d{11}$/,
68
+ PK: /^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,
69
+ PL: /^(PL[0-9]{2})\d{24}$/,
70
+ PS: /^(PS[0-9]{2})[A-Z0-9]{4}\d{21}$/,
71
+ PT: /^(PT[0-9]{2})\d{21}$/,
72
+ QA: /^(QA[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/,
73
+ RO: /^(RO[0-9]{2})[A-Z]{4}[A-Z0-9]{16}$/,
74
+ RS: /^(RS[0-9]{2})\d{18}$/,
75
+ SA: /^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,
76
+ SC: /^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,
77
+ SE: /^(SE[0-9]{2})\d{20}$/,
78
+ SI: /^(SI[0-9]{2})\d{15}$/,
79
+ SK: /^(SK[0-9]{2})\d{20}$/,
80
+ SM: /^(SM[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
81
+ SV: /^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,
82
+ TL: /^(TL[0-9]{2})\d{19}$/,
83
+ TN: /^(TN[0-9]{2})\d{20}$/,
84
+ TR: /^(TR[0-9]{2})\d{5}[A-Z0-9]{17}$/,
85
+ UA: /^(UA[0-9]{2})\d{6}[A-Z0-9]{19}$/,
86
+ VA: /^(VA[0-9]{2})\d{18}$/,
87
+ VG: /^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,
88
+ XK: /^(XK[0-9]{2})\d{16}$/
89
+ };
90
+
91
+ /**
92
+ * Check if the country codes passed are valid using the
93
+ * ibanRegexThroughCountryCode as a reference
94
+ *
95
+ * @param {array} countryCodeArray
96
+ * @return {boolean}
97
+ */
98
+
99
+ function hasOnlyValidCountryCodes(countryCodeArray) {
100
+ var countryCodeArrayFilteredWithObjectIbanCode = countryCodeArray.filter(function (countryCode) {
101
+ return !(countryCode in ibanRegexThroughCountryCode);
102
+ });
103
+ if (countryCodeArrayFilteredWithObjectIbanCode.length > 0) {
104
+ return false;
105
+ }
106
+ return true;
107
+ }
108
+
109
+ /**
110
+ * Check whether string has correct universal IBAN format
111
+ * The IBAN consists of up to 34 alphanumeric characters, as follows:
112
+ * Country Code using ISO 3166-1 alpha-2, two letters
113
+ * check digits, two digits and
114
+ * Basic Bank Account Number (BBAN), up to 30 alphanumeric characters.
115
+ * NOTE: Permitted IBAN characters are: digits [0-9] and the 26 latin alphabetic [A-Z]
116
+ *
117
+ * @param {string} str - string under validation
118
+ * @param {object} options - object to pass the countries to be either whitelisted or blacklisted
119
+ * @return {boolean}
120
+ */
121
+ function hasValidIbanFormat(str, options) {
122
+ // Strip white spaces and hyphens
123
+ var strippedStr = str.replace(/[\s\-]+/gi, '').toUpperCase();
124
+ var isoCountryCode = strippedStr.slice(0, 2).toUpperCase();
125
+ var isoCountryCodeInIbanRegexCodeObject = (isoCountryCode in ibanRegexThroughCountryCode);
126
+ if (options.whitelist) {
127
+ if (!hasOnlyValidCountryCodes(options.whitelist)) {
128
+ return false;
129
+ }
130
+ var isoCountryCodeInWhiteList = options.whitelist.includes(isoCountryCode);
131
+ if (!isoCountryCodeInWhiteList) {
132
+ return false;
133
+ }
134
+ }
135
+ if (options.blacklist) {
136
+ var isoCountryCodeInBlackList = options.blacklist.includes(isoCountryCode);
137
+ if (isoCountryCodeInBlackList) {
138
+ return false;
139
+ }
140
+ }
141
+ return isoCountryCodeInIbanRegexCodeObject && ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
142
+ }
143
+
144
+ /**
145
+ * Check whether string has valid IBAN Checksum
146
+ * by performing basic mod-97 operation and
147
+ * the remainder should equal 1
148
+ * -- Start by rearranging the IBAN by moving the four initial characters to the end of the string
149
+ * -- Replace each letter in the string with two digits, A -> 10, B = 11, Z = 35
150
+ * -- Interpret the string as a decimal integer and
151
+ * -- compute the remainder on division by 97 (mod 97)
152
+ * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
153
+ *
154
+ * @param {string} str
155
+ * @return {boolean}
156
+ */
157
+ function hasValidIbanChecksum(str) {
158
+ var strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase(); // Keep only digits and A-Z latin alphabetic
159
+ var rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4);
160
+ var alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, function (_char) {
161
+ return _char.charCodeAt(0) - 55;
162
+ });
163
+ var remainder = alphaCapsReplacedWithDigits.match(/\d{1,7}/g).reduce(function (acc, value) {
164
+ return Number(acc + value) % 97;
165
+ }, '');
166
+ return remainder === 1;
167
+ }
168
+ export default function isIBAN(str) {
169
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
170
+ assertString(str);
171
+ return hasValidIbanFormat(str, options) && hasValidIbanChecksum(str);
172
+ }
173
+ export var locales = Object.keys(ibanRegexThroughCountryCode);
@@ -0,0 +1,40 @@
1
+ import assertString from './util/assertString';
2
+ var imeiRegexWithoutHypens = /^[0-9]{15}$/;
3
+ var imeiRegexWithHypens = /^\d{2}-\d{6}-\d{6}-\d{1}$/;
4
+ export default function isIMEI(str, options) {
5
+ assertString(str);
6
+ options = options || {};
7
+
8
+ // default regex for checking imei is the one without hyphens
9
+
10
+ var imeiRegex = imeiRegexWithoutHypens;
11
+ if (options.allow_hyphens) {
12
+ imeiRegex = imeiRegexWithHypens;
13
+ }
14
+ if (!imeiRegex.test(str)) {
15
+ return false;
16
+ }
17
+ str = str.replace(/-/g, '');
18
+ var sum = 0,
19
+ mul = 2,
20
+ l = 14;
21
+ for (var i = 0; i < l; i++) {
22
+ var digit = str.substring(l - i - 1, l - i);
23
+ var tp = parseInt(digit, 10) * mul;
24
+ if (tp >= 10) {
25
+ sum += tp % 10 + 1;
26
+ } else {
27
+ sum += tp;
28
+ }
29
+ if (mul === 1) {
30
+ mul += 1;
31
+ } else {
32
+ mul -= 1;
33
+ }
34
+ }
35
+ var chk = (10 - sum % 10) % 10;
36
+ if (chk !== parseInt(str.substring(14, 15), 10)) {
37
+ return false;
38
+ }
39
+ return true;
40
+ }