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/lib/isTaxID.js ADDED
@@ -0,0 +1,1399 @@
1
+ "use strict";
2
+
3
+ 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); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = isTaxID;
8
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
9
+ var algorithms = _interopRequireWildcard(require("./util/algorithms"));
10
+ var _isDate = _interopRequireDefault(require("./isDate"));
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
15
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
16
+ 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); }
17
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
18
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
19
+ 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; }
20
+ /**
21
+ * TIN Validation
22
+ * Validates Tax Identification Numbers (TINs) from the US, EU member states and the United Kingdom.
23
+ *
24
+ * EU-UK:
25
+ * National TIN validity is calculated using public algorithms as made available by DG TAXUD.
26
+ *
27
+ * See `https://ec.europa.eu/taxation_customs/tin/specs/FS-TIN%20Algorithms-Public.docx` for more information.
28
+ *
29
+ * US:
30
+ * An Employer Identification Number (EIN), also known as a Federal Tax Identification Number,
31
+ * is used to identify a business entity.
32
+ *
33
+ * NOTES:
34
+ * - Prefix 47 is being reserved for future use
35
+ * - Prefixes 26, 27, 45, 46 and 47 were previously assigned by the Philadelphia campus.
36
+ *
37
+ * See `http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes`
38
+ * for more information.
39
+ */
40
+
41
+ // Locale functions
42
+
43
+ /*
44
+ * bg-BG validation function
45
+ * (Edinen graždanski nomer (EGN/ЕГН), persons only)
46
+ * Checks if birth date (first six digits) is valid and calculates check (last) digit
47
+ */
48
+ function bgBgCheck(tin) {
49
+ // Extract full year, normalize month and check birth date validity
50
+ var century_year = tin.slice(0, 2);
51
+ var month = parseInt(tin.slice(2, 4), 10);
52
+ if (month > 40) {
53
+ month -= 40;
54
+ century_year = "20".concat(century_year);
55
+ } else if (month > 20) {
56
+ month -= 20;
57
+ century_year = "18".concat(century_year);
58
+ } else {
59
+ century_year = "19".concat(century_year);
60
+ }
61
+ if (month < 10) {
62
+ month = "0".concat(month);
63
+ }
64
+ var date = "".concat(century_year, "/").concat(month, "/").concat(tin.slice(4, 6));
65
+ if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
66
+ return false;
67
+ }
68
+
69
+ // split digits into an array for further processing
70
+ var digits = tin.split('').map(function (a) {
71
+ return parseInt(a, 10);
72
+ });
73
+
74
+ // Calculate checksum by multiplying digits with fixed values
75
+ var multip_lookup = [2, 4, 8, 5, 10, 9, 7, 3, 6];
76
+ var checksum = 0;
77
+ for (var i = 0; i < multip_lookup.length; i++) {
78
+ checksum += digits[i] * multip_lookup[i];
79
+ }
80
+ checksum = checksum % 11 === 10 ? 0 : checksum % 11;
81
+ return checksum === digits[9];
82
+ }
83
+
84
+ /**
85
+ * Check if an input is a valid Canadian SIN (Social Insurance Number)
86
+ *
87
+ * The Social Insurance Number (SIN) is a 9 digit number that
88
+ * you need to work in Canada or to have access to government programs and benefits.
89
+ *
90
+ * https://en.wikipedia.org/wiki/Social_Insurance_Number
91
+ * https://www.canada.ca/en/employment-social-development/services/sin.html
92
+ * https://www.codercrunch.com/challenge/819302488/sin-validator
93
+ *
94
+ * @param {string} input
95
+ * @return {boolean}
96
+ */
97
+ function isCanadianSIN(input) {
98
+ var digitsArray = input.split('');
99
+ var even = digitsArray.filter(function (_, idx) {
100
+ return idx % 2;
101
+ }).map(function (i) {
102
+ return Number(i) * 2;
103
+ }).join('').split('');
104
+ var total = digitsArray.filter(function (_, idx) {
105
+ return !(idx % 2);
106
+ }).concat(even).map(function (i) {
107
+ return Number(i);
108
+ }).reduce(function (acc, cur) {
109
+ return acc + cur;
110
+ });
111
+ return total % 10 === 0;
112
+ }
113
+
114
+ /*
115
+ * cs-CZ validation function
116
+ * (Rodné číslo (RČ), persons only)
117
+ * Checks if birth date (first six digits) is valid and divisibility by 11
118
+ * Material not in DG TAXUD document sourced from:
119
+ * -`https://lorenc.info/3MA381/overeni-spravnosti-rodneho-cisla.htm`
120
+ * -`https://www.mvcr.cz/clanek/rady-a-sluzby-dokumenty-rodne-cislo.aspx`
121
+ */
122
+ function csCzCheck(tin) {
123
+ tin = tin.replace(/\W/, '');
124
+
125
+ // Extract full year from TIN length
126
+ var full_year = parseInt(tin.slice(0, 2), 10);
127
+ if (tin.length === 10) {
128
+ if (full_year < 54) {
129
+ full_year = "20".concat(full_year);
130
+ } else {
131
+ full_year = "19".concat(full_year);
132
+ }
133
+ } else {
134
+ if (tin.slice(6) === '000') {
135
+ return false;
136
+ } // Three-zero serial not assigned before 1954
137
+ if (full_year < 54) {
138
+ full_year = "19".concat(full_year);
139
+ } else {
140
+ return false; // No 18XX years seen in any of the resources
141
+ }
142
+ }
143
+ // Add missing zero if needed
144
+ if (full_year.length === 3) {
145
+ full_year = [full_year.slice(0, 2), '0', full_year.slice(2)].join('');
146
+ }
147
+
148
+ // Extract month from TIN and normalize
149
+ var month = parseInt(tin.slice(2, 4), 10);
150
+ if (month > 50) {
151
+ month -= 50;
152
+ }
153
+ if (month > 20) {
154
+ // Month-plus-twenty was only introduced in 2004
155
+ if (parseInt(full_year, 10) < 2004) {
156
+ return false;
157
+ }
158
+ month -= 20;
159
+ }
160
+ if (month < 10) {
161
+ month = "0".concat(month);
162
+ }
163
+
164
+ // Check date validity
165
+ var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
166
+ if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
167
+ return false;
168
+ }
169
+
170
+ // Verify divisibility by 11
171
+ if (tin.length === 10) {
172
+ if (parseInt(tin, 10) % 11 !== 0) {
173
+ // Some numbers up to and including 1985 are still valid if
174
+ // check (last) digit equals 0 and modulo of first 9 digits equals 10
175
+ var checkdigit = parseInt(tin.slice(0, 9), 10) % 11;
176
+ if (parseInt(full_year, 10) < 1986 && checkdigit === 10) {
177
+ if (parseInt(tin.slice(9), 10) !== 0) {
178
+ return false;
179
+ }
180
+ } else {
181
+ return false;
182
+ }
183
+ }
184
+ }
185
+ return true;
186
+ }
187
+
188
+ /*
189
+ * de-AT validation function
190
+ * (Abgabenkontonummer, persons/entities)
191
+ * Verify TIN validity by calling luhnCheck()
192
+ */
193
+ function deAtCheck(tin) {
194
+ return algorithms.luhnCheck(tin);
195
+ }
196
+
197
+ /*
198
+ * de-DE validation function
199
+ * (Steueridentifikationsnummer (Steuer-IdNr.), persons only)
200
+ * Tests for single duplicate/triplicate value, then calculates ISO 7064 check (last) digit
201
+ * Partial implementation of spec (same result with both algorithms always)
202
+ */
203
+ function deDeCheck(tin) {
204
+ // Split digits into an array for further processing
205
+ var digits = tin.split('').map(function (a) {
206
+ return parseInt(a, 10);
207
+ });
208
+
209
+ // Fill array with strings of number positions
210
+ var occurences = [];
211
+ for (var i = 0; i < digits.length - 1; i++) {
212
+ occurences.push('');
213
+ for (var j = 0; j < digits.length - 1; j++) {
214
+ if (digits[i] === digits[j]) {
215
+ occurences[i] += j;
216
+ }
217
+ }
218
+ }
219
+
220
+ // Remove digits with one occurence and test for only one duplicate/triplicate
221
+ occurences = occurences.filter(function (a) {
222
+ return a.length > 1;
223
+ });
224
+ if (occurences.length !== 2 && occurences.length !== 3) {
225
+ return false;
226
+ }
227
+
228
+ // In case of triplicate value only two digits are allowed next to each other
229
+ if (occurences[0].length === 3) {
230
+ var trip_locations = occurences[0].split('').map(function (a) {
231
+ return parseInt(a, 10);
232
+ });
233
+ var recurrent = 0; // Amount of neighbour occurences
234
+ for (var _i = 0; _i < trip_locations.length - 1; _i++) {
235
+ if (trip_locations[_i] + 1 === trip_locations[_i + 1]) {
236
+ recurrent += 1;
237
+ }
238
+ }
239
+ if (recurrent === 2) {
240
+ return false;
241
+ }
242
+ }
243
+ return algorithms.iso7064Check(tin);
244
+ }
245
+
246
+ /*
247
+ * dk-DK validation function
248
+ * (CPR-nummer (personnummer), persons only)
249
+ * Checks if birth date (first six digits) is valid and assigned to century (seventh) digit,
250
+ * and calculates check (last) digit
251
+ */
252
+ function dkDkCheck(tin) {
253
+ tin = tin.replace(/\W/, '');
254
+
255
+ // Extract year, check if valid for given century digit and add century
256
+ var year = parseInt(tin.slice(4, 6), 10);
257
+ var century_digit = tin.slice(6, 7);
258
+ switch (century_digit) {
259
+ case '0':
260
+ case '1':
261
+ case '2':
262
+ case '3':
263
+ year = "19".concat(year);
264
+ break;
265
+ case '4':
266
+ case '9':
267
+ if (year < 37) {
268
+ year = "20".concat(year);
269
+ } else {
270
+ year = "19".concat(year);
271
+ }
272
+ break;
273
+ default:
274
+ if (year < 37) {
275
+ year = "20".concat(year);
276
+ } else if (year > 58) {
277
+ year = "18".concat(year);
278
+ } else {
279
+ return false;
280
+ }
281
+ break;
282
+ }
283
+ // Add missing zero if needed
284
+ if (year.length === 3) {
285
+ year = [year.slice(0, 2), '0', year.slice(2)].join('');
286
+ }
287
+ // Check date validity
288
+ var date = "".concat(year, "/").concat(tin.slice(2, 4), "/").concat(tin.slice(0, 2));
289
+ if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
290
+ return false;
291
+ }
292
+
293
+ // Split digits into an array for further processing
294
+ var digits = tin.split('').map(function (a) {
295
+ return parseInt(a, 10);
296
+ });
297
+ var checksum = 0;
298
+ var weight = 4;
299
+ // Multiply by weight and add to checksum
300
+ for (var i = 0; i < 9; i++) {
301
+ checksum += digits[i] * weight;
302
+ weight -= 1;
303
+ if (weight === 1) {
304
+ weight = 7;
305
+ }
306
+ }
307
+ checksum %= 11;
308
+ if (checksum === 1) {
309
+ return false;
310
+ }
311
+ return checksum === 0 ? digits[9] === 0 : digits[9] === 11 - checksum;
312
+ }
313
+
314
+ /*
315
+ * el-CY validation function
316
+ * (Arithmos Forologikou Mitroou (AFM/ΑΦΜ), persons only)
317
+ * Verify TIN validity by calculating ASCII value of check (last) character
318
+ */
319
+ function elCyCheck(tin) {
320
+ // split digits into an array for further processing
321
+ var digits = tin.slice(0, 8).split('').map(function (a) {
322
+ return parseInt(a, 10);
323
+ });
324
+ var checksum = 0;
325
+ // add digits in even places
326
+ for (var i = 1; i < digits.length; i += 2) {
327
+ checksum += digits[i];
328
+ }
329
+
330
+ // add digits in odd places
331
+ for (var _i2 = 0; _i2 < digits.length; _i2 += 2) {
332
+ if (digits[_i2] < 2) {
333
+ checksum += 1 - digits[_i2];
334
+ } else {
335
+ checksum += 2 * (digits[_i2] - 2) + 5;
336
+ if (digits[_i2] > 4) {
337
+ checksum += 2;
338
+ }
339
+ }
340
+ }
341
+ return String.fromCharCode(checksum % 26 + 65) === tin.charAt(8);
342
+ }
343
+
344
+ /*
345
+ * el-GR validation function
346
+ * (Arithmos Forologikou Mitroou (AFM/ΑΦΜ), persons/entities)
347
+ * Verify TIN validity by calculating check (last) digit
348
+ * Algorithm not in DG TAXUD document- sourced from:
349
+ * - `http://epixeirisi.gr/%CE%9A%CE%A1%CE%99%CE%A3%CE%99%CE%9C%CE%91-%CE%98%CE%95%CE%9C%CE%91%CE%A4%CE%91-%CE%A6%CE%9F%CE%A1%CE%9F%CE%9B%CE%9F%CE%93%CE%99%CE%91%CE%A3-%CE%9A%CE%91%CE%99-%CE%9B%CE%9F%CE%93%CE%99%CE%A3%CE%A4%CE%99%CE%9A%CE%97%CE%A3/23791/%CE%91%CF%81%CE%B9%CE%B8%CE%BC%CF%8C%CF%82-%CE%A6%CE%BF%CF%81%CE%BF%CE%BB%CE%BF%CE%B3%CE%B9%CE%BA%CE%BF%CF%8D-%CE%9C%CE%B7%CF%84%CF%81%CF%8E%CE%BF%CF%85`
350
+ */
351
+ function elGrCheck(tin) {
352
+ // split digits into an array for further processing
353
+ var digits = tin.split('').map(function (a) {
354
+ return parseInt(a, 10);
355
+ });
356
+ var checksum = 0;
357
+ for (var i = 0; i < 8; i++) {
358
+ checksum += digits[i] * Math.pow(2, 8 - i);
359
+ }
360
+ return checksum % 11 % 10 === digits[8];
361
+ }
362
+
363
+ /*
364
+ * en-GB validation function (should go here if needed)
365
+ * (National Insurance Number (NINO) or Unique Taxpayer Reference (UTR),
366
+ * persons/entities respectively)
367
+ */
368
+
369
+ /*
370
+ * en-IE validation function
371
+ * (Personal Public Service Number (PPS No), persons only)
372
+ * Verify TIN validity by calculating check (second to last) character
373
+ */
374
+ function enIeCheck(tin) {
375
+ var checksum = algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 7).map(function (a) {
376
+ return parseInt(a, 10);
377
+ }), 8);
378
+ if (tin.length === 9 && tin[8] !== 'W') {
379
+ checksum += (tin[8].charCodeAt(0) - 64) * 9;
380
+ }
381
+ checksum %= 23;
382
+ if (checksum === 0) {
383
+ return tin[7].toUpperCase() === 'W';
384
+ }
385
+ return tin[7].toUpperCase() === String.fromCharCode(64 + checksum);
386
+ }
387
+
388
+ // Valid US IRS campus prefixes
389
+ var enUsCampusPrefix = {
390
+ andover: ['10', '12'],
391
+ atlanta: ['60', '67'],
392
+ austin: ['50', '53'],
393
+ brookhaven: ['01', '02', '03', '04', '05', '06', '11', '13', '14', '16', '21', '22', '23', '25', '34', '51', '52', '54', '55', '56', '57', '58', '59', '65'],
394
+ cincinnati: ['30', '32', '35', '36', '37', '38', '61'],
395
+ fresno: ['15', '24'],
396
+ internet: ['20', '26', '27', '45', '46', '47'],
397
+ kansas: ['40', '44'],
398
+ memphis: ['94', '95'],
399
+ ogden: ['80', '90'],
400
+ philadelphia: ['33', '39', '41', '42', '43', '46', '48', '62', '63', '64', '66', '68', '71', '72', '73', '74', '75', '76', '77', '81', '82', '83', '84', '85', '86', '87', '88', '91', '92', '93', '98', '99'],
401
+ sba: ['31']
402
+ };
403
+
404
+ // Return an array of all US IRS campus prefixes
405
+ function enUsGetPrefixes() {
406
+ var prefixes = [];
407
+ for (var location in enUsCampusPrefix) {
408
+ // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
409
+ // istanbul ignore else
410
+ if (enUsCampusPrefix.hasOwnProperty(location)) {
411
+ prefixes.push.apply(prefixes, _toConsumableArray(enUsCampusPrefix[location]));
412
+ }
413
+ }
414
+ return prefixes;
415
+ }
416
+
417
+ /*
418
+ * en-US validation function
419
+ * Verify that the TIN starts with a valid IRS campus prefix
420
+ */
421
+ function enUsCheck(tin) {
422
+ return enUsGetPrefixes().indexOf(tin.slice(0, 2)) !== -1;
423
+ }
424
+
425
+ /*
426
+ * es-AR validation function
427
+ * Clave Única de Identificación Tributaria (CUIT/CUIL)
428
+ * Sourced from:
429
+ * - https://servicioscf.afip.gob.ar/publico/abc/ABCpaso2.aspx?id_nivel1=3036&id_nivel2=3040&p=Conceptos%20b%C3%A1sicos
430
+ * - https://es.wikipedia.org/wiki/Clave_%C3%9Anica_de_Identificaci%C3%B3n_Tributaria
431
+ */
432
+
433
+ function esArCheck(tin) {
434
+ var accum = 0;
435
+ var digits = tin.split('');
436
+ var digit = parseInt(digits.pop(), 10);
437
+ for (var i = 0; i < digits.length; i++) {
438
+ accum += digits[9 - i] * (2 + i % 6);
439
+ }
440
+ var verif = 11 - accum % 11;
441
+ if (verif === 11) {
442
+ verif = 0;
443
+ } else if (verif === 10) {
444
+ verif = 9;
445
+ }
446
+ return digit === verif;
447
+ }
448
+
449
+ /*
450
+ * es-ES validation function
451
+ * (Documento Nacional de Identidad (DNI)
452
+ * or Número de Identificación de Extranjero (NIE), persons only)
453
+ * Verify TIN validity by calculating check (last) character
454
+ */
455
+ function esEsCheck(tin) {
456
+ // Split characters into an array for further processing
457
+ var chars = tin.toUpperCase().split('');
458
+
459
+ // Replace initial letter if needed
460
+ if (isNaN(parseInt(chars[0], 10)) && chars.length > 1) {
461
+ var lead_replace = 0;
462
+ switch (chars[0]) {
463
+ case 'Y':
464
+ lead_replace = 1;
465
+ break;
466
+ case 'Z':
467
+ lead_replace = 2;
468
+ break;
469
+ default:
470
+ }
471
+ chars.splice(0, 1, lead_replace);
472
+ // Fill with zeros if smaller than proper
473
+ } else {
474
+ while (chars.length < 9) {
475
+ chars.unshift(0);
476
+ }
477
+ }
478
+
479
+ // Calculate checksum and check according to lookup
480
+ var lookup = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E'];
481
+ chars = chars.join('');
482
+ var checksum = parseInt(chars.slice(0, 8), 10) % 23;
483
+ return chars[8] === lookup[checksum];
484
+ }
485
+
486
+ /*
487
+ * et-EE validation function
488
+ * (Isikukood (IK), persons only)
489
+ * Checks if birth date (century digit and six following) is valid and calculates check (last) digit
490
+ * Material not in DG TAXUD document sourced from:
491
+ * - `https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/Estonia-TIN.pdf`
492
+ */
493
+ function etEeCheck(tin) {
494
+ // Extract year and add century
495
+ var full_year = tin.slice(1, 3);
496
+ var century_digit = tin.slice(0, 1);
497
+ switch (century_digit) {
498
+ case '1':
499
+ case '2':
500
+ full_year = "18".concat(full_year);
501
+ break;
502
+ case '3':
503
+ case '4':
504
+ full_year = "19".concat(full_year);
505
+ break;
506
+ default:
507
+ full_year = "20".concat(full_year);
508
+ break;
509
+ }
510
+ // Check date validity
511
+ var date = "".concat(full_year, "/").concat(tin.slice(3, 5), "/").concat(tin.slice(5, 7));
512
+ if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
513
+ return false;
514
+ }
515
+
516
+ // Split digits into an array for further processing
517
+ var digits = tin.split('').map(function (a) {
518
+ return parseInt(a, 10);
519
+ });
520
+ var checksum = 0;
521
+ var weight = 1;
522
+ // Multiply by weight and add to checksum
523
+ for (var i = 0; i < 10; i++) {
524
+ checksum += digits[i] * weight;
525
+ weight += 1;
526
+ if (weight === 10) {
527
+ weight = 1;
528
+ }
529
+ }
530
+ // Do again if modulo 11 of checksum is 10
531
+ if (checksum % 11 === 10) {
532
+ checksum = 0;
533
+ weight = 3;
534
+ for (var _i3 = 0; _i3 < 10; _i3++) {
535
+ checksum += digits[_i3] * weight;
536
+ weight += 1;
537
+ if (weight === 10) {
538
+ weight = 1;
539
+ }
540
+ }
541
+ if (checksum % 11 === 10) {
542
+ return digits[10] === 0;
543
+ }
544
+ }
545
+ return checksum % 11 === digits[10];
546
+ }
547
+
548
+ /*
549
+ * fi-FI validation function
550
+ * (Henkilötunnus (HETU), persons only)
551
+ * Checks if birth date (first six digits plus century symbol) is valid
552
+ * and calculates check (last) digit
553
+ */
554
+ function fiFiCheck(tin) {
555
+ // Extract year and add century
556
+ var full_year = tin.slice(4, 6);
557
+ var century_symbol = tin.slice(6, 7);
558
+ switch (century_symbol) {
559
+ case '+':
560
+ full_year = "18".concat(full_year);
561
+ break;
562
+ case '-':
563
+ full_year = "19".concat(full_year);
564
+ break;
565
+ default:
566
+ full_year = "20".concat(full_year);
567
+ break;
568
+ }
569
+ // Check date validity
570
+ var date = "".concat(full_year, "/").concat(tin.slice(2, 4), "/").concat(tin.slice(0, 2));
571
+ if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
572
+ return false;
573
+ }
574
+
575
+ // Calculate check character
576
+ var checksum = parseInt(tin.slice(0, 6) + tin.slice(7, 10), 10) % 31;
577
+ if (checksum < 10) {
578
+ return checksum === parseInt(tin.slice(10), 10);
579
+ }
580
+ checksum -= 10;
581
+ var letters_lookup = ['A', 'B', 'C', 'D', 'E', 'F', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'];
582
+ return letters_lookup[checksum] === tin.slice(10);
583
+ }
584
+
585
+ /*
586
+ * fr/nl-BE validation function
587
+ * (Numéro national (N.N.), persons only)
588
+ * Checks if birth date (first six digits) is valid and calculates check (last two) digits
589
+ */
590
+ function frBeCheck(tin) {
591
+ // Zero month/day value is acceptable
592
+ if (tin.slice(2, 4) !== '00' || tin.slice(4, 6) !== '00') {
593
+ // Extract date from first six digits of TIN
594
+ var date = "".concat(tin.slice(0, 2), "/").concat(tin.slice(2, 4), "/").concat(tin.slice(4, 6));
595
+ if (!(0, _isDate.default)(date, 'YY/MM/DD')) {
596
+ return false;
597
+ }
598
+ }
599
+ var checksum = 97 - parseInt(tin.slice(0, 9), 10) % 97;
600
+ var checkdigits = parseInt(tin.slice(9, 11), 10);
601
+ if (checksum !== checkdigits) {
602
+ checksum = 97 - parseInt("2".concat(tin.slice(0, 9)), 10) % 97;
603
+ if (checksum !== checkdigits) {
604
+ return false;
605
+ }
606
+ }
607
+ return true;
608
+ }
609
+
610
+ /*
611
+ * fr-FR validation function
612
+ * (Numéro fiscal de référence (numéro SPI), persons only)
613
+ * Verify TIN validity by calculating check (last three) digits
614
+ */
615
+ function frFrCheck(tin) {
616
+ tin = tin.replace(/\s/g, '');
617
+ var checksum = parseInt(tin.slice(0, 10), 10) % 511;
618
+ var checkdigits = parseInt(tin.slice(10, 13), 10);
619
+ return checksum === checkdigits;
620
+ }
621
+
622
+ /*
623
+ * fr/lb-LU validation function
624
+ * (numéro d’identification personnelle, persons only)
625
+ * Verify birth date validity and run Luhn and Verhoeff checks
626
+ */
627
+ function frLuCheck(tin) {
628
+ // Extract date and check validity
629
+ var date = "".concat(tin.slice(0, 4), "/").concat(tin.slice(4, 6), "/").concat(tin.slice(6, 8));
630
+ if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
631
+ return false;
632
+ }
633
+
634
+ // Run Luhn check
635
+ if (!algorithms.luhnCheck(tin.slice(0, 12))) {
636
+ return false;
637
+ }
638
+ // Remove Luhn check digit and run Verhoeff check
639
+ return algorithms.verhoeffCheck("".concat(tin.slice(0, 11)).concat(tin[12]));
640
+ }
641
+
642
+ /*
643
+ * hr-HR validation function
644
+ * (Osobni identifikacijski broj (OIB), persons/entities)
645
+ * Verify TIN validity by calling iso7064Check(digits)
646
+ */
647
+ function hrHrCheck(tin) {
648
+ return algorithms.iso7064Check(tin);
649
+ }
650
+
651
+ /*
652
+ * hu-HU validation function
653
+ * (Adóazonosító jel, persons only)
654
+ * Verify TIN validity by calculating check (last) digit
655
+ */
656
+ function huHuCheck(tin) {
657
+ // split digits into an array for further processing
658
+ var digits = tin.split('').map(function (a) {
659
+ return parseInt(a, 10);
660
+ });
661
+ var checksum = 8;
662
+ for (var i = 1; i < 9; i++) {
663
+ checksum += digits[i] * (i + 1);
664
+ }
665
+ return checksum % 11 === digits[9];
666
+ }
667
+
668
+ /*
669
+ * lt-LT validation function (should go here if needed)
670
+ * (Asmens kodas, persons/entities respectively)
671
+ * Current validation check is alias of etEeCheck- same format applies
672
+ */
673
+
674
+ /*
675
+ * it-IT first/last name validity check
676
+ * Accepts it-IT TIN-encoded names as a three-element character array and checks their validity
677
+ * Due to lack of clarity between resources ("Are only Italian consonants used?
678
+ * What happens if a person has X in their name?" etc.) only two test conditions
679
+ * have been implemented:
680
+ * Vowels may only be followed by other vowels or an X character
681
+ * and X characters after vowels may only be followed by other X characters.
682
+ */
683
+ function itItNameCheck(name) {
684
+ // true at the first occurence of a vowel
685
+ var vowelflag = false;
686
+
687
+ // true at the first occurence of an X AFTER vowel
688
+ // (to properly handle last names with X as consonant)
689
+ var xflag = false;
690
+ for (var i = 0; i < 3; i++) {
691
+ if (!vowelflag && /[AEIOU]/.test(name[i])) {
692
+ vowelflag = true;
693
+ } else if (!xflag && vowelflag && name[i] === 'X') {
694
+ xflag = true;
695
+ } else if (i > 0) {
696
+ if (vowelflag && !xflag) {
697
+ if (!/[AEIOU]/.test(name[i])) {
698
+ return false;
699
+ }
700
+ }
701
+ if (xflag) {
702
+ if (!/X/.test(name[i])) {
703
+ return false;
704
+ }
705
+ }
706
+ }
707
+ }
708
+ return true;
709
+ }
710
+
711
+ /*
712
+ * it-IT validation function
713
+ * (Codice fiscale (TIN-IT), persons only)
714
+ * Verify name, birth date and codice catastale validity
715
+ * and calculate check character.
716
+ * Material not in DG-TAXUD document sourced from:
717
+ * `https://en.wikipedia.org/wiki/Italian_fiscal_code`
718
+ */
719
+ function itItCheck(tin) {
720
+ // Capitalize and split characters into an array for further processing
721
+ var chars = tin.toUpperCase().split('');
722
+
723
+ // Check first and last name validity calling itItNameCheck()
724
+ if (!itItNameCheck(chars.slice(0, 3))) {
725
+ return false;
726
+ }
727
+ if (!itItNameCheck(chars.slice(3, 6))) {
728
+ return false;
729
+ }
730
+
731
+ // Convert letters in number spaces back to numbers if any
732
+ var number_locations = [6, 7, 9, 10, 12, 13, 14];
733
+ var number_replace = {
734
+ L: '0',
735
+ M: '1',
736
+ N: '2',
737
+ P: '3',
738
+ Q: '4',
739
+ R: '5',
740
+ S: '6',
741
+ T: '7',
742
+ U: '8',
743
+ V: '9'
744
+ };
745
+ for (var _i4 = 0, _number_locations = number_locations; _i4 < _number_locations.length; _i4++) {
746
+ var i = _number_locations[_i4];
747
+ if (chars[i] in number_replace) {
748
+ chars.splice(i, 1, number_replace[chars[i]]);
749
+ }
750
+ }
751
+
752
+ // Extract month and day, and check date validity
753
+ var month_replace = {
754
+ A: '01',
755
+ B: '02',
756
+ C: '03',
757
+ D: '04',
758
+ E: '05',
759
+ H: '06',
760
+ L: '07',
761
+ M: '08',
762
+ P: '09',
763
+ R: '10',
764
+ S: '11',
765
+ T: '12'
766
+ };
767
+ var month = month_replace[chars[8]];
768
+ var day = parseInt(chars[9] + chars[10], 10);
769
+ if (day > 40) {
770
+ day -= 40;
771
+ }
772
+ if (day < 10) {
773
+ day = "0".concat(day);
774
+ }
775
+ var date = "".concat(chars[6]).concat(chars[7], "/").concat(month, "/").concat(day);
776
+ if (!(0, _isDate.default)(date, 'YY/MM/DD')) {
777
+ return false;
778
+ }
779
+
780
+ // Calculate check character by adding up even and odd characters as numbers
781
+ var checksum = 0;
782
+ for (var _i5 = 1; _i5 < chars.length - 1; _i5 += 2) {
783
+ var char_to_int = parseInt(chars[_i5], 10);
784
+ if (isNaN(char_to_int)) {
785
+ char_to_int = chars[_i5].charCodeAt(0) - 65;
786
+ }
787
+ checksum += char_to_int;
788
+ }
789
+ var odd_convert = {
790
+ // Maps of characters at odd places
791
+ A: 1,
792
+ B: 0,
793
+ C: 5,
794
+ D: 7,
795
+ E: 9,
796
+ F: 13,
797
+ G: 15,
798
+ H: 17,
799
+ I: 19,
800
+ J: 21,
801
+ K: 2,
802
+ L: 4,
803
+ M: 18,
804
+ N: 20,
805
+ O: 11,
806
+ P: 3,
807
+ Q: 6,
808
+ R: 8,
809
+ S: 12,
810
+ T: 14,
811
+ U: 16,
812
+ V: 10,
813
+ W: 22,
814
+ X: 25,
815
+ Y: 24,
816
+ Z: 23,
817
+ 0: 1,
818
+ 1: 0
819
+ };
820
+ for (var _i6 = 0; _i6 < chars.length - 1; _i6 += 2) {
821
+ var _char_to_int = 0;
822
+ if (chars[_i6] in odd_convert) {
823
+ _char_to_int = odd_convert[chars[_i6]];
824
+ } else {
825
+ var multiplier = parseInt(chars[_i6], 10);
826
+ _char_to_int = 2 * multiplier + 1;
827
+ if (multiplier > 4) {
828
+ _char_to_int += 2;
829
+ }
830
+ }
831
+ checksum += _char_to_int;
832
+ }
833
+ if (String.fromCharCode(65 + checksum % 26) !== chars[15]) {
834
+ return false;
835
+ }
836
+ return true;
837
+ }
838
+
839
+ /*
840
+ * lv-LV validation function
841
+ * (Personas kods (PK), persons only)
842
+ * Check validity of birth date and calculate check (last) digit
843
+ * Support only for old format numbers (not starting with '32', issued before 2017/07/01)
844
+ * Material not in DG TAXUD document sourced from:
845
+ * `https://boot.ritakafija.lv/forums/index.php?/topic/88314-personas-koda-algoritms-%C4%8Deksumma/`
846
+ */
847
+ function lvLvCheck(tin) {
848
+ tin = tin.replace(/\W/, '');
849
+ // Extract date from TIN
850
+ var day = tin.slice(0, 2);
851
+ if (day !== '32') {
852
+ // No date/checksum check if new format
853
+ var month = tin.slice(2, 4);
854
+ if (month !== '00') {
855
+ // No date check if unknown month
856
+ var full_year = tin.slice(4, 6);
857
+ switch (tin[6]) {
858
+ case '0':
859
+ full_year = "18".concat(full_year);
860
+ break;
861
+ case '1':
862
+ full_year = "19".concat(full_year);
863
+ break;
864
+ default:
865
+ full_year = "20".concat(full_year);
866
+ break;
867
+ }
868
+ // Check date validity
869
+ var date = "".concat(full_year, "/").concat(tin.slice(2, 4), "/").concat(day);
870
+ if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
871
+ return false;
872
+ }
873
+ }
874
+
875
+ // Calculate check digit
876
+ var checksum = 1101;
877
+ var multip_lookup = [1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
878
+ for (var i = 0; i < tin.length - 1; i++) {
879
+ checksum -= parseInt(tin[i], 10) * multip_lookup[i];
880
+ }
881
+ return parseInt(tin[10], 10) === checksum % 11;
882
+ }
883
+ return true;
884
+ }
885
+
886
+ /*
887
+ * mt-MT validation function
888
+ * (Identity Card Number or Unique Taxpayer Reference, persons/entities)
889
+ * Verify Identity Card Number structure (no other tests found)
890
+ */
891
+ function mtMtCheck(tin) {
892
+ if (tin.length !== 9) {
893
+ // No tests for UTR
894
+ var chars = tin.toUpperCase().split('');
895
+ // Fill with zeros if smaller than proper
896
+ while (chars.length < 8) {
897
+ chars.unshift(0);
898
+ }
899
+ // Validate format according to last character
900
+ switch (tin[7]) {
901
+ case 'A':
902
+ case 'P':
903
+ if (parseInt(chars[6], 10) === 0) {
904
+ return false;
905
+ }
906
+ break;
907
+ default:
908
+ {
909
+ var first_part = parseInt(chars.join('').slice(0, 5), 10);
910
+ if (first_part > 32000) {
911
+ return false;
912
+ }
913
+ var second_part = parseInt(chars.join('').slice(5, 7), 10);
914
+ if (first_part === second_part) {
915
+ return false;
916
+ }
917
+ }
918
+ }
919
+ }
920
+ return true;
921
+ }
922
+
923
+ /*
924
+ * nl-NL validation function
925
+ * (Burgerservicenummer (BSN) or Rechtspersonen Samenwerkingsverbanden Informatie Nummer (RSIN),
926
+ * persons/entities respectively)
927
+ * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
928
+ */
929
+ function nlNlCheck(tin) {
930
+ return algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
931
+ return parseInt(a, 10);
932
+ }), 9) % 11 === parseInt(tin[8], 10);
933
+ }
934
+
935
+ /*
936
+ * pl-PL validation function
937
+ * (Powszechny Elektroniczny System Ewidencji Ludności (PESEL)
938
+ * or Numer identyfikacji podatkowej (NIP), persons/entities)
939
+ * Verify TIN validity by validating birth date (PESEL) and calculating check (last) digit
940
+ */
941
+ function plPlCheck(tin) {
942
+ // NIP
943
+ if (tin.length === 10) {
944
+ // Calculate last digit by multiplying with lookup
945
+ var lookup = [6, 5, 7, 2, 3, 4, 5, 6, 7];
946
+ var _checksum = 0;
947
+ for (var i = 0; i < lookup.length; i++) {
948
+ _checksum += parseInt(tin[i], 10) * lookup[i];
949
+ }
950
+ _checksum %= 11;
951
+ if (_checksum === 10) {
952
+ return false;
953
+ }
954
+ return _checksum === parseInt(tin[9], 10);
955
+ }
956
+
957
+ // PESEL
958
+ // Extract full year using month
959
+ var full_year = tin.slice(0, 2);
960
+ var month = parseInt(tin.slice(2, 4), 10);
961
+ if (month > 80) {
962
+ full_year = "18".concat(full_year);
963
+ month -= 80;
964
+ } else if (month > 60) {
965
+ full_year = "22".concat(full_year);
966
+ month -= 60;
967
+ } else if (month > 40) {
968
+ full_year = "21".concat(full_year);
969
+ month -= 40;
970
+ } else if (month > 20) {
971
+ full_year = "20".concat(full_year);
972
+ month -= 20;
973
+ } else {
974
+ full_year = "19".concat(full_year);
975
+ }
976
+ // Add leading zero to month if needed
977
+ if (month < 10) {
978
+ month = "0".concat(month);
979
+ }
980
+ // Check date validity
981
+ var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
982
+ if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
983
+ return false;
984
+ }
985
+
986
+ // Calculate last digit by mulitplying with odd one-digit numbers except 5
987
+ var checksum = 0;
988
+ var multiplier = 1;
989
+ for (var _i7 = 0; _i7 < tin.length - 1; _i7++) {
990
+ checksum += parseInt(tin[_i7], 10) * multiplier % 10;
991
+ multiplier += 2;
992
+ if (multiplier > 10) {
993
+ multiplier = 1;
994
+ } else if (multiplier === 5) {
995
+ multiplier += 2;
996
+ }
997
+ }
998
+ checksum = 10 - checksum % 10;
999
+ return checksum === parseInt(tin[10], 10);
1000
+ }
1001
+
1002
+ /*
1003
+ * pt-BR validation function
1004
+ * (Cadastro de Pessoas Físicas (CPF, persons)
1005
+ * Cadastro Nacional de Pessoas Jurídicas (CNPJ, entities)
1006
+ * Both inputs will be validated
1007
+ */
1008
+
1009
+ function ptBrCheck(tin) {
1010
+ if (tin.length === 11) {
1011
+ var _sum;
1012
+ var remainder;
1013
+ _sum = 0;
1014
+ if (
1015
+ // Reject known invalid CPFs
1016
+ tin === '11111111111' || tin === '22222222222' || tin === '33333333333' || tin === '44444444444' || tin === '55555555555' || tin === '66666666666' || tin === '77777777777' || tin === '88888888888' || tin === '99999999999' || tin === '00000000000') return false;
1017
+ for (var i = 1; i <= 9; i++) _sum += parseInt(tin.substring(i - 1, i), 10) * (11 - i);
1018
+ remainder = _sum * 10 % 11;
1019
+ if (remainder === 10) remainder = 0;
1020
+ if (remainder !== parseInt(tin.substring(9, 10), 10)) return false;
1021
+ _sum = 0;
1022
+ for (var _i8 = 1; _i8 <= 10; _i8++) _sum += parseInt(tin.substring(_i8 - 1, _i8), 10) * (12 - _i8);
1023
+ remainder = _sum * 10 % 11;
1024
+ if (remainder === 10) remainder = 0;
1025
+ if (remainder !== parseInt(tin.substring(10, 11), 10)) return false;
1026
+ return true;
1027
+ }
1028
+ if (
1029
+ // Reject know invalid CNPJs
1030
+ tin === '00000000000000' || tin === '11111111111111' || tin === '22222222222222' || tin === '33333333333333' || tin === '44444444444444' || tin === '55555555555555' || tin === '66666666666666' || tin === '77777777777777' || tin === '88888888888888' || tin === '99999999999999') {
1031
+ return false;
1032
+ }
1033
+ var length = tin.length - 2;
1034
+ var identifiers = tin.substring(0, length);
1035
+ var verificators = tin.substring(length);
1036
+ var sum = 0;
1037
+ var pos = length - 7;
1038
+ for (var _i9 = length; _i9 >= 1; _i9--) {
1039
+ sum += identifiers.charAt(length - _i9) * pos;
1040
+ pos -= 1;
1041
+ if (pos < 2) {
1042
+ pos = 9;
1043
+ }
1044
+ }
1045
+ var result = sum % 11 < 2 ? 0 : 11 - sum % 11;
1046
+ if (result !== parseInt(verificators.charAt(0), 10)) {
1047
+ return false;
1048
+ }
1049
+ length += 1;
1050
+ identifiers = tin.substring(0, length);
1051
+ sum = 0;
1052
+ pos = length - 7;
1053
+ for (var _i10 = length; _i10 >= 1; _i10--) {
1054
+ sum += identifiers.charAt(length - _i10) * pos;
1055
+ pos -= 1;
1056
+ if (pos < 2) {
1057
+ pos = 9;
1058
+ }
1059
+ }
1060
+ result = sum % 11 < 2 ? 0 : 11 - sum % 11;
1061
+ if (result !== parseInt(verificators.charAt(1), 10)) {
1062
+ return false;
1063
+ }
1064
+ return true;
1065
+ }
1066
+
1067
+ /*
1068
+ * pt-PT validation function
1069
+ * (Número de identificação fiscal (NIF), persons/entities)
1070
+ * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
1071
+ */
1072
+ function ptPtCheck(tin) {
1073
+ var checksum = 11 - algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
1074
+ return parseInt(a, 10);
1075
+ }), 9) % 11;
1076
+ if (checksum > 9) {
1077
+ return parseInt(tin[8], 10) === 0;
1078
+ }
1079
+ return checksum === parseInt(tin[8], 10);
1080
+ }
1081
+
1082
+ /*
1083
+ * ro-RO validation function
1084
+ * (Cod Numeric Personal (CNP) or Cod de înregistrare fiscală (CIF),
1085
+ * persons only)
1086
+ * Verify CNP validity by calculating check (last) digit (test not found for CIF)
1087
+ * Material not in DG TAXUD document sourced from:
1088
+ * `https://en.wikipedia.org/wiki/National_identification_number#Romania`
1089
+ */
1090
+ function roRoCheck(tin) {
1091
+ if (tin.slice(0, 4) !== '9000') {
1092
+ // No test found for this format
1093
+ // Extract full year using century digit if possible
1094
+ var full_year = tin.slice(1, 3);
1095
+ switch (tin[0]) {
1096
+ case '1':
1097
+ case '2':
1098
+ full_year = "19".concat(full_year);
1099
+ break;
1100
+ case '3':
1101
+ case '4':
1102
+ full_year = "18".concat(full_year);
1103
+ break;
1104
+ case '5':
1105
+ case '6':
1106
+ full_year = "20".concat(full_year);
1107
+ break;
1108
+ default:
1109
+ }
1110
+
1111
+ // Check date validity
1112
+ var date = "".concat(full_year, "/").concat(tin.slice(3, 5), "/").concat(tin.slice(5, 7));
1113
+ if (date.length === 8) {
1114
+ if (!(0, _isDate.default)(date, 'YY/MM/DD')) {
1115
+ return false;
1116
+ }
1117
+ } else if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
1118
+ return false;
1119
+ }
1120
+
1121
+ // Calculate check digit
1122
+ var digits = tin.split('').map(function (a) {
1123
+ return parseInt(a, 10);
1124
+ });
1125
+ var multipliers = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9];
1126
+ var checksum = 0;
1127
+ for (var i = 0; i < multipliers.length; i++) {
1128
+ checksum += digits[i] * multipliers[i];
1129
+ }
1130
+ if (checksum % 11 === 10) {
1131
+ return digits[12] === 1;
1132
+ }
1133
+ return digits[12] === checksum % 11;
1134
+ }
1135
+ return true;
1136
+ }
1137
+
1138
+ /*
1139
+ * sk-SK validation function
1140
+ * (Rodné číslo (RČ) or bezvýznamové identifikačné číslo (BIČ), persons only)
1141
+ * Checks validity of pre-1954 birth numbers (rodné číslo) only
1142
+ * Due to the introduction of the pseudo-random BIČ it is not possible to test
1143
+ * post-1954 birth numbers without knowing whether they are BIČ or RČ beforehand
1144
+ */
1145
+ function skSkCheck(tin) {
1146
+ if (tin.length === 9) {
1147
+ tin = tin.replace(/\W/, '');
1148
+ if (tin.slice(6) === '000') {
1149
+ return false;
1150
+ } // Three-zero serial not assigned before 1954
1151
+
1152
+ // Extract full year from TIN length
1153
+ var full_year = parseInt(tin.slice(0, 2), 10);
1154
+ if (full_year > 53) {
1155
+ return false;
1156
+ }
1157
+ if (full_year < 10) {
1158
+ full_year = "190".concat(full_year);
1159
+ } else {
1160
+ full_year = "19".concat(full_year);
1161
+ }
1162
+
1163
+ // Extract month from TIN and normalize
1164
+ var month = parseInt(tin.slice(2, 4), 10);
1165
+ if (month > 50) {
1166
+ month -= 50;
1167
+ }
1168
+ if (month < 10) {
1169
+ month = "0".concat(month);
1170
+ }
1171
+
1172
+ // Check date validity
1173
+ var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
1174
+ if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
1175
+ return false;
1176
+ }
1177
+ }
1178
+ return true;
1179
+ }
1180
+
1181
+ /*
1182
+ * sl-SI validation function
1183
+ * (Davčna številka, persons/entities)
1184
+ * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
1185
+ */
1186
+ function slSiCheck(tin) {
1187
+ var checksum = 11 - algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 7).map(function (a) {
1188
+ return parseInt(a, 10);
1189
+ }), 8) % 11;
1190
+ if (checksum === 10) {
1191
+ return parseInt(tin[7], 10) === 0;
1192
+ }
1193
+ return checksum === parseInt(tin[7], 10);
1194
+ }
1195
+
1196
+ /*
1197
+ * sv-SE validation function
1198
+ * (Personnummer or samordningsnummer, persons only)
1199
+ * Checks validity of birth date and calls luhnCheck() to validate check (last) digit
1200
+ */
1201
+ function svSeCheck(tin) {
1202
+ // Make copy of TIN and normalize to two-digit year form
1203
+ var tin_copy = tin.slice(0);
1204
+ if (tin.length > 11) {
1205
+ tin_copy = tin_copy.slice(2);
1206
+ }
1207
+
1208
+ // Extract date of birth
1209
+ var full_year = '';
1210
+ var month = tin_copy.slice(2, 4);
1211
+ var day = parseInt(tin_copy.slice(4, 6), 10);
1212
+ if (tin.length > 11) {
1213
+ full_year = tin.slice(0, 4);
1214
+ } else {
1215
+ full_year = tin.slice(0, 2);
1216
+ if (tin.length === 11 && day < 60) {
1217
+ // Extract full year from centenarian symbol
1218
+ // Should work just fine until year 10000 or so
1219
+ var current_year = new Date().getFullYear().toString();
1220
+ var current_century = parseInt(current_year.slice(0, 2), 10);
1221
+ current_year = parseInt(current_year, 10);
1222
+ if (tin[6] === '-') {
1223
+ if (parseInt("".concat(current_century).concat(full_year), 10) > current_year) {
1224
+ full_year = "".concat(current_century - 1).concat(full_year);
1225
+ } else {
1226
+ full_year = "".concat(current_century).concat(full_year);
1227
+ }
1228
+ } else {
1229
+ full_year = "".concat(current_century - 1).concat(full_year);
1230
+ if (current_year - parseInt(full_year, 10) < 100) {
1231
+ return false;
1232
+ }
1233
+ }
1234
+ }
1235
+ }
1236
+
1237
+ // Normalize day and check date validity
1238
+ if (day > 60) {
1239
+ day -= 60;
1240
+ }
1241
+ if (day < 10) {
1242
+ day = "0".concat(day);
1243
+ }
1244
+ var date = "".concat(full_year, "/").concat(month, "/").concat(day);
1245
+ if (date.length === 8) {
1246
+ if (!(0, _isDate.default)(date, 'YY/MM/DD')) {
1247
+ return false;
1248
+ }
1249
+ } else if (!(0, _isDate.default)(date, 'YYYY/MM/DD')) {
1250
+ return false;
1251
+ }
1252
+ return algorithms.luhnCheck(tin.replace(/\W/, ''));
1253
+ }
1254
+
1255
+ /**
1256
+ * uk-UA validation function
1257
+ * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
1258
+ */
1259
+ function ukUaCheck(tin) {
1260
+ // Calculate check digit
1261
+ var digits = tin.split('').map(function (a) {
1262
+ return parseInt(a, 10);
1263
+ });
1264
+ var multipliers = [-1, 5, 7, 9, 4, 6, 10, 5, 7];
1265
+ var checksum = 0;
1266
+ for (var i = 0; i < multipliers.length; i++) {
1267
+ checksum += digits[i] * multipliers[i];
1268
+ }
1269
+ return checksum % 11 === 10 ? digits[9] === 0 : digits[9] === checksum % 11;
1270
+ }
1271
+
1272
+ // Locale lookup objects
1273
+
1274
+ /*
1275
+ * Tax id regex formats for various locales
1276
+ *
1277
+ * Where not explicitly specified in DG-TAXUD document both
1278
+ * uppercase and lowercase letters are acceptable.
1279
+ */
1280
+ var taxIdFormat = {
1281
+ 'bg-BG': /^\d{10}$/,
1282
+ 'cs-CZ': /^\d{6}\/{0,1}\d{3,4}$/,
1283
+ 'de-AT': /^\d{9}$/,
1284
+ 'de-DE': /^[1-9]\d{10}$/,
1285
+ 'dk-DK': /^\d{6}-{0,1}\d{4}$/,
1286
+ 'el-CY': /^[09]\d{7}[A-Z]$/,
1287
+ 'el-GR': /^([0-4]|[7-9])\d{8}$/,
1288
+ 'en-CA': /^\d{9}$/,
1289
+ 'en-GB': /^\d{10}$|^(?!GB|NK|TN|ZZ)(?![DFIQUV])[A-Z](?![DFIQUVO])[A-Z]\d{6}[ABCD ]$/i,
1290
+ 'en-IE': /^\d{7}[A-W][A-IW]{0,1}$/i,
1291
+ 'en-US': /^\d{2}[- ]{0,1}\d{7}$/,
1292
+ 'es-AR': /(20|23|24|27|30|33|34)[0-9]{8}[0-9]/,
1293
+ 'es-ES': /^(\d{0,8}|[XYZKLM]\d{7})[A-HJ-NP-TV-Z]$/i,
1294
+ 'et-EE': /^[1-6]\d{6}(00[1-9]|0[1-9][0-9]|[1-6][0-9]{2}|70[0-9]|710)\d$/,
1295
+ 'fi-FI': /^\d{6}[-+A]\d{3}[0-9A-FHJ-NPR-Y]$/i,
1296
+ 'fr-BE': /^\d{11}$/,
1297
+ 'fr-FR': /^[0-3]\d{12}$|^[0-3]\d\s\d{2}(\s\d{3}){3}$/,
1298
+ // Conforms both to official spec and provided example
1299
+ 'fr-LU': /^\d{13}$/,
1300
+ 'hr-HR': /^\d{11}$/,
1301
+ 'hu-HU': /^8\d{9}$/,
1302
+ 'it-IT': /^[A-Z]{6}[L-NP-V0-9]{2}[A-EHLMPRST][L-NP-V0-9]{2}[A-ILMZ][L-NP-V0-9]{3}[A-Z]$/i,
1303
+ 'lv-LV': /^\d{6}-{0,1}\d{5}$/,
1304
+ // Conforms both to DG TAXUD spec and original research
1305
+ 'mt-MT': /^\d{3,7}[APMGLHBZ]$|^([1-8])\1\d{7}$/i,
1306
+ 'nl-NL': /^\d{9}$/,
1307
+ 'pl-PL': /^\d{10,11}$/,
1308
+ 'pt-BR': /(?:^\d{11}$)|(?:^\d{14}$)/,
1309
+ 'pt-PT': /^\d{9}$/,
1310
+ 'ro-RO': /^\d{13}$/,
1311
+ 'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/,
1312
+ 'sl-SI': /^[1-9]\d{7}$/,
1313
+ 'sv-SE': /^(\d{6}[-+]{0,1}\d{4}|(18|19|20)\d{6}[-+]{0,1}\d{4})$/,
1314
+ 'uk-UA': /^\d{10}$/
1315
+ };
1316
+ // taxIdFormat locale aliases
1317
+ taxIdFormat['lb-LU'] = taxIdFormat['fr-LU'];
1318
+ taxIdFormat['lt-LT'] = taxIdFormat['et-EE'];
1319
+ taxIdFormat['nl-BE'] = taxIdFormat['fr-BE'];
1320
+ taxIdFormat['fr-CA'] = taxIdFormat['en-CA'];
1321
+
1322
+ // Algorithmic tax id check functions for various locales
1323
+ var taxIdCheck = {
1324
+ 'bg-BG': bgBgCheck,
1325
+ 'cs-CZ': csCzCheck,
1326
+ 'de-AT': deAtCheck,
1327
+ 'de-DE': deDeCheck,
1328
+ 'dk-DK': dkDkCheck,
1329
+ 'el-CY': elCyCheck,
1330
+ 'el-GR': elGrCheck,
1331
+ 'en-CA': isCanadianSIN,
1332
+ 'en-IE': enIeCheck,
1333
+ 'en-US': enUsCheck,
1334
+ 'es-AR': esArCheck,
1335
+ 'es-ES': esEsCheck,
1336
+ 'et-EE': etEeCheck,
1337
+ 'fi-FI': fiFiCheck,
1338
+ 'fr-BE': frBeCheck,
1339
+ 'fr-FR': frFrCheck,
1340
+ 'fr-LU': frLuCheck,
1341
+ 'hr-HR': hrHrCheck,
1342
+ 'hu-HU': huHuCheck,
1343
+ 'it-IT': itItCheck,
1344
+ 'lv-LV': lvLvCheck,
1345
+ 'mt-MT': mtMtCheck,
1346
+ 'nl-NL': nlNlCheck,
1347
+ 'pl-PL': plPlCheck,
1348
+ 'pt-BR': ptBrCheck,
1349
+ 'pt-PT': ptPtCheck,
1350
+ 'ro-RO': roRoCheck,
1351
+ 'sk-SK': skSkCheck,
1352
+ 'sl-SI': slSiCheck,
1353
+ 'sv-SE': svSeCheck,
1354
+ 'uk-UA': ukUaCheck
1355
+ };
1356
+ // taxIdCheck locale aliases
1357
+ taxIdCheck['lb-LU'] = taxIdCheck['fr-LU'];
1358
+ taxIdCheck['lt-LT'] = taxIdCheck['et-EE'];
1359
+ taxIdCheck['nl-BE'] = taxIdCheck['fr-BE'];
1360
+ taxIdCheck['fr-CA'] = taxIdCheck['en-CA'];
1361
+
1362
+ // Regexes for locales where characters should be omitted before checking format
1363
+ var allsymbols = /[-\\\/!@#$%\^&\*\(\)\+\=\[\]]+/g;
1364
+ var sanitizeRegexes = {
1365
+ 'de-AT': allsymbols,
1366
+ 'de-DE': /[\/\\]/g,
1367
+ 'fr-BE': allsymbols
1368
+ };
1369
+ // sanitizeRegexes locale aliases
1370
+ sanitizeRegexes['nl-BE'] = sanitizeRegexes['fr-BE'];
1371
+
1372
+ /*
1373
+ * Validator function
1374
+ * Return true if the passed string is a valid tax identification number
1375
+ * for the specified locale.
1376
+ * Throw an error exception if the locale is not supported.
1377
+ */
1378
+ function isTaxID(str) {
1379
+ var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
1380
+ (0, _assertString.default)(str);
1381
+ // Copy TIN to avoid replacement if sanitized
1382
+ var strcopy = str.slice(0);
1383
+ if (locale in taxIdFormat) {
1384
+ if (locale in sanitizeRegexes) {
1385
+ strcopy = strcopy.replace(sanitizeRegexes[locale], '');
1386
+ }
1387
+ if (!taxIdFormat[locale].test(strcopy)) {
1388
+ return false;
1389
+ }
1390
+ if (locale in taxIdCheck) {
1391
+ return taxIdCheck[locale](strcopy);
1392
+ }
1393
+ // Fallthrough; not all locales have algorithmic checks
1394
+ return true;
1395
+ }
1396
+ throw new Error("Invalid locale '".concat(locale, "'"));
1397
+ }
1398
+ module.exports = exports.default;
1399
+ module.exports.default = exports.default;