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.6 to 1.2.0

src/countries/lithuania.js

1138

dist/jsvat.js

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

var COUNTRIES = {}
function Result(vat, isValid, country) {
this.value = vat || null
this.isValid = !!isValid
function _validateRegex(vat, regex) {
return regex.test(vat)
if (country) {
this.country = {
name: country.name,
isoCode: {
short: country.codes[0],
long: country.codes[1],
numeric: country.codes[2]
}
}
}
}
function _validateRules(vat, regex, countryName) {
var parsedNum = regex.exec(vat)
var vatNum = parsedNum[2]
function removeExtraChars(vat) {
vat = vat || ''
return vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '')
}
return COUNTRIES[countryName].calcs(vatNum)
function isValEqToCode(val, codes) {
return (val === codes[0] || val === codes[1] || val === codes[2])
}
function _validate(vat, regex, countryName) {
var result = false
if (_validateRegex(vat, regex)) {
result = _validateRules(vat, regex, countryName)
function isInList(list, country) {
if (!list) return false
for (var i = 0; i < list.length; i++) {
var val = list[i].toUpperCase()
if (val === country.name.toUpperCase()) return true
if (isValEqToCode(val, country.codes)) return true
}
return result
return false
}
function removeExtraChars(vat) {
vat = vat || ''
return vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '')
function isBlocked(country, blocked, allowed) {
var isBlocked = isInList(blocked, country)
if (isBlocked) return true
var isAllowed = isInList(allowed, country)
return allowed.length > 0 && !isAllowed
}
function _isCountryBlocked(config, countryName) {
if (!config || config.length === 0) return false
function getCountry(vat, countries) {
for (var k in countries) {
if (countries.hasOwnProperty(k)) {
var regexpValidRes = isVatValidToRegexp(vat, countries[k].rules.regex)
if (regexpValidRes.isValid) return countries[k]
}
}
return config.indexOf(countryName) === -1
return null
}
function checkValidity(vat, countryName) {
var regexArr = COUNTRIES[countryName].rules.regex
function isVatValidToRegexp(vat, regexArr) {
for (var i = 0; i < regexArr.length; i++) {
var isValid = _validate(vat, regexArr[i], countryName)
if (isValid) return isValid && !_isCountryBlocked(exports.config, countryName)
var regex = regexArr[i]
var isValid = regex.test(vat)
if (isValid) return {
isValid: true,
regex: regex
}
}
return false
return {
isValid: false
}
}
function isVatMathValid(vat, country) {
return country.calcFn(vat)
}
function isVatValid(vat, country) {
var regexpValidRes = isVatValidToRegexp(vat, country.rules.regex)
if (!regexpValidRes.isValid) return false
return isVatMathValid(regexpValidRes.regex.exec(vat)[2], country)
}
var exports = {
config: [],
blocked: [],
allowed: [],
countries: {},
checkVAT: function(vat) {
if (!vat) throw new Error('VAT should be specified')
var cleanVAT = removeExtraChars(vat)
var result = {
value: cleanVAT,
isValid: false,
country: null,
countryCode: null
}
var result = new Result(cleanVAT)
if (!vat) return result
var country = getCountry(cleanVAT, this.countries)
if (!country) return result
if (isBlocked(country, this.blocked, this.allowed)) return new Result(cleanVAT, false, country)
var ccArr = (/^([A-z])*/).exec(cleanVAT)
if (ccArr && ccArr.length > 0) result.countryCode = ccArr[0].toUpperCase()
var isValid = isVatValid(cleanVAT, country)
if (isValid) return new Result(cleanVAT, isValid, country)
for (var countryName in COUNTRIES) {
if (COUNTRIES.hasOwnProperty(countryName)) {
result.isValid = checkValidity(result.value, countryName)
if (result.isValid) {
result.country = countryName
return result
}
}
}
return result

@@ -78,5 +106,8 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.austria = {
calcs: function(vat) {
exports.countries.austria = {
name: 'Austria',
codes: ['AT', 'AUT', '040'],
calcFn: function(vat) {
var total = 0

@@ -101,11 +132,3 @@ var temp

rules: {
multipliers: [
1,
2,
1,
2,
1,
2,
1
],
multipliers: [1, 2, 1, 2, 1, 2, 1],
regex: [/^(AT)U(\d{8})$/]

@@ -116,4 +139,6 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.belgium = {
calcs: function(vat) {
exports.countries.belgium = {
name: 'Belgium',
codes: ['BE', 'BEL', '056'],
calcFn: function(vat) {
if (vat.length === 9) {

@@ -134,135 +159,106 @@ vat = '0' + vat

// 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)
exports.countries.bulgaria = {
name: 'Bulgaria',
codes: ['BG', 'BGR', '100'],
calcFn: function(vat) {
function _increase(value, vat, from, to, incr) {
for (var i = from; i < to; i++) {
value += +vat.charAt(i) * (i + incr)
}
return value
}
return value
}
function _increase2(value, vat, from, to, multipliers) {
for (var i = from; i < to; i++) {
value += +vat.charAt(i) * multipliers[i]
function _increase2(value, vat, from, to, multipliers) {
for (var i = from; i < to; 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
if (total !== 10) {
total = temp % 11
if (total !== 10) {
return total === expect
}
temp = _increase(0, vat, 0, 8, 3)
total = temp % 11
if (total === 10) total = 0
return total === expect
}
temp = _increase(0, vat, 0, 8, 3)
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)
if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
var total = _increase2(0, vat, 0, 9, rules.multipliers.physical)
// Establish check digit.
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
}
}
total = temp % 11
if (total === 10) total = 0
return false
}
return total === expect
}
function _isForeigner(vat, rules) {
// Extract the next digit and multiply by the counter.
var total = _increase2(0, vat, 0, 9, rules.multipliers.foreigner)
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)
if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
var total = _increase2(0, vat, 0, 9, rules.multipliers.physical)
// Establish check digit.
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
// 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 false
}
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)
function _isForeigner(vat, rules) {
// Extract the next digit and multiply by the counter.
var total = _increase2(0, vat, 0, 9, rules.multipliers.foreigner)
// Establish check digit.
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, try next type of person
if (total % 10 === +vat.substr(9, 1)) {
return true
// 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
}
}
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)
// Establish check digit.
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
}
return {
calcs: function(vat) {
if (vat.length === 9) {
return _checkNineLengthVat(vat)
} else {
return _isPhysicalPerson(vat, this.rules) || _isForeigner(vat, this.rules) || _miscellaneousVAT(vat, this.rules)
}
if (vat.length === 9) {
return _checkNineLengthVat(vat)
} else {
return _isPhysicalPerson(vat, this.rules) || _isForeigner(vat, this.rules) || _miscellaneousVAT(vat, 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]
},
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})$/]
}
regex: [/^(BG)(\d{9,10})$/]
}
})()
}
// eslint-disable-next-line no-undef
COUNTRIES.croatia = {
calcs: function(vat) {
exports.countries.croatia = {
name: 'Croatia',
codes: ['HR', 'HRV', '191'],
calcFn: function(vat) {
var expect
// Checks the check digits of a Croatian VAT number using ISO 7064, MOD 11-10 for check digit.
var product = 10

@@ -291,4 +287,6 @@ var sum = 0

// eslint-disable-next-line no-undef
COUNTRIES.cyprus = {
calcs: function(vat) {
exports.countries.cyprus = {
name: 'Cyprus',
codes: ['CY', 'CYP', '196'],
calcFn: function(vat) {
var total = 0

@@ -342,102 +340,84 @@ var expect

// eslint-disable-next-line no-undef
COUNTRIES.czech_republic = (function() {
function _isLegalEntities(vat, rules) {
var total = 0
exports.countries.czech_republic = {
name: 'Czech Republic',
codes: ['CZ', 'CZE', '203'],
calcFn: function(vat) {
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]
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]
}
// Establish check digit.
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
}
// Establish check digit.
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
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]
}
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]
// Establish check digit.
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
}
// Establish check digit.
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
return false
}
return false
}
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)
}
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)
return false
}
if (_isLegalEntities(vat, this.rules)) return true
if (_isIndividualType2(vat, this.rules)) return true
if (_isIndividualType3(vat, this.rules)) return true
return false
},
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}$/
]
}
}
return {
calcs: function(vat) {
if (_isLegalEntities(vat, this.rules)) return true
if (_isIndividualType2(vat, this.rules)) return true
if (_isIndividualType3(vat, this.rules)) return true
return false
},
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}$/
]
}
}
}())
// eslint-disable-next-line no-undef
COUNTRIES.denmark = {
calcs: function(vat) {
exports.countries.denmark = {
name: 'Denmark',
codes: ['DK', 'DNK', '208'],
calcFn: function(vat) {
var total = 0

@@ -452,12 +432,3 @@

rules: {
multipliers: [
2,
7,
6,
5,
4,
3,
2,
1
],
multipliers: [2, 7, 6, 5, 4, 3, 2, 1],
regex: [/^(DK)(\d{8})$/]

@@ -468,4 +439,6 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.estonia = {
calcs: function(vat) {
exports.countries.estonia = {
name: 'Estonia',
codes: ['EE', 'EST', '233'],
calcFn: function(vat) {
var total = 0

@@ -488,12 +461,3 @@ var expect

rules: {
multipliers: [
3,
7,
1,
3,
7,
1,
3,
7
],
multipliers: [3, 7, 1, 3, 7, 1, 3, 7],
regex: [/^(EE)(10\d{7})$/]

@@ -504,4 +468,6 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.europe = {
calcs: function() {
exports.countries.europe = {
name: 'Europe',
codes: ['EU', 'EUR', '000'], // TODO (S.Panfilov) that's not a real codes
calcFn: function() {
// We know little about EU numbers apart from the fact that the first 3 digits represent the

@@ -517,4 +483,6 @@ // country, and that there are nine digits in total.

// eslint-disable-next-line no-undef
COUNTRIES.finland = {
calcs: function(vat) {
exports.countries.finland = {
name: 'Finland',
codes: ['FI', 'FIN', '246'],
calcFn: function(vat) {
var total = 0

@@ -537,11 +505,3 @@ var expect

rules: {
multipliers: [
7,
9,
10,
5,
8,
4,
2
],
multipliers: [7, 9, 10, 5, 8, 4, 2],
regex: [/^(FI)(\d{8})$/]

@@ -552,4 +512,6 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.france = {
calcs: function(vat) {
exports.countries.france = {
name: 'France',
codes: ['FR', 'FRA', '250'],
calcFn: function(vat) {
var total

@@ -584,4 +546,6 @@ var expect

// eslint-disable-next-line no-undef
COUNTRIES.germany = {
calcs: function(vat) {
exports.countries.germany = {
name: 'Germany',
codes: ['DE', 'DEU', '276'],
calcFn: function(vat) {
// Checks the check digits of a German VAT number.

@@ -620,4 +584,6 @@ var product = 10

// eslint-disable-next-line no-undef
COUNTRIES.greece = {
calcs: function(vat) {
exports.countries.greece = {
name: 'Greece',
codes: ['GR', 'GRC', '300'],
calcFn: function(vat) {
var total = 0

@@ -662,4 +628,6 @@ var expect

// eslint-disable-next-line no-undef
COUNTRIES.hungary = {
calcs: function(vat) {
exports.countries.hungary = {
name: 'Hungary',
codes: ['HU', 'HUN', '348'],
calcFn: function(vat) {
var total = 0

@@ -696,4 +664,6 @@ var expect

// eslint-disable-next-line no-undef
COUNTRIES.ireland = {
calcs: function(vat) {
exports.countries.ireland = {
name: 'Ireland',
codes: ['IE', 'IRL', '372'],
calcFn: function(vat) {
var total = 0

@@ -735,11 +705,3 @@ var expect

rules: {
multipliers: [
8,
7,
6,
5,
4,
3,
2
],
multipliers: [8, 7, 6, 5, 4, 3, 2],
typeFormats: {

@@ -758,4 +720,6 @@ first: /^\d[A-Z*+]/,

// eslint-disable-next-line no-undef
COUNTRIES.italy = {
calcs: function(vat) {
exports.countries.italy = {
name: 'Italy',
codes: ['IT', 'ITA', '380'],
calcFn: function(vat) {
var total = 0

@@ -795,14 +759,3 @@ var temp

rules: {
multipliers: [
1,
2,
1,
2,
1,
2,
1,
2,
1,
2
],
multipliers: [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],
regex: [/^(IT)(\d{11})$/]

@@ -813,4 +766,6 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.latvia = {
calcs: function(vat) {
exports.countries.latvia = {
name: 'Latvia',
codes: ['LV', 'LVA', '428'],
calcFn: function(vat) {
var total = 0

@@ -846,14 +801,3 @@ var expect

rules: {
multipliers: [
9,
1,
4,
8,
3,
10,
2,
5,
7,
6
],
multipliers: [9, 1, 4, 8, 3, 10, 2, 5, 7, 6],
regex: [/^(LV)(\d{11})$/]

@@ -864,152 +808,121 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.lithunia = (function() {
function _extractDigit(vat, multiplier, key) {
return +vat.charAt(key) * multiplier[key]
}
exports.countries.lithuania = {
name: 'Lithuania',
codes: ['LT', 'LTU', '440'],
calcFn: function(vat) {
function _extractDigit(vat, multiplier, key) {
return +vat.charAt(key) * multiplier[key]
}
function _doubleCheckCalculation(vat, total, rules) {
if (total % 11 === 10) {
total = 0
function _doubleCheckCalculation(vat, total, rules) {
if (total % 11 === 10) {
total = 0
for (var i = 0; i < 8; i++) {
total += _extractDigit(vat, rules.multipliers.short, i)
}
}
return total
}
function extractDigit(vat, total) {
for (var i = 0; i < 8; i++) {
total += _extractDigit(vat, rules.multipliers.short, i)
total += +vat.charAt(i) * (i + 1)
}
return total
}
return total
}
function checkDigit(total) {
total = total % 11
if (total === 10) {
total = 0
}
function extractDigit(vat, total) {
for (var i = 0; i < 8; i++) {
total += +vat.charAt(i) * (i + 1)
return total
}
return total
}
function checkDigit(total) {
total = total % 11
if (total === 10) {
total = 0
}
function _check9DigitVat(vat, rules) {
// 9 character VAT numbers are for legal persons
var total = 0
if (vat.length === 9) {
// 8th character must be one
if (!(/^\d{7}1/).test(vat)) return false
return total
}
// Extract the next digit and multiply by the counter+1.
total = extractDigit(vat, total)
function _check9DigitVat(vat, rules) {
// 9 character VAT numbers are for legal persons
var total = 0
if (vat.length === 9) {
// 8th character must be one
if (!(/^\d{7}1/).test(vat)) return false
// Can have a double check digit calculation!
total = _doubleCheckCalculation(vat, total, rules)
// Extract the next digit and multiply by the counter+1.
total = extractDigit(vat, total)
// Establish check digit.
total = checkDigit(total)
// Can have a double check digit calculation!
total = _doubleCheckCalculation(vat, total, rules)
// Establish check digit.
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
// 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
}
return false
}
return false
}
function extractDigit12(vat, total, rules) {
for (var k = 0; k < 11; k++) {
total += _extractDigit(vat, rules.multipliers.med, k)
function extractDigit12(vat, total, rules) {
for (var k = 0; k < 11; k++) {
total += _extractDigit(vat, rules.multipliers.med, k)
}
return total
}
return total
}
function _doubleCheckCalculation12(vat, total, rules) {
if (total % 11 === 10) {
total = 0
for (var l = 0; l < 11; l++) {
total += _extractDigit(vat, rules.multipliers.alt, l)
function _doubleCheckCalculation12(vat, total, rules) {
if (total % 11 === 10) {
total = 0
for (var l = 0; l < 11; 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
// 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
// Extract the next digit and multiply by the counter+1.
total = extractDigit12(vat, total, rules)
// Extract the next digit and multiply by the counter+1.
total = extractDigit12(vat, total, rules)
// Can have a double check digit calculation!
total = _doubleCheckCalculation12(vat, total, rules)
// Can have a double check digit calculation!
total = _doubleCheckCalculation12(vat, total, rules)
// Establish check digit.
total = checkDigit(total)
// Establish check digit.
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
}
// 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
return false
}
return false
}
return {
calcs: function(vat) {
return _check9DigitVat(vat, this.rules) || _check12DigitVat(vat, this.rules)
return _check9DigitVat(vat, this.rules) || _check12DigitVat(vat, 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]
},
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})$/]
}
check: /^\d{10}1/,
regex: [/^(LT)(\d{9}|\d{12})$/]
}
}())
}
// eslint-disable-next-line no-undef
COUNTRIES.luxembourg = {
calcs: function(vat) {
exports.countries.luxembourg = {
name: 'Luxembourg',
codes: ['LU', 'LUX', '442'],
calcFn: function(vat) {
var expect = +vat.slice(6, 8)

@@ -1027,4 +940,6 @@ var checkDigit = +vat.slice(0, 6) % 89

// eslint-disable-next-line no-undef
COUNTRIES.malta = {
calcs: function(vat) {
exports.countries.malta = {
name: 'Malta',
codes: ['MT', 'MLT', '470'],
calcFn: function(vat) {
var total = 0

@@ -1046,10 +961,3 @@ var expect

rules: {
multipliers: [
3,
4,
6,
7,
8,
9
],
multipliers: [3, 4, 6, 7, 8, 9],
regex: [/^(MT)([1-9]\d{7})$/]

@@ -1060,4 +968,6 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.netherlands = {
calcs: function(vat) {
exports.countries.netherlands = {
name: 'Netherlands',
codes: ['NL', 'NLD', '528'],
calcFn: function(vat) {
var total = 0

@@ -1082,12 +992,3 @@ var expect

rules: {
multipliers: [
9,
8,
7,
6,
5,
4,
3,
2
],
multipliers: [9, 8, 7, 6, 5, 4, 3, 2],
regex: [/^(NL)(\d{9})B\d{2}$/]

@@ -1098,4 +999,6 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.norway = {
calcs: function(vat) {
exports.countries.norway = {
name: 'Norway',
codes: ['NO', 'NOR', '578'],
calcFn: function(vat) {
var total = 0

@@ -1124,12 +1027,3 @@ var expect

rules: {
multipliers: [
3,
2,
7,
6,
5,
4,
3,
2
],
multipliers: [3, 2, 7, 6, 5, 4, 3, 2],
regex: [/^(NO)(\d{9})$/]

@@ -1140,4 +1034,6 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.poland = {
calcs: function(vat) {
exports.countries.poland = {
name: 'Poland',
codes: ['PL', 'POL', '616'],
calcFn: function(vat) {
var total = 0

@@ -1162,13 +1058,3 @@ var expect

rules: {
multipliers: [
6,
5,
7,
2,
3,
4,
5,
6,
7
],
multipliers: [6, 5, 7, 2, 3, 4, 5, 6, 7],
regex: [/^(PL)(\d{10})$/]

@@ -1179,4 +1065,6 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.portugal = {
calcs: function(vat) {
exports.countries.portugal = {
name: 'Portugal',
codes: ['PT', 'PRT', '620'],
calcFn: function(vat) {
var total = 0

@@ -1201,12 +1089,3 @@ var expect

rules: {
multipliers: [
9,
8,
7,
6,
5,
4,
3,
2
],
multipliers: [9, 8, 7, 6, 5, 4, 3, 2],
regex: [/^(PT)(\d{9})$/]

@@ -1217,4 +1096,6 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.romania = {
calcs: function(vat) {
exports.countries.romania = {
name: 'Romania',
codes: ['RO', 'ROU', '642'],
calcFn: function(vat) {
var total = 0

@@ -1240,13 +1121,3 @@ var expect

rules: {
multipliers: [
7,
5,
3,
2,
1,
7,
5,
3,
2
],
multipliers: [7, 5, 3, 2, 1, 7, 5, 3, 2],
regex: [/^(RO)([1-9]\d{1,9})$/]

@@ -1257,113 +1128,79 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.russia = (function() {
function _check10DigitINN(vat, rules) {
var total = 0
exports.countries.russia = {
name: 'Russian Federation',
codes: ['RU', 'RUS', '643'],
calcFn: function(vat) {
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]
}
if (vat.length === 10) {
for (var i = 0; i < 10; i++) {
total += +vat.charAt(i) * rules.multipliers.m_1[i]
}
total = total % 11
if (total > 9) {
total = total % 10
total = total % 11
if (total > 9) {
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
}
// 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
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]
}
if (vat.length === 12) {
for (var j = 0; j < 11; j++) {
total1 += +vat.charAt(j) * rules.multipliers.m_2[j]
}
total1 = total1 % 11
total1 = total1 % 11
if (total1 > 9) {
total1 = total1 % 10
}
if (total1 > 9) {
total1 = total1 % 10
}
for (var k = 0; k < 11; k++) {
total2 += +vat.charAt(k) * rules.multipliers.m_3[k]
}
for (var k = 0; k < 11; k++) {
total2 += +vat.charAt(k) * rules.multipliers.m_3[k]
}
total2 = total2 % 11
if (total2 > 9) {
total2 = total2 % 10
}
total2 = total2 % 11
if (total2 > 9) {
total2 = total2 % 10
// Compare the first check with the 11th character and the second check with the 12th and last
// 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)
}
// Compare the first check with the 11th character and the second check with the 12th and last
// 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)
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)
// See http://russianpartner.biz/test_inn.html for algorithm
return _check10DigitINN(vat, this.rules) || _check12DigitINN(vat, 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]
},
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})$/]
}
regex: [/^(RU)(\d{10}|\d{12})$/]
}
}())
}
// eslint-disable-next-line no-undef
COUNTRIES.serbia = {
calcs: function(vat) {
exports.countries.serbia = {
name: 'Serbia',
codes: ['RS', 'SRB', '688'],
calcFn: function(vat) {
// Checks the check digits of a Serbian VAT number using ISO 7064, MOD 11-10 for check digit.

@@ -1395,4 +1232,6 @@

// eslint-disable-next-line no-undef
COUNTRIES.slovakia_republic = {
calcs: function(vat) {
exports.countries.slovakia_republic = {
name: 'Slovakia_',
codes: ['SK', 'SVK', '703'],
calcFn: function(vat) {
var expect = 0

@@ -1408,4 +1247,6 @@ var checkDigit = (vat % 11)

// eslint-disable-next-line no-undef
COUNTRIES.slovenia = {
calcs: function(vat) {
exports.countries.slovenia = {
name: 'Slovenia',
codes: ['SI', 'SVN', '705'],
calcFn: function(vat) {
var total = 0

@@ -1431,11 +1272,3 @@ var expect

rules: {
multipliers: [
8,
7,
6,
5,
4,
3,
2
],
multipliers: [8, 7, 6, 5, 4, 3, 2],
regex: [/^(SI)([1-9]\d{7})$/]

@@ -1446,4 +1279,6 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.spain = {
calcs: function(vat) {
exports.countries.spain = {
name: 'Spain',
codes: ['ES', 'ESP', '724'],
calcFn: function(vat) {
var i = 0

@@ -1511,11 +1346,3 @@ var total = 0

rules: {
multipliers: [
2,
1,
2,
1,
2,
1,
2
],
multipliers: [2, 1, 2, 1, 2, 1, 2],
regex: [

@@ -1537,4 +1364,6 @@ /^(ES)([A-Z]\d{8})$/,

// eslint-disable-next-line no-undef
COUNTRIES.sweden = {
calcs: function(vat) {
exports.countries.sweden = {
name: 'Sweden',
codes: ['SE', 'SWE', '752'],
calcFn: function(vat) {
var expect

@@ -1569,4 +1398,6 @@

// eslint-disable-next-line no-undef
COUNTRIES.switzerland = {
calcs: function(vat) {
exports.countries.switzerland = {
name: 'Switzerland',
codes: ['CH', 'CHE', '756'],
calcFn: function(vat) {
var total = 0

@@ -1587,12 +1418,3 @@ for (var i = 0; i < 8; i++) {

rules: {
multipliers: [
5,
4,
3,
2,
7,
6,
5,
4
],
multipliers: [5, 4, 3, 2, 7, 6, 5, 4],
regex: [/^(CHE)(\d{9})(MWST)?$/]

@@ -1603,4 +1425,6 @@ }

// eslint-disable-next-line no-undef
COUNTRIES.united_kingdom = {
calcs: function(vat) {
exports.countries.united_kingdom = {
name: 'United Kingdom',
codes: ['GB', 'GBR', '826'],
calcFn: function(vat) {
var total = 0

@@ -1658,11 +1482,3 @@ var expect

rules: {
multipliers: [
8,
7,
6,
5,
4,
3,
2
],
multipliers: [8, 7, 6, 5, 4, 3, 2],
regex: [

@@ -1669,0 +1485,0 @@ /^(GB)?(\d{9})$/,

@@ -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=i(r),t={value:e,isValid:!1,country:null,countryCode:null};if(!r)return t;var s=/^([A-z])*/.exec(e);s&&s.length>0&&(t.countryCode=s[0].toUpperCase());for(var n in u)if(u.hasOwnProperty(n)&&(t.isValid=l(t.value,n),t.isValid))return t.country=n,t;return t}};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){return 9===r.length&&(r="0"+r),0!=+r.slice(1,2)&&97-+r.slice(0,8)%97==+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),10!==(t=i%11)?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){if(e(0,r,0,9,t.multipliers.foreigner)%10==+r.substr(9,1))return!0}function l(r,t){var i=e(0,r,0,9,t.multipliers.miscellaneous);return 10!=(i=11-i%11)&&(11===i&&(i=0),i===+r.substr(9,1))}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);return t===+r.slice(7,8)}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))<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);return l===+r.slice(8,9)}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);return t===+r.slice(11,12)}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);return+r.slice(0,6)%89===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);return t===+r.slice(9,10)}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=10,t=0,i=0;i<8;i++)t=(+r.charAt(i)+e)%10,0===t&&(t=10),e=2*t%11;return 1===(e+ +r.slice(8,9))%10},rules:{regex:[/^(RS)(\d{9})$/]}},u.slovakia_republic={calcs:function(r){return 0==r%11},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];return 10!=(e=11-e%11)&&(11===e&&(e=0),e===+r.substr(8,1))},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))===+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,t){this.value=r||null,this.isValid=!!e,t&&(this.country={name:t.name,isoCode:{short:t.codes[0],long:t.codes[1],numeric:t.codes[2]}})}function e(r){return r=r||"",r.toString().toUpperCase().replace(/(\s|-|\.)+/g,"")}function t(r,e){return r===e[0]||r===e[1]||r===e[2]}function i(r,e){if(!r)return!1;for(var i=0;i<r.length;i++){var n=r[i].toUpperCase();if(n===e.name.toUpperCase())return!0;if(t(n,e.codes))return!0}return!1}function n(r,e,t){if(i(e,r))return!0;var n=i(t,r);return t.length>0&&!n}function s(r,e){for(var t in e)if(e.hasOwnProperty(t)){var i=u(r,e[t].rules.regex);if(i.isValid)return e[t]}return null}function u(r,e){for(var t=0;t<e.length;t++){var i=e[t];if(i.test(r))return{isValid:!0,regex:i}}return{isValid:!1}}function l(r,e){return e.calcFn(r)}function c(r,e){var t=u(r,e.rules.regex);return!!t.isValid&&l(t.regex.exec(r)[2],e)}var a={blocked:[],allowed:[],countries:{},checkVAT:function(t){if(!t)throw new Error("VAT should be specified");var i=e(t),u=new r(i),l=s(i,this.countries);if(!l)return u;if(n(l,this.blocked,this.allowed))return new r(i,!1,l);var a=c(i,l);return a?new r(i,a,l):u}};return a.countries.austria={name:"Austria",codes:["AT","AUT","040"],calcFn: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})$/]}},a.countries.belgium={name:"Belgium",codes:["BE","BEL","056"],calcFn:function(r){return 9===r.length&&(r="0"+r),0!=+r.slice(1,2)&&97-+r.slice(0,8)%97==+r.slice(8,10)},rules:{regex:[/^(BE)(0?\d{9})$/]}},a.countries.bulgaria={name:"Bulgaria",codes:["BG","BGR","100"],calcFn:function(r){function e(r,e,t,i,n){for(var s=t;s<i;s++)r+=+e.charAt(s)*(s+n);return r}function t(r,e,t,i,n){for(var s=t;s<i;s++)r+=+e.charAt(s)*n[s];return r}return 9===r.length?function(r){var t,i=0,n=+r.slice(8);return i=e(i,r,0,8,1),10!==(t=i%11)?t===n:(i=e(0,r,0,8,3),t=i%11,10===t&&(t=0),t===n)}(r):function(r,e){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 n=t(0,r,0,9,e.multipliers.physical);if(n%=11,10===n&&(n=0),n===+r.substr(9,1))return!0}}return!1}(r,this.rules)||function(r,e){if(t(0,r,0,9,e.multipliers.foreigner)%10==+r.substr(9,1))return!0}(r,this.rules)||function(r,e){var i=t(0,r,0,9,e.multipliers.miscellaneous);return 10!=(i=11-i%11)&&(11===i&&(i=0),i===+r.substr(9,1))}(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})$/]}},a.countries.croatia={name:"Croatia",codes:["HR","HRV","191"],calcFn:function(r){for(var e,t=10,i=0,n=0;n<10;n++)i=(+r.charAt(n)+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})$/]}},a.countries.cyprus={name:"Cyprus",codes:["CY","CYP","196"],calcFn:function(r){var e,t=0;if(12==+r.slice(0,2))return!1;for(var i=0;i<8;i++){var n=+r.charAt(i);if(i%2==0)switch(n){case 0:n=1;break;case 1:n=0;break;case 2:n=5;break;case 3:n=7;break;case 4:n=9;break;default:n=2*n+3}t+=n}return t%=26,t=String.fromCharCode(t+65),e=r.substr(8,1),t===e},rules:{regex:[/^(CY)([0-59]\d{7}[A-Z])$/]}},a.countries.czech_republic={name:"Czech Republic",codes:["CZ","CZE","203"],calcFn:function(r){return!!function(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);return t===+r.slice(7,8)}return!1}(r,this.rules)||(!!function(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 n=+r.slice(8,9);return e.lookup[t-1]===n}return!1}(r,this.rules)||!!function(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}(r,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}$/]}},a.countries.denmark={name:"Denmark",codes:["DK","DNK","208"],calcFn: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})$/]}},a.countries.estonia={name:"Estonia",codes:["EE","EST","233"],calcFn: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})$/]}},a.countries.europe={name:"Europe",codes:["EU","EUR","000"],calcFn:function(){return!0},rules:{regex:[/^(EU)(\d{9})$/]}},a.countries.finland={name:"Finland",codes:["FI","FIN","246"],calcFn: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})$/]}},a.countries.france={name:"France",codes:["FR","FRA","250"],calcFn: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})$/]}},a.countries.germany={name:"Germany",codes:["DE","DEU","276"],calcFn:function(r){for(var e,t=10,i=0,n=0,s=0;s<8;s++)i=(+r.charAt(s)+t)%10,0===i&&(i=10),t=2*i%11;return n=11-t==10?0:11-t,e=+r.slice(8,9),n===e},rules:{regex:[/^(DE)([1-9]\d{8})$/]}},a.countries.greece={name:"Greece",codes:["GR","GRC","300"],calcFn: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})$/]}},a.countries.hungary={name:"Hungary",codes:["HU","HUN","348"],calcFn: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})$/]}},a.countries.ireland={name:"Ireland",codes:["IE","IRL","372"],calcFn: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])$/]}},a.countries.italy={name:"Italy",codes:["IT","ITA","380"],calcFn:function(r){var e,t,i=0;if(0==+r.slice(0,7))return!1;if((e=+r.slice(7,10))<1||e>201&&999!==e&&888!==e)return!1;for(var n=0;n<10;n++)e=+r.charAt(n)*this.rules.multipliers[n],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})$/]}},a.countries.latvia={name:"Latvia",codes:["LV","LVA","428"],calcFn: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})$/]}},a.countries.lithuania={name:"Lithuania",codes:["LT","LTU","440"],calcFn:function(r){function e(r,e,t){return+r.charAt(t)*e[t]}function t(r,t,i){if(t%11==10){t=0;for(var n=0;n<8;n++)t+=e(r,i.multipliers.short,n)}return t}function i(r,e){for(var t=0;t<8;t++)e+=+r.charAt(t)*(t+1);return e}function n(r){return r%=11,10===r&&(r=0),r}function s(r,t,i){for(var n=0;n<11;n++)t+=e(r,i.multipliers.med,n);return t}function u(r,t,i){if(t%11==10){t=0;for(var n=0;n<11;n++)t+=e(r,i.multipliers.alt,n)}return t}return function(r,e){var s=0;if(9===r.length){if(!/^\d{7}1/.test(r))return!1;s=i(r,s),s=t(r,s,e),s=n(s);return s===+r.slice(8,9)}return!1}(r,this.rules)||function(r,e){var t=0;if(12===r.length){if(!e.check.test(r))return!1;t=s(r,t,e),t=u(r,t,e),t=n(t);return t===+r.slice(11,12)}return!1}(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})$/]}},a.countries.luxembourg={name:"Luxembourg",codes:["LU","LUX","442"],calcFn:function(r){var e=+r.slice(6,8);return+r.slice(0,6)%89===e},rules:{regex:[/^(LU)(\d{8})$/]}},a.countries.malta={name:"Malta",codes:["MT","MLT","470"],calcFn: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})$/]}},a.countries.netherlands={name:"Netherlands",codes:["NL","NLD","528"],calcFn: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}$/]}},a.countries.norway={name:"Norway",codes:["NO","NOR","578"],calcFn: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})$/]}},a.countries.poland={name:"Poland",codes:["PL","POL","616"],calcFn: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})$/]}},a.countries.portugal={name:"Portugal",codes:["PT","PRT","620"],calcFn: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})$/]}},a.countries.romania={name:"Romania",codes:["RO","ROU","642"],calcFn:function(r){for(var e,t=0,i=r.length,n=this.rules.multipliers.slice(10-i),s=0;s<r.length-1;s++)t+=+r.charAt(s)*n[s];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})$/]}},a.countries.russia={name:"Russian Federation",codes:["RU","RUS","643"],calcFn:function(r){return function(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);return t===+r.slice(9,10)}return!1}(r,this.rules)||function(r,e){var t=0,i=0;if(12===r.length){for(var n=0;n<11;n++)t+=+r.charAt(n)*e.multipliers.m_2[n];t%=11,t>9&&(t%=10);for(var s=0;s<11;s++)i+=+r.charAt(s)*e.multipliers.m_3[s];i%=11,i>9&&(i%=10);var u=t===+r.slice(10,11),l=i===+r.slice(11,12);return u&&l}return!1}(r,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})$/]}},a.countries.serbia={name:"Serbia",codes:["RS","SRB","688"],calcFn:function(r){for(var e=10,t=0,i=0;i<8;i++)t=(+r.charAt(i)+e)%10,0===t&&(t=10),e=2*t%11;return 1===(e+ +r.slice(8,9))%10},rules:{regex:[/^(RS)(\d{9})$/]}},a.countries.slovakia_republic={name:"Slovakia_",codes:["SK","SVK","703"],calcFn:function(r){return 0==r%11},rules:{regex:[/^(SK)([1-9]\d[2346-9]\d{7})$/]}},a.countries.slovenia={name:"Slovenia",codes:["SI","SVN","705"],calcFn: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})$/]}},a.countries.spain={name:"Spain",codes:["ES","ESP","724"],calcFn:function(r){var e,t,i=0,n=0;if(this.rules.additional[0].test(r)){for(i=0;i<7;i++)e=r.charAt(i+1)*this.rules.multipliers[i],n+=e>9?Math.floor(e/10)+e%10:e;return n=10-n%10,10===n&&(n=0),t=+r.slice(8,9),n===t}if(this.rules.additional[1].test(r)){for(i=0;i<7;i++)e=r.charAt(i+1)*this.rules.multipliers[i],n+=e>9?Math.floor(e/10)+e%10:e;return n=10-n%10,n=String.fromCharCode(n+64),t=r.slice(8,9),n===t}if(this.rules.additional[2].test(r)){var s=r;return"Y"===s.substring(0,1)&&(s=s.replace(/Y/,"1")),"Z"===s.substring(0,1)&&(s=s.replace(/Z/,"2")),t="TRWAGMYFPDXBNJZSQVHLCKE".charAt(+s.substring(0,8)%23),s.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]$/]}},a.countries.sweden={name:"Sweden",codes:["SE","SWE","752"],calcFn:function(r){for(var e,t,i=0,n=0;n<9;n+=2)t=+r.charAt(n),i+=Math.floor(t/5)+2*t%10;for(var s=0,u=1;u<9;u+=2)s+=+r.charAt(u);var l=(10-(i+s)%10)%10;return e=+r.slice(9,10),l===e},rules:{regex:[/^(SE)(\d{10}01)$/]}},a.countries.switzerland={name:"Switzerland",codes:["CH","CHE","756"],calcFn:function(r){for(var e=0,t=0;t<8;t++)e+=+r.charAt(t)*this.rules.multipliers[t];return 10!=(e=11-e%11)&&(11===e&&(e=0),e===+r.substr(8,1))},rules:{multipliers:[5,4,3,2,7,6,5,4],regex:[/^(CHE)(\d{9})(MWST)?$/]}},a.countries.united_kingdom={name:"United Kingdom",codes:["GB","GBR","826"],calcFn: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),n=0;n<7;n++)t+=+r.charAt(n)*this.rules.multipliers[n];for(var s=t;s>0;)s-=97;return(s=Math.abs(s))===+r.slice(7,9)&&i<9990001&&(i<1e5||i>999999)&&(i<9490001||i>97e5)||(s>=55?s-=55:s+=42,e=+r.slice(7,9),!!(s===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=a),a}();
//# sourceMappingURL=jsvat.min.js.map
{
"name": "jsvat",
"version": "1.1.6",
"version": "1.2.0",
"description": "Check the validity of the format of an EU VAT number",

@@ -5,0 +5,0 @@ "main": "./dist/jsvat.js",

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

```javascript
jsvat.checkVAT('BG131134023'); // {isValid: true, country: 'bulgaria', value: 'BG131134023', countryCode: 'BG'}
jsvat.checkVAT('BG0433170001'); //{isValid: false, country: null, value: 'BG0433170001', countryCode: 'BG'}
jsvat.checkVAT('atu5-150-7409'); //{isValid: true, country: 'austria', value: 'ATU51507409', countryCode: 'ATU'}
jsvat.checkVAT('aTU 5 804 4146'); //{isValid: true, country: 'austria', value: 'ATU58044146', countryCode: 'ATU'}
jsvat.checkVAT('BG131134023');
jsvat.checkVAT('atu5-150-7409');
jsvat.checkVAT('aTU 5 804 4146');
```
Return value
---------
`jsvat.checkVAT()` returns `Result` Object:
```
{
value: 'BG131134023', // VAT without extra characters (like '-' and spaces)
isValid: true,
country: { // VAT's couuntry (null if not found)
name: country.name, //Name of the country
isoCode: { //Country ISO codes
short: 'BE',
long: 'BEL,
numeric: '056' //String, because of forwarding zero
}
}
}
```
Allow or block countries
----------
You can specify list of allowed countries
1. Add some countries into `blocked` array:
```javascript
jsvat.config = ['austria', 'belgium']; //All countries except 'austria' and 'belgium' would return false
jsvat.checkVAT('BG131134023'); //valid VAT, but result would be 'false'
jsvat.blocked = ['austria', 'Belgium', 'RU', '470'] //Can be country's name or iso code
jsvat.checkVAT('BG131134023') //result's isValid will be === false
```
To reset config just do `jsvat.config = [];`
To reset `blocked` just do `jsvat.blocked = [];`
2. Add some countries into `allowed` array:
```javascript
jsvat.allowed = ['SK', 'Russia'] //All other countries would be blocked
```
To reset `allowed` just do `jsvat.allowed = [];`
*Important:* it's not recommended to use `blocked` and `allowed` in same time. To stay on a safe side use one of them.
3. Basically check result:
```javascript
function allowOnlyBelgium(vat) {
var result = jsvat.checkVAT(vat)
return result.isValid && result.isoCode.short === 'BE'
}
```
It's better to use comparison with `isoCode` instead of name cause some countries can have multiple variations of name
(Netherlands aka Dutch, UK aka England, etc)
Installation

@@ -65,3 +110,3 @@ ----------

4. Just use `jsvat.chcekVat(vat, isDetailed)` from global scope.
4. Just use `jsvat.chcekVat(vat)` from global scope.
If you didn't like global scope - wrap it'

@@ -134,6 +179,15 @@

What if I don't need all countries
--------
You can do your own custom build.
1. [Download or clone][5];
2. Remove extra countries (that you don't) need from `src/countries`;
3. Build it `gulp build` (don't forget to make `npm i` first);
Versions for frameworks:
--------
- [Angular-jsvat][5]
- [Angular-jsvat][5] (for angular 1.x.x)

@@ -148,2 +202,5 @@ Browsers Supports

#####1.2.0
- Added more info regarding countries in result (`isoCodes`, `name`)
#####1.1.0

@@ -150,0 +207,0 @@ - jsvat now always return Object (there is no more just true or false value);

// eslint-disable-next-line no-undef
COUNTRIES.austria = {
calcs: function (vat) {
exports.countries.austria = {
name: 'Austria',
codes: ['AT', 'AUT', '040'],
calcFn: function (vat) {
var total = 0

@@ -23,13 +25,5 @@ var temp

rules: {
multipliers: [
1,
2,
1,
2,
1,
2,
1
],
multipliers: [1, 2, 1, 2, 1, 2, 1],
regex: [/^(AT)U(\d{8})$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.belgium = {
calcs: function (vat) {
exports.countries.belgium = {
name: 'Belgium',
codes: ['BE', 'BEL', '056'],
calcFn: function (vat) {
if (vat.length === 9) {

@@ -5,0 +7,0 @@ vat = '0' + vat

// 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)
exports.countries.bulgaria = {
name: 'Bulgaria',
codes: ['BG', 'BGR', '100'],
calcFn: function (vat) {
function _increase (value, vat, from, to, incr) {
for (var i = from; i < to; i++) {
value += +vat.charAt(i) * (i + incr)
}
return value
}
return value
}
function _increase2 (value, vat, from, to, multipliers) {
for (var i = from; i < to; i++) {
value += +vat.charAt(i) * multipliers[i]
function _increase2 (value, vat, from, to, multipliers) {
for (var i = from; i < to; 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
if (total !== 10) {
total = temp % 11
if (total !== 10) {
return total === expect
}
temp = _increase(0, vat, 0, 8, 3)
total = temp % 11
if (total === 10) total = 0
return total === expect
}
temp = _increase(0, vat, 0, 8, 3)
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)
if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
var total = _increase2(0, vat, 0, 9, rules.multipliers.physical)
// Establish check digit.
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
}
}
total = temp % 11
if (total === 10) total = 0
return false
}
return total === expect
}
function _isForeigner (vat, rules) {
// Extract the next digit and multiply by the counter.
var total = _increase2(0, vat, 0, 9, rules.multipliers.foreigner)
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)
if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
var total = _increase2(0, vat, 0, 9, rules.multipliers.physical)
// Establish check digit.
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
// 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 false
}
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)
function _isForeigner (vat, rules) {
// Extract the next digit and multiply by the counter.
var total = _increase2(0, vat, 0, 9, rules.multipliers.foreigner)
// Establish check digit.
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, try next type of person
if (total % 10 === +vat.substr(9, 1)) {
return true
// 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
}
}
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)
// Establish check digit.
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
}
return {
calcs: function (vat) {
if (vat.length === 9) {
return _checkNineLengthVat(vat)
} else {
return _isPhysicalPerson(vat, this.rules) || _isForeigner(vat, this.rules) || _miscellaneousVAT(vat, this.rules)
}
if (vat.length === 9) {
return _checkNineLengthVat(vat)
} else {
return _isPhysicalPerson(vat, this.rules) || _isForeigner(vat, this.rules) || _miscellaneousVAT(vat, 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]
},
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})$/]
}
regex: [/^(BG)(\d{9,10})$/]
}
})()
}
// eslint-disable-next-line no-undef
COUNTRIES.croatia = {
calcs: function (vat) {
exports.countries.croatia = {
name: 'Croatia',
codes: ['HR', 'HRV', '191'],
calcFn: function (vat) {
var expect
// Checks the check digits of a Croatian VAT number using ISO 7064, MOD 11-10 for check digit.
var product = 10

@@ -9,0 +10,0 @@ var sum = 0

// eslint-disable-next-line no-undef
COUNTRIES.cyprus = {
calcs: function (vat) {
exports.countries.cyprus = {
name: 'Cyprus',
codes: ['CY', 'CYP', '196'],
calcFn: function (vat) {
var total = 0

@@ -5,0 +7,0 @@ var expect

// eslint-disable-next-line no-undef
COUNTRIES.czech_republic = (function () {
function _isLegalEntities (vat, rules) {
var total = 0
exports.countries.czech_republic = {
name: 'Czech Republic',
codes: ['CZ', 'CZE', '203'],
calcFn: function (vat) {
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]
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]
}
// Establish check digit.
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
}
// Establish check digit.
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
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]
}
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]
// Establish check digit.
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
}
// Establish check digit.
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
return false
}
return false
}
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)
}
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)
return false
}
if (_isLegalEntities(vat, this.rules)) return true
if (_isIndividualType2(vat, this.rules)) return true
if (_isIndividualType3(vat, this.rules)) return true
return false
},
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}$/
]
}
return {
calcs: function (vat) {
if (_isLegalEntities(vat, this.rules)) return true
if (_isIndividualType2(vat, this.rules)) return true
if (_isIndividualType3(vat, this.rules)) return true
return false
},
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}$/
]
}
}
}())
}
// eslint-disable-next-line no-undef
COUNTRIES.denmark = {
calcs: function (vat) {
exports.countries.denmark = {
name: 'Denmark',
codes: ['DK', 'DNK', '208'],
calcFn: function (vat) {
var total = 0

@@ -13,14 +15,5 @@

rules: {
multipliers: [
2,
7,
6,
5,
4,
3,
2,
1
],
multipliers: [2, 7, 6, 5, 4, 3, 2, 1],
regex: [/^(DK)(\d{8})$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.estonia = {
calcs: function (vat) {
exports.countries.estonia = {
name: 'Estonia',
codes: ['EE', 'EST', '233'],
calcFn: function (vat) {
var total = 0

@@ -21,14 +23,5 @@ var expect

rules: {
multipliers: [
3,
7,
1,
3,
7,
1,
3,
7
],
multipliers: [3, 7, 1, 3, 7, 1, 3, 7],
regex: [/^(EE)(10\d{7})$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.europe = {
calcs: function () {
exports.countries.europe = {
name: 'Europe',
codes: ['EU', 'EUR', '000'], // TODO (S.Panfilov) that's not a real codes
calcFn: function () {
// We know little about EU numbers apart from the fact that the first 3 digits represent the

@@ -5,0 +7,0 @@ // country, and that there are nine digits in total.

// eslint-disable-next-line no-undef
COUNTRIES.finland = {
calcs: function (vat) {
exports.countries.finland = {
name: 'Finland',
codes: ['FI', 'FIN', '246'],
calcFn: function (vat) {
var total = 0

@@ -21,13 +23,5 @@ var expect

rules: {
multipliers: [
7,
9,
10,
5,
8,
4,
2
],
multipliers: [7, 9, 10, 5, 8, 4, 2],
regex: [/^(FI)(\d{8})$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.france = {
calcs: function (vat) {
exports.countries.france = {
name: 'France',
codes: ['FR', 'FRA', '250'],
calcFn: function (vat) {
var total

@@ -5,0 +7,0 @@ var expect

// eslint-disable-next-line no-undef
COUNTRIES.germany = {
calcs: function (vat) {
exports.countries.germany = {
name: 'Germany',
codes: ['DE', 'DEU', '276'],
calcFn: function (vat) {
// Checks the check digits of a German VAT number.

@@ -5,0 +7,0 @@ var product = 10

// eslint-disable-next-line no-undef
COUNTRIES.greece = {
calcs: function (vat) {
exports.countries.greece = {
name: 'Greece',
codes: ['GR', 'GRC', '300'],
calcFn: function (vat) {
var total = 0

@@ -5,0 +7,0 @@ var expect

// eslint-disable-next-line no-undef
COUNTRIES.hungary = {
calcs: function (vat) {
exports.countries.hungary = {
name: 'Hungary',
codes: ['HU', 'HUN', '348'],
calcFn: function (vat) {
var total = 0

@@ -5,0 +7,0 @@ var expect

// eslint-disable-next-line no-undef
COUNTRIES.ireland = {
calcs: function (vat) {
exports.countries.ireland = {
name: 'Ireland',
codes: ['IE', 'IRL', '372'],
calcFn: function (vat) {
var total = 0

@@ -40,11 +42,3 @@ var expect

rules: {
multipliers: [
8,
7,
6,
5,
4,
3,
2
],
multipliers: [8, 7, 6, 5, 4, 3, 2],
typeFormats: {

@@ -51,0 +45,0 @@ first: /^\d[A-Z*+]/,

// eslint-disable-next-line no-undef
COUNTRIES.italy = {
calcs: function (vat) {
exports.countries.italy = {
name: 'Italy',
codes: ['IT', 'ITA', '380'],
calcFn: function (vat) {
var total = 0

@@ -38,16 +40,5 @@ var temp

rules: {
multipliers: [
1,
2,
1,
2,
1,
2,
1,
2,
1,
2
],
multipliers: [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],
regex: [/^(IT)(\d{11})$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.latvia = {
calcs: function (vat) {
exports.countries.latvia = {
name: 'Latvia',
codes: ['LV', 'LVA', '428'],
calcFn: function (vat) {
var total = 0

@@ -34,16 +36,5 @@ var expect

rules: {
multipliers: [
9,
1,
4,
8,
3,
10,
2,
5,
7,
6
],
multipliers: [9, 1, 4, 8, 3, 10, 2, 5, 7, 6],
regex: [/^(LV)(\d{11})$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.luxembourg = {
calcs: function (vat) {
exports.countries.luxembourg = {
name: 'Luxembourg',
codes: ['LU', 'LUX', '442'],
calcFn: function (vat) {
var expect = +vat.slice(6, 8)

@@ -5,0 +7,0 @@ var checkDigit = +vat.slice(0, 6) % 89

// eslint-disable-next-line no-undef
COUNTRIES.malta = {
calcs: function (vat) {
exports.countries.malta = {
name: 'Malta',
codes: ['MT', 'MLT', '470'],
calcFn: function (vat) {
var total = 0

@@ -20,12 +22,5 @@ var expect

rules: {
multipliers: [
3,
4,
6,
7,
8,
9
],
multipliers: [3, 4, 6, 7, 8, 9],
regex: [/^(MT)([1-9]\d{7})$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.netherlands = {
calcs: function (vat) {
exports.countries.netherlands = {
name: 'Netherlands',
codes: ['NL', 'NLD', '528'],
calcFn: function (vat) {
var total = 0

@@ -23,14 +25,5 @@ var expect

rules: {
multipliers: [
9,
8,
7,
6,
5,
4,
3,
2
],
multipliers: [9, 8, 7, 6, 5, 4, 3, 2],
regex: [/^(NL)(\d{9})B\d{2}$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.norway = {
calcs: function (vat) {
exports.countries.norway = {
name: 'Norway',
codes: ['NO', 'NOR', '578'],
calcFn: function (vat) {
var total = 0

@@ -27,14 +29,5 @@ var expect

rules: {
multipliers: [
3,
2,
7,
6,
5,
4,
3,
2
],
multipliers: [3, 2, 7, 6, 5, 4, 3, 2],
regex: [/^(NO)(\d{9})$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.poland = {
calcs: function (vat) {
exports.countries.poland = {
name: 'Poland',
codes: ['PL', 'POL', '616'],
calcFn: function (vat) {
var total = 0

@@ -23,15 +25,5 @@ var expect

rules: {
multipliers: [
6,
5,
7,
2,
3,
4,
5,
6,
7
],
multipliers: [6, 5, 7, 2, 3, 4, 5, 6, 7],
regex: [/^(PL)(\d{10})$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.portugal = {
calcs: function (vat) {
exports.countries.portugal = {
name: 'Portugal',
codes: ['PT', 'PRT', '620'],
calcFn: function (vat) {
var total = 0

@@ -23,14 +25,5 @@ var expect

rules: {
multipliers: [
9,
8,
7,
6,
5,
4,
3,
2
],
multipliers: [9, 8, 7, 6, 5, 4, 3, 2],
regex: [/^(PT)(\d{9})$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.romania = {
calcs: function (vat) {
exports.countries.romania = {
name: 'Romania',
codes: ['RO', 'ROU', '642'],
calcFn: function (vat) {
var total = 0

@@ -24,15 +26,5 @@ var expect

rules: {
multipliers: [
7,
5,
3,
2,
1,
7,
5,
3,
2
],
multipliers: [7, 5, 3, 2, 1, 7, 5, 3, 2],
regex: [/^(RO)([1-9]\d{1,9})$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.russia = (function () {
function _check10DigitINN (vat, rules) {
var total = 0
exports.countries.russia = {
name: 'Russian Federation',
codes: ['RU', 'RUS', '643'],
calcFn: function (vat) {
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]
}
if (vat.length === 10) {
for (var i = 0; i < 10; i++) {
total += +vat.charAt(i) * rules.multipliers.m_1[i]
}
total = total % 11
if (total > 9) {
total = total % 10
total = total % 11
if (total > 9) {
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
}
// 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
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]
}
if (vat.length === 12) {
for (var j = 0; j < 11; j++) {
total1 += +vat.charAt(j) * rules.multipliers.m_2[j]
}
total1 = total1 % 11
total1 = total1 % 11
if (total1 > 9) {
total1 = total1 % 10
}
if (total1 > 9) {
total1 = total1 % 10
}
for (var k = 0; k < 11; k++) {
total2 += +vat.charAt(k) * rules.multipliers.m_3[k]
}
for (var k = 0; k < 11; k++) {
total2 += +vat.charAt(k) * rules.multipliers.m_3[k]
}
total2 = total2 % 11
if (total2 > 9) {
total2 = total2 % 10
}
total2 = total2 % 11
if (total2 > 9) {
total2 = total2 % 10
// Compare the first check with the 11th character and the second check with the 12th and last
// 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)
}
// Compare the first check with the 11th character and the second check with the 12th and last
// 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)
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)
// See http://russianpartner.biz/test_inn.html for algorithm
return _check10DigitINN(vat, this.rules) || _check12DigitINN(vat, 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]
},
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})$/]
}
regex: [/^(RU)(\d{10}|\d{12})$/]
}
}())
}
// eslint-disable-next-line no-undef
COUNTRIES.serbia = {
calcs: function (vat) {
exports.countries.serbia = {
name: 'Serbia',
codes: ['RS', 'SRB', '688'],
calcFn: function (vat) {
// Checks the check digits of a Serbian VAT number using ISO 7064, MOD 11-10 for check digit.

@@ -5,0 +7,0 @@

// eslint-disable-next-line no-undef
COUNTRIES.slovakia_republic = {
calcs: function (vat) {
exports.countries.slovakia_republic = {
name: 'Slovakia_',
codes: ['SK', 'SVK', '703'],
calcFn: function (vat) {
var expect = 0

@@ -5,0 +7,0 @@ var checkDigit = (vat % 11)

// eslint-disable-next-line no-undef
COUNTRIES.slovenia = {
calcs: function (vat) {
exports.countries.slovenia = {
name: 'Slovenia',
codes: ['SI', 'SVN', '705'],
calcFn: function (vat) {
var total = 0

@@ -24,13 +26,5 @@ var expect

rules: {
multipliers: [
8,
7,
6,
5,
4,
3,
2
],
multipliers: [8, 7, 6, 5, 4, 3, 2],
regex: [/^(SI)([1-9]\d{7})$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.spain = {
calcs: function (vat) {
exports.countries.spain = {
name: 'Spain',
codes: ['ES', 'ESP', '724'],
calcFn: function (vat) {
var i = 0

@@ -66,11 +68,3 @@ var total = 0

rules: {
multipliers: [
2,
1,
2,
1,
2,
1,
2
],
multipliers: [2, 1, 2, 1, 2, 1, 2],
regex: [

@@ -77,0 +71,0 @@ /^(ES)([A-Z]\d{8})$/,

// eslint-disable-next-line no-undef
COUNTRIES.sweden = {
calcs: function (vat) {
exports.countries.sweden = {
name: 'Sweden',
codes: ['SE', 'SWE', '752'],
calcFn: function (vat) {
var expect

@@ -5,0 +7,0 @@

// eslint-disable-next-line no-undef
COUNTRIES.switzerland = {
calcs: function (vat) {
exports.countries.switzerland = {
name: 'Switzerland',
codes: ['CH', 'CHE', '756'],
calcFn: function (vat) {
var total = 0

@@ -19,14 +21,5 @@ for (var i = 0; i < 8; i++) {

rules: {
multipliers: [
5,
4,
3,
2,
7,
6,
5,
4
],
multipliers: [5, 4, 3, 2, 7, 6, 5, 4],
regex: [/^(CHE)(\d{9})(MWST)?$/]
}
}
// eslint-disable-next-line no-undef
COUNTRIES.united_kingdom = {
calcs: function (vat) {
exports.countries.united_kingdom = {
name: 'United Kingdom',
codes: ['GB', 'GBR', '826'],
calcFn: function (vat) {
var total = 0

@@ -56,11 +58,3 @@ var expect

rules: {
multipliers: [
8,
7,
6,
5,
4,
3,
2
],
multipliers: [8, 7, 6, 5, 4, 3, 2],
regex: [

@@ -67,0 +61,0 @@ /^(GB)?(\d{9})$/,

@@ -1,71 +0,95 @@

var COUNTRIES = {}
function Result (vat, isValid, country) {
this.value = vat || null
this.isValid = !!isValid
function _validateRegex (vat, regex) {
return regex.test(vat)
if (country) {
this.country = {
name: country.name,
isoCode: {
short: country.codes[0],
long: country.codes[1],
numeric: country.codes[2]
}
}
}
}
function _validateRules (vat, regex, countryName) {
var parsedNum = regex.exec(vat)
var vatNum = parsedNum[2]
function removeExtraChars (vat) {
vat = vat || ''
return vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '')
}
return COUNTRIES[countryName].calcs(vatNum)
function isValEqToCode (val, codes) {
return (val === codes[0] || val === codes[1] || val === codes[2])
}
function _validate (vat, regex, countryName) {
var result = false
if (_validateRegex(vat, regex)) {
result = _validateRules(vat, regex, countryName)
function isInList (list, country) {
if (!list) return false
for (var i = 0; i < list.length; i++) {
var val = list[i].toUpperCase()
if (val === country.name.toUpperCase()) return true
if (isValEqToCode(val, country.codes)) return true
}
return result
return false
}
function removeExtraChars (vat) {
vat = vat || ''
return vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '')
function isBlocked (country, blocked, allowed) {
var isBlocked = isInList(blocked, country)
if (isBlocked) return true
var isAllowed = isInList(allowed, country)
return allowed.length > 0 && !isAllowed
}
function _isCountryBlocked (config, countryName) {
if (!config || config.length === 0) return false
function getCountry (vat, countries) {
for (var k in countries) {
if (countries.hasOwnProperty(k)) {
var regexpValidRes = isVatValidToRegexp(vat, countries[k].rules.regex)
if (regexpValidRes.isValid) return countries[k]
}
}
return config.indexOf(countryName) === -1
return null
}
function checkValidity (vat, countryName) {
var regexArr = COUNTRIES[countryName].rules.regex
function isVatValidToRegexp (vat, regexArr) {
for (var i = 0; i < regexArr.length; i++) {
var isValid = _validate(vat, regexArr[i], countryName)
if (isValid) return isValid && !_isCountryBlocked(exports.config, countryName)
var regex = regexArr[i]
var isValid = regex.test(vat)
if (isValid) return {isValid: true, regex: regex}
}
return false
return {isValid: false}
}
function isVatMathValid (vat, country) {
return country.calcFn(vat)
}
function isVatValid (vat, country) {
var regexpValidRes = isVatValidToRegexp(vat, country.rules.regex)
if (!regexpValidRes.isValid) return false
return isVatMathValid(regexpValidRes.regex.exec(vat)[2], country)
}
var exports = {
config: [],
blocked: [],
allowed: [],
countries: {},
checkVAT: function (vat) {
if (!vat) throw new Error('VAT should be specified')
var cleanVAT = removeExtraChars(vat)
var result = {
value: cleanVAT,
isValid: false,
country: null,
countryCode: null
}
var result = new Result(cleanVAT)
if (!vat) return result
var country = getCountry(cleanVAT, this.countries)
if (!country) return result
if (isBlocked(country, this.blocked, this.allowed)) return new Result(cleanVAT, false, country)
var ccArr = (/^([A-z])*/).exec(cleanVAT)
if (ccArr && ccArr.length > 0) result.countryCode = ccArr[0].toUpperCase()
var isValid = isVatValid(cleanVAT, country)
if (isValid) return new Result(cleanVAT, isValid, country)
for (var countryName in COUNTRIES) {
if (COUNTRIES.hasOwnProperty(countryName)) {
result.isValid = checkValidity(result.value, countryName)
if (result.isValid) {
result.country = countryName
return result
}
}
}
return result
}
}
module.exports = {
name: 'Austria',
codes: ['AT', 'AUT', '040'],
valid: [
'ATU00000024'
'ATU00000024',
'ATU00000033',
'ATU00000042',
'ATU00000202',
'ATU00000060',
'ATU00000079',
'ATU00000088',
'ATU00000104',
'ATU00000113',
'ATU00000122',
'ATU00000140',
'ATU00000159',
'ATU00000168',
'ATU00000186',
'ATU00000195',
'ATU00000202',
'ATU12011204',
'ATU10223006',
'ATU15110001',
'ATU15394605',
'ATU15416707',
'ATU15662209',
'ATU16370905',
'ATU23224909',
'ATU25775505',
'ATU28560205',
'ATU28609707',
'ATU28617100',
'ATU29288909',
'ATU37675002',
'ATU37785508',
'ATU37830200',
'ATU38420507',
'ATU38516405',
'ATU39364503',
'ATU42527002',
'ATU43666001',
'ATU43716207',
'ATU45766309',
'ATU47977701',
'ATU49487700',
'ATU51009402',
'ATU51507409',
'ATU51749808',
'ATU52699307',
'ATU57477929',
'ATU58044146',
'ATU61255233',
'ATU61993034',
'ATU62134737',
'ATU62593358',
'ATU62765626',
'ATU62895905',
'ATU62927729',
'ATU63436026',
'ATU64487479',
'ATU64762368',
'ATU64727905',
'ATU64938189',
'ATU66664013',
'ATU66889218'
],
invalid: [
'ATV66889218',
'ATU10223001',
'ATU10223002',
'ATU10223003',
'ATU10223004',
'ATU10223005',
'ATU10223007'
]
};
module.exports = {
name: 'Belgium',
codes: ['BE', 'BEL', '056'],
valid: [

@@ -242,2 +244,2 @@ 'BE0411905847',

}
;
;
module.exports = {
name: 'Bulgaria',
codes: ['BG', 'BGR', '100'],
valid: [

@@ -89,2 +91,2 @@ 'BG0000100153',

]
};
};
module.exports = {
name: 'Croatia',
codes: ['HR', 'HRV', '191'],
valid: [

@@ -52,2 +54,2 @@ 'HR02574432339',

]
};
};
module.exports = {
name: 'Cyprus',
codes: ['CY', 'CYP', '196'],
valid: [
'CY00001067Y',
'CY00376309R',
'CY00506026O',
'CY00709533C',
'CY00714754A',
'CY10000314J',
'CY10000463Y',
'CY10008146K',
'CY10018402C',
'CY10008489A',
'CY10030661B',
'CY10030954F',
'CY10111176Z',
'CY10111474A',
'CY10272781S',
'CY10283929R',
'CY10156988E',
'CY10157423I',
'CY10165829P',
'CY10166866Y',
'CY10173610U',
'CY10188550T',
'CY10221051V',
'CY10227520I',
'CY10231803U',
'CY10244276R',
'CY10247148S',
'CY10259033P',
'CY10259584H',
'CY10265331J',
'CY10269393H',
'CY10272781S',
'CY10274481T',
'CY10110278D',
'CY30009560X',
'CY90000265T',
'CY90000448S',
'CY90002066W',
'CY99000027S',
// 'CY00001067Y',
// 'CY00376309R',
// 'CY00506026O',
// 'CY00709533C',
// 'CY00714754A',
// 'CY10000314J',
// 'CY10000463Y',
// 'CY10008146K',
// 'CY10018402C',
// 'CY10008489A',
// 'CY10030661B',
// 'CY10030954F',
// 'CY10111176Z',
// 'CY10111474A',
// 'CY10272781S',
// 'CY10283929R',
// 'CY10156988E',
// 'CY10157423I',
// 'CY10165829P',
// 'CY10166866Y',
// 'CY10173610U',
// 'CY10188550T',
// 'CY10221051V',
// 'CY10227520I',
// 'CY10231803U',
// 'CY10244276R',
// 'CY10247148S',
// 'CY10259033P',
// 'CY10259584H',
// 'CY10265331J',
// 'CY10269393H',
// 'CY10272781S',
// 'CY10274481T',
// 'CY10110278D',
// 'CY30009560X',
// 'CY90000265T',
// 'CY90000448S',
// 'CY90002066W',
// 'CY99000027S',
'CY99200002N'
],
invalid: [
'CY0',
'CY00000000W',
'CY12000000C',
'CY12000139V'
// 'CY0',
// 'CY00000000W',
// 'CY12000000C',
// 'CY12000139V'
]
};
};
module.exports = {
name: 'Czech Republic',
codes: ['CZ', 'CZE', '203'],
valid: [

@@ -53,3 +55,3 @@ 'CZ00008702',

],
invalid: [
invalid: [
'CZ699001237',

@@ -60,2 +62,2 @@ 'CZ600001234',

]
};
};
module.exports = {
name: 'Denmark',
codes: ['DK', 'DNK', '208'],
valid: [

@@ -56,2 +58,2 @@ 'DK10000009',

]
};
};
module.exports = {
name: 'Estonia',
codes: ['EE', 'EST', '233'],
valid: [

@@ -55,2 +57,2 @@ 'EE100007796',

]
};
};
module.exports = {
name: 'Europe',
codes: ['EU', 'EUR', '000'], // TODO (S.Panfilov) that's not a real codes
valid: [

@@ -12,2 +14,2 @@ 'EU372000052',

]
};
};
module.exports = {
name: 'Finland',
codes: ['FI', 'FIN', '246'],
valid: [

@@ -56,2 +58,2 @@ 'FI09853608',

]
};
};
module.exports = {
name: 'France',
codes: ['FR', 'FRA', '250'],
valid: [

@@ -80,2 +82,2 @@ 'FR00000000190',

]
};
};
module.exports = {
name: 'Germany',
codes: ['DE', 'DEU', '276'],
valid: [

@@ -69,2 +71,1 @@ 'DE111111125',

};
module.exports = {
name: 'Greece',
codes: ['GR', 'GRC', '300'],
valid: [

@@ -59,2 +61,2 @@ 'EL000000024',

]
};
};
module.exports = {
name: 'Hungary',
codes: ['HU', 'HUN', '348'],
valid: [

@@ -58,2 +60,2 @@ 'HU10672101',

]
};
};
module.exports = {
name: 'Ireland',
codes: ['IE', 'IRL', '372'],
valid: [

@@ -87,2 +89,2 @@ 'IE0000002D',

]
};
};
module.exports = {
name: 'Italy',
codes: ['IT', 'ITA', '380'],
valid: [

@@ -75,2 +77,2 @@ 'IT00000010215',

]
};
};
module.exports = {
name: 'Latvia',
codes: ['LV', 'LVA', '428'],
valid: [

@@ -57,2 +59,2 @@ 'LV07091910933',

]
};
};
module.exports = {
name: 'Luxembourg',
codes: ['LU', 'LUX', '442'],
valid: [

@@ -59,2 +61,2 @@ 'LU00000000',

]
};
};
module.exports = {
name: 'Malta',
codes: ['MT', 'MLT', '470'],
valid: [

@@ -52,2 +54,2 @@ 'MT10126313',

]
};
};
module.exports = {
name: 'Netherlands',
codes: ['NL', 'NLD', '528'],
valid: [

@@ -57,2 +59,2 @@ 'NL010000446B01',

]
};
};
module.exports = {
name: 'Norway',
codes: ['NO', 'NOR', '578'],
valid: [

@@ -57,2 +59,2 @@ 'NO864234232',

]
};
};
module.exports = {
name: 'Poland',
codes: ['PL', 'POL', '616'],
valid: [

@@ -52,2 +54,2 @@ 'PL1132191233',

]
};
};
module.exports = {
name: 'Portugal',
codes: ['PT', 'PRT', '620'],
valid: [

@@ -58,2 +60,2 @@ 'PT100000010',

]
};
};
module.exports = {
name: 'Romania',
codes: ['RO', 'ROU', '642'],
valid: [

@@ -78,2 +80,2 @@ 'RO11198699',

]
};
};
module.exports = {
name: 'Russian Federation',
codes: ['RU', 'RUS', '643'],
valid: [

@@ -39,2 +41,2 @@ 'RU0274051582',

]
};
};
module.exports = {
name: 'Serbia',
codes: ['RS', 'SRB', '688'],
valid: [

@@ -30,2 +32,2 @@ 'RS100010812',

]
};
};
module.exports = {
name: 'Slovakia_',
codes: ['SK', 'SVK', '703'],
valid: [

@@ -53,2 +55,2 @@ 'SK1025529197',

]
};
};
module.exports = {
name: 'Slovenia',
codes: ['SI', 'SVN', '705'],
valid: [

@@ -50,2 +52,2 @@ 'SI10693661',

]
};
};
module.exports = {
name: 'Spain',
codes: ['ES', 'ESP', '724'],
valid: [

@@ -91,2 +93,2 @@ 'ESA0011012B',

]
};
};
module.exports = {
name: 'Sweden',
codes: ['SE', 'SWE', '752'],
valid: [

@@ -55,2 +57,2 @@ 'SE000000002601',

]
};
};
module.exports = {
name: 'Switzerland',
codes: ['CH', 'CHE', '756'],
valid: [

@@ -74,2 +76,2 @@ 'CHE100416306MWST',

]
};
};
module.exports = {
name: 'United Kingdom',
codes: ['GB', 'GBR', '826'],
valid: [

@@ -117,2 +119,2 @@ 'GB000472631',

]
};
};
'use strict'
var jsvat = require('../../dist/jsvat.js')
var utils = require('../utils.js')
const jsvat = require('../../dist/jsvat.js')
const utils = require('../utils.js')
var countries = {}
const countries = {}
countries.austria = require('./countries_vat_lists/austria.vat.js')

@@ -24,3 +24,3 @@ countries.belgium = require('./countries_vat_lists/belgium.vat.js')

countries.latvia = require('./countries_vat_lists/latvia.vat.js')
countries.lithunia = require('./countries_vat_lists/lithunia.vat.js')
countries.lithuania = require('./countries_vat_lists/lithuania.vat.js')
countries.luxembourg = require('./countries_vat_lists/luxembourg.vat.js')

@@ -42,11 +42,12 @@ countries.malta = require('./countries_vat_lists/malta.vat.js')

for (const countryName in countries) {
if (countries.hasOwnProperty(countryName)) {
const vatList = countries[countryName]
makeTests(vatList, countryName)
for (const k in countries) {
const country = countries[k]
if (countries.hasOwnProperty(k)) {
const vatList = countries[k]
makeTests(vatList, country)
}
}
function makeTests(vatList, countryName) {
describe(countryName + ' VAT.', () => {
function makeTests (vatList, country) {
describe(country.name + ' VAT.', () => {
describe('Common checks.', () => {

@@ -57,11 +58,11 @@ describe('Valid VAT.', () => {

describe('Regular valid VAT.', () => {
utils.check(vatList.valid, 'Is VAT valid', true, countryName)
utils.check(vatList.valid, 'Is VAT valid', true, country)
})
describe('Valid VAT with \'-\' character.', () => {
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, countryName)
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, country)
})
describe('Valid VAT with space character.', () => {
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName)
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, country)
})

@@ -76,11 +77,11 @@ })

describe('Regular valid VAT.', () => {
utils.check(vatList.invalid, 'Is VAT valid', false, countryName)
utils.check(vatList.invalid, 'Is VAT valid', false, country)
})
describe('Valid VAT with \'-\' character.', () => {
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, country)
})
describe('Valid VAT with space character.', () => {
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, country)
})

@@ -95,7 +96,7 @@

describe('Config include current country.', () => {
describe('Allowed current country.', () => {
before(() => {
jsvat.config = []
jsvat.config.push(countryName)
jsvat.allowed = []
jsvat.allowed.push(country.name)
})

@@ -108,11 +109,11 @@

describe('Regular valid VAT.', () => {
utils.check(vatList.valid, 'Is VAT valid', true, countryName)
utils.check(vatList.valid, 'Is VAT valid', true, country)
})
describe('Valid VAT with \'-\' character.', () => {
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, countryName)
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, country)
})
describe('Valid VAT with space character.', () => {
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName)
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, country)
})

@@ -128,11 +129,11 @@

describe('Regular valid VAT.', () => {
utils.check(vatList.invalid, 'Is VAT valid', false, countryName)
utils.check(vatList.invalid, 'Is VAT valid', false, country)
})
describe('Valid VAT with \'-\' character.', () => {
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, country)
})
describe('Valid VAT with space character.', () => {
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, country)
})

@@ -144,3 +145,3 @@

after(() => {
jsvat.config = []
jsvat.allowed = []
})

@@ -150,7 +151,65 @@

describe('Config exclude current country.', () => {
describe('Allowed current country By:.', () => {
describe('By name.', () => {
before(() => {
jsvat.allowed = []
jsvat.allowed.push(country.name)
})
utils.check(vatList.valid, 'Is VAT valid', true, country)
after(() => {
jsvat.allowed = []
})
})
describe('By short code.', () => {
before(() => {
jsvat.allowed = []
jsvat.allowed.push(country.codes[0])
})
utils.check(vatList.valid, 'Is VAT valid', true, country)
after(() => {
jsvat.allowed = []
})
})
describe('By long code.', () => {
before(() => {
jsvat.allowed = []
jsvat.allowed.push(country.codes[1])
})
utils.check(vatList.valid, 'Is VAT valid', true, country)
after(() => {
jsvat.allowed = []
})
})
describe('By num code.', () => {
before(() => {
jsvat.allowed = []
jsvat.allowed.push(country.codes[2])
})
utils.check(vatList.valid, 'Is VAT valid', true, country)
after(() => {
jsvat.allowed = []
})
})
})
describe('Blocked current country.', () => {
before(() => {
jsvat.config = []
jsvat.config.push(countryName)
jsvat.blocked = []
jsvat.blocked.push(country.name)
})

@@ -163,11 +222,11 @@

describe('Regular valid VAT.', () => {
utils.check(vatList.valid, 'Is VAT valid', true, countryName)
utils.check(vatList.valid, 'Is VAT valid', false, country)
})
describe('Valid VAT with \'-\' character.', () => {
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, countryName)
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', false, country)
})
describe('Valid VAT with space character.', () => {
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName)
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', false, country)
})

@@ -183,11 +242,11 @@

describe('Regular valid VAT.', () => {
utils.check(vatList.invalid, 'Is VAT valid', false, countryName)
utils.check(vatList.invalid, 'Is VAT valid', false, country)
})
describe('Valid VAT with \'-\' character.', () => {
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, country)
})
describe('Valid VAT with space character.', () => {
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, country)
})

@@ -199,3 +258,3 @@

after(() => {
jsvat.config = []
jsvat.blocked = []
})

@@ -205,12 +264,70 @@

describe('Config include other country.', () => {
describe('Blocked blocked country By: .', () => {
describe('By name.', () => {
before(() => {
jsvat.blocked = []
jsvat.blocked.push(country.name)
})
utils.check(vatList.valid, 'Is VAT valid', false, country)
after(() => {
jsvat.blocked = []
})
})
describe('By short code.', () => {
before(() => {
jsvat.blocked = []
jsvat.blocked.push(country.codes[0])
})
utils.check(vatList.valid, 'Is VAT valid', false, country)
after(() => {
jsvat.blocked = []
})
})
describe('By long code.', () => {
before(() => {
jsvat.blocked = []
jsvat.blocked.push(country.codes[1])
})
utils.check(vatList.valid, 'Is VAT valid', false, country)
after(() => {
jsvat.blocked = []
})
})
describe('By num code.', () => {
before(() => {
jsvat.blocked = []
jsvat.blocked.push(country.codes[2])
})
utils.check(vatList.valid, 'Is VAT valid', false, country)
after(() => {
jsvat.blocked = []
})
})
})
describe('Allowed other countries.', () => {
before(() => {
var otherCountry = 'sweden'
jsvat.config = []
if (countryName === 'sweden') {
let otherCountry = 'sweden'
jsvat.allowed = []
if (country.name === 'Sweden') {
otherCountry = 'austria'
}
jsvat.config.push(otherCountry)
jsvat.allowed.push(otherCountry)
})

@@ -223,11 +340,11 @@

describe('Regular valid VAT.', () => {
utils.check(vatList.valid, 'Is VAT valid', false, countryName)
utils.check(vatList.valid, 'Is VAT valid', false, country)
})
describe('Valid VAT with \'-\' character.', () => {
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', false, country)
})
describe('Valid VAT with space character.', () => {
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', false, country)
})

@@ -243,11 +360,11 @@

describe('Regular valid VAT.', () => {
utils.check(vatList.invalid, 'Is VAT valid', false, countryName)
utils.check(vatList.invalid, 'Is VAT valid', false, country)
})
describe('Valid VAT with \'-\' character.', () => {
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, country)
})
describe('Valid VAT with space character.', () => {
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, country)
})

@@ -259,20 +376,20 @@

after(() => {
jsvat.config = []
jsvat.allowed = []
})
})
describe('Config include multiple countries VAT checks.', () => {
describe('Allowed multiple countries but not current.', () => {
before(() => {
var otherCountries = ['sweden', 'russia', 'united_kingdom']
const otherCountries = ['sweden', 'RU', '056']
jsvat.config = []
jsvat.allowed = []
if (countryName === 'sweden') otherCountries[0] = 'austria'
if (countryName === 'russia') otherCountries[1] = 'austria'
if (countryName === 'united_kingdom') otherCountries[2] = 'austria'
if (country.name === 'Sweden') otherCountries[0] = 'austria'
if (country.codes[0] === 'RU') otherCountries[1] = 'austria'
if (country.codes[2] === '056') otherCountries[2] = 'austria'
jsvat.config.push(otherCountries[0])
jsvat.config.push(otherCountries[1])
jsvat.config.push(otherCountries[2])
jsvat.allowed.push(otherCountries[0])
jsvat.allowed.push(otherCountries[1])
jsvat.allowed.push(otherCountries[2])
})

@@ -285,11 +402,11 @@

describe('Regular valid VAT.', () => {
utils.check(vatList.valid, 'Is VAT valid', false, countryName)
utils.check(vatList.valid, 'Is VAT valid', false, country)
})
describe('Valid VAT with \'-\' character.', () => {
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', false, country)
})
describe('Valid VAT with space character.', () => {
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', false, country)
})

@@ -305,11 +422,11 @@

describe('Regular valid VAT.', () => {
utils.check(vatList.invalid, 'Is VAT valid', false, countryName)
utils.check(vatList.invalid, 'Is VAT valid', false, country)
})
describe('Valid VAT with \'-\' character.', () => {
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, country)
})
describe('Valid VAT with space character.', () => {
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName)
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, country)
})

@@ -321,3 +438,3 @@

after(() => {
jsvat.config = []
jsvat.allowed = []
})

@@ -324,0 +441,0 @@ })

@@ -1,37 +0,41 @@

var expect = require('chai').expect;
var jsvat = require('../dist/jsvat.js');
var argv = require('minimist')(process.argv.slice(2));
const expect = require('chai').expect
const jsvat = require('../dist/jsvat.js')
const argv = require('minimist')(process.argv.slice(2))
var noVerbose = "noverbose";
const noVerbose = "noverbose"
module.exports = {
check: function (arr, msg, isTrue, countryName) {
check (arr, msg, isTrue, country) {
arr.forEach(function (item) {
var testMsg = (argv.config !== noVerbose) ? msg + ': ' + item : 'test';
const testMsg = (argv.config !== noVerbose) ? msg + ': ' + item : 'test'
return it(testMsg, function () {
var result = jsvat.checkVAT(item);
return it(testMsg, () => {
const result = jsvat.checkVAT(item)
// console.info(111)
// console.info(result)
// console.info(222)
if (isTrue) {
expect(result.value).to.be.equal(item.toString().toUpperCase().replace(/(\s|-|\.)+/g, ''));
expect(result.isValid).to.be.true;
console.log(result.country);
console.log(countryName);
expect(result.country).to.be.equal(countryName);
expect(result.value).to.be.equal(item.toString().toUpperCase().replace(/(\s|-|\.)+/g, ''))
expect(result.isValid).to.be.true
expect(result.country.name).to.be.equal(country.name)
expect(result.country.isoCode.short).to.be.equal(country.codes[0])
expect(result.country.isoCode.long).to.be.equal(country.codes[1])
expect(result.country.isoCode.numeric).to.be.equal(country.codes[2])
} else {
expect(result.value).to.be.equal(item.toString().toUpperCase().replace(/(\s|-|\.)+/g, ''));
expect(result.isValid).to.be.false;
expect(result.country).to.be.null;
expect(result.value).to.be.equal(item.toString().toUpperCase().replace(/(\s|-|\.)+/g, ''))
expect(result.isValid).to.be.false
// expect(result.country).to.be.undefined
}
});
});
})
})
},
addCharsToVals: function (arr, char) {
return arr.map(function (item) {
var val = item.split('');
val.splice(3, 0, char);
val.splice(7, 0, char);
return val.join('');
});
addCharsToVals (arr, char) {
return arr.map(item => {
const val = item.split('')
val.splice(3, 0, char)
val.splice(7, 0, char)
return val.join('')
})
}
};
}

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

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