validator-string 13.15.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +269 -0
  3. package/es/index.js +218 -0
  4. package/es/lib/alpha.js +151 -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 +10 -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 +15 -0
  16. package/es/lib/isBase58.js +8 -0
  17. package/es/lib/isBase64.js +23 -0
  18. package/es/lib/isBefore.js +10 -0
  19. package/es/lib/isBoolean.js +15 -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 +93 -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 +165 -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 +14 -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 +13 -0
  39. package/es/lib/isHexadecimal.js +6 -0
  40. package/es/lib/isIBAN.js +171 -0
  41. package/es/lib/isIMEI.js +40 -0
  42. package/es/lib/isIP.js +58 -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/isISO15924.js +9 -0
  47. package/es/lib/isISO31661Alpha2.js +21 -0
  48. package/es/lib/isISO31661Alpha3.js +20 -0
  49. package/es/lib/isISO31661Numeric.js +8 -0
  50. package/es/lib/isISO4217.js +9 -0
  51. package/es/lib/isISO6346.js +28 -0
  52. package/es/lib/isISO6391.js +6 -0
  53. package/es/lib/isISO8601.js +42 -0
  54. package/es/lib/isISRC.js +8 -0
  55. package/es/lib/isISSN.js +19 -0
  56. package/es/lib/isIdentityCard.js +407 -0
  57. package/es/lib/isIn.js +23 -0
  58. package/es/lib/isInt.js +19 -0
  59. package/es/lib/isJSON.js +26 -0
  60. package/es/lib/isJWT.js +15 -0
  61. package/es/lib/isLatLong.js +21 -0
  62. package/es/lib/isLength.js +27 -0
  63. package/es/lib/isLicensePlate.js +58 -0
  64. package/es/lib/isLocale.js +107 -0
  65. package/es/lib/isLowercase.js +5 -0
  66. package/es/lib/isLuhnNumber.js +25 -0
  67. package/es/lib/isMACAddress.js +36 -0
  68. package/es/lib/isMD5.js +6 -0
  69. package/es/lib/isMagnetURI.js +9 -0
  70. package/es/lib/isMailtoURI.js +75 -0
  71. package/es/lib/isMimeType.js +40 -0
  72. package/es/lib/isMobilePhone.js +212 -0
  73. package/es/lib/isMongoId.js +6 -0
  74. package/es/lib/isMultibyte.js +10 -0
  75. package/es/lib/isNumeric.js +10 -0
  76. package/es/lib/isOctal.js +6 -0
  77. package/es/lib/isPassportNumber.js +145 -0
  78. package/es/lib/isPort.js +8 -0
  79. package/es/lib/isPostalCode.js +100 -0
  80. package/es/lib/isRFC3339.js +21 -0
  81. package/es/lib/isRgbColor.js +34 -0
  82. package/es/lib/isSemVer.js +14 -0
  83. package/es/lib/isSlug.js +6 -0
  84. package/es/lib/isStrongPassword.js +90 -0
  85. package/es/lib/isSurrogatePair.js +6 -0
  86. package/es/lib/isTaxID.js +1407 -0
  87. package/es/lib/isTime.js +22 -0
  88. package/es/lib/isULID.js +5 -0
  89. package/es/lib/isURL.js +241 -0
  90. package/es/lib/isUUID.js +23 -0
  91. package/es/lib/isUppercase.js +5 -0
  92. package/es/lib/isVAT.js +264 -0
  93. package/es/lib/isVariableWidth.js +7 -0
  94. package/es/lib/isWhitelisted.js +10 -0
  95. package/es/lib/ltrim.js +7 -0
  96. package/es/lib/matches.js +8 -0
  97. package/es/lib/normalizeEmail.js +131 -0
  98. package/es/lib/rtrim.js +15 -0
  99. package/es/lib/stripLow.js +7 -0
  100. package/es/lib/toBoolean.js +8 -0
  101. package/es/lib/toDate.js +6 -0
  102. package/es/lib/toFloat.js +5 -0
  103. package/es/lib/toInt.js +5 -0
  104. package/es/lib/trim.js +5 -0
  105. package/es/lib/unescape.js +8 -0
  106. package/es/lib/util/algorithms.js +79 -0
  107. package/es/lib/util/assertString.js +4 -0
  108. package/es/lib/util/checkHost.js +12 -0
  109. package/es/lib/util/includesArray.js +6 -0
  110. package/es/lib/util/includesString.js +4 -0
  111. package/es/lib/util/merge.js +14 -0
  112. package/es/lib/util/multilineRegex.js +12 -0
  113. package/es/lib/util/nullUndefinedCheck.js +3 -0
  114. package/es/lib/util/toString.js +13 -0
  115. package/es/lib/util/typeOf.js +10 -0
  116. package/es/lib/whitelist.js +5 -0
  117. package/index.js +229 -0
  118. package/lib/alpha.js +157 -0
  119. package/lib/blacklist.js +14 -0
  120. package/lib/contains.js +24 -0
  121. package/lib/equals.js +14 -0
  122. package/lib/escape.js +14 -0
  123. package/lib/isAbaRouting.js +23 -0
  124. package/lib/isAfter.js +19 -0
  125. package/lib/isAlpha.js +31 -0
  126. package/lib/isAlphanumeric.js +31 -0
  127. package/lib/isAscii.js +18 -0
  128. package/lib/isBIC.js +24 -0
  129. package/lib/isBase32.js +24 -0
  130. package/lib/isBase58.js +16 -0
  131. package/lib/isBase64.js +32 -0
  132. package/lib/isBefore.js +19 -0
  133. package/lib/isBoolean.js +24 -0
  134. package/lib/isBtcAddress.js +16 -0
  135. package/lib/isByteLength.js +27 -0
  136. package/lib/isCreditCard.js +52 -0
  137. package/lib/isCurrency.js +83 -0
  138. package/lib/isDataURI.js +40 -0
  139. package/lib/isDate.js +102 -0
  140. package/lib/isDecimal.js +31 -0
  141. package/lib/isDivisibleBy.js +15 -0
  142. package/lib/isEAN.js +78 -0
  143. package/lib/isEmail.js +174 -0
  144. package/lib/isEmpty.js +19 -0
  145. package/lib/isEthereumAddress.js +15 -0
  146. package/lib/isFQDN.js +76 -0
  147. package/lib/isFloat.js +22 -0
  148. package/lib/isFullWidth.js +14 -0
  149. package/lib/isHSL.js +22 -0
  150. package/lib/isHalfWidth.js +14 -0
  151. package/lib/isHash.js +30 -0
  152. package/lib/isHexColor.js +22 -0
  153. package/lib/isHexadecimal.js +15 -0
  154. package/lib/isIBAN.js +178 -0
  155. package/lib/isIMEI.js +49 -0
  156. package/lib/isIP.js +67 -0
  157. package/lib/isIPRange.js +50 -0
  158. package/lib/isISBN.js +56 -0
  159. package/lib/isISIN.js +64 -0
  160. package/lib/isISO15924.js +16 -0
  161. package/lib/isISO31661Alpha2.js +28 -0
  162. package/lib/isISO31661Alpha3.js +28 -0
  163. package/lib/isISO31661Numeric.js +16 -0
  164. package/lib/isISO4217.js +16 -0
  165. package/lib/isISO6346.js +35 -0
  166. package/lib/isISO6391.js +15 -0
  167. package/lib/isISO8601.js +50 -0
  168. package/lib/isISRC.js +16 -0
  169. package/lib/isISSN.js +28 -0
  170. package/lib/isIdentityCard.js +416 -0
  171. package/lib/isIn.js +32 -0
  172. package/lib/isInt.js +28 -0
  173. package/lib/isJSON.js +35 -0
  174. package/lib/isJWT.js +24 -0
  175. package/lib/isLatLong.js +30 -0
  176. package/lib/isLength.js +35 -0
  177. package/lib/isLicensePlate.js +67 -0
  178. package/lib/isLocale.js +115 -0
  179. package/lib/isLowercase.js +14 -0
  180. package/lib/isLuhnNumber.js +34 -0
  181. package/lib/isMACAddress.js +45 -0
  182. package/lib/isMD5.js +15 -0
  183. package/lib/isMagnetURI.js +18 -0
  184. package/lib/isMailtoURI.js +84 -0
  185. package/lib/isMimeType.js +48 -0
  186. package/lib/isMobilePhone.js +219 -0
  187. package/lib/isMongoId.js +15 -0
  188. package/lib/isMultibyte.js +18 -0
  189. package/lib/isNumeric.js +19 -0
  190. package/lib/isOctal.js +15 -0
  191. package/lib/isPassportNumber.js +152 -0
  192. package/lib/isPort.js +17 -0
  193. package/lib/isPostalCode.js +107 -0
  194. package/lib/isRFC3339.js +29 -0
  195. package/lib/isRgbColor.js +42 -0
  196. package/lib/isSemVer.js +22 -0
  197. package/lib/isSlug.js +15 -0
  198. package/lib/isStrongPassword.js +99 -0
  199. package/lib/isSurrogatePair.js +15 -0
  200. package/lib/isTaxID.js +1417 -0
  201. package/lib/isTime.js +31 -0
  202. package/lib/isULID.js +14 -0
  203. package/lib/isURL.js +249 -0
  204. package/lib/isUUID.js +32 -0
  205. package/lib/isUppercase.js +14 -0
  206. package/lib/isVAT.js +274 -0
  207. package/lib/isVariableWidth.js +16 -0
  208. package/lib/isWhitelisted.js +19 -0
  209. package/lib/ltrim.js +16 -0
  210. package/lib/matches.js +17 -0
  211. package/lib/normalizeEmail.js +140 -0
  212. package/lib/rtrim.js +24 -0
  213. package/lib/stripLow.js +16 -0
  214. package/lib/toBoolean.js +17 -0
  215. package/lib/toDate.js +15 -0
  216. package/lib/toFloat.js +14 -0
  217. package/lib/toInt.js +14 -0
  218. package/lib/trim.js +14 -0
  219. package/lib/unescape.js +17 -0
  220. package/lib/util/algorithms.js +88 -0
  221. package/lib/util/assertString.js +12 -0
  222. package/lib/util/checkHost.js +20 -0
  223. package/lib/util/includesArray.js +14 -0
  224. package/lib/util/includesString.js +12 -0
  225. package/lib/util/merge.js +22 -0
  226. package/lib/util/multilineRegex.js +20 -0
  227. package/lib/util/nullUndefinedCheck.js +11 -0
  228. package/lib/util/toString.js +21 -0
  229. package/lib/util/typeOf.js +18 -0
  230. package/lib/whitelist.js +14 -0
  231. package/package.json +83 -0
  232. package/validator.js +5808 -0
  233. package/validator.min.js +23 -0
@@ -0,0 +1,22 @@
1
+ import merge from './util/merge';
2
+ import assertString from './util/assertString';
3
+ import includes from './util/includesArray';
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 Lengths; 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 numeric 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,165 @@
1
+ import assertString from './util/assertString';
2
+ import checkHost from './util/checkHost';
3
+ import isByteLength from './isByteLength';
4
+ import isFQDN from './isFQDN';
5
+ import isIP from './isIP';
6
+ import merge from './util/merge';
7
+ var default_email_options = {
8
+ allow_display_name: false,
9
+ allow_underscores: false,
10
+ require_display_name: false,
11
+ allow_utf8_local_part: true,
12
+ require_tld: true,
13
+ blacklisted_chars: '',
14
+ ignore_max_length: false,
15
+ host_blacklist: [],
16
+ host_whitelist: []
17
+ };
18
+
19
+ /* eslint-disable max-len */
20
+ /* eslint-disable no-control-regex */
21
+ var splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)</i;
22
+ var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
23
+ var gmailUserPart = /^[a-z\d]+$/;
24
+ var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
25
+ var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A1-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
26
+ 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;
27
+ var defaultMaxEmailLength = 254;
28
+ /* eslint-enable max-len */
29
+ /* eslint-enable no-control-regex */
30
+
31
+ /**
32
+ * Validate display name according to the RFC2822: https://tools.ietf.org/html/rfc2822#appendix-A.1.2
33
+ * @param {String} display_name
34
+ */
35
+ function validateDisplayName(display_name) {
36
+ var display_name_without_quotes = display_name.replace(/^"(.+)"$/, '$1');
37
+ // display name with only spaces is not valid
38
+ if (!display_name_without_quotes.trim()) {
39
+ return false;
40
+ }
41
+
42
+ // check whether display name contains illegal character
43
+ var contains_illegal = /[\.";<>]/.test(display_name_without_quotes);
44
+ if (contains_illegal) {
45
+ // if contains illegal characters,
46
+ // must to be enclosed in double-quotes, otherwise it's not a valid display name
47
+ if (display_name_without_quotes === display_name) {
48
+ return false;
49
+ }
50
+
51
+ // the quotes in display name must start with character symbol \
52
+ var all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
53
+ if (!all_start_with_back_slash) {
54
+ return false;
55
+ }
56
+ }
57
+ return true;
58
+ }
59
+ export default function isEmail(str, options) {
60
+ assertString(str);
61
+ options = merge(options, default_email_options);
62
+ if (options.require_display_name || options.allow_display_name) {
63
+ var display_email = str.match(splitNameAddress);
64
+ if (display_email) {
65
+ var display_name = display_email[1];
66
+
67
+ // Remove display name and angle brackets to get email address
68
+ // Can be done in the regex but will introduce a ReDOS (See #1597 for more info)
69
+ str = str.replace(display_name, '').replace(/(^<|>$)/g, '');
70
+
71
+ // sometimes need to trim the last space to get the display name
72
+ // because there may be a space between display name and email address
73
+ // eg. myname <address@gmail.com>
74
+ // the display name is `myname` instead of `myname `, so need to trim the last space
75
+ if (display_name.endsWith(' ')) {
76
+ display_name = display_name.slice(0, -1);
77
+ }
78
+ if (!validateDisplayName(display_name)) {
79
+ return false;
80
+ }
81
+ } else if (options.require_display_name) {
82
+ return false;
83
+ }
84
+ }
85
+ if (!options.ignore_max_length && str.length > defaultMaxEmailLength) {
86
+ return false;
87
+ }
88
+ var parts = str.split('@');
89
+ var domain = parts.pop();
90
+ var lower_domain = domain.toLowerCase();
91
+ if (options.host_blacklist.length > 0 && checkHost(lower_domain, options.host_blacklist)) {
92
+ return false;
93
+ }
94
+ if (options.host_whitelist.length > 0 && !checkHost(lower_domain, options.host_whitelist)) {
95
+ return false;
96
+ }
97
+ var user = parts.join('@');
98
+ if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
99
+ /*
100
+ Previously we removed dots for gmail addresses before validating.
101
+ This was removed because it allows `multiple..dots@gmail.com`
102
+ to be reported as valid, but it is not.
103
+ Gmail only normalizes single dots, removing them from here is pointless,
104
+ should be done in normalizeEmail
105
+ */
106
+ user = user.toLowerCase();
107
+
108
+ // Removing sub-address from username before gmail validation
109
+ var username = user.split('+')[0];
110
+
111
+ // Dots are not included in gmail length restriction
112
+ if (!isByteLength(username.replace(/\./g, ''), {
113
+ min: 6,
114
+ max: 30
115
+ })) {
116
+ return false;
117
+ }
118
+ var _user_parts = username.split('.');
119
+ for (var i = 0; i < _user_parts.length; i++) {
120
+ if (!gmailUserPart.test(_user_parts[i])) {
121
+ return false;
122
+ }
123
+ }
124
+ }
125
+ if (options.ignore_max_length === false && (!isByteLength(user, {
126
+ max: 64
127
+ }) || !isByteLength(domain, {
128
+ max: 254
129
+ }))) {
130
+ return false;
131
+ }
132
+ if (!isFQDN(domain, {
133
+ require_tld: options.require_tld,
134
+ ignore_max_length: options.ignore_max_length,
135
+ allow_underscores: options.allow_underscores
136
+ })) {
137
+ if (!options.allow_ip_domain) {
138
+ return false;
139
+ }
140
+ if (!isIP(domain)) {
141
+ if (!domain.startsWith('[') || !domain.endsWith(']')) {
142
+ return false;
143
+ }
144
+ var noBracketdomain = domain.slice(1, -1);
145
+ if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) {
146
+ return false;
147
+ }
148
+ }
149
+ }
150
+ if (options.blacklisted_chars) {
151
+ if (user.search(new RegExp("[".concat(options.blacklisted_chars, "]+"), 'g')) !== -1) return false;
152
+ }
153
+ if (user[0] === '"' && user[user.length - 1] === '"') {
154
+ user = user.slice(1, user.length - 1);
155
+ return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user);
156
+ }
157
+ var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart;
158
+ var user_parts = user.split('.');
159
+ for (var _i = 0; _i < user_parts.length; _i++) {
160
+ if (!pattern.test(user_parts[_i])) {
161
+ return false;
162
+ }
163
+ }
164
+ return true;
165
+ }
@@ -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,14 @@
1
+ import assertString from './util/assertString';
2
+ import isNullOrUndefined from './util/nullUndefinedCheck';
3
+ import { decimal } from './alpha';
4
+ export default function isFloat(str, options) {
5
+ assertString(str);
6
+ options = options || {};
7
+ var _float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"));
8
+ if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') {
9
+ return false;
10
+ }
11
+ var value = parseFloat(str.replace(',', '.'));
12
+ return _float.test(str) && (!options.hasOwnProperty('min') || isNullOrUndefined(options.min) || value >= options.min) && (!options.hasOwnProperty('max') || isNullOrUndefined(options.max) || value <= options.max) && (!options.hasOwnProperty('lt') || isNullOrUndefined(options.lt) || value < options.lt) && (!options.hasOwnProperty('gt') || isNullOrUndefined(options.gt) || value > options.gt);
13
+ }
14
+ 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,13 @@
1
+ import assertString from './util/assertString';
2
+ import merge from './util/merge';
3
+ var hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
4
+ var hexcolor_with_prefix = /^#([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
5
+ var default_is_hexcolor_options = {
6
+ require_hashtag: false
7
+ };
8
+ export default function isHexColor(str, options) {
9
+ assertString(str);
10
+ options = merge(options, default_is_hexcolor_options);
11
+ var hexcolor_regex = options.require_hashtag ? hexcolor_with_prefix : hexcolor;
12
+ return hexcolor_regex.test(str);
13
+ }
@@ -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,171 @@
1
+ import assertString from './util/assertString';
2
+ import includes from './util/includesArray';
3
+
4
+ /**
5
+ * List of country codes with
6
+ * corresponding IBAN regular expression
7
+ * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
8
+ */
9
+ var ibanRegexThroughCountryCode = {
10
+ AD: /^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,
11
+ AE: /^(AE[0-9]{2})\d{3}\d{16}$/,
12
+ AL: /^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,
13
+ AT: /^(AT[0-9]{2})\d{16}$/,
14
+ AZ: /^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,
15
+ BA: /^(BA[0-9]{2})\d{16}$/,
16
+ BE: /^(BE[0-9]{2})\d{12}$/,
17
+ BG: /^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,
18
+ BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,
19
+ BR: /^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,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 SA: /^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,
77
+ SC: /^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,
78
+ SE: /^(SE[0-9]{2})\d{20}$/,
79
+ SI: /^(SI[0-9]{2})\d{15}$/,
80
+ SK: /^(SK[0-9]{2})\d{20}$/,
81
+ SM: /^(SM[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
82
+ SV: /^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,
83
+ TL: /^(TL[0-9]{2})\d{19}$/,
84
+ TN: /^(TN[0-9]{2})\d{20}$/,
85
+ TR: /^(TR[0-9]{2})\d{5}[A-Z0-9]{17}$/,
86
+ UA: /^(UA[0-9]{2})\d{6}[A-Z0-9]{19}$/,
87
+ VA: /^(VA[0-9]{2})\d{18}$/,
88
+ VG: /^(VG[0-9]{2})[A-Z]{4}\d{16}$/,
89
+ XK: /^(XK[0-9]{2})\d{16}$/
90
+ };
91
+
92
+ /**
93
+ * Check if the country codes passed are valid using the
94
+ * ibanRegexThroughCountryCode as a reference
95
+ *
96
+ * @param {array} countryCodeArray
97
+ * @return {boolean}
98
+ */
99
+
100
+ function hasOnlyValidCountryCodes(countryCodeArray) {
101
+ var countryCodeArrayFilteredWithObjectIbanCode = countryCodeArray.filter(function (countryCode) {
102
+ return !(countryCode in ibanRegexThroughCountryCode);
103
+ });
104
+ return countryCodeArrayFilteredWithObjectIbanCode.length === 0;
105
+ }
106
+
107
+ /**
108
+ * Check whether string has correct universal IBAN format
109
+ * The IBAN consists of up to 34 alphanumeric characters, as follows:
110
+ * Country Code using ISO 3166-1 alpha-2, two letters
111
+ * check digits, two digits and
112
+ * Basic Bank Account Number (BBAN), up to 30 alphanumeric characters.
113
+ * NOTE: Permitted IBAN characters are: digits [0-9] and the 26 latin alphabetic [A-Z]
114
+ *
115
+ * @param {string} str - string under validation
116
+ * @param {object} options - object to pass the countries to be either whitelisted or blacklisted
117
+ * @return {boolean}
118
+ */
119
+ function hasValidIbanFormat(str, options) {
120
+ // Strip white spaces and hyphens
121
+ var strippedStr = str.replace(/[\s\-]+/gi, '').toUpperCase();
122
+ var isoCountryCode = strippedStr.slice(0, 2).toUpperCase();
123
+ var isoCountryCodeInIbanRegexCodeObject = isoCountryCode in ibanRegexThroughCountryCode;
124
+ if (options.whitelist) {
125
+ if (!hasOnlyValidCountryCodes(options.whitelist)) {
126
+ return false;
127
+ }
128
+ var isoCountryCodeInWhiteList = includes(options.whitelist, isoCountryCode);
129
+ if (!isoCountryCodeInWhiteList) {
130
+ return false;
131
+ }
132
+ }
133
+ if (options.blacklist) {
134
+ var isoCountryCodeInBlackList = includes(options.blacklist, isoCountryCode);
135
+ if (isoCountryCodeInBlackList) {
136
+ return false;
137
+ }
138
+ }
139
+ return isoCountryCodeInIbanRegexCodeObject && ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
140
+ }
141
+
142
+ /**
143
+ * Check whether string has valid IBAN Checksum
144
+ * by performing basic mod-97 operation and
145
+ * the remainder should equal 1
146
+ * -- Start by rearranging the IBAN by moving the four initial characters to the end of the string
147
+ * -- Replace each letter in the string with two digits, A -> 10, B = 11, Z = 35
148
+ * -- Interpret the string as a decimal integer and
149
+ * -- compute the remainder on division by 97 (mod 97)
150
+ * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
151
+ *
152
+ * @param {string} str
153
+ * @return {boolean}
154
+ */
155
+ function hasValidIbanChecksum(str) {
156
+ var strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase(); // Keep only digits and A-Z latin alphabetic
157
+ var rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4);
158
+ var alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, function (_char) {
159
+ return _char.charCodeAt(0) - 55;
160
+ });
161
+ var remainder = alphaCapsReplacedWithDigits.match(/\d{1,7}/g).reduce(function (acc, value) {
162
+ return Number(acc + value) % 97;
163
+ }, '');
164
+ return remainder === 1;
165
+ }
166
+ export default function isIBAN(str) {
167
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
168
+ assertString(str);
169
+ return hasValidIbanFormat(str, options) && hasValidIbanChecksum(str);
170
+ }
171
+ export var locales = Object.keys(ibanRegexThroughCountryCode);
@@ -0,0 +1,40 @@
1
+ import assertString from './util/assertString';
2
+ var imeiRegexWithoutHyphens = /^[0-9]{15}$/;
3
+ var imeiRegexWithHyphens = /^\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 = imeiRegexWithoutHyphens;
11
+ if (options.allow_hyphens) {
12
+ imeiRegex = imeiRegexWithHyphens;
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
+ }