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