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
package/es/lib/isIP.js ADDED
@@ -0,0 +1,50 @@
1
+ import assertString from './util/assertString';
2
+ /**
3
+ 11.3. Examples
4
+
5
+ The following addresses
6
+
7
+ fe80::1234 (on the 1st link of the node)
8
+ ff02::5678 (on the 5th link of the node)
9
+ ff08::9abc (on the 10th organization of the node)
10
+
11
+ would be represented as follows:
12
+
13
+ fe80::1234%1
14
+ ff02::5678%5
15
+ ff08::9abc%10
16
+
17
+ (Here we assume a natural translation from a zone index to the
18
+ <zone_id> part, where the Nth zone of any scope is translated into
19
+ "N".)
20
+
21
+ If we use interface names as <zone_id>, those addresses could also be
22
+ represented as follows:
23
+
24
+ fe80::1234%ne0
25
+ ff02::5678%pvc1.3
26
+ ff08::9abc%interface10
27
+
28
+ where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
29
+ to the 5th link, and "interface10" belongs to the 10th organization.
30
+ * * */
31
+ var IPv4SegmentFormat = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
32
+ var IPv4AddressFormat = "(".concat(IPv4SegmentFormat, "[.]){3}").concat(IPv4SegmentFormat);
33
+ var IPv4AddressRegExp = new RegExp("^".concat(IPv4AddressFormat, "$"));
34
+ var IPv6SegmentFormat = '(?:[0-9a-fA-F]{1,4})';
35
+ var IPv6AddressRegExp = new RegExp('^(' + "(?:".concat(IPv6SegmentFormat, ":){7}(?:").concat(IPv6SegmentFormat, "|:)|") + "(?:".concat(IPv6SegmentFormat, ":){6}(?:").concat(IPv4AddressFormat, "|:").concat(IPv6SegmentFormat, "|:)|") + "(?:".concat(IPv6SegmentFormat, ":){5}(?::").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,2}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){4}(?:(:").concat(IPv6SegmentFormat, "){0,1}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,3}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){3}(?:(:").concat(IPv6SegmentFormat, "){0,2}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,4}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){2}(?:(:").concat(IPv6SegmentFormat, "){0,3}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,5}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){1}(?:(:").concat(IPv6SegmentFormat, "){0,4}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,6}|:)|") + "(?::((?::".concat(IPv6SegmentFormat, "){0,5}:").concat(IPv4AddressFormat, "|(?::").concat(IPv6SegmentFormat, "){1,7}|:))") + ')(%[0-9a-zA-Z-.:]{1,})?$');
36
+ export default function isIP(str) {
37
+ var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
38
+ assertString(str);
39
+ version = String(version);
40
+ if (!version) {
41
+ return isIP(str, 4) || isIP(str, 6);
42
+ }
43
+ if (version === '4') {
44
+ return IPv4AddressRegExp.test(str);
45
+ }
46
+ if (version === '6') {
47
+ return IPv6AddressRegExp.test(str);
48
+ }
49
+ return false;
50
+ }
@@ -0,0 +1,41 @@
1
+ import assertString from './util/assertString';
2
+ import isIP from './isIP';
3
+ var subnetMaybe = /^\d{1,3}$/;
4
+ var v4Subnet = 32;
5
+ var v6Subnet = 128;
6
+ export default function isIPRange(str) {
7
+ var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
8
+ assertString(str);
9
+ var parts = str.split('/');
10
+
11
+ // parts[0] -> ip, parts[1] -> subnet
12
+ if (parts.length !== 2) {
13
+ return false;
14
+ }
15
+ if (!subnetMaybe.test(parts[1])) {
16
+ return false;
17
+ }
18
+
19
+ // Disallow preceding 0 i.e. 01, 02, ...
20
+ if (parts[1].length > 1 && parts[1].startsWith('0')) {
21
+ return false;
22
+ }
23
+ var isValidIP = isIP(parts[0], version);
24
+ if (!isValidIP) {
25
+ return false;
26
+ }
27
+
28
+ // Define valid subnet according to IP's version
29
+ var expectedSubnet = null;
30
+ switch (String(version)) {
31
+ case '4':
32
+ expectedSubnet = v4Subnet;
33
+ break;
34
+ case '6':
35
+ expectedSubnet = v6Subnet;
36
+ break;
37
+ default:
38
+ expectedSubnet = isIP(parts[0], '6') ? v6Subnet : v4Subnet;
39
+ }
40
+ return parts[1] <= expectedSubnet && parts[1] >= 0;
41
+ }
@@ -0,0 +1,47 @@
1
+ import assertString from './util/assertString';
2
+ var possibleIsbn10 = /^(?:[0-9]{9}X|[0-9]{10})$/;
3
+ var possibleIsbn13 = /^(?:[0-9]{13})$/;
4
+ var factor = [1, 3];
5
+ export default function isISBN(isbn, options) {
6
+ assertString(isbn);
7
+
8
+ // For backwards compatibility:
9
+ // isISBN(str [, version]), i.e. `options` could be used as argument for the legacy `version`
10
+ var version = String((options === null || options === void 0 ? void 0 : options.version) || options);
11
+ if (!(options !== null && options !== void 0 && options.version || options)) {
12
+ return isISBN(isbn, {
13
+ version: 10
14
+ }) || isISBN(isbn, {
15
+ version: 13
16
+ });
17
+ }
18
+ var sanitizedIsbn = isbn.replace(/[\s-]+/g, '');
19
+ var checksum = 0;
20
+ if (version === '10') {
21
+ if (!possibleIsbn10.test(sanitizedIsbn)) {
22
+ return false;
23
+ }
24
+ for (var i = 0; i < version - 1; i++) {
25
+ checksum += (i + 1) * sanitizedIsbn.charAt(i);
26
+ }
27
+ if (sanitizedIsbn.charAt(9) === 'X') {
28
+ checksum += 10 * 10;
29
+ } else {
30
+ checksum += 10 * sanitizedIsbn.charAt(9);
31
+ }
32
+ if (checksum % 11 === 0) {
33
+ return true;
34
+ }
35
+ } else if (version === '13') {
36
+ if (!possibleIsbn13.test(sanitizedIsbn)) {
37
+ return false;
38
+ }
39
+ for (var _i = 0; _i < 12; _i++) {
40
+ checksum += factor[_i % 2] * sanitizedIsbn.charAt(_i);
41
+ }
42
+ if (sanitizedIsbn.charAt(12) - (10 - checksum % 10) % 10 === 0) {
43
+ return true;
44
+ }
45
+ }
46
+ return false;
47
+ }
@@ -0,0 +1,55 @@
1
+ import assertString from './util/assertString';
2
+ var isin = /^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;
3
+
4
+ // this link details how the check digit is calculated:
5
+ // https://www.isin.org/isin-format/. it is a little bit
6
+ // odd in that it works with digits, not numbers. in order
7
+ // to make only one pass through the ISIN characters, the
8
+ // each alpha character is handled as 2 characters within
9
+ // the loop.
10
+
11
+ export default function isISIN(str) {
12
+ assertString(str);
13
+ if (!isin.test(str)) {
14
+ return false;
15
+ }
16
+ var _double = true;
17
+ var sum = 0;
18
+ // convert values
19
+ for (var i = str.length - 2; i >= 0; i--) {
20
+ if (str[i] >= 'A' && str[i] <= 'Z') {
21
+ var value = str[i].charCodeAt(0) - 55;
22
+ var lo = value % 10;
23
+ var hi = Math.trunc(value / 10);
24
+ // letters have two digits, so handle the low order
25
+ // and high order digits separately.
26
+ for (var _i = 0, _arr = [lo, hi]; _i < _arr.length; _i++) {
27
+ var digit = _arr[_i];
28
+ if (_double) {
29
+ if (digit >= 5) {
30
+ sum += 1 + (digit - 5) * 2;
31
+ } else {
32
+ sum += digit * 2;
33
+ }
34
+ } else {
35
+ sum += digit;
36
+ }
37
+ _double = !_double;
38
+ }
39
+ } else {
40
+ var _digit = str[i].charCodeAt(0) - '0'.charCodeAt(0);
41
+ if (_double) {
42
+ if (_digit >= 5) {
43
+ sum += 1 + (_digit - 5) * 2;
44
+ } else {
45
+ sum += _digit * 2;
46
+ }
47
+ } else {
48
+ sum += _digit;
49
+ }
50
+ _double = !_double;
51
+ }
52
+ }
53
+ var check = Math.trunc((sum + 9) / 10) * 10 - sum;
54
+ return +str[str.length - 1] === check;
55
+ }
@@ -0,0 +1,9 @@
1
+ import assertString from './util/assertString';
2
+
3
+ // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
4
+ var validISO31661Alpha2CountriesCodes = new Set(['AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SX', 'SY', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW']);
5
+ export default function isISO31661Alpha2(str) {
6
+ assertString(str);
7
+ return validISO31661Alpha2CountriesCodes.has(str.toUpperCase());
8
+ }
9
+ export var CountryCodes = validISO31661Alpha2CountriesCodes;
@@ -0,0 +1,8 @@
1
+ import assertString from './util/assertString';
2
+
3
+ // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
4
+ var validISO31661Alpha3CountriesCodes = new Set(['AFG', 'ALA', 'ALB', 'DZA', 'ASM', 'AND', 'AGO', 'AIA', 'ATA', 'ATG', 'ARG', 'ARM', 'ABW', 'AUS', 'AUT', 'AZE', 'BHS', 'BHR', 'BGD', 'BRB', 'BLR', 'BEL', 'BLZ', 'BEN', 'BMU', 'BTN', 'BOL', 'BES', 'BIH', 'BWA', 'BVT', 'BRA', 'IOT', 'BRN', 'BGR', 'BFA', 'BDI', 'KHM', 'CMR', 'CAN', 'CPV', 'CYM', 'CAF', 'TCD', 'CHL', 'CHN', 'CXR', 'CCK', 'COL', 'COM', 'COG', 'COD', 'COK', 'CRI', 'CIV', 'HRV', 'CUB', 'CUW', 'CYP', 'CZE', 'DNK', 'DJI', 'DMA', 'DOM', 'ECU', 'EGY', 'SLV', 'GNQ', 'ERI', 'EST', 'ETH', 'FLK', 'FRO', 'FJI', 'FIN', 'FRA', 'GUF', 'PYF', 'ATF', 'GAB', 'GMB', 'GEO', 'DEU', 'GHA', 'GIB', 'GRC', 'GRL', 'GRD', 'GLP', 'GUM', 'GTM', 'GGY', 'GIN', 'GNB', 'GUY', 'HTI', 'HMD', 'VAT', 'HND', 'HKG', 'HUN', 'ISL', 'IND', 'IDN', 'IRN', 'IRQ', 'IRL', 'IMN', 'ISR', 'ITA', 'JAM', 'JPN', 'JEY', 'JOR', 'KAZ', 'KEN', 'KIR', 'PRK', 'KOR', 'KWT', 'KGZ', 'LAO', 'LVA', 'LBN', 'LSO', 'LBR', 'LBY', 'LIE', 'LTU', 'LUX', 'MAC', 'MKD', 'MDG', 'MWI', 'MYS', 'MDV', 'MLI', 'MLT', 'MHL', 'MTQ', 'MRT', 'MUS', 'MYT', 'MEX', 'FSM', 'MDA', 'MCO', 'MNG', 'MNE', 'MSR', 'MAR', 'MOZ', 'MMR', 'NAM', 'NRU', 'NPL', 'NLD', 'NCL', 'NZL', 'NIC', 'NER', 'NGA', 'NIU', 'NFK', 'MNP', 'NOR', 'OMN', 'PAK', 'PLW', 'PSE', 'PAN', 'PNG', 'PRY', 'PER', 'PHL', 'PCN', 'POL', 'PRT', 'PRI', 'QAT', 'REU', 'ROU', 'RUS', 'RWA', 'BLM', 'SHN', 'KNA', 'LCA', 'MAF', 'SPM', 'VCT', 'WSM', 'SMR', 'STP', 'SAU', 'SEN', 'SRB', 'SYC', 'SLE', 'SGP', 'SXM', 'SVK', 'SVN', 'SLB', 'SOM', 'ZAF', 'SGS', 'SSD', 'ESP', 'LKA', 'SDN', 'SUR', 'SJM', 'SWZ', 'SWE', 'CHE', 'SYR', 'TWN', 'TJK', 'TZA', 'THA', 'TLS', 'TGO', 'TKL', 'TON', 'TTO', 'TUN', 'TUR', 'TKM', 'TCA', 'TUV', 'UGA', 'UKR', 'ARE', 'GBR', 'USA', 'UMI', 'URY', 'UZB', 'VUT', 'VEN', 'VNM', 'VGB', 'VIR', 'WLF', 'ESH', 'YEM', 'ZMB', 'ZWE']);
5
+ export default function isISO31661Alpha3(str) {
6
+ assertString(str);
7
+ return validISO31661Alpha3CountriesCodes.has(str.toUpperCase());
8
+ }
@@ -0,0 +1,9 @@
1
+ import assertString from './util/assertString';
2
+
3
+ // from https://en.wikipedia.org/wiki/ISO_4217
4
+ var validISO4217CurrencyCodes = new Set(['AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD', 'CAD', 'CDF', 'CHE', 'CHF', 'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRU', 'MUR', 'MVR', 'MWK', 'MXN', 'MXV', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLE', 'SLL', 'SOS', 'SRD', 'SSP', 'STN', 'SVC', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'USN', 'UYI', 'UYU', 'UYW', 'UZS', 'VES', 'VND', 'VUV', 'WST', 'XAF', 'XAG', 'XAU', 'XBA', 'XBB', 'XBC', 'XBD', 'XCD', 'XDR', 'XOF', 'XPD', 'XPF', 'XPT', 'XSU', 'XTS', 'XUA', 'XXX', 'YER', 'ZAR', 'ZMW', 'ZWL']);
5
+ export default function isISO4217(str) {
6
+ assertString(str);
7
+ return validISO4217CurrencyCodes.has(str.toUpperCase());
8
+ }
9
+ export var CurrencyCodes = validISO4217CurrencyCodes;
@@ -0,0 +1,27 @@
1
+ import assertString from './util/assertString';
2
+
3
+ // https://en.wikipedia.org/wiki/ISO_6346
4
+ // according to ISO6346 standard, checksum digit is mandatory for freight container but recommended
5
+ // for other container types (J and Z)
6
+ var isISO6346Str = /^[A-Z]{3}(U[0-9]{7})|([J,Z][0-9]{6,7})$/;
7
+ var isDigit = /^[0-9]$/;
8
+ export function isISO6346(str) {
9
+ assertString(str);
10
+ str = str.toUpperCase();
11
+ if (!isISO6346Str.test(str)) return false;
12
+ if (str.length === 11) {
13
+ var sum = 0;
14
+ for (var i = 0; i < str.length - 1; i++) {
15
+ if (!isDigit.test(str[i])) {
16
+ var convertedCode = void 0;
17
+ var letterCode = str.charCodeAt(i) - 55;
18
+ if (letterCode < 11) convertedCode = letterCode;else if (letterCode >= 11 && letterCode <= 20) convertedCode = 12 + letterCode % 11;else if (letterCode >= 21 && letterCode <= 30) convertedCode = 23 + letterCode % 21;else convertedCode = 34 + letterCode % 31;
19
+ sum += convertedCode * Math.pow(2, i);
20
+ } else sum += str[i] * Math.pow(2, i);
21
+ }
22
+ var checkSumDigit = sum % 11;
23
+ return Number(str[str.length - 1]) === checkSumDigit;
24
+ }
25
+ return true;
26
+ }
27
+ export var isFreightContainerID = isISO6346;
@@ -0,0 +1,6 @@
1
+ import assertString from './util/assertString';
2
+ var isISO6391Set = new Set(['aa', 'ab', 'ae', 'af', 'ak', 'am', 'an', 'ar', 'as', 'av', 'ay', 'az', 'az', 'ba', 'be', 'bg', 'bh', 'bi', 'bm', 'bn', 'bo', 'br', 'bs', 'ca', 'ce', 'ch', 'co', 'cr', 'cs', 'cu', 'cv', 'cy', 'da', 'de', 'dv', 'dz', 'ee', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fa', 'ff', 'fi', 'fj', 'fo', 'fr', 'fy', 'ga', 'gd', 'gl', 'gn', 'gu', 'gv', 'ha', 'he', 'hi', 'ho', 'hr', 'ht', 'hu', 'hy', 'hz', 'ia', 'id', 'ie', 'ig', 'ii', 'ik', 'io', 'is', 'it', 'iu', 'ja', 'jv', 'ka', 'kg', 'ki', 'kj', 'kk', 'kl', 'km', 'kn', 'ko', 'kr', 'ks', 'ku', 'kv', 'kw', 'ky', 'la', 'lb', 'lg', 'li', 'ln', 'lo', 'lt', 'lu', 'lv', 'mg', 'mh', 'mi', 'mk', 'ml', 'mn', 'mr', 'ms', 'mt', 'my', 'na', 'nb', 'nd', 'ne', 'ng', 'nl', 'nn', 'no', 'nr', 'nv', 'ny', 'oc', 'oj', 'om', 'or', 'os', 'pa', 'pi', 'pl', 'ps', 'pt', 'qu', 'rm', 'rn', 'ro', 'ru', 'rw', 'sa', 'sc', 'sd', 'se', 'sg', 'si', 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'ss', 'st', 'su', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'ti', 'tk', 'tl', 'tn', 'to', 'tr', 'ts', 'tt', 'tw', 'ty', 'ug', 'uk', 'ur', 'uz', 've', 'vi', 'vo', 'wa', 'wo', 'xh', 'yi', 'yo', 'za', 'zh', 'zu']);
3
+ export default function isISO6391(str) {
4
+ assertString(str);
5
+ return isISO6391Set.has(str);
6
+ }
@@ -0,0 +1,42 @@
1
+ import assertString from './util/assertString';
2
+
3
+ /* eslint-disable max-len */
4
+ // from http://goo.gl/0ejHHW
5
+ var iso8601 = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
6
+ // same as above, except with a strict 'T' separator between date and time
7
+ var iso8601StrictSeparator = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
8
+ /* eslint-enable max-len */
9
+ var isValidDate = function isValidDate(str) {
10
+ // str must have passed the ISO8601 check
11
+ // this check is meant to catch invalid dates
12
+ // like 2009-02-31
13
+ // first check for ordinal dates
14
+ var ordinalMatch = str.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/);
15
+ if (ordinalMatch) {
16
+ var oYear = Number(ordinalMatch[1]);
17
+ var oDay = Number(ordinalMatch[2]);
18
+ // if is leap year
19
+ if (oYear % 4 === 0 && oYear % 100 !== 0 || oYear % 400 === 0) return oDay <= 366;
20
+ return oDay <= 365;
21
+ }
22
+ var match = str.match(/(\d{4})-?(\d{0,2})-?(\d*)/).map(Number);
23
+ var year = match[1];
24
+ var month = match[2];
25
+ var day = match[3];
26
+ var monthString = month ? "0".concat(month).slice(-2) : month;
27
+ var dayString = day ? "0".concat(day).slice(-2) : day;
28
+
29
+ // create a date object and compare
30
+ var d = new Date("".concat(year, "-").concat(monthString || '01', "-").concat(dayString || '01'));
31
+ if (month && day) {
32
+ return d.getUTCFullYear() === year && d.getUTCMonth() + 1 === month && d.getUTCDate() === day;
33
+ }
34
+ return true;
35
+ };
36
+ export default function isISO8601(str) {
37
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
38
+ assertString(str);
39
+ var check = options.strictSeparator ? iso8601StrictSeparator.test(str) : iso8601.test(str);
40
+ if (check && options.strict) return isValidDate(str);
41
+ return check;
42
+ }
@@ -0,0 +1,8 @@
1
+ import assertString from './util/assertString';
2
+
3
+ // see http://isrc.ifpi.org/en/isrc-standard/code-syntax
4
+ var isrc = /^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;
5
+ export default function isISRC(str) {
6
+ assertString(str);
7
+ return isrc.test(str);
8
+ }
@@ -0,0 +1,19 @@
1
+ import assertString from './util/assertString';
2
+ var issn = '^\\d{4}-?\\d{3}[\\dX]$';
3
+ export default function isISSN(str) {
4
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5
+ assertString(str);
6
+ var testIssn = issn;
7
+ testIssn = options.require_hyphen ? testIssn.replace('?', '') : testIssn;
8
+ testIssn = options.case_sensitive ? new RegExp(testIssn) : new RegExp(testIssn, 'i');
9
+ if (!testIssn.test(str)) {
10
+ return false;
11
+ }
12
+ var digits = str.replace('-', '').toUpperCase();
13
+ var checksum = 0;
14
+ for (var i = 0; i < digits.length; i++) {
15
+ var digit = digits[i];
16
+ checksum += (digit === 'X' ? 10 : +digit) * (8 - i);
17
+ }
18
+ return checksum % 11 === 0;
19
+ }