Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsvat

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsvat - npm Package Compare versions

Comparing version 1.1.4 to 1.1.5

.editorconfig

929

dist/jsvat.js

@@ -5,41 +5,41 @@ var jsvat = (function() {

var COUNTRIES = {};
var COUNTRIES = {}
function _validateRegex(vat, regex) {
return regex.test(vat);
return regex.test(vat)
}
function _validateRules(vat, regex, countryName) {
var parsedNum = regex.exec(vat);
var vatNum = parsedNum[2];
var parsedNum = regex.exec(vat)
var vatNum = parsedNum[2]
return COUNTRIES[countryName].calcs(vatNum);
return COUNTRIES[countryName].calcs(vatNum)
}
function _validate(vat, regex, countryName) {
var result = false;
var result = false
if (_validateRegex(vat, regex)) {
result = _validateRules(vat, regex, countryName);
result = _validateRules(vat, regex, countryName)
}
return result;
return result
}
function _getPureVAT(vat) {
vat = vat || '';
return vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '');
vat = vat || ''
return vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '')
}
function _isCountryBlocked(config, countryName) {
if (!config || config.length === 0) return false;
if (!config || config.length === 0) return false
return config.indexOf(countryName) === -1;
return config.indexOf(countryName) === -1
}
function checkValidity(vat, countryName) {
var regexArr = COUNTRIES[countryName].rules.regex;
var regexArr = COUNTRIES[countryName].rules.regex
for (var i = 0; i < regexArr.length; i++) {
var isValid = _validate(vat, regexArr[i], countryName);
if (isValid) return isValid && !_isCountryBlocked(exports.config, countryName);
var isValid = _validate(vat, regexArr[i], countryName)
if (isValid) return isValid && !_isCountryBlocked(exports.config, countryName)
}
return false;
return false
}

@@ -54,14 +54,13 @@

country: null
};
}
if (!vat) return result;
if (!vat) return result
for (var countryName in COUNTRIES) {
if (COUNTRIES.hasOwnProperty(countryName)) {
result.isValid = checkValidity(result.value, countryName)
result.isValid = checkValidity(result.value, countryName);
if (result.isValid) {
result.country = countryName;
return result;
result.country = countryName
return result
}

@@ -71,25 +70,26 @@ }

return result;
return result
}
}
}
};
// eslint-disable-next-line no-undef
COUNTRIES.austria = {
calcs: function(vat) {
var total = 0;
var temp;
var total = 0
var temp
for (var i = 0; i < 7; i++) {
temp = vat.charAt(i) * this.rules.multipliers[i];
temp = vat.charAt(i) * this.rules.multipliers[i]
if (temp > 9) {
total += Math.floor(temp / 10) + temp % 10;
total += Math.floor(temp / 10) + temp % 10
} else {
total += temp;
total += temp
}
}
total = 10 - (total + 4) % 10;
if (total === 10) total = 0;
total = 10 - (total + 4) % 10
if (total === 10) total = 0
return total === +vat.slice(7, 8);
return total === +vat.slice(7, 8)
},

@@ -108,13 +108,15 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.belgium = {
calcs: function(vat) {
if (vat.length === 9) {
vat = '0' + vat;
vat = '0' + vat
}
if (+vat.slice(1, 2) === 0) return false;
if (+vat.slice(1, 2) === 0) return false
var check = (97 - +vat.slice(0, 8) % 97);
return check === +vat.slice(8, 10);
var check = (97 - +vat.slice(0, 8) % 97)
return check === +vat.slice(8, 10)
},

@@ -124,10 +126,11 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.bulgaria = (function() {
function _increase(value, vat, from, to, incr) {
for (var i = from; i < to; i++) {
value += +vat.charAt(i) * (i + incr);
value += +vat.charAt(i) * (i + incr)
}
return value;
return value
}

@@ -137,25 +140,25 @@

for (var i = from; i < to; i++) {
value += +vat.charAt(i) * multipliers[i];
value += +vat.charAt(i) * multipliers[i]
}
return value;
return value
}
function _checkNineLengthVat(vat) {
var total;
var temp = 0;
var expect = +vat.slice(8);
var total
var temp = 0
var expect = +vat.slice(8)
temp = _increase(temp, vat, 0, 8, 1);
temp = _increase(temp, vat, 0, 8, 1)
total = temp % 11;
total = temp % 11
if (total !== 10) {
return total === expect;
return total === expect
}
temp = _increase(0, vat, 0, 8, 3);
temp = _increase(0, vat, 0, 8, 3)
total = temp % 11;
if (total === 10) total = 0;
total = temp % 11
if (total === 10) total = 0
return total === expect;
return total === expect
}

@@ -167,16 +170,14 @@

// Check month
var month = +vat.slice(2, 4);
var month = +vat.slice(2, 4)
if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
var total = _increase2(0, vat, 0, 9, rules.multipliers.physical);
var total = _increase2(0, vat, 0, 9, rules.multipliers.physical)
// Establish check digit.
total = total % 11;
if (total === 10) total = 0;
total = total % 11
if (total === 10) total = 0
// Check to see if the check digit given is correct, If not, try next type of person
if (total === +vat.substr(9, 1)) return true;
if (total === +vat.substr(9, 1)) return true
}
}
return false;
return false
}

@@ -186,7 +187,7 @@

// Extract the next digit and multiply by the counter.
var total = _increase2(0, vat, 0, 9, rules.multipliers.foreigner);
var total = _increase2(0, vat, 0, 9, rules.multipliers.foreigner)
// Check to see if the check digit given is correct, If not, try next type of person
if (total % 10 === +vat.substr(9, 1)) {
return true;
return true
}

@@ -197,12 +198,12 @@ }

// Finally, if not yet identified, see if it conforms to a miscellaneous VAT number
var total = _increase2(0, vat, 0, 9, rules.multipliers.miscellaneous);
var total = _increase2(0, vat, 0, 9, rules.multipliers.miscellaneous)
// Establish check digit.
total = 11 - total % 11;
if (total === 10) return false;
if (total === 11) total = 0;
total = 11 - total % 11
if (total === 10) return false
if (total === 11) total = 0
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
var expect = +vat.substr(9, 1);
return total === expect;
var expect = +vat.substr(9, 1)
return total === expect
}

@@ -213,7 +214,6 @@

if (vat.length === 9) {
return _checkNineLengthVat(vat);
return _checkNineLengthVat(vat)
} else {
return _isPhysicalPerson(vat, this.rules) || _isForeigner(vat, this.rules) || _miscellaneousVAT(vat, this.rules);
return _isPhysicalPerson(vat, this.rules) || _isForeigner(vat, this.rules) || _miscellaneousVAT(vat, this.rules)
}
},

@@ -258,27 +258,28 @@ rules: {

}
};
})();
}
})()
// eslint-disable-next-line no-undef
COUNTRIES.croatia = {
calcs: function(vat) {
var expect;
var expect
// Checks the check digits of a Croatian VAT number using ISO 7064, MOD 11-10 for check digit.
var product = 10;
var sum = 0;
var product = 10
var sum = 0
for (var i = 0; i < 10; i++) {
// Extract the next digit and implement the algorithm
sum = (+vat.charAt(i) + product) % 10;
sum = (+vat.charAt(i) + product) % 10
if (sum === 0) {
sum = 10;
sum = 10
}
product = (2 * sum) % 11;
product = (2 * sum) % 11
}
// Now check that we have the right check digit
expect = +vat.slice(10, 11);
return (product + expect) % 10 === 1;
expect = +vat.slice(10, 11)
return (product + expect) % 10 === 1
},

@@ -288,10 +289,12 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.cyprus = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// Not allowed to start with '12'
if (+vat.slice(0, 2) === 12) return false;
if (+vat.slice(0, 2) === 12) return false

@@ -301,34 +304,34 @@ // Extract the next digit and multiply by the counter.

for (var i = 0; i < 8; i++) {
var temp = +vat.charAt(i);
var temp = +vat.charAt(i)
if (i % 2 === 0) {
switch (temp) {
case 0:
temp = 1;
break;
temp = 1
break
case 1:
temp = 0;
break;
temp = 0
break
case 2:
temp = 5;
break;
temp = 5
break
case 3:
temp = 7;
break;
temp = 7
break
case 4:
temp = 9;
break;
temp = 9
break
default:
temp = temp * 2 + 3;
temp = temp * 2 + 3
}
}
total += temp;
total += temp
}
// Establish check digit using modulus 26, and translate to char. equivalent.
total = total % 26;
total = String.fromCharCode(total + 65);
total = total % 26
total = String.fromCharCode(total + 65)
// Check to see if the check digit given is correct
expect = vat.substr(8, 1);
return total === expect;
expect = vat.substr(8, 1)
return total === expect
},

@@ -338,7 +341,8 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.czech_republic = (function() {
function _isLegalEntities(vat, rules) {
var total = 0;
var total = 0

@@ -348,39 +352,38 @@ if (rules.additional[0].test(vat)) {

for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * rules.multipliers[i];
total += +vat.charAt(i) * rules.multipliers[i]
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) total = 0;
if (total === 11) total = 1;
total = 11 - total % 11
if (total === 10) total = 0
if (total === 11) total = 1
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
var expect = +vat.slice(7, 8);
return total === expect;
var expect = +vat.slice(7, 8)
return total === expect
}
return false;
return false
}
function _isIndividualType2(vat, rules) {
var total = 0;
var total = 0
if (rules.additional[2].test(vat)) {
// Extract the next digit and multiply by the counter.
for (var j = 0; j < 7; j++) {
total += +vat.charAt(j + 1) * rules.multipliers[j];
total += +vat.charAt(j + 1) * rules.multipliers[j]
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) total = 0;
if (total === 11) total = 1;
total = 11 - total % 11
if (total === 10) total = 0
if (total === 11) total = 1
// Convert calculated check digit according to a lookup table;
var expect = +vat.slice(8, 9);
return rules.lookup[total - 1] === expect;
// Convert calculated check digit according to a lookup table
var expect = +vat.slice(8, 9)
return rules.lookup[total - 1] === expect
}
return false;
return false
}

@@ -390,8 +393,8 @@

if (rules.additional[3].test(vat)) {
var temp = +vat.slice(0, 2) + vat.slice(2, 4) + vat.slice(4, 6) + vat.slice(6, 8) + vat.slice(8);
var expect = +vat % 11 === 0;
return !!(temp % 11 === 0 && expect);
var temp = +vat.slice(0, 2) + vat.slice(2, 4) + vat.slice(4, 6) + vat.slice(6, 8) + vat.slice(8)
var expect = +vat % 11 === 0
return !!(temp % 11 === 0 && expect)
}
return false;
return false
}

@@ -401,8 +404,7 @@

calcs: function(vat) {
if (_isLegalEntities(vat, this.rules)) return true
if (_isIndividualType2(vat, this.rules)) return true
if (_isIndividualType3(vat, this.rules)) return true
if (_isLegalEntities(vat, this.rules)) return true;
if (_isIndividualType2(vat, this.rules)) return true;
if (_isIndividualType3(vat, this.rules)) return true;
return false;
return false
},

@@ -440,13 +442,15 @@ rules: {

}
};
}());
}
}())
// eslint-disable-next-line no-undef
COUNTRIES.denmark = {
calcs: function(vat) {
var total = 0;
var total = 0
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
return total % 11 === 0;
return total % 11 === 0
},

@@ -466,20 +470,22 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.estonia = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits using modulus 10.
total = 10 - total % 10;
if (total === 10) total = 0;
total = 10 - total % 10
if (total === 10) total = 0
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
expect = +vat.slice(8, 9)
return total === expect
},

@@ -499,3 +505,5 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.europe = {

@@ -505,3 +513,3 @@ calcs: function() {

// country, and that there are nine digits in total.
return true;
return true
},

@@ -511,20 +519,22 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.finland = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * this.rules.multipliers[i];
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * this.rules.multipliers[i]
// Establish check digit.
total = 11 - total % 11;
total = 11 - total % 11
if (total > 9) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
expect = +vat.slice(7, 8)
return total === expect
},

@@ -543,22 +553,24 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.france = {
calcs: function(vat) {
var total;
var expect;
var total
var expect
// Checks the check digits of a French VAT number.
if (!(/^\d{11}$/).test(vat)) {
return true;
return true
}
// Extract the last nine digits as an integer.
total = +vat.substring(2);
total = +vat.substring(2)
// Establish check digit.
total = (total * 100 + 12) % 97;
total = (total * 100 + 12) % 97
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(0, 2);
return total === expect;
expect = +vat.slice(0, 2)
return total === expect
},

@@ -573,19 +585,20 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.germany = {
calcs: function(vat) {
// Checks the check digits of a German VAT number.
var product = 10;
var sum = 0;
var checkDigit = 0;
var expect;
var product = 10
var sum = 0
var checkDigit = 0
var expect
for (var i = 0; i < 8; i++) {
// Extract the next digit and implement peculiar algorithm!.
sum = (+vat.charAt(i) + product) % 10;
sum = (+vat.charAt(i) + product) % 10
if (sum === 0) {
sum = 10;
sum = 10
}
product = (2 * sum) % 11;
product = (2 * sum) % 11
}

@@ -595,5 +608,5 @@

if (11 - product === 10) {
checkDigit = 0;
checkDigit = 0
} else {
checkDigit = 11 - product;
checkDigit = 11 - product
}

@@ -603,4 +616,4 @@

// check digit.
expect = +vat.slice(8, 9);
return checkDigit === expect;
expect = +vat.slice(8, 9)
return checkDigit === expect
},

@@ -610,11 +623,13 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.greece = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
//eight character numbers should be prefixed with an 0.
// eight character numbers should be prefixed with an 0.
if (vat.length === 8) {
vat = '0' + vat;
vat = '0' + vat
}

@@ -624,14 +639,14 @@

for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digit.
total = total % 11;
total = total % 11
if (total > 9) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
expect = +vat.slice(8, 9)
return total === expect
},

@@ -651,20 +666,22 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.hungary = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digit.
total = 10 - total % 10;
if (total === 10) total = 0;
total = 10 - total % 10
if (total === 10) total = 0
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
expect = +vat.slice(7, 8)
return total === expect
},

@@ -683,11 +700,13 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.ireland = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// If the code is type 1 format, we need to convert it to the new before performing the validation.
if (this.rules.typeFormats.first.test(vat)) {
vat = '0' + vat.substring(2, 7) + vat.substring(0, 1) + vat.substring(7, 8);
vat = '0' + vat.substring(2, 7) + vat.substring(0, 1) + vat.substring(7, 8)
}

@@ -697,3 +716,3 @@

for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}

@@ -705,5 +724,5 @@

if (vat.charAt(8) === 'H') {
total += 72;
total += 72
} else {
total += 9;
total += 9
}

@@ -713,12 +732,12 @@ }

// Establish check digit using modulus 23, and translate to char. equivalent.
total = total % 23;
total = total % 23
if (total === 0) {
total = 'W';
total = 'W'
} else {
total = String.fromCharCode(total + 64);
total = String.fromCharCode(total + 64)
}
// Compare it with the eighth character of the VAT number. If it's the same, then it's valid.
expect = vat.slice(7, 8);
return total === expect;
expect = vat.slice(7, 8)
return total === expect
},

@@ -736,3 +755,3 @@ rules: {

typeFormats: {
first: /^\d[A-Z\*\+]/,
first: /^\d[A-Z*+]/,
third: /^\d{7}[A-Z][AH]$/

@@ -742,21 +761,23 @@ },

/^(IE)(\d{7}[A-W])$/,
/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/,
/^(IE)([7-9][A-Z*+)]\d{5}[A-W])$/,
/^(IE)(\d{7}[A-W][AH])$/
]
}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.italy = {
calcs: function(vat) {
var total = 0;
var temp;
var expect;
var total = 0
var temp
var expect
// The last three digits are the issuing office, and cannot exceed more 201, unless 999 or 888
if (+vat.slice(0, 7) === 0) {
return false;
return false
}
temp = +vat.slice(7, 10);
temp = +vat.slice(7, 10)
if ((temp < 1) || (temp > 201) && temp !== 999 && temp !== 888) {
return false;
return false
}

@@ -766,18 +787,18 @@

for (var i = 0; i < 10; i++) {
temp = +vat.charAt(i) * this.rules.multipliers[i];
temp = +vat.charAt(i) * this.rules.multipliers[i]
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
total += Math.floor(temp / 10) + temp % 10
else
total += temp;
total += temp
}
// Establish check digit.
total = 10 - total % 10;
total = 10 - total % 10
if (total > 9) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(10, 11);
return total === expect;
expect = +vat.slice(10, 11)
return total === expect
},

@@ -799,7 +820,9 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.latvia = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect

@@ -809,24 +832,23 @@ // Differentiate between legal entities and natural bodies. For the latter we simply check that

if ((/^[0-3]/).test(vat)) {
return !!(/^[0-3][0-9][0-1][0-9]/).test(vat);
return !!(/^[0-3][0-9][0-1][0-9]/).test(vat)
} else {
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 10; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits by getting modulus 11.
if (total % 11 === 4 && vat[0] === 9) total = total - 45;
if (total % 11 === 4 && vat[0] === 9) total = total - 45
if (total % 11 === 4) {
total = 4 - total % 11;
total = 4 - total % 11
} else if (total % 11 > 4) {
total = 14 - total % 11;
total = 14 - total % 11
} else if (total % 11 < 4) {
total = 3 - total % 11;
total = 3 - total % 11
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(10, 11);
return total === expect;
expect = +vat.slice(10, 11)
return total === expect
}

@@ -849,19 +871,19 @@ },

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.lithunia = (function() {
function _extractDigit(vat, multiplier, key) {
return +vat.charAt(key) * multiplier[key];
return +vat.charAt(key) * multiplier[key]
}
function _doubleCheckCalculation(vat, total, rules) {
if (total % 11 === 10) {
total = 0;
total = 0
for (var i = 0; i < 8; i++) {
total += _extractDigit(vat, rules.multipliers.short, i);
total += _extractDigit(vat, rules.multipliers.short, i)
}
}
return total;
return total
}

@@ -871,14 +893,14 @@

for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * (i + 1);
total += +vat.charAt(i) * (i + 1)
}
return total;
return total
}
function checkDigit(total) {
total = total % 11;
total = total % 11
if (total === 10) {
total = 0;
total = 0
}
return total;
return total
}

@@ -888,22 +910,21 @@

// 9 character VAT numbers are for legal persons
var total = 0;
var total = 0
if (vat.length === 9) {
// 8th character must be one
if (!(/^\d{7}1/).test(vat)) return false;
if (!(/^\d{7}1/).test(vat)) return false
// Extract the next digit and multiply by the counter+1.
total = extractDigit(vat, total);
total = extractDigit(vat, total)
// Can have a double check digit calculation!
total = _doubleCheckCalculation(vat, total, rules);
total = _doubleCheckCalculation(vat, total, rules)
// Establish check digit.
total = checkDigit(total);
total = checkDigit(total)
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
var expect = +vat.slice(8, 9);
return total === expect;
var expect = +vat.slice(8, 9)
return total === expect
}
return false;
return false
}

@@ -913,5 +934,5 @@

for (var k = 0; k < 11; k++) {
total += _extractDigit(vat, rules.multipliers.med, k);
total += _extractDigit(vat, rules.multipliers.med, k)
}
return total;
return total
}

@@ -921,35 +942,34 @@

if (total % 11 === 10) {
total = 0;
total = 0
for (var l = 0; l < 11; l++) {
total += _extractDigit(vat, rules.multipliers.alt, l);
total += _extractDigit(vat, rules.multipliers.alt, l)
}
}
return total;
return total
}
function _check12DigitVat(vat, rules) {
var total = 0;
var total = 0
// 12 character VAT numbers are for temporarily registered taxpayers
if (vat.length === 12) {
// 11th character must be one
if (!(rules.check).test(vat)) return false;
if (!(rules.check).test(vat)) return false
// Extract the next digit and multiply by the counter+1.
total = extractDigit12(vat, total, rules);
total = extractDigit12(vat, total, rules)
// Can have a double check digit calculation!
total = _doubleCheckCalculation12(vat, total, rules);
total = _doubleCheckCalculation12(vat, total, rules)
// Establish check digit.
total = checkDigit(total);
total = checkDigit(total)
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
var expect = +vat.slice(11, 12);
return total === expect;
var expect = +vat.slice(11, 12)
return total === expect
}
return false;
return false
}

@@ -959,3 +979,3 @@

calcs: function(vat) {
return _check9DigitVat(vat, this.rules) || _check12DigitVat(vat, this.rules);
return _check9DigitVat(vat, this.rules) || _check12DigitVat(vat, this.rules)
},

@@ -1004,11 +1024,13 @@ rules: {

}
};
}());
}
}())
// eslint-disable-next-line no-undef
COUNTRIES.luxembourg = {
calcs: function(vat) {
var expect = +vat.slice(6, 8);
var checkDigit = +vat.slice(0, 6) % 89;
var expect = +vat.slice(6, 8)
var checkDigit = +vat.slice(0, 6) % 89
// Checks the check digits of a Luxembourg VAT number.
return checkDigit === expect;
return checkDigit === expect
},

@@ -1018,19 +1040,21 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.malta = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 6; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits by getting modulus 37.
total = 37 - total % 37;
total = 37 - total % 37
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(6, 8);
return total === expect;
expect = +vat.slice(6, 8)
return total === expect
},

@@ -1048,22 +1072,24 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.netherlands = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits by getting modulus 11.
total = total % 11;
total = total % 11
if (total > 9) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
expect = +vat.slice(8, 9)
return total === expect
},

@@ -1083,7 +1109,9 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.norway = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// See http://www.brreg.no/english/coordination/number.html

@@ -1093,10 +1121,10 @@

for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits by getting modulus 11. Check digits > 9 are invalid
total = 11 - total % 11;
total = 11 - total % 11
if (total === 11) {
total = 0;
total = 0
}

@@ -1106,4 +1134,4 @@

// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
expect = +vat.slice(8, 9)
return total === expect
}

@@ -1124,22 +1152,24 @@ },

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.poland = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 9; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits subtracting modulus 11 from 11.
total = total % 11;
total = total % 11
if (total > 9) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(9, 10);
return total === expect;
expect = +vat.slice(9, 10)
return total === expect
},

@@ -1160,22 +1190,24 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.portugal = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits subtracting modulus 11 from 11.
total = 11 - total % 11;
total = 11 - total % 11
if (total > 9) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
expect = +vat.slice(8, 9)
return total === expect
},

@@ -1195,23 +1227,25 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.romania = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
var vatLength = vat.length;
var multipliers = this.rules.multipliers.slice(10 - vatLength);
var vatLength = vat.length
var multipliers = this.rules.multipliers.slice(10 - vatLength)
for (var i = 0; i < vat.length - 1; i++) {
total += +vat.charAt(i) * multipliers[i];
total += +vat.charAt(i) * multipliers[i]
}
// Establish check digits by getting modulus 11.
total = (10 * total) % 11;
if (total === 10) total = 0;
total = (10 * total) % 11
if (total === 10) total = 0
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(vat.length - 1, vat.length);
return total === expect;
expect = +vat.slice(vat.length - 1, vat.length)
return total === expect
},

@@ -1232,50 +1266,49 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.russia = (function() {
function _check10DigitINN(vat, rules) {
var total = 0;
var total = 0
if (vat.length === 10) {
for (var i = 0; i < 10; i++) {
total += +vat.charAt(i) * rules.multipliers.m_1[i];
total += +vat.charAt(i) * rules.multipliers.m_1[i]
}
total = total % 11;
total = total % 11
if (total > 9) {
total = total % 10;
total = total % 10
}
// Compare it with the last character of the VAT number. If it is the same, then it's valid
var expect = +vat.slice(9, 10);
return total === expect;
var expect = +vat.slice(9, 10)
return total === expect
}
return false;
return false
}
function _check12DigitINN(vat, rules) {
var total1 = 0;
var total2 = 0;
var total1 = 0
var total2 = 0
if (vat.length === 12) {
for (var j = 0; j < 11; j++) {
total1 += +vat.charAt(j) * rules.multipliers.m_2[j];
total1 += +vat.charAt(j) * rules.multipliers.m_2[j]
}
total1 = total1 % 11;
total1 = total1 % 11
if (total1 > 9) {
total1 = total1 % 10;
total1 = total1 % 10
}
for (var k = 0; k < 11; k++) {
total2 += +vat.charAt(k) * rules.multipliers.m_3[k];
total2 += +vat.charAt(k) * rules.multipliers.m_3[k]
}
total2 = total2 % 11;
total2 = total2 % 11
if (total2 > 9) {
total2 = total2 % 10;
total2 = total2 % 10
}

@@ -1285,15 +1318,14 @@

// character of the VAT number. If they're both the same, then it's valid
var expect = (total1 === +vat.slice(10, 11));
var expect2 = (total2 === +vat.slice(11, 12));
return (expect) && (expect2);
var expect = (total1 === +vat.slice(10, 11))
var expect2 = (total2 === +vat.slice(11, 12))
return (expect) && (expect2)
}
return false;
return false
}
return {
calcs: function(vat) {
// See http://russianpartner.biz/test_inn.html for algorithm
return _check10DigitINN(vat, this.rules) || _check12DigitINN(vat, this.rules);
return _check10DigitINN(vat, this.rules) || _check12DigitINN(vat, this.rules)
},

@@ -1344,4 +1376,6 @@ rules: {

}
};
}());
}
}())
// eslint-disable-next-line no-undef
COUNTRIES.serbia = {

@@ -1351,20 +1385,19 @@ calcs: function(vat) {

var product = 10;
var sum = 0;
var checkDigit;
var product = 10
var sum = 0
var checkDigit
for (var i = 0; i < 8; i++) {
// Extract the next digit and implement the algorithm
sum = (+vat.charAt(i) + product) % 10;
sum = (+vat.charAt(i) + product) % 10
if (sum === 0) {
sum = 10;
sum = 10
}
product = (2 * sum) % 11;
product = (2 * sum) % 11
}
// Now check that we have the right check digit
var expect = 1;
checkDigit = (product + (+vat.slice(8, 9))) % 10;
return checkDigit === expect;
var expect = 1
checkDigit = (product + (+vat.slice(8, 9))) % 10
return checkDigit === expect
},

@@ -1374,8 +1407,10 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.slovakia_republic = {
calcs: function(vat) {
var expect = 0;
var checkDigit = (vat % 11);
return checkDigit === expect;
var expect = 0
var checkDigit = (vat % 11)
return checkDigit === expect
},

@@ -1385,17 +1420,19 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.slovenia = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits using modulus 11
total = 11 - total % 11;
total = 11 - total % 11
if (total === 10) {
total = 0;
total = 0
}

@@ -1405,4 +1442,4 @@

// same, then it's a valid check digit.
expect = +vat.slice(7, 8);
return !!(total !== 11 && total === expect);
expect = +vat.slice(7, 8)
return !!(total !== 11 && total === expect)
},

@@ -1421,30 +1458,31 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.spain = {
calcs: function(vat) {
var i = 0;
var total = 0;
var temp;
var expect;
var i = 0
var total = 0
var temp
var expect
// National juridical entities
if (this.rules.additional[0].test(vat)) {
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = vat.charAt(i + 1) * this.rules.multipliers[i];
temp = vat.charAt(i + 1) * this.rules.multipliers[i]
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
total += Math.floor(temp / 10) + temp % 10
else
total += temp;
total += temp
}
// Now calculate the check digit itself.
total = 10 - total % 10;
total = 10 - total % 10
if (total === 10) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
expect = +vat.slice(8, 9)
return total === expect
}

@@ -1454,19 +1492,18 @@

else if (this.rules.additional[1].test(vat)) {
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = vat.charAt(i + 1) * this.rules.multipliers[i];
temp = vat.charAt(i + 1) * this.rules.multipliers[i]
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
total += Math.floor(temp / 10) + temp % 10
else
total += temp;
total += temp
}
// Now calculate the check digit itself.
total = 10 - total % 10;
total = String.fromCharCode(total + 64);
total = 10 - total % 10
total = String.fromCharCode(total + 64)
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = vat.slice(8, 9);
return total === expect;
expect = vat.slice(8, 9)
return total === expect
}

@@ -1476,7 +1513,7 @@

else if (this.rules.additional[2].test(vat)) {
var tempnumber = vat;
if (tempnumber.substring(0, 1) === 'Y') tempnumber = tempnumber.replace(/Y/, '1');
if (tempnumber.substring(0, 1) === 'Z') tempnumber = tempnumber.replace(/Z/, '2');
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+tempnumber.substring(0, 8) % 23);
return tempnumber.charAt(8) === expect;
var tempnumber = vat
if (tempnumber.substring(0, 1) === 'Y') tempnumber = tempnumber.replace(/Y/, '1')
if (tempnumber.substring(0, 1) === 'Z') tempnumber = tempnumber.replace(/Z/, '2')
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+tempnumber.substring(0, 8) % 23)
return tempnumber.charAt(8) === expect
}

@@ -1486,5 +1523,5 @@

else if (this.rules.additional[3].test(vat)) {
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+vat.substring(1, 8) % 23);
return vat.charAt(8) === expect;
} else return false;
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+vat.substring(1, 8) % 23)
return vat.charAt(8) === expect
} else return false
},

@@ -1514,27 +1551,29 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.sweden = {
calcs: function(vat) {
var expect;
var expect
// Calculate R where R = R1 + R3 + R5 + R7 + R9, and Ri = INT(Ci/5) + (Ci*2) modulo 10
var R = 0;
var digit;
var R = 0
var digit
for (var i = 0; i < 9; i = i + 2) {
digit = +vat.charAt(i);
R += Math.floor(digit / 5) + ((digit * 2) % 10);
digit = +vat.charAt(i)
R += Math.floor(digit / 5) + ((digit * 2) % 10)
}
// Calculate S where S = C2 + C4 + C6 + C8
var S = 0;
var S = 0
for (var j = 1; j < 9; j = j + 2) {
S += +vat.charAt(j);
S += +vat.charAt(j)
}
var checkDigit = (10 - (R + S) % 10) % 10;
var checkDigit = (10 - (R + S) % 10) % 10
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(9, 10);
expect = +vat.slice(9, 10)
return checkDigit === expect;
return checkDigit === expect
},

@@ -1544,18 +1583,20 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.switzerland = {
calcs: function(vat) {
var total = 0;
var total = 0
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) return false;
if (total === 11) total = 0;
total = 11 - total % 11
if (total === 10) return false
if (total === 11) total = 0
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
var expect = +vat.substr(8, 1);
return total === expect;
var expect = +vat.substr(8, 1)
return total === expect
},

@@ -1575,12 +1616,14 @@ rules: {

}
};
}
// eslint-disable-next-line no-undef
COUNTRIES.united_kingdom = {
calcs: function(vat) {
var total = 0;
var expect;
var total = 0
var expect
// Government departments
if (vat.substr(0, 2) === 'GD') {
expect = 500;
return vat.substr(2, 3) < expect;
expect = 500
return vat.substr(2, 3) < expect
}

@@ -1590,4 +1633,4 @@

if (vat.substr(0, 2) === 'HA') {
expect = 499;
return vat.substr(2, 3) > expect;
expect = 499
return vat.substr(2, 3) > expect
}

@@ -1597,12 +1640,11 @@

// 0 VAT numbers disallowed!
if (+vat.slice(0) === 0) return false;
if (+vat.slice(0) === 0) return false
// Check range is OK for modulus 97 calculation
var no = +vat.slice(0, 7);
var no = +vat.slice(0, 7)
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}

@@ -1614,5 +1656,5 @@

// Establish check digits by subtracting 97 from total until negative.
var checkDigit = total;
var checkDigit = total
while (checkDigit > 0) {
checkDigit = checkDigit - 97;
checkDigit = checkDigit - 97
}

@@ -1623,12 +1665,12 @@

// certain specified ranges.
checkDigit = Math.abs(checkDigit);
if (checkDigit === +vat.slice(7, 9) && no < 9990001 && (no < 100000 || no > 999999) && (no < 9490001 || no > 9700000)) return true;
checkDigit = Math.abs(checkDigit)
if (checkDigit === +vat.slice(7, 9) && no < 9990001 && (no < 100000 || no > 999999) && (no < 9490001 || no > 9700000)) return true
// Now try the new method by subtracting 55 from the check digit if we can - else add 42
if (checkDigit >= 55)
checkDigit = checkDigit - 55;
checkDigit = checkDigit - 55
else
checkDigit = checkDigit + 42;
expect = +vat.slice(7, 9);
return !!(checkDigit === expect && no > 1000000);
checkDigit = checkDigit + 42
expect = +vat.slice(7, 9)
return !!(checkDigit === expect && no > 1000000)
},

@@ -1652,4 +1694,5 @@ rules: {

}
};
}
//Support of node.js

@@ -1656,0 +1699,0 @@

@@ -1,2 +0,2 @@

var jsvat=function(){"use strict";function r(r,e){return e.test(r)}function e(r,e,t){var i=e.exec(r),s=i[2];return u[t].calcs(s)}function t(t,i,s){var l=!1;return r(t,i)&&(l=e(t,i,s)),l}function i(r){return r=r||"",r.toString().toUpperCase().replace(/(\s|-|\.)+/g,"")}function s(r,e){return!(!r||0===r.length)&&r.indexOf(e)===-1}function l(r,e){for(var i=u[e].rules.regex,l=0;l<i.length;l++){var c=t(r,i[l],e);if(c)return c&&!s(n.config,e)}return!1}var u={},n={config:[],checkVAT:function(r){var e={value:i(r),isValid:!1,country:null};if(!r)return e;for(var t in u)if(u.hasOwnProperty(t)&&(e.isValid=l(e.value,t),e.isValid))return e.country=t,e;return e}};return u.austria={calcs:function(r){for(var e,t=0,i=0;i<7;i++)e=r.charAt(i)*this.rules.multipliers[i],t+=e>9?Math.floor(e/10)+e%10:e;return t=10-(t+4)%10,10===t&&(t=0),t===+r.slice(7,8)},rules:{multipliers:[1,2,1,2,1,2,1],regex:[/^(AT)U(\d{8})$/]}},u.belgium={calcs:function(r){if(9===r.length&&(r="0"+r),0===+r.slice(1,2))return!1;var e=97-+r.slice(0,8)%97;return e===+r.slice(8,10)},rules:{regex:[/^(BE)(0?\d{9})$/]}},u.bulgaria=function(){function r(r,e,t,i,s){for(var l=t;l<i;l++)r+=+e.charAt(l)*(l+s);return r}function e(r,e,t,i,s){for(var l=t;l<i;l++)r+=+e.charAt(l)*s[l];return r}function t(e){var t,i=0,s=+e.slice(8);return i=r(i,e,0,8,1),t=i%11,10!==t?t===s:(i=r(0,e,0,8,3),t=i%11,10===t&&(t=0),t===s)}function i(r,t){if(/^\d\d[0-5]\d[0-3]\d\d{4}$/.test(r)){var i=+r.slice(2,4);if(i>0&&i<13||i>20&&i<33||i>40&&i<53){var s=e(0,r,0,9,t.multipliers.physical);if(s%=11,10===s&&(s=0),s===+r.substr(9,1))return!0}}return!1}function s(r,t){var i=e(0,r,0,9,t.multipliers.foreigner);if(i%10===+r.substr(9,1))return!0}function l(r,t){var i=e(0,r,0,9,t.multipliers.miscellaneous);if(i=11-i%11,10===i)return!1;11===i&&(i=0);var s=+r.substr(9,1);return i===s}return{calcs:function(r){return 9===r.length?t(r):i(r,this.rules)||s(r,this.rules)||l(r,this.rules)},rules:{multipliers:{physical:[2,4,8,5,10,9,7,3,6],foreigner:[21,19,17,13,11,9,7,3,1],miscellaneous:[4,3,2,7,6,5,4,3,2]},regex:[/^(BG)(\d{9,10})$/]}}}(),u.croatia={calcs:function(r){for(var e,t=10,i=0,s=0;s<10;s++)i=(+r.charAt(s)+t)%10,0===i&&(i=10),t=2*i%11;return e=+r.slice(10,11),(t+e)%10===1},rules:{regex:[/^(HR)(\d{11})$/]}},u.cyprus={calcs:function(r){var e,t=0;if(12===+r.slice(0,2))return!1;for(var i=0;i<8;i++){var s=+r.charAt(i);if(i%2===0)switch(s){case 0:s=1;break;case 1:s=0;break;case 2:s=5;break;case 3:s=7;break;case 4:s=9;break;default:s=2*s+3}t+=s}return t%=26,t=String.fromCharCode(t+65),e=r.substr(8,1),t===e},rules:{regex:[/^(CY)([0-59]\d{7}[A-Z])$/]}},u.czech_republic=function(){function r(r,e){var t=0;if(e.additional[0].test(r)){for(var i=0;i<7;i++)t+=+r.charAt(i)*e.multipliers[i];t=11-t%11,10===t&&(t=0),11===t&&(t=1);var s=+r.slice(7,8);return t===s}return!1}function e(r,e){var t=0;if(e.additional[2].test(r)){for(var i=0;i<7;i++)t+=+r.charAt(i+1)*e.multipliers[i];t=11-t%11,10===t&&(t=0),11===t&&(t=1);var s=+r.slice(8,9);return e.lookup[t-1]===s}return!1}function t(r,e){if(e.additional[3].test(r)){var t=+r.slice(0,2)+r.slice(2,4)+r.slice(4,6)+r.slice(6,8)+r.slice(8),i=+r%11===0;return!(t%11!==0||!i)}return!1}return{calcs:function(i){return!!r(i,this.rules)||(!!e(i,this.rules)||!!t(i,this.rules))},rules:{multipliers:[8,7,6,5,4,3,2],lookup:[8,7,6,5,4,3,2,1,0,9,10],regex:[/^(CZ)(\d{8,10})(\d{3})?$/],additional:[/^\d{8}$/,/^[0-5][0-9][0|1|5|6]\d[0-3]\d\d{3}$/,/^6\d{8}$/,/^\d{2}[0-3|5-8]\d[0-3]\d\d{4}$/]}}}(),u.denmark={calcs:function(r){for(var e=0,t=0;t<8;t++)e+=+r.charAt(t)*this.rules.multipliers[t];return e%11===0},rules:{multipliers:[2,7,6,5,4,3,2,1],regex:[/^(DK)(\d{8})$/]}},u.estonia={calcs:function(r){for(var e,t=0,i=0;i<8;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=10-t%10,10===t&&(t=0),e=+r.slice(8,9),t===e},rules:{multipliers:[3,7,1,3,7,1,3,7],regex:[/^(EE)(10\d{7})$/]}},u.europe={calcs:function(){return!0},rules:{regex:[/^(EU)(\d{9})$/]}},u.finland={calcs:function(r){for(var e,t=0,i=0;i<7;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=11-t%11,t>9&&(t=0),e=+r.slice(7,8),t===e},rules:{multipliers:[7,9,10,5,8,4,2],regex:[/^(FI)(\d{8})$/]}},u.france={calcs:function(r){var e,t;return!/^\d{11}$/.test(r)||(e=+r.substring(2),e=(100*e+12)%97,t=+r.slice(0,2),e===t)},rules:{regex:[/^(FR)(\d{11})$/,/^(FR)([A-HJ-NP-Z]\d{10})$/,/^(FR)(\d[A-HJ-NP-Z]\d{9})$/,/^(FR)([A-HJ-NP-Z]{2}\d{9})$/]}},u.germany={calcs:function(r){for(var e,t=10,i=0,s=0,l=0;l<8;l++)i=(+r.charAt(l)+t)%10,0===i&&(i=10),t=2*i%11;return s=11-t===10?0:11-t,e=+r.slice(8,9),s===e},rules:{regex:[/^(DE)([1-9]\d{8})$/]}},u.greece={calcs:function(r){var e,t=0;8===r.length&&(r="0"+r);for(var i=0;i<8;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t%=11,t>9&&(t=0),e=+r.slice(8,9),t===e},rules:{multipliers:[256,128,64,32,16,8,4,2],regex:[/^(EL)(\d{9})$/]}},u.hungary={calcs:function(r){for(var e,t=0,i=0;i<7;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=10-t%10,10===t&&(t=0),e=+r.slice(7,8),t===e},rules:{multipliers:[9,7,3,1,9,7,3],regex:[/^(HU)(\d{8})$/]}},u.ireland={calcs:function(r){var e,t=0;this.rules.typeFormats.first.test(r)&&(r="0"+r.substring(2,7)+r.substring(0,1)+r.substring(7,8));for(var i=0;i<7;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return this.rules.typeFormats.third.test(r)&&(t+="H"===r.charAt(8)?72:9),t%=23,t=0===t?"W":String.fromCharCode(t+64),e=r.slice(7,8),t===e},rules:{multipliers:[8,7,6,5,4,3,2],typeFormats:{first:/^\d[A-Z\*\+]/,third:/^\d{7}[A-Z][AH]$/},regex:[/^(IE)(\d{7}[A-W])$/,/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/,/^(IE)(\d{7}[A-W][AH])$/]}},u.italy={calcs:function(r){var e,t,i=0;if(0===+r.slice(0,7))return!1;if(e=+r.slice(7,10),e<1||e>201&&999!==e&&888!==e)return!1;for(var s=0;s<10;s++)e=+r.charAt(s)*this.rules.multipliers[s],i+=e>9?Math.floor(e/10)+e%10:e;return i=10-i%10,i>9&&(i=0),t=+r.slice(10,11),i===t},rules:{multipliers:[1,2,1,2,1,2,1,2,1,2],regex:[/^(IT)(\d{11})$/]}},u.latvia={calcs:function(r){var e,t=0;if(/^[0-3]/.test(r))return!!/^[0-3][0-9][0-1][0-9]/.test(r);for(var i=0;i<10;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t%11===4&&9===r[0]&&(t-=45),t%11===4?t=4-t%11:t%11>4?t=14-t%11:t%11<4&&(t=3-t%11),e=+r.slice(10,11),t===e},rules:{multipliers:[9,1,4,8,3,10,2,5,7,6],regex:[/^(LV)(\d{11})$/]}},u.lithunia=function(){function r(r,e,t){return+r.charAt(t)*e[t]}function e(e,t,i){if(t%11===10){t=0;for(var s=0;s<8;s++)t+=r(e,i.multipliers.short,s)}return t}function t(r,e){for(var t=0;t<8;t++)e+=+r.charAt(t)*(t+1);return e}function i(r){return r%=11,10===r&&(r=0),r}function s(r,s){var l=0;if(9===r.length){if(!/^\d{7}1/.test(r))return!1;l=t(r,l),l=e(r,l,s),l=i(l);var u=+r.slice(8,9);return l===u}return!1}function l(e,t,i){for(var s=0;s<11;s++)t+=r(e,i.multipliers.med,s);return t}function u(e,t,i){if(t%11===10){t=0;for(var s=0;s<11;s++)t+=r(e,i.multipliers.alt,s)}return t}function n(r,e){var t=0;if(12===r.length){if(!e.check.test(r))return!1;t=l(r,t,e),t=u(r,t,e),t=i(t);var s=+r.slice(11,12);return t===s}return!1}return{calcs:function(r){return s(r,this.rules)||n(r,this.rules)},rules:{multipliers:{short:[3,4,5,6,7,8,9,1],med:[1,2,3,4,5,6,7,8,9,1,2],alt:[3,4,5,6,7,8,9,1,2,3,4]},check:/^\d{10}1/,regex:[/^(LT)(\d{9}|\d{12})$/]}}}(),u.luxembourg={calcs:function(r){var e=+r.slice(6,8),t=+r.slice(0,6)%89;return t===e},rules:{regex:[/^(LU)(\d{8})$/]}},u.malta={calcs:function(r){for(var e,t=0,i=0;i<6;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=37-t%37,e=+r.slice(6,8),t===e},rules:{multipliers:[3,4,6,7,8,9],regex:[/^(MT)([1-9]\d{7})$/]}},u.netherlands={calcs:function(r){for(var e,t=0,i=0;i<8;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t%=11,t>9&&(t=0),e=+r.slice(8,9),t===e},rules:{multipliers:[9,8,7,6,5,4,3,2],regex:[/^(NL)(\d{9})B\d{2}$/]}},u.norway={calcs:function(r){for(var e,t=0,i=0;i<8;i++)t+=+r.charAt(i)*this.rules.multipliers[i];if(t=11-t%11,11===t&&(t=0),t<10)return e=+r.slice(8,9),t===e},rules:{multipliers:[3,2,7,6,5,4,3,2],regex:[/^(NO)(\d{9})$/]}},u.poland={calcs:function(r){for(var e,t=0,i=0;i<9;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t%=11,t>9&&(t=0),e=+r.slice(9,10),t===e},rules:{multipliers:[6,5,7,2,3,4,5,6,7],regex:[/^(PL)(\d{10})$/]}},u.portugal={calcs:function(r){for(var e,t=0,i=0;i<8;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=11-t%11,t>9&&(t=0),e=+r.slice(8,9),t===e},rules:{multipliers:[9,8,7,6,5,4,3,2],regex:[/^(PT)(\d{9})$/]}},u.romania={calcs:function(r){for(var e,t=0,i=r.length,s=this.rules.multipliers.slice(10-i),l=0;l<r.length-1;l++)t+=+r.charAt(l)*s[l];return t=10*t%11,10===t&&(t=0),e=+r.slice(r.length-1,r.length),t===e},rules:{multipliers:[7,5,3,2,1,7,5,3,2],regex:[/^(RO)([1-9]\d{1,9})$/]}},u.russia=function(){function r(r,e){var t=0;if(10===r.length){for(var i=0;i<10;i++)t+=+r.charAt(i)*e.multipliers.m_1[i];t%=11,t>9&&(t%=10);var s=+r.slice(9,10);return t===s}return!1}function e(r,e){var t=0,i=0;if(12===r.length){for(var s=0;s<11;s++)t+=+r.charAt(s)*e.multipliers.m_2[s];t%=11,t>9&&(t%=10);for(var l=0;l<11;l++)i+=+r.charAt(l)*e.multipliers.m_3[l];i%=11,i>9&&(i%=10);var u=t===+r.slice(10,11),n=i===+r.slice(11,12);return u&&n}return!1}return{calcs:function(t){return r(t,this.rules)||e(t,this.rules)},rules:{multipliers:{m_1:[2,4,10,3,5,9,4,6,8,0],m_2:[7,2,4,10,3,5,9,4,6,8,0],m_3:[3,7,2,4,10,3,5,9,4,6,8,0]},regex:[/^(RU)(\d{10}|\d{12})$/]}}}(),u.serbia={calcs:function(r){for(var e,t=10,i=0,s=0;s<8;s++)i=(+r.charAt(s)+t)%10,0===i&&(i=10),t=2*i%11;var l=1;return e=(t+ +r.slice(8,9))%10,e===l},rules:{regex:[/^(RS)(\d{9})$/]}},u.slovakia_republic={calcs:function(r){var e=0,t=r%11;return t===e},rules:{regex:[/^(SK)([1-9]\d[2346-9]\d{7})$/]}},u.slovenia={calcs:function(r){for(var e,t=0,i=0;i<7;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=11-t%11,10===t&&(t=0),e=+r.slice(7,8),!(11===t||t!==e)},rules:{multipliers:[8,7,6,5,4,3,2],regex:[/^(SI)([1-9]\d{7})$/]}},u.spain={calcs:function(r){var e,t,i=0,s=0;if(this.rules.additional[0].test(r)){for(i=0;i<7;i++)e=r.charAt(i+1)*this.rules.multipliers[i],s+=e>9?Math.floor(e/10)+e%10:e;return s=10-s%10,10===s&&(s=0),t=+r.slice(8,9),s===t}if(this.rules.additional[1].test(r)){for(i=0;i<7;i++)e=r.charAt(i+1)*this.rules.multipliers[i],s+=e>9?Math.floor(e/10)+e%10:e;return s=10-s%10,s=String.fromCharCode(s+64),t=r.slice(8,9),s===t}if(this.rules.additional[2].test(r)){var l=r;return"Y"===l.substring(0,1)&&(l=l.replace(/Y/,"1")),"Z"===l.substring(0,1)&&(l=l.replace(/Z/,"2")),t="TRWAGMYFPDXBNJZSQVHLCKE".charAt(+l.substring(0,8)%23),l.charAt(8)===t}return!!this.rules.additional[3].test(r)&&(t="TRWAGMYFPDXBNJZSQVHLCKE".charAt(+r.substring(1,8)%23),r.charAt(8)===t)},rules:{multipliers:[2,1,2,1,2,1,2],regex:[/^(ES)([A-Z]\d{8})$/,/^(ES)([A-HN-SW]\d{7}[A-J])$/,/^(ES)([0-9YZ]\d{7}[A-Z])$/,/^(ES)([KLMX]\d{7}[A-Z])$/],additional:[/^[A-H|J|U|V]\d{8}$/,/^[A-H|N-S|W]\d{7}[A-J]$/,/^[0-9|Y|Z]\d{7}[A-Z]$/,/^[K|L|M|X]\d{7}[A-Z]$/]}},u.sweden={calcs:function(r){for(var e,t,i=0,s=0;s<9;s+=2)t=+r.charAt(s),i+=Math.floor(t/5)+2*t%10;for(var l=0,u=1;u<9;u+=2)l+=+r.charAt(u);var n=(10-(i+l)%10)%10;return e=+r.slice(9,10),n===e},rules:{regex:[/^(SE)(\d{10}01)$/]}},u.switzerland={calcs:function(r){for(var e=0,t=0;t<8;t++)e+=+r.charAt(t)*this.rules.multipliers[t];if(e=11-e%11,10===e)return!1;11===e&&(e=0);var i=+r.substr(8,1);return e===i},rules:{multipliers:[5,4,3,2,7,6,5,4],regex:[/^(CHE)(\d{9})(MWST)?$/]}},u.united_kingdom={calcs:function(r){var e,t=0;if("GD"===r.substr(0,2))return e=500,r.substr(2,3)<e;if("HA"===r.substr(0,2))return e=499,r.substr(2,3)>e;if(0===+r.slice(0))return!1;for(var i=+r.slice(0,7),s=0;s<7;s++)t+=+r.charAt(s)*this.rules.multipliers[s];for(var l=t;l>0;)l-=97;return l=Math.abs(l),l===+r.slice(7,9)&&i<9990001&&(i<1e5||i>999999)&&(i<9490001||i>97e5)||(l>=55?l-=55:l+=42,e=+r.slice(7,9),!!(l===e&&i>1e6))},rules:{multipliers:[8,7,6,5,4,3,2],regex:[/^(GB)?(\d{9})$/,/^(GB)?(\d{12})$/,/^(GB)?(GD\d{3})$/,/^(GB)?(HA\d{3})$/]}},"object"==typeof module&&module.exports&&(module.exports=n),n}();
var jsvat=function(){"use strict";function r(r,e){return e.test(r)}function e(r,e,t){var i=e.exec(r),s=i[2];return u[t].calcs(s)}function t(t,i,s){var l=!1;return r(t,i)&&(l=e(t,i,s)),l}function i(r){return r=r||"",r.toString().toUpperCase().replace(/(\s|-|\.)+/g,"")}function s(r,e){return!(!r||0===r.length)&&r.indexOf(e)===-1}function l(r,e){for(var i=u[e].rules.regex,l=0;l<i.length;l++){var c=t(r,i[l],e);if(c)return c&&!s(n.config,e)}return!1}var u={},n={config:[],checkVAT:function(r){var e={value:i(r),isValid:!1,country:null};if(!r)return e;for(var t in u)if(u.hasOwnProperty(t)&&(e.isValid=l(e.value,t),e.isValid))return e.country=t,e;return e}};return u.austria={calcs:function(r){for(var e,t=0,i=0;i<7;i++)e=r.charAt(i)*this.rules.multipliers[i],t+=e>9?Math.floor(e/10)+e%10:e;return t=10-(t+4)%10,10===t&&(t=0),t===+r.slice(7,8)},rules:{multipliers:[1,2,1,2,1,2,1],regex:[/^(AT)U(\d{8})$/]}},u.belgium={calcs:function(r){if(9===r.length&&(r="0"+r),0===+r.slice(1,2))return!1;var e=97-+r.slice(0,8)%97;return e===+r.slice(8,10)},rules:{regex:[/^(BE)(0?\d{9})$/]}},u.bulgaria=function(){function r(r,e,t,i,s){for(var l=t;l<i;l++)r+=+e.charAt(l)*(l+s);return r}function e(r,e,t,i,s){for(var l=t;l<i;l++)r+=+e.charAt(l)*s[l];return r}function t(e){var t,i=0,s=+e.slice(8);return i=r(i,e,0,8,1),t=i%11,10!==t?t===s:(i=r(0,e,0,8,3),t=i%11,10===t&&(t=0),t===s)}function i(r,t){if(/^\d\d[0-5]\d[0-3]\d\d{4}$/.test(r)){var i=+r.slice(2,4);if(i>0&&i<13||i>20&&i<33||i>40&&i<53){var s=e(0,r,0,9,t.multipliers.physical);if(s%=11,10===s&&(s=0),s===+r.substr(9,1))return!0}}return!1}function s(r,t){var i=e(0,r,0,9,t.multipliers.foreigner);if(i%10===+r.substr(9,1))return!0}function l(r,t){var i=e(0,r,0,9,t.multipliers.miscellaneous);if(i=11-i%11,10===i)return!1;11===i&&(i=0);var s=+r.substr(9,1);return i===s}return{calcs:function(r){return 9===r.length?t(r):i(r,this.rules)||s(r,this.rules)||l(r,this.rules)},rules:{multipliers:{physical:[2,4,8,5,10,9,7,3,6],foreigner:[21,19,17,13,11,9,7,3,1],miscellaneous:[4,3,2,7,6,5,4,3,2]},regex:[/^(BG)(\d{9,10})$/]}}}(),u.croatia={calcs:function(r){for(var e,t=10,i=0,s=0;s<10;s++)i=(+r.charAt(s)+t)%10,0===i&&(i=10),t=2*i%11;return e=+r.slice(10,11),(t+e)%10===1},rules:{regex:[/^(HR)(\d{11})$/]}},u.cyprus={calcs:function(r){var e,t=0;if(12===+r.slice(0,2))return!1;for(var i=0;i<8;i++){var s=+r.charAt(i);if(i%2===0)switch(s){case 0:s=1;break;case 1:s=0;break;case 2:s=5;break;case 3:s=7;break;case 4:s=9;break;default:s=2*s+3}t+=s}return t%=26,t=String.fromCharCode(t+65),e=r.substr(8,1),t===e},rules:{regex:[/^(CY)([0-59]\d{7}[A-Z])$/]}},u.czech_republic=function(){function r(r,e){var t=0;if(e.additional[0].test(r)){for(var i=0;i<7;i++)t+=+r.charAt(i)*e.multipliers[i];t=11-t%11,10===t&&(t=0),11===t&&(t=1);var s=+r.slice(7,8);return t===s}return!1}function e(r,e){var t=0;if(e.additional[2].test(r)){for(var i=0;i<7;i++)t+=+r.charAt(i+1)*e.multipliers[i];t=11-t%11,10===t&&(t=0),11===t&&(t=1);var s=+r.slice(8,9);return e.lookup[t-1]===s}return!1}function t(r,e){if(e.additional[3].test(r)){var t=+r.slice(0,2)+r.slice(2,4)+r.slice(4,6)+r.slice(6,8)+r.slice(8),i=+r%11===0;return!(t%11!==0||!i)}return!1}return{calcs:function(i){return!!r(i,this.rules)||(!!e(i,this.rules)||!!t(i,this.rules))},rules:{multipliers:[8,7,6,5,4,3,2],lookup:[8,7,6,5,4,3,2,1,0,9,10],regex:[/^(CZ)(\d{8,10})(\d{3})?$/],additional:[/^\d{8}$/,/^[0-5][0-9][0|1|5|6]\d[0-3]\d\d{3}$/,/^6\d{8}$/,/^\d{2}[0-3|5-8]\d[0-3]\d\d{4}$/]}}}(),u.denmark={calcs:function(r){for(var e=0,t=0;t<8;t++)e+=+r.charAt(t)*this.rules.multipliers[t];return e%11===0},rules:{multipliers:[2,7,6,5,4,3,2,1],regex:[/^(DK)(\d{8})$/]}},u.estonia={calcs:function(r){for(var e,t=0,i=0;i<8;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=10-t%10,10===t&&(t=0),e=+r.slice(8,9),t===e},rules:{multipliers:[3,7,1,3,7,1,3,7],regex:[/^(EE)(10\d{7})$/]}},u.europe={calcs:function(){return!0},rules:{regex:[/^(EU)(\d{9})$/]}},u.finland={calcs:function(r){for(var e,t=0,i=0;i<7;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=11-t%11,t>9&&(t=0),e=+r.slice(7,8),t===e},rules:{multipliers:[7,9,10,5,8,4,2],regex:[/^(FI)(\d{8})$/]}},u.france={calcs:function(r){var e,t;return!/^\d{11}$/.test(r)||(e=+r.substring(2),e=(100*e+12)%97,t=+r.slice(0,2),e===t)},rules:{regex:[/^(FR)(\d{11})$/,/^(FR)([A-HJ-NP-Z]\d{10})$/,/^(FR)(\d[A-HJ-NP-Z]\d{9})$/,/^(FR)([A-HJ-NP-Z]{2}\d{9})$/]}},u.germany={calcs:function(r){for(var e,t=10,i=0,s=0,l=0;l<8;l++)i=(+r.charAt(l)+t)%10,0===i&&(i=10),t=2*i%11;return s=11-t===10?0:11-t,e=+r.slice(8,9),s===e},rules:{regex:[/^(DE)([1-9]\d{8})$/]}},u.greece={calcs:function(r){var e,t=0;8===r.length&&(r="0"+r);for(var i=0;i<8;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t%=11,t>9&&(t=0),e=+r.slice(8,9),t===e},rules:{multipliers:[256,128,64,32,16,8,4,2],regex:[/^(EL)(\d{9})$/]}},u.hungary={calcs:function(r){for(var e,t=0,i=0;i<7;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=10-t%10,10===t&&(t=0),e=+r.slice(7,8),t===e},rules:{multipliers:[9,7,3,1,9,7,3],regex:[/^(HU)(\d{8})$/]}},u.ireland={calcs:function(r){var e,t=0;this.rules.typeFormats.first.test(r)&&(r="0"+r.substring(2,7)+r.substring(0,1)+r.substring(7,8));for(var i=0;i<7;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return this.rules.typeFormats.third.test(r)&&(t+="H"===r.charAt(8)?72:9),t%=23,t=0===t?"W":String.fromCharCode(t+64),e=r.slice(7,8),t===e},rules:{multipliers:[8,7,6,5,4,3,2],typeFormats:{first:/^\d[A-Z*+]/,third:/^\d{7}[A-Z][AH]$/},regex:[/^(IE)(\d{7}[A-W])$/,/^(IE)([7-9][A-Z*+)]\d{5}[A-W])$/,/^(IE)(\d{7}[A-W][AH])$/]}},u.italy={calcs:function(r){var e,t,i=0;if(0===+r.slice(0,7))return!1;if(e=+r.slice(7,10),e<1||e>201&&999!==e&&888!==e)return!1;for(var s=0;s<10;s++)e=+r.charAt(s)*this.rules.multipliers[s],i+=e>9?Math.floor(e/10)+e%10:e;return i=10-i%10,i>9&&(i=0),t=+r.slice(10,11),i===t},rules:{multipliers:[1,2,1,2,1,2,1,2,1,2],regex:[/^(IT)(\d{11})$/]}},u.latvia={calcs:function(r){var e,t=0;if(/^[0-3]/.test(r))return!!/^[0-3][0-9][0-1][0-9]/.test(r);for(var i=0;i<10;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t%11===4&&9===r[0]&&(t-=45),t%11===4?t=4-t%11:t%11>4?t=14-t%11:t%11<4&&(t=3-t%11),e=+r.slice(10,11),t===e},rules:{multipliers:[9,1,4,8,3,10,2,5,7,6],regex:[/^(LV)(\d{11})$/]}},u.lithunia=function(){function r(r,e,t){return+r.charAt(t)*e[t]}function e(e,t,i){if(t%11===10){t=0;for(var s=0;s<8;s++)t+=r(e,i.multipliers.short,s)}return t}function t(r,e){for(var t=0;t<8;t++)e+=+r.charAt(t)*(t+1);return e}function i(r){return r%=11,10===r&&(r=0),r}function s(r,s){var l=0;if(9===r.length){if(!/^\d{7}1/.test(r))return!1;l=t(r,l),l=e(r,l,s),l=i(l);var u=+r.slice(8,9);return l===u}return!1}function l(e,t,i){for(var s=0;s<11;s++)t+=r(e,i.multipliers.med,s);return t}function u(e,t,i){if(t%11===10){t=0;for(var s=0;s<11;s++)t+=r(e,i.multipliers.alt,s)}return t}function n(r,e){var t=0;if(12===r.length){if(!e.check.test(r))return!1;t=l(r,t,e),t=u(r,t,e),t=i(t);var s=+r.slice(11,12);return t===s}return!1}return{calcs:function(r){return s(r,this.rules)||n(r,this.rules)},rules:{multipliers:{short:[3,4,5,6,7,8,9,1],med:[1,2,3,4,5,6,7,8,9,1,2],alt:[3,4,5,6,7,8,9,1,2,3,4]},check:/^\d{10}1/,regex:[/^(LT)(\d{9}|\d{12})$/]}}}(),u.luxembourg={calcs:function(r){var e=+r.slice(6,8),t=+r.slice(0,6)%89;return t===e},rules:{regex:[/^(LU)(\d{8})$/]}},u.malta={calcs:function(r){for(var e,t=0,i=0;i<6;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=37-t%37,e=+r.slice(6,8),t===e},rules:{multipliers:[3,4,6,7,8,9],regex:[/^(MT)([1-9]\d{7})$/]}},u.netherlands={calcs:function(r){for(var e,t=0,i=0;i<8;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t%=11,t>9&&(t=0),e=+r.slice(8,9),t===e},rules:{multipliers:[9,8,7,6,5,4,3,2],regex:[/^(NL)(\d{9})B\d{2}$/]}},u.norway={calcs:function(r){for(var e,t=0,i=0;i<8;i++)t+=+r.charAt(i)*this.rules.multipliers[i];if(t=11-t%11,11===t&&(t=0),t<10)return e=+r.slice(8,9),t===e},rules:{multipliers:[3,2,7,6,5,4,3,2],regex:[/^(NO)(\d{9})$/]}},u.poland={calcs:function(r){for(var e,t=0,i=0;i<9;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t%=11,t>9&&(t=0),e=+r.slice(9,10),t===e},rules:{multipliers:[6,5,7,2,3,4,5,6,7],regex:[/^(PL)(\d{10})$/]}},u.portugal={calcs:function(r){for(var e,t=0,i=0;i<8;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=11-t%11,t>9&&(t=0),e=+r.slice(8,9),t===e},rules:{multipliers:[9,8,7,6,5,4,3,2],regex:[/^(PT)(\d{9})$/]}},u.romania={calcs:function(r){for(var e,t=0,i=r.length,s=this.rules.multipliers.slice(10-i),l=0;l<r.length-1;l++)t+=+r.charAt(l)*s[l];return t=10*t%11,10===t&&(t=0),e=+r.slice(r.length-1,r.length),t===e},rules:{multipliers:[7,5,3,2,1,7,5,3,2],regex:[/^(RO)([1-9]\d{1,9})$/]}},u.russia=function(){function r(r,e){var t=0;if(10===r.length){for(var i=0;i<10;i++)t+=+r.charAt(i)*e.multipliers.m_1[i];t%=11,t>9&&(t%=10);var s=+r.slice(9,10);return t===s}return!1}function e(r,e){var t=0,i=0;if(12===r.length){for(var s=0;s<11;s++)t+=+r.charAt(s)*e.multipliers.m_2[s];t%=11,t>9&&(t%=10);for(var l=0;l<11;l++)i+=+r.charAt(l)*e.multipliers.m_3[l];i%=11,i>9&&(i%=10);var u=t===+r.slice(10,11),n=i===+r.slice(11,12);return u&&n}return!1}return{calcs:function(t){return r(t,this.rules)||e(t,this.rules)},rules:{multipliers:{m_1:[2,4,10,3,5,9,4,6,8,0],m_2:[7,2,4,10,3,5,9,4,6,8,0],m_3:[3,7,2,4,10,3,5,9,4,6,8,0]},regex:[/^(RU)(\d{10}|\d{12})$/]}}}(),u.serbia={calcs:function(r){for(var e,t=10,i=0,s=0;s<8;s++)i=(+r.charAt(s)+t)%10,0===i&&(i=10),t=2*i%11;var l=1;return e=(t+ +r.slice(8,9))%10,e===l},rules:{regex:[/^(RS)(\d{9})$/]}},u.slovakia_republic={calcs:function(r){var e=0,t=r%11;return t===e},rules:{regex:[/^(SK)([1-9]\d[2346-9]\d{7})$/]}},u.slovenia={calcs:function(r){for(var e,t=0,i=0;i<7;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=11-t%11,10===t&&(t=0),e=+r.slice(7,8),!(11===t||t!==e)},rules:{multipliers:[8,7,6,5,4,3,2],regex:[/^(SI)([1-9]\d{7})$/]}},u.spain={calcs:function(r){var e,t,i=0,s=0;if(this.rules.additional[0].test(r)){for(i=0;i<7;i++)e=r.charAt(i+1)*this.rules.multipliers[i],s+=e>9?Math.floor(e/10)+e%10:e;return s=10-s%10,10===s&&(s=0),t=+r.slice(8,9),s===t}if(this.rules.additional[1].test(r)){for(i=0;i<7;i++)e=r.charAt(i+1)*this.rules.multipliers[i],s+=e>9?Math.floor(e/10)+e%10:e;return s=10-s%10,s=String.fromCharCode(s+64),t=r.slice(8,9),s===t}if(this.rules.additional[2].test(r)){var l=r;return"Y"===l.substring(0,1)&&(l=l.replace(/Y/,"1")),"Z"===l.substring(0,1)&&(l=l.replace(/Z/,"2")),t="TRWAGMYFPDXBNJZSQVHLCKE".charAt(+l.substring(0,8)%23),l.charAt(8)===t}return!!this.rules.additional[3].test(r)&&(t="TRWAGMYFPDXBNJZSQVHLCKE".charAt(+r.substring(1,8)%23),r.charAt(8)===t)},rules:{multipliers:[2,1,2,1,2,1,2],regex:[/^(ES)([A-Z]\d{8})$/,/^(ES)([A-HN-SW]\d{7}[A-J])$/,/^(ES)([0-9YZ]\d{7}[A-Z])$/,/^(ES)([KLMX]\d{7}[A-Z])$/],additional:[/^[A-H|J|U|V]\d{8}$/,/^[A-H|N-S|W]\d{7}[A-J]$/,/^[0-9|Y|Z]\d{7}[A-Z]$/,/^[K|L|M|X]\d{7}[A-Z]$/]}},u.sweden={calcs:function(r){for(var e,t,i=0,s=0;s<9;s+=2)t=+r.charAt(s),i+=Math.floor(t/5)+2*t%10;for(var l=0,u=1;u<9;u+=2)l+=+r.charAt(u);var n=(10-(i+l)%10)%10;return e=+r.slice(9,10),n===e},rules:{regex:[/^(SE)(\d{10}01)$/]}},u.switzerland={calcs:function(r){for(var e=0,t=0;t<8;t++)e+=+r.charAt(t)*this.rules.multipliers[t];if(e=11-e%11,10===e)return!1;11===e&&(e=0);var i=+r.substr(8,1);return e===i},rules:{multipliers:[5,4,3,2,7,6,5,4],regex:[/^(CHE)(\d{9})(MWST)?$/]}},u.united_kingdom={calcs:function(r){var e,t=0;if("GD"===r.substr(0,2))return e=500,r.substr(2,3)<e;if("HA"===r.substr(0,2))return e=499,r.substr(2,3)>e;if(0===+r.slice(0))return!1;for(var i=+r.slice(0,7),s=0;s<7;s++)t+=+r.charAt(s)*this.rules.multipliers[s];for(var l=t;l>0;)l-=97;return l=Math.abs(l),l===+r.slice(7,9)&&i<9990001&&(i<1e5||i>999999)&&(i<9490001||i>97e5)||(l>=55?l-=55:l+=42,e=+r.slice(7,9),!!(l===e&&i>1e6))},rules:{multipliers:[8,7,6,5,4,3,2],regex:[/^(GB)?(\d{9})$/,/^(GB)?(\d{12})$/,/^(GB)?(GD\d{3})$/,/^(GB)?(HA\d{3})$/]}},"object"==typeof module&&module.exports&&(module.exports=n),n}();
//# sourceMappingURL=jsvat.min.js.map
{
"name": "jsvat",
"version": "1.1.4",
"version": "1.1.5",
"description": "Check the validity of the format of an EU VAT number",
"main": "./dist/jsvat.js",
"scripts": {
"test": "mocha \"test/acceptance/test_cases.js\""
"test": "mocha \"test/acceptance/test_cases.js\"",
"lint": "eslint src --ext .js",
"fix": "eslint src --fix .js"
},

@@ -42,24 +44,26 @@ "license": "MIT",

"gulp": "^3.9.1",
"gulp-beautify": "^2.0.0",
"gulp-beautify": "^2.0.1",
"gulp-buddy.js": "^1.0.0",
"gulp-concat": "^2.6.0",
"gulp-concat": "^2.6.1",
"gulp-gzip": "^1.4.0",
"gulp-jshint": "^2.0.1",
"gulp-notify": "^2.2.0",
"gulp-jshint": "^2.0.4",
"gulp-notify": "^3.0.0",
"gulp-plumber": "^1.1.0",
"gulp-rename": "^1.2.2",
"gulp-size": "^2.1.0",
"gulp-sourcemaps": "^2.0.0-alpha",
"gulp-todo": "^5.0.0",
"gulp-uglify": "^2.0.0",
"gulp-watch": "^4.3.10",
"gulp-sourcemaps": "^2.4.1",
"gulp-todo": "^5.3.0",
"gulp-uglify": "^2.0.1",
"gulp-watch": "^4.3.11",
"gulp-webstandards": "^0.1.1",
"gulp-wrap": "^0.13.0",
"jshint": "^2.9.3",
"jshint-stylish": "^2.2.1",
"eslint": "^3.14.1",
"eslint-config-standard": "^6.2.1",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"minimist": "^1.2.0",
"mocha": "^3.1.0",
"require-dir": "^0.3.0",
"mocha": "^3.2.0",
"require-dir": "^0.3.1",
"run-sequence": "^1.2.2"
}
}

@@ -142,11 +142,2 @@ [![Codacy Badge](https://api.codacy.com/project/badge/grade/874e7dce623149e18807bdc0a02671c2)](https://www.codacy.com/app/se-panfilov/jsvat)

Source of inspiration:
---------
Based on this great work: http://www.braemoor.co.uk/software/vat.shtml
At the moment the code was in public access without any license information.
I'm totally rewrite all the code.
Changelog

@@ -153,0 +144,0 @@ --------

@@ -0,20 +1,21 @@

// eslint-disable-next-line no-undef
COUNTRIES.austria = {
calcs: function (vat) {
var total = 0;
var temp;
var total = 0
var temp
for (var i = 0; i < 7; i++) {
temp = vat.charAt(i) * this.rules.multipliers[i];
temp = vat.charAt(i) * this.rules.multipliers[i]
if (temp > 9) {
total += Math.floor(temp / 10) + temp % 10;
total += Math.floor(temp / 10) + temp % 10
} else {
total += temp;
total += temp
}
}
total = 10 - (total + 4) % 10;
if (total === 10) total = 0;
total = 10 - (total + 4) % 10
if (total === 10) total = 0
return total === +vat.slice(7, 8);
return total === +vat.slice(7, 8)
},

@@ -33,2 +34,2 @@ rules: {

}
};
}

@@ -0,11 +1,12 @@

// eslint-disable-next-line no-undef
COUNTRIES.belgium = {
calcs: function (vat) {
if (vat.length === 9) {
vat = '0' + vat;
vat = '0' + vat
}
if (+vat.slice(1, 2) === 0) return false;
if (+vat.slice(1, 2) === 0) return false
var check = (97 - +vat.slice(0, 8) % 97);
return check === +vat.slice(8, 10);
var check = (97 - +vat.slice(0, 8) % 97)
return check === +vat.slice(8, 10)
},

@@ -16,2 +17,1 @@ rules: {

}
;

@@ -0,79 +1,77 @@

// eslint-disable-next-line no-undef
COUNTRIES.bulgaria = (function () {
function _increase(value, vat, from, to, incr) {
function _increase (value, vat, from, to, incr) {
for (var i = from; i < to; i++) {
value += +vat.charAt(i) * (i + incr);
value += +vat.charAt(i) * (i + incr)
}
return value;
return value
}
function _increase2(value, vat, from, to, multipliers) {
function _increase2 (value, vat, from, to, multipliers) {
for (var i = from; i < to; i++) {
value += +vat.charAt(i) * multipliers[i];
value += +vat.charAt(i) * multipliers[i]
}
return value;
return value
}
function _checkNineLengthVat(vat) {
var total;
var temp = 0;
var expect = +vat.slice(8);
function _checkNineLengthVat (vat) {
var total
var temp = 0
var expect = +vat.slice(8)
temp = _increase(temp, vat, 0, 8, 1);
temp = _increase(temp, vat, 0, 8, 1)
total = temp % 11;
total = temp % 11
if (total !== 10) {
return total === expect;
return total === expect
}
temp = _increase(0, vat, 0, 8, 3);
temp = _increase(0, vat, 0, 8, 3)
total = temp % 11;
if (total === 10) total = 0;
total = temp % 11
if (total === 10) total = 0
return total === expect;
return total === expect
}
function _isPhysicalPerson(vat, rules) {
function _isPhysicalPerson (vat, rules) {
// 10 digit VAT code - see if it relates to a standard physical person
if ((/^\d\d[0-5]\d[0-3]\d\d{4}$/).test(vat)) {
// Check month
var month = +vat.slice(2, 4);
var month = +vat.slice(2, 4)
if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
var total = _increase2(0, vat, 0, 9, rules.multipliers.physical);
var total = _increase2(0, vat, 0, 9, rules.multipliers.physical)
// Establish check digit.
total = total % 11;
if (total === 10) total = 0;
total = total % 11
if (total === 10) total = 0
// Check to see if the check digit given is correct, If not, try next type of person
if (total === +vat.substr(9, 1)) return true;
if (total === +vat.substr(9, 1)) return true
}
}
return false;
return false
}
function _isForeigner(vat, rules) {
function _isForeigner (vat, rules) {
// Extract the next digit and multiply by the counter.
var total = _increase2(0, vat, 0, 9, rules.multipliers.foreigner);
var total = _increase2(0, vat, 0, 9, rules.multipliers.foreigner)
// Check to see if the check digit given is correct, If not, try next type of person
if (total % 10 === +vat.substr(9, 1)) {
return true;
return true
}
}
function _miscellaneousVAT(vat, rules) {
function _miscellaneousVAT (vat, rules) {
// Finally, if not yet identified, see if it conforms to a miscellaneous VAT number
var total = _increase2(0, vat, 0, 9, rules.multipliers.miscellaneous);
var total = _increase2(0, vat, 0, 9, rules.multipliers.miscellaneous)
// Establish check digit.
total = 11 - total % 11;
if (total === 10) return false;
if (total === 11) total = 0;
total = 11 - total % 11
if (total === 10) return false
if (total === 11) total = 0
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
var expect = +vat.substr(9, 1);
return total === expect;
var expect = +vat.substr(9, 1)
return total === expect
}

@@ -84,7 +82,6 @@

if (vat.length === 9) {
return _checkNineLengthVat(vat);
return _checkNineLengthVat(vat)
} else {
return _isPhysicalPerson(vat, this.rules) || _isForeigner(vat, this.rules) || _miscellaneousVAT(vat, this.rules);
return _isPhysicalPerson(vat, this.rules) || _isForeigner(vat, this.rules) || _miscellaneousVAT(vat, this.rules)
}
},

@@ -129,3 +126,3 @@ rules: {

}
};
})();
}
})()

@@ -0,24 +1,24 @@

// eslint-disable-next-line no-undef
COUNTRIES.croatia = {
calcs: function (vat) {
var expect;
var expect
// Checks the check digits of a Croatian VAT number using ISO 7064, MOD 11-10 for check digit.
var product = 10;
var sum = 0;
var product = 10
var sum = 0
for (var i = 0; i < 10; i++) {
// Extract the next digit and implement the algorithm
sum = (+vat.charAt(i) + product) % 10;
sum = (+vat.charAt(i) + product) % 10
if (sum === 0) {
sum = 10;
sum = 10
}
product = (2 * sum) % 11;
product = (2 * sum) % 11
}
// Now check that we have the right check digit
expect = +vat.slice(10, 11);
return (product + expect) % 10 === 1;
expect = +vat.slice(10, 11)
return (product + expect) % 10 === 1
},

@@ -28,2 +28,2 @@ rules: {

}
};
}

@@ -0,8 +1,9 @@

// eslint-disable-next-line no-undef
COUNTRIES.cyprus = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// Not allowed to start with '12'
if (+vat.slice(0, 2) === 12) return false;
if (+vat.slice(0, 2) === 12) return false

@@ -12,34 +13,34 @@ // Extract the next digit and multiply by the counter.

for (var i = 0; i < 8; i++) {
var temp = +vat.charAt(i);
var temp = +vat.charAt(i)
if (i % 2 === 0) {
switch (temp) {
case 0:
temp = 1;
break;
temp = 1
break
case 1:
temp = 0;
break;
temp = 0
break
case 2:
temp = 5;
break;
temp = 5
break
case 3:
temp = 7;
break;
temp = 7
break
case 4:
temp = 9;
break;
temp = 9
break
default:
temp = temp * 2 + 3;
temp = temp * 2 + 3
}
}
total += temp;
total += temp
}
// Establish check digit using modulus 26, and translate to char. equivalent.
total = total % 26;
total = String.fromCharCode(total + 65);
total = total % 26
total = String.fromCharCode(total + 65)
// Check to see if the check digit given is correct
expect = vat.substr(8, 1);
return total === expect;
expect = vat.substr(8, 1)
return total === expect
},

@@ -49,2 +50,2 @@ rules: {

}
};
}

@@ -0,56 +1,55 @@

// eslint-disable-next-line no-undef
COUNTRIES.czech_republic = (function () {
function _isLegalEntities (vat, rules) {
var total = 0
function _isLegalEntities(vat, rules) {
var total = 0;
if (rules.additional[0].test(vat)) {
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * rules.multipliers[i];
total += +vat.charAt(i) * rules.multipliers[i]
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) total = 0;
if (total === 11) total = 1;
total = 11 - total % 11
if (total === 10) total = 0
if (total === 11) total = 1
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
var expect = +vat.slice(7, 8);
return total === expect;
var expect = +vat.slice(7, 8)
return total === expect
}
return false;
return false
}
function _isIndividualType2(vat, rules) {
var total = 0;
function _isIndividualType2 (vat, rules) {
var total = 0
if (rules.additional[2].test(vat)) {
// Extract the next digit and multiply by the counter.
for (var j = 0; j < 7; j++) {
total += +vat.charAt(j + 1) * rules.multipliers[j];
total += +vat.charAt(j + 1) * rules.multipliers[j]
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) total = 0;
if (total === 11) total = 1;
total = 11 - total % 11
if (total === 10) total = 0
if (total === 11) total = 1
// Convert calculated check digit according to a lookup table;
var expect = +vat.slice(8, 9);
return rules.lookup[total - 1] === expect;
// Convert calculated check digit according to a lookup table
var expect = +vat.slice(8, 9)
return rules.lookup[total - 1] === expect
}
return false;
return false
}
function _isIndividualType3(vat, rules) {
function _isIndividualType3 (vat, rules) {
if (rules.additional[3].test(vat)) {
var temp = +vat.slice(0, 2) + vat.slice(2, 4) + vat.slice(4, 6) + vat.slice(6, 8) + vat.slice(8);
var expect = +vat % 11 === 0;
return !!(temp % 11 === 0 && expect);
var temp = +vat.slice(0, 2) + vat.slice(2, 4) + vat.slice(4, 6) + vat.slice(6, 8) + vat.slice(8)
var expect = +vat % 11 === 0
return !!(temp % 11 === 0 && expect)
}
return false;
return false
}

@@ -60,8 +59,7 @@

calcs: function (vat) {
if (_isLegalEntities(vat, this.rules)) return true
if (_isIndividualType2(vat, this.rules)) return true
if (_isIndividualType3(vat, this.rules)) return true
if (_isLegalEntities(vat, this.rules)) return true;
if (_isIndividualType2(vat, this.rules)) return true;
if (_isIndividualType3(vat, this.rules)) return true;
return false;
return false
},

@@ -99,3 +97,3 @@ rules: {

}
};
}());
}
}())

@@ -0,10 +1,11 @@

// eslint-disable-next-line no-undef
COUNTRIES.denmark = {
calcs: function (vat) {
var total = 0;
var total = 0
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
return total % 11 === 0;
return total % 11 === 0
},

@@ -24,2 +25,2 @@ rules: {

}
};
}

@@ -0,18 +1,19 @@

// eslint-disable-next-line no-undef
COUNTRIES.estonia = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits using modulus 10.
total = 10 - total % 10;
if (total === 10) total = 0;
total = 10 - total % 10
if (total === 10) total = 0
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
expect = +vat.slice(8, 9)
return total === expect
},

@@ -32,2 +33,2 @@ rules: {

}
};
}

@@ -0,1 +1,2 @@

// eslint-disable-next-line no-undef
COUNTRIES.europe = {

@@ -5,3 +6,3 @@ calcs: function () {

// country, and that there are nine digits in total.
return true;
return true
},

@@ -12,2 +13,1 @@ rules: {

}
;

@@ -0,18 +1,19 @@

// eslint-disable-next-line no-undef
COUNTRIES.finland = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * this.rules.multipliers[i];
for (var i = 0; i < 7; i++) total += +vat.charAt(i) * this.rules.multipliers[i]
// Establish check digit.
total = 11 - total % 11;
total = 11 - total % 11
if (total > 9) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
expect = +vat.slice(7, 8)
return total === expect
},

@@ -31,2 +32,2 @@ rules: {

}
};
}

@@ -0,20 +1,21 @@

// eslint-disable-next-line no-undef
COUNTRIES.france = {
calcs: function (vat) {
var total;
var expect;
var total
var expect
// Checks the check digits of a French VAT number.
if (!(/^\d{11}$/).test(vat)) {
return true;
return true
}
// Extract the last nine digits as an integer.
total = +vat.substring(2);
total = +vat.substring(2)
// Establish check digit.
total = (total * 100 + 12) % 97;
total = (total * 100 + 12) % 97
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(0, 2);
return total === expect;
expect = +vat.slice(0, 2)
return total === expect
},

@@ -29,2 +30,2 @@ rules: {

}
};
}

@@ -0,17 +1,17 @@

// eslint-disable-next-line no-undef
COUNTRIES.germany = {
calcs: function (vat) {
// Checks the check digits of a German VAT number.
var product = 10;
var sum = 0;
var checkDigit = 0;
var expect;
var product = 10
var sum = 0
var checkDigit = 0
var expect
for (var i = 0; i < 8; i++) {
// Extract the next digit and implement peculiar algorithm!.
sum = (+vat.charAt(i) + product) % 10;
sum = (+vat.charAt(i) + product) % 10
if (sum === 0) {
sum = 10;
sum = 10
}
product = (2 * sum) % 11;
product = (2 * sum) % 11
}

@@ -21,5 +21,5 @@

if (11 - product === 10) {
checkDigit = 0;
checkDigit = 0
} else {
checkDigit = 11 - product;
checkDigit = 11 - product
}

@@ -29,4 +29,4 @@

// check digit.
expect = +vat.slice(8, 9);
return checkDigit === expect;
expect = +vat.slice(8, 9)
return checkDigit === expect
},

@@ -36,2 +36,2 @@ rules: {

}
};
}

@@ -0,9 +1,10 @@

// eslint-disable-next-line no-undef
COUNTRIES.greece = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
//eight character numbers should be prefixed with an 0.
// eight character numbers should be prefixed with an 0.
if (vat.length === 8) {
vat = '0' + vat;
vat = '0' + vat
}

@@ -13,14 +14,14 @@

for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digit.
total = total % 11;
total = total % 11
if (total > 9) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
expect = +vat.slice(8, 9)
return total === expect
},

@@ -40,2 +41,2 @@ rules: {

}
};
}

@@ -0,18 +1,19 @@

// eslint-disable-next-line no-undef
COUNTRIES.hungary = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digit.
total = 10 - total % 10;
if (total === 10) total = 0;
total = 10 - total % 10
if (total === 10) total = 0
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(7, 8);
return total === expect;
expect = +vat.slice(7, 8)
return total === expect
},

@@ -31,2 +32,2 @@ rules: {

}
};
}

@@ -0,9 +1,10 @@

// eslint-disable-next-line no-undef
COUNTRIES.ireland = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// If the code is type 1 format, we need to convert it to the new before performing the validation.
if (this.rules.typeFormats.first.test(vat)) {
vat = '0' + vat.substring(2, 7) + vat.substring(0, 1) + vat.substring(7, 8);
vat = '0' + vat.substring(2, 7) + vat.substring(0, 1) + vat.substring(7, 8)
}

@@ -13,3 +14,3 @@

for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}

@@ -21,5 +22,5 @@

if (vat.charAt(8) === 'H') {
total += 72;
total += 72
} else {
total += 9;
total += 9
}

@@ -29,12 +30,12 @@ }

// Establish check digit using modulus 23, and translate to char. equivalent.
total = total % 23;
total = total % 23
if (total === 0) {
total = 'W';
total = 'W'
} else {
total = String.fromCharCode(total + 64);
total = String.fromCharCode(total + 64)
}
// Compare it with the eighth character of the VAT number. If it's the same, then it's valid.
expect = vat.slice(7, 8);
return total === expect;
expect = vat.slice(7, 8)
return total === expect
},

@@ -52,3 +53,3 @@ rules: {

typeFormats: {
first: /^\d[A-Z\*\+]/,
first: /^\d[A-Z*+]/,
third: /^\d{7}[A-Z][AH]$/

@@ -58,6 +59,6 @@ },

/^(IE)(\d{7}[A-W])$/,
/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/,
/^(IE)([7-9][A-Z*+)]\d{5}[A-W])$/,
/^(IE)(\d{7}[A-W][AH])$/
]
}
};
}

@@ -0,15 +1,16 @@

// eslint-disable-next-line no-undef
COUNTRIES.italy = {
calcs: function (vat) {
var total = 0;
var temp;
var expect;
var total = 0
var temp
var expect
// The last three digits are the issuing office, and cannot exceed more 201, unless 999 or 888
if (+vat.slice(0, 7) === 0) {
return false;
return false
}
temp = +vat.slice(7, 10);
temp = +vat.slice(7, 10)
if ((temp < 1) || (temp > 201) && temp !== 999 && temp !== 888) {
return false;
return false
}

@@ -19,18 +20,18 @@

for (var i = 0; i < 10; i++) {
temp = +vat.charAt(i) * this.rules.multipliers[i];
temp = +vat.charAt(i) * this.rules.multipliers[i]
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
total += Math.floor(temp / 10) + temp % 10
else
total += temp;
total += temp
}
// Establish check digit.
total = 10 - total % 10;
total = 10 - total % 10
if (total > 9) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(10, 11);
return total === expect;
expect = +vat.slice(10, 11)
return total === expect
},

@@ -52,2 +53,2 @@ rules: {

}
};
}

@@ -0,5 +1,6 @@

// eslint-disable-next-line no-undef
COUNTRIES.latvia = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect

@@ -9,24 +10,23 @@ // Differentiate between legal entities and natural bodies. For the latter we simply check that

if ((/^[0-3]/).test(vat)) {
return !!(/^[0-3][0-9][0-1][0-9]/).test(vat);
return !!(/^[0-3][0-9][0-1][0-9]/).test(vat)
} else {
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 10; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits by getting modulus 11.
if (total % 11 === 4 && vat[0] === 9) total = total - 45;
if (total % 11 === 4 && vat[0] === 9) total = total - 45
if (total % 11 === 4) {
total = 4 - total % 11;
total = 4 - total % 11
} else if (total % 11 > 4) {
total = 14 - total % 11;
total = 14 - total % 11
} else if (total % 11 < 4) {
total = 3 - total % 11;
total = 3 - total % 11
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(10, 11);
return total === expect;
expect = +vat.slice(10, 11)
return total === expect
}

@@ -49,2 +49,2 @@ },

}
};
}

@@ -0,101 +1,98 @@

// eslint-disable-next-line no-undef
COUNTRIES.lithunia = (function () {
function _extractDigit(vat, multiplier, key) {
return +vat.charAt(key) * multiplier[key];
function _extractDigit (vat, multiplier, key) {
return +vat.charAt(key) * multiplier[key]
}
function _doubleCheckCalculation(vat, total, rules) {
function _doubleCheckCalculation (vat, total, rules) {
if (total % 11 === 10) {
total = 0;
total = 0
for (var i = 0; i < 8; i++) {
total += _extractDigit(vat, rules.multipliers.short, i);
total += _extractDigit(vat, rules.multipliers.short, i)
}
}
return total;
return total
}
function extractDigit(vat, total) {
function extractDigit (vat, total) {
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * (i + 1);
total += +vat.charAt(i) * (i + 1)
}
return total;
return total
}
function checkDigit(total) {
total = total % 11;
function checkDigit (total) {
total = total % 11
if (total === 10) {
total = 0;
total = 0
}
return total;
return total
}
function _check9DigitVat(vat, rules) {
function _check9DigitVat (vat, rules) {
// 9 character VAT numbers are for legal persons
var total = 0;
var total = 0
if (vat.length === 9) {
// 8th character must be one
if (!(/^\d{7}1/).test(vat)) return false;
if (!(/^\d{7}1/).test(vat)) return false
// Extract the next digit and multiply by the counter+1.
total = extractDigit(vat, total);
total = extractDigit(vat, total)
// Can have a double check digit calculation!
total = _doubleCheckCalculation(vat, total, rules);
total = _doubleCheckCalculation(vat, total, rules)
// Establish check digit.
total = checkDigit(total);
total = checkDigit(total)
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
var expect = +vat.slice(8, 9);
return total === expect;
var expect = +vat.slice(8, 9)
return total === expect
}
return false;
return false
}
function extractDigit12(vat, total, rules) {
function extractDigit12 (vat, total, rules) {
for (var k = 0; k < 11; k++) {
total += _extractDigit(vat, rules.multipliers.med, k);
total += _extractDigit(vat, rules.multipliers.med, k)
}
return total;
return total
}
function _doubleCheckCalculation12(vat, total, rules) {
function _doubleCheckCalculation12 (vat, total, rules) {
if (total % 11 === 10) {
total = 0;
total = 0
for (var l = 0; l < 11; l++) {
total += _extractDigit(vat, rules.multipliers.alt, l);
total += _extractDigit(vat, rules.multipliers.alt, l)
}
}
return total;
return total
}
function _check12DigitVat(vat, rules) {
var total = 0;
function _check12DigitVat (vat, rules) {
var total = 0
// 12 character VAT numbers are for temporarily registered taxpayers
if (vat.length === 12) {
// 11th character must be one
if (!(rules.check).test(vat)) return false;
if (!(rules.check).test(vat)) return false
// Extract the next digit and multiply by the counter+1.
total = extractDigit12(vat, total, rules);
total = extractDigit12(vat, total, rules)
// Can have a double check digit calculation!
total = _doubleCheckCalculation12(vat, total, rules);
total = _doubleCheckCalculation12(vat, total, rules)
// Establish check digit.
total = checkDigit(total);
total = checkDigit(total)
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
var expect = +vat.slice(11, 12);
return total === expect;
var expect = +vat.slice(11, 12)
return total === expect
}
return false;
return false
}

@@ -105,3 +102,3 @@

calcs: function (vat) {
return _check9DigitVat(vat, this.rules) || _check12DigitVat(vat, this.rules);
return _check9DigitVat(vat, this.rules) || _check12DigitVat(vat, this.rules)
},

@@ -150,3 +147,3 @@ rules: {

}
};
}());
}
}())

@@ -0,8 +1,9 @@

// eslint-disable-next-line no-undef
COUNTRIES.luxembourg = {
calcs: function (vat) {
var expect = +vat.slice(6, 8);
var checkDigit = +vat.slice(0, 6) % 89;
var expect = +vat.slice(6, 8)
var checkDigit = +vat.slice(0, 6) % 89
// Checks the check digits of a Luxembourg VAT number.
return checkDigit === expect;
return checkDigit === expect
},

@@ -12,2 +13,2 @@ rules: {

}
};
}

@@ -0,17 +1,18 @@

// eslint-disable-next-line no-undef
COUNTRIES.malta = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 6; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits by getting modulus 37.
total = 37 - total % 37;
total = 37 - total % 37
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(6, 8);
return total === expect;
expect = +vat.slice(6, 8)
return total === expect
},

@@ -29,2 +30,2 @@ rules: {

}
};
}

@@ -0,20 +1,21 @@

// eslint-disable-next-line no-undef
COUNTRIES.netherlands = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits by getting modulus 11.
total = total % 11;
total = total % 11
if (total > 9) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
expect = +vat.slice(8, 9)
return total === expect
},

@@ -34,2 +35,2 @@ rules: {

}
};
}

@@ -0,5 +1,6 @@

// eslint-disable-next-line no-undef
COUNTRIES.norway = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// See http://www.brreg.no/english/coordination/number.html

@@ -9,16 +10,16 @@

for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits by getting modulus 11. Check digits > 9 are invalid
total = 11 - total % 11;
total = 11 - total % 11
if (total === 11) {
total = 0;
total = 0
}
if (total < 10) {
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
expect = +vat.slice(8, 9)
return total === expect
}

@@ -39,2 +40,2 @@ },

}
};
}

@@ -0,20 +1,21 @@

// eslint-disable-next-line no-undef
COUNTRIES.poland = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 9; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits subtracting modulus 11 from 11.
total = total % 11;
total = total % 11
if (total > 9) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(9, 10);
return total === expect;
expect = +vat.slice(9, 10)
return total === expect
},

@@ -35,2 +36,2 @@ rules: {

}
};
}

@@ -0,20 +1,21 @@

// eslint-disable-next-line no-undef
COUNTRIES.portugal = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits subtracting modulus 11 from 11.
total = 11 - total % 11;
total = 11 - total % 11
if (total > 9) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
expect = +vat.slice(8, 9)
return total === expect
},

@@ -34,2 +35,2 @@ rules: {

}
};
}

@@ -0,21 +1,22 @@

// eslint-disable-next-line no-undef
COUNTRIES.romania = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
var vatLength = vat.length;
var multipliers = this.rules.multipliers.slice(10 - vatLength);
var vatLength = vat.length
var multipliers = this.rules.multipliers.slice(10 - vatLength)
for (var i = 0; i < vat.length - 1; i++) {
total += +vat.charAt(i) * multipliers[i];
total += +vat.charAt(i) * multipliers[i]
}
// Establish check digits by getting modulus 11.
total = (10 * total) % 11;
if (total === 10) total = 0;
total = (10 * total) % 11
if (total === 10) total = 0
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(vat.length - 1, vat.length);
return total === expect;
expect = +vat.slice(vat.length - 1, vat.length)
return total === expect
},

@@ -36,2 +37,2 @@ rules: {

}
};
}

@@ -0,47 +1,46 @@

// eslint-disable-next-line no-undef
COUNTRIES.russia = (function () {
function _check10DigitINN (vat, rules) {
var total = 0
function _check10DigitINN(vat, rules) {
var total = 0;
if (vat.length === 10) {
for (var i = 0; i < 10; i++) {
total += +vat.charAt(i) * rules.multipliers.m_1[i];
total += +vat.charAt(i) * rules.multipliers.m_1[i]
}
total = total % 11;
total = total % 11
if (total > 9) {
total = total % 10;
total = total % 10
}
// Compare it with the last character of the VAT number. If it is the same, then it's valid
var expect = +vat.slice(9, 10);
return total === expect;
var expect = +vat.slice(9, 10)
return total === expect
}
return false;
return false
}
function _check12DigitINN(vat, rules) {
var total1 = 0;
var total2 = 0;
function _check12DigitINN (vat, rules) {
var total1 = 0
var total2 = 0
if (vat.length === 12) {
for (var j = 0; j < 11; j++) {
total1 += +vat.charAt(j) * rules.multipliers.m_2[j];
total1 += +vat.charAt(j) * rules.multipliers.m_2[j]
}
total1 = total1 % 11;
total1 = total1 % 11
if (total1 > 9) {
total1 = total1 % 10;
total1 = total1 % 10
}
for (var k = 0; k < 11; k++) {
total2 += +vat.charAt(k) * rules.multipliers.m_3[k];
total2 += +vat.charAt(k) * rules.multipliers.m_3[k]
}
total2 = total2 % 11;
total2 = total2 % 11
if (total2 > 9) {
total2 = total2 % 10;
total2 = total2 % 10
}

@@ -51,15 +50,14 @@

// character of the VAT number. If they're both the same, then it's valid
var expect = (total1 === +vat.slice(10, 11));
var expect2 = (total2 === +vat.slice(11, 12));
return (expect) && (expect2);
var expect = (total1 === +vat.slice(10, 11))
var expect2 = (total2 === +vat.slice(11, 12))
return (expect) && (expect2)
}
return false;
return false
}
return {
calcs: function (vat) {
// See http://russianpartner.biz/test_inn.html for algorithm
return _check10DigitINN(vat, this.rules) || _check12DigitINN(vat, this.rules);
return _check10DigitINN(vat, this.rules) || _check12DigitINN(vat, this.rules)
},

@@ -110,3 +108,3 @@ rules: {

}
};
}());
}
}())

@@ -0,1 +1,2 @@

// eslint-disable-next-line no-undef
COUNTRIES.serbia = {

@@ -5,20 +6,19 @@ calcs: function (vat) {

var product = 10;
var sum = 0;
var checkDigit;
var product = 10
var sum = 0
var checkDigit
for (var i = 0; i < 8; i++) {
// Extract the next digit and implement the algorithm
sum = (+vat.charAt(i) + product) % 10;
sum = (+vat.charAt(i) + product) % 10
if (sum === 0) {
sum = 10;
sum = 10
}
product = (2 * sum) % 11;
product = (2 * sum) % 11
}
// Now check that we have the right check digit
var expect = 1;
checkDigit = (product + (+vat.slice(8, 9))) % 10;
return checkDigit === expect;
var expect = 1
checkDigit = (product + (+vat.slice(8, 9))) % 10
return checkDigit === expect
},

@@ -28,2 +28,2 @@ rules: {

}
};
}

@@ -0,6 +1,7 @@

// eslint-disable-next-line no-undef
COUNTRIES.slovakia_republic = {
calcs: function (vat) {
var expect = 0;
var checkDigit = (vat % 11);
return checkDigit === expect;
var expect = 0
var checkDigit = (vat % 11)
return checkDigit === expect
},

@@ -10,2 +11,2 @@ rules: {

}
};
}

@@ -0,15 +1,16 @@

// eslint-disable-next-line no-undef
COUNTRIES.slovenia = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digits using modulus 11
total = 11 - total % 11;
total = 11 - total % 11
if (total === 10) {
total = 0;
total = 0
}

@@ -19,4 +20,4 @@

// same, then it's a valid check digit.
expect = +vat.slice(7, 8);
return !!(total !== 11 && total === expect);
expect = +vat.slice(7, 8)
return !!(total !== 11 && total === expect)
},

@@ -35,2 +36,2 @@ rules: {

}
};
}

@@ -0,28 +1,28 @@

// eslint-disable-next-line no-undef
COUNTRIES.spain = {
calcs: function (vat) {
var i = 0;
var total = 0;
var temp;
var expect;
var i = 0
var total = 0
var temp
var expect
// National juridical entities
if (this.rules.additional[0].test(vat)) {
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = vat.charAt(i + 1) * this.rules.multipliers[i];
temp = vat.charAt(i + 1) * this.rules.multipliers[i]
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
total += Math.floor(temp / 10) + temp % 10
else
total += temp;
total += temp
}
// Now calculate the check digit itself.
total = 10 - total % 10;
total = 10 - total % 10
if (total === 10) {
total = 0;
total = 0
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(8, 9);
return total === expect;
expect = +vat.slice(8, 9)
return total === expect
}

@@ -32,19 +32,18 @@

else if (this.rules.additional[1].test(vat)) {
// Extract the next digit and multiply by the counter.
for (i = 0; i < 7; i++) {
temp = vat.charAt(i + 1) * this.rules.multipliers[i];
temp = vat.charAt(i + 1) * this.rules.multipliers[i]
if (temp > 9)
total += Math.floor(temp / 10) + temp % 10;
total += Math.floor(temp / 10) + temp % 10
else
total += temp;
total += temp
}
// Now calculate the check digit itself.
total = 10 - total % 10;
total = String.fromCharCode(total + 64);
total = 10 - total % 10
total = String.fromCharCode(total + 64)
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = vat.slice(8, 9);
return total === expect;
expect = vat.slice(8, 9)
return total === expect
}

@@ -54,7 +53,7 @@

else if (this.rules.additional[2].test(vat)) {
var tempnumber = vat;
if (tempnumber.substring(0, 1) === 'Y') tempnumber = tempnumber.replace(/Y/, '1');
if (tempnumber.substring(0, 1) === 'Z') tempnumber = tempnumber.replace(/Z/, '2');
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+tempnumber.substring(0, 8) % 23);
return tempnumber.charAt(8) === expect;
var tempnumber = vat
if (tempnumber.substring(0, 1) === 'Y') tempnumber = tempnumber.replace(/Y/, '1')
if (tempnumber.substring(0, 1) === 'Z') tempnumber = tempnumber.replace(/Z/, '2')
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+tempnumber.substring(0, 8) % 23)
return tempnumber.charAt(8) === expect
}

@@ -64,7 +63,5 @@

else if (this.rules.additional[3].test(vat)) {
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+vat.substring(1, 8) % 23);
return vat.charAt(8) === expect;
}
else return false;
expect = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(+vat.substring(1, 8) % 23)
return vat.charAt(8) === expect
} else return false
},

@@ -94,2 +91,2 @@ rules: {

}
};
}

@@ -0,25 +1,26 @@

// eslint-disable-next-line no-undef
COUNTRIES.sweden = {
calcs: function (vat) {
var expect;
var expect
// Calculate R where R = R1 + R3 + R5 + R7 + R9, and Ri = INT(Ci/5) + (Ci*2) modulo 10
var R = 0;
var digit;
var R = 0
var digit
for (var i = 0; i < 9; i = i + 2) {
digit = +vat.charAt(i);
R += Math.floor(digit / 5) + ((digit * 2) % 10);
digit = +vat.charAt(i)
R += Math.floor(digit / 5) + ((digit * 2) % 10)
}
// Calculate S where S = C2 + C4 + C6 + C8
var S = 0;
var S = 0
for (var j = 1; j < 9; j = j + 2) {
S += +vat.charAt(j);
S += +vat.charAt(j)
}
var checkDigit = (10 - (R + S) % 10) % 10;
var checkDigit = (10 - (R + S) % 10) % 10
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
expect = +vat.slice(9, 10);
expect = +vat.slice(9, 10)
return checkDigit === expect;
return checkDigit === expect
},

@@ -30,2 +31,1 @@ rules: {

}
;

@@ -0,16 +1,17 @@

// eslint-disable-next-line no-undef
COUNTRIES.switzerland = {
calcs: function (vat) {
var total = 0;
var total = 0
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}
// Establish check digit.
total = 11 - total % 11;
if (total === 10) return false;
if (total === 11) total = 0;
total = 11 - total % 11
if (total === 10) return false
if (total === 11) total = 0
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
var expect = +vat.substr(8, 1);
return total === expect;
var expect = +vat.substr(8, 1)
return total === expect
},

@@ -30,2 +31,2 @@ rules: {

}
};
}

@@ -0,10 +1,11 @@

// eslint-disable-next-line no-undef
COUNTRIES.united_kingdom = {
calcs: function (vat) {
var total = 0;
var expect;
var total = 0
var expect
// Government departments
if (vat.substr(0, 2) === 'GD') {
expect = 500;
return vat.substr(2, 3) < expect;
expect = 500
return vat.substr(2, 3) < expect
}

@@ -14,4 +15,4 @@

if (vat.substr(0, 2) === 'HA') {
expect = 499;
return vat.substr(2, 3) > expect;
expect = 499
return vat.substr(2, 3) > expect
}

@@ -21,12 +22,11 @@

// 0 VAT numbers disallowed!
if (+vat.slice(0) === 0) return false;
if (+vat.slice(0) === 0) return false
// Check range is OK for modulus 97 calculation
var no = +vat.slice(0, 7);
var no = +vat.slice(0, 7)
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 7; i++) {
total += +vat.charAt(i) * this.rules.multipliers[i];
total += +vat.charAt(i) * this.rules.multipliers[i]
}

@@ -38,5 +38,5 @@

// Establish check digits by subtracting 97 from total until negative.
var checkDigit = total;
var checkDigit = total
while (checkDigit > 0) {
checkDigit = checkDigit - 97;
checkDigit = checkDigit - 97
}

@@ -47,12 +47,12 @@

// certain specified ranges.
checkDigit = Math.abs(checkDigit);
if (checkDigit === +vat.slice(7, 9) && no < 9990001 && (no < 100000 || no > 999999) && (no < 9490001 || no > 9700000)) return true;
checkDigit = Math.abs(checkDigit)
if (checkDigit === +vat.slice(7, 9) && no < 9990001 && (no < 100000 || no > 999999) && (no < 9490001 || no > 9700000)) return true
// Now try the new method by subtracting 55 from the check digit if we can - else add 42
if (checkDigit >= 55)
checkDigit = checkDigit - 55;
checkDigit = checkDigit - 55
else
checkDigit = checkDigit + 42;
expect = +vat.slice(7, 9);
return !!(checkDigit === expect && no > 1000000);
checkDigit = checkDigit + 42
expect = +vat.slice(7, 9)
return !!(checkDigit === expect && no > 1000000)
},

@@ -76,2 +76,2 @@ rules: {

}
};
}

@@ -1,40 +0,40 @@

var COUNTRIES = {};
var COUNTRIES = {}
function _validateRegex(vat, regex) {
return regex.test(vat);
function _validateRegex (vat, regex) {
return regex.test(vat)
}
function _validateRules(vat, regex, countryName) {
var parsedNum = regex.exec(vat);
var vatNum = parsedNum[2];
function _validateRules (vat, regex, countryName) {
var parsedNum = regex.exec(vat)
var vatNum = parsedNum[2]
return COUNTRIES[countryName].calcs(vatNum);
return COUNTRIES[countryName].calcs(vatNum)
}
function _validate(vat, regex, countryName) {
var result = false;
function _validate (vat, regex, countryName) {
var result = false
if (_validateRegex(vat, regex)) {
result = _validateRules(vat, regex, countryName);
result = _validateRules(vat, regex, countryName)
}
return result;
return result
}
function _getPureVAT(vat) {
vat = vat || '';
return vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '');
function _getPureVAT (vat) {
vat = vat || ''
return vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '')
}
function _isCountryBlocked(config, countryName) {
if (!config || config.length === 0) return false;
function _isCountryBlocked (config, countryName) {
if (!config || config.length === 0) return false
return config.indexOf(countryName) === -1;
return config.indexOf(countryName) === -1
}
function checkValidity(vat, countryName) {
var regexArr = COUNTRIES[countryName].rules.regex;
function checkValidity (vat, countryName) {
var regexArr = COUNTRIES[countryName].rules.regex
for (var i = 0; i < regexArr.length; i++) {
var isValid = _validate(vat, regexArr[i], countryName);
if (isValid) return isValid && !_isCountryBlocked(exports.config, countryName);
var isValid = _validate(vat, regexArr[i], countryName)
if (isValid) return isValid && !_isCountryBlocked(exports.config, countryName)
}
return false;
return false
}

@@ -49,14 +49,13 @@

country: null
};
}
if (!vat) return result;
if (!vat) return result
for (var countryName in COUNTRIES) {
if (COUNTRIES.hasOwnProperty(countryName)) {
result.isValid = checkValidity(result.value, countryName)
result.isValid = checkValidity(result.value, countryName);
if (result.isValid) {
result.country = countryName;
return result;
result.country = countryName
return result
}

@@ -66,5 +65,4 @@ }

return result;
return result
}
};
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc