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.0.0 to 1.1.0

2

bower.json
{
"name": "jsvat",
"version": "1.0.0",
"version": "1.1.0",
"description": "Check the validity of the format of an EU VAT number",

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

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

function getClearVAT(vat) {
function _getPureVAT(vat) {
vat = vat || '';
return vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '');
}
function _makeArr(regex) {
if (!Array.isArray(regex)) {
return [regex];
}
function _isCountryBlocked(config, countryName) {
if (!config || config.length === 0) return false;
return regex;
return config.indexOf(countryName) === -1;
}
function isCountryBlocked(config, countryName) {
if (!config || Object.keys(config).length === 0) return false;
var country = config[countryName];
return (country === null || country === null) ? true : !country;
function checkValidity(vat, countryName) {
var regexArr = COUNTRIES[countryName].rules.regex;
for (var i = 0; i < regexArr.length; i++) {
var isValid = _validate(vat, regexArr[i], countryName);
if (isValid) return isValid && !_isCountryBlocked(exports.config, countryName);
}
return false;
}
var exports = {
config: {},
checkVAT: function(vat, isDetailed) {
if (!vat) return false;
vat = getClearVAT(vat);
config: [],
checkVAT: function(vat) {
var result = {
value: _getPureVAT(vat),
isValid: false,
countries: []
country: null
};
if (!vat) return result;
for (var countryName in COUNTRIES) {
if (COUNTRIES.hasOwnProperty(countryName)) {
//Make sure country check not skipped in config
if (!isCountryBlocked(exports.config, countryName)) {
result.isValid = checkValidity(result.value, countryName);
var regexArr = _makeArr(COUNTRIES[countryName].rules.regex);
for (var i = 0; i < regexArr.length; i++) {
//If once become a true, shouldn't be a false any more
result.isValid = (_validate(vat, regexArr[i], countryName)) ? true : result.isValid;
if (!isDetailed && result.isValid) return result.isValid;
var isValidForCurrCountry = _validate(vat, regexArr[i], countryName);
if (isValidForCurrCountry) {
result.countries.push(countryName);
}
}
if (result.isValid) {
result.country = countryName;
return result;
}

@@ -85,3 +70,3 @@ }

return isDetailed ? result : result.isValid;
return result;

@@ -120,3 +105,3 @@ }

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

@@ -136,3 +121,3 @@ };

rules: {
regex: /^(BE)(0?\d{9})$/
regex: [/^(BE)(0?\d{9})$/]
}

@@ -142,2 +127,16 @@ };

function _increase(value, vat, from, to, incr) {
for (var i = from; i < to; i++) {
value += +vat.charAt(i) * (i + incr);
}
return value;
}
function _increase2(value, vat, from, to, multipliers) {
for (var i = from; i < to; i++) {
value += +vat.charAt(i) * multipliers[i];
}
return value;
}
function _checkNineLengthVat(vat) {

@@ -148,5 +147,3 @@ var total;

for (var i = 0; i < 8; i++) {
temp += +vat.charAt(i) * (i + 1);
}
temp = _increase(temp, vat, 0, 8, 1);

@@ -158,6 +155,3 @@ total = temp % 11;

temp = 0;
for (var j = 0; j < 8; j++) {
temp += +vat.charAt(j) * (j + 3);
}
temp = _increase(0, vat, 0, 8, 3);

@@ -171,3 +165,2 @@ total = temp % 11;

function _isPhysicalPerson(vat, rules) {
var total = 0;
// 10 digit VAT code - see if it relates to a standard physical person

@@ -179,6 +172,3 @@ if ((/^\d\d[0-5]\d[0-3]\d\d{4}$/).test(vat)) {

total = 0;
for (var i = 0; i < 9; i++) {
total += +vat.charAt(i) * rules.multipliers.physical[i];
}
var total = _increase2(0, vat, 0, 9, rules.multipliers.physical);
// Establish check digit.

@@ -197,7 +187,4 @@ total = total % 11;

function _isForeigner(vat, rules) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 9; i++) {
total += +vat.charAt(i) * rules.multipliers.foreigner[i];
}
var total = _increase2(0, vat, 0, 9, rules.multipliers.foreigner);

@@ -211,9 +198,5 @@ // Check to see if the check digit given is correct, If not, try next type of person

function _miscellaneousVAT(vat, rules) {
var total = 0;
// Finally, if not yet identified, see if it conforms to a miscellaneous VAT number
var total = _increase2(0, vat, 0, 9, rules.multipliers.miscellaneous);
for (var i = 0; i < 9; i++) {
total += +vat.charAt(i) * rules.multipliers.miscellaneous[i];
}
// Establish check digit.

@@ -274,3 +257,3 @@ total = 11 - total % 11;

},
regex: /^(BG)(\d{9,10})$/
regex: [/^(BG)(\d{9,10})$/]
}

@@ -304,3 +287,3 @@ };

rules: {
regex: /^(HR)(\d{11})$/
regex: [/^(HR)(\d{11})$/]
}

@@ -353,3 +336,3 @@ };

rules: {
regex: /^(CY)([0-59]\d{7}[A-Z])$/
regex: [/^(CY)([0-59]\d{7}[A-Z])$/]
}

@@ -446,3 +429,3 @@ };

],
regex: /^(CZ)(\d{8,10})(\d{3})?$/,
regex: [/^(CZ)(\d{8,10})(\d{3})?$/],
additional: [

@@ -478,3 +461,3 @@ /^\d{8}$/,

],
regex: /^(DK)(\d{8})$/
regex: [/^(DK)(\d{8})$/]
}

@@ -511,3 +494,3 @@ };

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

@@ -522,3 +505,3 @@ };

rules: {
regex: /^(EU)(\d{9})$/
regex: [/^(EU)(\d{9})$/]
}

@@ -554,3 +537,3 @@ };

],
regex: /^(FI)(\d{8})$/
regex: [/^(FI)(\d{8})$/]
}

@@ -618,3 +601,3 @@ };

rules: {
regex: /^(DE)([1-9]\d{8})$/
regex: [/^(DE)([1-9]\d{8})$/]
}

@@ -658,3 +641,3 @@ };

],
regex: /^(EL)(\d{9})$/
regex: [/^(EL)(\d{9})$/]
}

@@ -690,3 +673,3 @@ };

],
regex: /^(HU)(\d{8})$/
regex: [/^(HU)(\d{8})$/]
}

@@ -800,3 +783,3 @@ };

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

@@ -849,3 +832,3 @@ };

],
regex: /^(LV)(\d{11})$/
regex: [/^(LV)(\d{11})$/]
}

@@ -999,3 +982,3 @@ };

check: /^\d{10}1/,
regex: /^(LT)(\d{9}|\d{12})$/
regex: [/^(LT)(\d{9}|\d{12})$/]
}

@@ -1013,3 +996,3 @@ };

rules: {
regex: /^(LU)(\d{8})$/
regex: [/^(LU)(\d{8})$/]
}

@@ -1043,3 +1026,3 @@ };

],
regex: /^(MT)([1-9]\d{7})$/
regex: [/^(MT)([1-9]\d{7})$/]
}

@@ -1078,3 +1061,3 @@ };

],
regex: /^(NL)(\d{9})B\d{2}$/
regex: [/^(NL)(\d{9})B\d{2}$/]
}

@@ -1117,3 +1100,3 @@ };

],
regex: /^(NO)(\d{9})$/
regex: [/^(NO)(\d{9})$/]
}

@@ -1153,3 +1136,3 @@ };

],
regex: /^(PL)(\d{10})$/
regex: [/^(PL)(\d{10})$/]
}

@@ -1188,3 +1171,3 @@ };

],
regex: /^(PT)(\d{9})$/
regex: [/^(PT)(\d{9})$/]
}

@@ -1225,3 +1208,3 @@ };

],
regex: /^(RO)([1-9]\d{1,9})$/
regex: [/^(RO)([1-9]\d{1,9})$/]
}

@@ -1336,3 +1319,3 @@ };

},
regex: /^(RU)(\d{10}|\d{12})$/
regex: [/^(RU)(\d{10}|\d{12})$/]
}

@@ -1365,3 +1348,3 @@ };

rules: {
regex: /^(RS)(\d{9})$/
regex: [/^(RS)(\d{9})$/]
}

@@ -1376,3 +1359,3 @@ };

rules: {
regex: /^(SK)([1-9]\d[2346-9]\d{7})$/
regex: [/^(SK)([1-9]\d[2346-9]\d{7})$/]
}

@@ -1411,3 +1394,3 @@ };

],
regex: /^(SI)([1-9]\d{7})$/
regex: [/^(SI)([1-9]\d{7})$/]
}

@@ -1530,3 +1513,3 @@ };

rules: {
regex: /^(SE)(\d{10}01)$/
regex: [/^(SE)(\d{10}01)$/]
}

@@ -1561,3 +1544,3 @@ };

],
regex: /^(CHE)(\d{9})(MWST)?$/
regex: [/^(CHE)(\d{9})(MWST)?$/]
}

@@ -1564,0 +1547,0 @@ };

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

var jsvat=function(){"use strict";function r(r,e){return e.test(r)}function e(r,e,t){var i=e.exec(r),s=i[2];return u[t].calcs(s)}function t(t,i,s){var l=!1;return r(t,i)&&(l=e(t,i,s)),l}function i(r){return r.toString().toUpperCase().replace(/(\s|-|\.)+/g,"")}function s(r){return Array.isArray(r)?r:[r]}function l(r,e){if(!r||0===Object.keys(r).length)return!1;var t=r[e];return null===t||null===t?!0:!t}var u={},n={config:{},checkVAT:function(r,e){if(!r)return!1;r=i(r);var c={isValid:!1,countries:[]};for(var a in u)if(u.hasOwnProperty(a)&&!l(n.config,a))for(var o=s(u[a].rules.regex),f=0;f<o.length;f++){if(c.isValid=t(r,o[f],a)?!0:c.isValid,!e&&c.isValid)return c.isValid;var d=t(r,o[f],a);d&&c.countries.push(a)}return e?c:c.isValid}};return u.austria={calcs:function(r){for(var e,t=0,i=0;7>i;i++)e=r.charAt(i)*this.rules.multipliers[i],t+=e>9?Math.floor(e/10)+e%10:e;return t=10-(t+4)%10,10===t&&(t=0),t===+r.slice(7,8)},rules:{multipliers:[1,2,1,2,1,2,1],regex:/^(AT)U(\d{8})$/}},u.belgium={calcs:function(r){if(9===r.length&&(r="0"+r),0===+r.slice(1,2))return!1;var e=97-+r.slice(0,8)%97;return e===+r.slice(8,10)},rules:{regex:/^(BE)(0?\d{9})$/}},u.bulgaria=function(){function r(r){for(var e,t=0,i=+r.slice(8),s=0;8>s;s++)t+=+r.charAt(s)*(s+1);if(e=t%11,10!==e)return e===i;t=0;for(var l=0;8>l;l++)t+=+r.charAt(l)*(l+3);return e=t%11,10===e&&(e=0),e===i}function e(r,e){var t=0;if(/^\d\d[0-5]\d[0-3]\d\d{4}$/.test(r)){var i=+r.slice(2,4);if(i>0&&13>i||i>20&&33>i||i>40&&53>i){t=0;for(var s=0;9>s;s++)t+=+r.charAt(s)*e.multipliers.physical[s];if(t%=11,10===t&&(t=0),t===+r.substr(9,1))return!0}}return!1}function t(r,e){for(var t=0,i=0;9>i;i++)t+=+r.charAt(i)*e.multipliers.foreigner[i];return t%10===+r.substr(9,1)?!0:void 0}function i(r,e){for(var t=0,i=0;9>i;i++)t+=+r.charAt(i)*e.multipliers.miscellaneous[i];if(t=11-t%11,10===t)return!1;11===t&&(t=0);var s=+r.substr(9,1);return t===s}return{calcs:function(s){return 9===s.length?r(s):e(s,this.rules)||t(s,this.rules)||i(s,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;10>s;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;8>i;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;7>i;i++)t+=+r.charAt(i)*e.multipliers[i];t=11-t%11,10===t&&(t=0),11===t&&(t=1);var s=+r.slice(7,8);return t===s}return!1}function e(r,e){var t=0;if(e.additional[2].test(r)){for(var i=0;7>i;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)?!0:e(i,this.rules)?!0:!!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;8>t;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;8>i;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;7>i;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):!0},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;8>l;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;8>i;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;7>i;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;7>i;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||e>201&&999!==e&&888!==e)return!1;for(var s=0;10>s;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;10>i;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:4>t%11&&(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;8>s;s++)t+=r(e,i.multipliers["short"],s)}return t}function t(r,e){for(var t=0;8>t;t++)e+=+r.charAt(t)*(t+1);return e}function i(r){return r%=11,10===r&&(r=0),r}function s(r,s){var l=0;if(9===r.length){if(!/^\d{7}1/.test(r))return!1;l=t(r,l),l=e(r,l,s),l=i(l);var u=+r.slice(8,9);return l===u}return!1}function l(e,t,i){for(var s=0;11>s;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;11>s;s++)t+=r(e,i.multipliers.alt,s)}return t}function n(r,e){var t=0;if(12===r.length){if(!e.check.test(r))return!1;t=l(r,t,e),t=u(r,t,e),t=i(t);var s=+r.slice(11,12);return t===s}return!1}return{calcs:function(r){return s(r,this.rules)||n(r,this.rules)},rules:{multipliers:{"short":[3,4,5,6,7,8,9,1],med:[1,2,3,4,5,6,7,8,9,1,2],alt:[3,4,5,6,7,8,9,1,2,3,4]},check:/^\d{10}1/,regex:/^(LT)(\d{9}|\d{12})$/}}}(),u.luxembourg={calcs:function(r){var e=+r.slice(6,8),t=+r.slice(0,6)%89;return t===e},rules:{regex:/^(LU)(\d{8})$/}},u.malta={calcs:function(r){for(var e,t=0,i=0;6>i;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;8>i;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;8>i;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=11-t%11,11===t&&(t=0),10>t?(e=+r.slice(8,9),t===e):void 0},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;9>i;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;8>i;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;10>i;i++)t+=+r.charAt(i)*e.multipliers.m_1[i];t%=11,t>9&&(t%=10);var s=+r.slice(9,10);return t===s}return!1}function e(r,e){var t=0,i=0;if(12===r.length){for(var s=0;11>s;s++)t+=+r.charAt(s)*e.multipliers.m_2[s];t%=11,t>9&&(t%=10);for(var l=0;11>l;l++)i+=+r.charAt(l)*e.multipliers.m_3[l];i%=11,i>9&&(i%=10);var u=t===+r.slice(10,11),n=i===+r.slice(11,12);return u&&n}return!1}return{calcs:function(t){return r(t,this.rules)||e(t,this.rules)},rules:{multipliers:{m_1:[2,4,10,3,5,9,4,6,8,0],m_2:[7,2,4,10,3,5,9,4,6,8,0],m_3:[3,7,2,4,10,3,5,9,4,6,8,0]},regex:/^(RU)(\d{10}|\d{12})$/}}}(),u.serbia={calcs:function(r){for(var e,t=10,i=0,s=0;8>s;s++)i=(+r.charAt(s)+t)%10,0===i&&(i=10),t=2*i%11;var l=1;return e=(t+ +r.slice(8,9))%10,e===l},rules:{regex:/^(RS)(\d{9})$/}},u.slovakia_republic={calcs:function(r){var e=0,t=r%11;return t===e},rules:{regex:/^(SK)([1-9]\d[2346-9]\d{7})$/}},u.slovenia={calcs:function(r){for(var e,t=0,i=0;7>i;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;7>i;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;7>i;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):!1},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;9>s;s+=2)t=+r.charAt(s),i+=Math.floor(t/5)+2*t%10;for(var l=0,u=1;9>u;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;8>t;t++)e+=+r.charAt(t)*this.rules.multipliers[t];if(e=11-e%11,10===e)return!1;11===e&&(e=0);var i=+r.substr(8,1);return e===i},rules:{multipliers:[5,4,3,2,7,6,5,4],regex:/^(CHE)(\d{9})(MWST)?$/}},u.united_kingdom={calcs:function(r){var e,t=0;if("GD"===r.substr(0,2))return e=500,r.substr(2,3)<e;if("HA"===r.substr(0,2))return e=499,r.substr(2,3)>e;if(0===+r.slice(0))return!1;for(var i=+r.slice(0,7),s=0;7>s;s++)t+=+r.charAt(s)*this.rules.multipliers[s];for(var l=t;l>0;)l-=97;return l=Math.abs(l),l===+r.slice(7,9)&&9990001>i&&(1e5>i||i>999999)&&(9490001>i||i>97e5)?!0:(l>=55?l-=55:l+=42,e=+r.slice(7,9),!!(l===e&&i>1e6))},rules:{multipliers:[8,7,6,5,4,3,2],regex:[/^(GB)?(\d{9})$/,/^(GB)?(\d{12})$/,/^(GB)?(GD\d{3})$/,/^(GB)?(HA\d{3})$/]}},"object"==typeof module&&module.exports&&(module.exports=n),n}();
var jsvat=function(){"use strict";function r(r,e){return e.test(r)}function e(r,e,t){var i=e.exec(r),s=i[2];return u[t].calcs(s)}function t(t,i,s){var l=!1;return r(t,i)&&(l=e(t,i,s)),l}function i(r){return r=r||"",r.toString().toUpperCase().replace(/(\s|-|\.)+/g,"")}function s(r,e){return r&&0!==r.length?-1===r.indexOf(e):!1}function l(r,e){for(var i=u[e].rules.regex,l=0;l<i.length;l++){var c=t(r,i[l],e);if(c)return c&&!s(n.config,e)}return!1}var u={},n={config:[],checkVAT:function(r){var e={value:i(r),isValid:!1,country:null};if(!r)return e;for(var t in u)if(u.hasOwnProperty(t)&&(e.isValid=l(e.value,t),e.isValid))return e.country=t,e;return e}};return u.austria={calcs:function(r){for(var e,t=0,i=0;7>i;i++)e=r.charAt(i)*this.rules.multipliers[i],t+=e>9?Math.floor(e/10)+e%10:e;return t=10-(t+4)%10,10===t&&(t=0),t===+r.slice(7,8)},rules:{multipliers:[1,2,1,2,1,2,1],regex:[/^(AT)U(\d{8})$/]}},u.belgium={calcs:function(r){if(9===r.length&&(r="0"+r),0===+r.slice(1,2))return!1;var e=97-+r.slice(0,8)%97;return e===+r.slice(8,10)},rules:{regex:[/^(BE)(0?\d{9})$/]}},u.bulgaria=function(){function r(r,e,t,i,s){for(var l=t;i>l;l++)r+=+e.charAt(l)*(l+s);return r}function e(r,e,t,i,s){for(var l=t;i>l;l++)r+=+e.charAt(l)*s[l];return r}function t(e){var t,i=0,s=+e.slice(8);return i=r(i,e,0,8,1),t=i%11,10!==t?t===s:(i=r(0,e,0,8,3),t=i%11,10===t&&(t=0),t===s)}function i(r,t){if(/^\d\d[0-5]\d[0-3]\d\d{4}$/.test(r)){var i=+r.slice(2,4);if(i>0&&13>i||i>20&&33>i||i>40&&53>i){var s=e(0,r,0,9,t.multipliers.physical);if(s%=11,10===s&&(s=0),s===+r.substr(9,1))return!0}}return!1}function s(r,t){var i=e(0,r,0,9,t.multipliers.foreigner);return i%10===+r.substr(9,1)?!0:void 0}function l(r,t){var i=e(0,r,0,9,t.multipliers.miscellaneous);if(i=11-i%11,10===i)return!1;11===i&&(i=0);var s=+r.substr(9,1);return i===s}return{calcs:function(r){return 9===r.length?t(r):i(r,this.rules)||s(r,this.rules)||l(r,this.rules)},rules:{multipliers:{physical:[2,4,8,5,10,9,7,3,6],foreigner:[21,19,17,13,11,9,7,3,1],miscellaneous:[4,3,2,7,6,5,4,3,2]},regex:[/^(BG)(\d{9,10})$/]}}}(),u.croatia={calcs:function(r){for(var e,t=10,i=0,s=0;10>s;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;8>i;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;7>i;i++)t+=+r.charAt(i)*e.multipliers[i];t=11-t%11,10===t&&(t=0),11===t&&(t=1);var s=+r.slice(7,8);return t===s}return!1}function e(r,e){var t=0;if(e.additional[2].test(r)){for(var i=0;7>i;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)?!0:e(i,this.rules)?!0:!!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;8>t;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;8>i;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;7>i;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):!0},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;8>l;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;8>i;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;7>i;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;7>i;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||e>201&&999!==e&&888!==e)return!1;for(var s=0;10>s;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;10>i;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:4>t%11&&(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;8>s;s++)t+=r(e,i.multipliers["short"],s)}return t}function t(r,e){for(var t=0;8>t;t++)e+=+r.charAt(t)*(t+1);return e}function i(r){return r%=11,10===r&&(r=0),r}function s(r,s){var l=0;if(9===r.length){if(!/^\d{7}1/.test(r))return!1;l=t(r,l),l=e(r,l,s),l=i(l);var u=+r.slice(8,9);return l===u}return!1}function l(e,t,i){for(var s=0;11>s;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;11>s;s++)t+=r(e,i.multipliers.alt,s)}return t}function n(r,e){var t=0;if(12===r.length){if(!e.check.test(r))return!1;t=l(r,t,e),t=u(r,t,e),t=i(t);var s=+r.slice(11,12);return t===s}return!1}return{calcs:function(r){return s(r,this.rules)||n(r,this.rules)},rules:{multipliers:{"short":[3,4,5,6,7,8,9,1],med:[1,2,3,4,5,6,7,8,9,1,2],alt:[3,4,5,6,7,8,9,1,2,3,4]},check:/^\d{10}1/,regex:[/^(LT)(\d{9}|\d{12})$/]}}}(),u.luxembourg={calcs:function(r){var e=+r.slice(6,8),t=+r.slice(0,6)%89;return t===e},rules:{regex:[/^(LU)(\d{8})$/]}},u.malta={calcs:function(r){for(var e,t=0,i=0;6>i;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;8>i;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;8>i;i++)t+=+r.charAt(i)*this.rules.multipliers[i];return t=11-t%11,11===t&&(t=0),10>t?(e=+r.slice(8,9),t===e):void 0},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;9>i;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;8>i;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;10>i;i++)t+=+r.charAt(i)*e.multipliers.m_1[i];t%=11,t>9&&(t%=10);var s=+r.slice(9,10);return t===s}return!1}function e(r,e){var t=0,i=0;if(12===r.length){for(var s=0;11>s;s++)t+=+r.charAt(s)*e.multipliers.m_2[s];t%=11,t>9&&(t%=10);for(var l=0;11>l;l++)i+=+r.charAt(l)*e.multipliers.m_3[l];i%=11,i>9&&(i%=10);var u=t===+r.slice(10,11),n=i===+r.slice(11,12);return u&&n}return!1}return{calcs:function(t){return r(t,this.rules)||e(t,this.rules)},rules:{multipliers:{m_1:[2,4,10,3,5,9,4,6,8,0],m_2:[7,2,4,10,3,5,9,4,6,8,0],m_3:[3,7,2,4,10,3,5,9,4,6,8,0]},regex:[/^(RU)(\d{10}|\d{12})$/]}}}(),u.serbia={calcs:function(r){for(var e,t=10,i=0,s=0;8>s;s++)i=(+r.charAt(s)+t)%10,0===i&&(i=10),t=2*i%11;var l=1;return e=(t+ +r.slice(8,9))%10,e===l},rules:{regex:[/^(RS)(\d{9})$/]}},u.slovakia_republic={calcs:function(r){var e=0,t=r%11;return t===e},rules:{regex:[/^(SK)([1-9]\d[2346-9]\d{7})$/]}},u.slovenia={calcs:function(r){for(var e,t=0,i=0;7>i;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;7>i;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;7>i;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):!1},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;9>s;s+=2)t=+r.charAt(s),i+=Math.floor(t/5)+2*t%10;for(var l=0,u=1;9>u;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;8>t;t++)e+=+r.charAt(t)*this.rules.multipliers[t];if(e=11-e%11,10===e)return!1;11===e&&(e=0);var i=+r.substr(8,1);return e===i},rules:{multipliers:[5,4,3,2,7,6,5,4],regex:[/^(CHE)(\d{9})(MWST)?$/]}},u.united_kingdom={calcs:function(r){var e,t=0;if("GD"===r.substr(0,2))return e=500,r.substr(2,3)<e;if("HA"===r.substr(0,2))return e=499,r.substr(2,3)>e;if(0===+r.slice(0))return!1;for(var i=+r.slice(0,7),s=0;7>s;s++)t+=+r.charAt(s)*this.rules.multipliers[s];for(var l=t;l>0;)l-=97;return l=Math.abs(l),l===+r.slice(7,9)&&9990001>i&&(1e5>i||i>999999)&&(9490001>i||i>97e5)?!0:(l>=55?l-=55:l+=42,e=+r.slice(7,9),!!(l===e&&i>1e6))},rules:{multipliers:[8,7,6,5,4,3,2],regex:[/^(GB)?(\d{9})$/,/^(GB)?(\d{12})$/,/^(GB)?(GD\d{3})$/,/^(GB)?(HA\d{3})$/]}},"object"==typeof module&&module.exports&&(module.exports=n),n}();
//# sourceMappingURL=jsvat.min.js.map
{
"name": "jsvat",
"version": "1.0.0",
"version": "1.1.0",
"description": "Check the validity of the format of an EU VAT number",

@@ -50,3 +50,3 @@ "main": "./dist/jsvat.js",

"gulp-size": "^2.1.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-sourcemaps": "^2.0.0-alpha",
"gulp-todo": "^4.1.0",

@@ -57,3 +57,3 @@ "gulp-uglify": "^1.5.3",

"gulp-wrap": "^0.11.0",
"jshint": "^2.9.1",
"jshint": "^2.9.2",
"jshint-stylish": "^2.1.0",

@@ -60,0 +60,0 @@ "minimist": "^1.2.0",

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

[Demo and Examples][2]
[[Demo and Examples]][2]

@@ -29,36 +29,23 @@ Check the validity of the format of an EU VAT number. No dependencies.

What jsvat can?
What jsvat do?
--------
Several things:
Just check is VAT number valid or not and which country this VAT is:
1. Say is VAT number valid or not:
```
jsvat.checkVAT('BG131134023'); //true
jsvat.checkVAT('BG131134023'); // {isValid: true, country: 'bulgaria', value: 'BG131134023'}
jsvat.checkVAT('BG0433170001'); //{isValid: false, country: null, value: 'BG0433170001'}
jsvat.checkVAT('atu5-150-7409'); //{isValid: true, country: 'austria', value: 'ATU51507409'}
jsvat.checkVAT('aTU 5 804 4146'); //{isValid: true, country: 'austria', value: 'ATU58044146'}
```
```
jsvat.checkVAT('BG0433170001'); //false
```
You can specify list of allowed countries
2. Check VAT and return country for this VAT:
```
jsvat.checkVAT('BG13 113 4023', true); //{isValid: true, countries: ['bulgaria']}
```
```
jsvat.checkVAT('BG0433170001', true); //{isValid: false, countries: []}
```
3. Validate VAT with only countries from the list:
```
jsvat.config = {austria: true, belgium: false};
jsvat.checkVAT('ATU5-150-7409'); //true
jsvat.checkVAT('ATU5-804-4146', true); //{isValid: true, countries: ['austria']}
jsvat.config = ['austria', 'belgium']; //All countries except 'austria' and 'belgium' would return false
jsvat.checkVAT('BG131134023'); //valid VAT, but result would be 'false'
```
To reset config just do `jsvat.config = [];`
Installation

@@ -87,3 +74,3 @@ ----------

```
jsvat.chcekVat(vat, isDetailed);
jsvat.chcekVat(vat); //returns Object
```

@@ -95,8 +82,3 @@

- `isDetailed` param is flag (`boolean`, default: `false`).
if `false`, the result of check will be simple boolean (true or false);
if `true`, the result of check will be an Object: `{isValid: true, countries: ['austria']}`. Countries is a list of countries which accept passed VAT as valid. Normally there should be only one country, but potentially it's can be more than one.
How does jsvat check the validity?

@@ -118,17 +100,2 @@ ---------

Source of inspiration:
---------
Based on this great work: http://www.braemoor.co.uk/software/vat.shtml
At the moment the code was in public access without any license information.
I'm totally rewrite all the code.
Browsers Supports
---------
Support all browsers down to IE9 (including IE9).
List of supported Countries:

@@ -170,3 +137,28 @@ ---------

Versions for frameworks:
--------
- [Angular-jsvat][5]
Browsers Supports
---------
Support all browsers down to IE9 (including IE9).
Source of inspiration:
---------
Based on this great work: http://www.braemoor.co.uk/software/vat.shtml
At the moment the code was in public access without any license information.
I'm totally rewrite all the code.
Changelog
--------
#####1.1.0
- jsvat now always return Object (there is no more just true or false value);
- Changed way of jsvat configuretion (instead of object with countries, now you should pass an array with list of allowed countries);
LICENSE

@@ -181,1 +173,2 @@ -------

[4]: https://github.com/se-panfilov/jsvat/releases
[5]: https://github.com/se-panfilov/angular-jsvat

@@ -31,4 +31,4 @@ COUNTRIES.austria = {

],
regex: /^(AT)U(\d{8})$/
regex: [/^(AT)U(\d{8})$/]
}
};

@@ -13,5 +13,5 @@ COUNTRIES.belgium = {

rules: {
regex: /^(BE)(0?\d{9})$/
regex: [/^(BE)(0?\d{9})$/]
}
}
;
COUNTRIES.bulgaria = (function () {
function _increase(value, vat, from, to, incr) {
for (var i = from; i < to; i++) {
value += +vat.charAt(i) * (i + incr);
}
return value;
}
function _increase2(value, vat, from, to, multipliers) {
for (var i = from; i < to; i++) {
value += +vat.charAt(i) * multipliers[i];
}
return value;
}
function _checkNineLengthVat(vat) {

@@ -8,5 +22,3 @@ var total;

for (var i = 0; i < 8; i++) {
temp += +vat.charAt(i) * (i + 1);
}
temp = _increase(temp, vat, 0, 8, 1);

@@ -18,6 +30,3 @@ total = temp % 11;

temp = 0;
for (var j = 0; j < 8; j++) {
temp += +vat.charAt(j) * (j + 3);
}
temp = _increase(0, vat, 0, 8, 3);

@@ -31,3 +40,2 @@ total = temp % 11;

function _isPhysicalPerson(vat, rules) {
var total = 0;
// 10 digit VAT code - see if it relates to a standard physical person

@@ -39,6 +47,3 @@ if ((/^\d\d[0-5]\d[0-3]\d\d{4}$/).test(vat)) {

total = 0;
for (var i = 0; i < 9; i++) {
total += +vat.charAt(i) * rules.multipliers.physical[i];
}
var total = _increase2(0, vat, 0, 9, rules.multipliers.physical);
// Establish check digit.

@@ -57,7 +62,4 @@ total = total % 11;

function _isForeigner(vat, rules) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (var i = 0; i < 9; i++) {
total += +vat.charAt(i) * rules.multipliers.foreigner[i];
}
var total = _increase2(0, vat, 0, 9, rules.multipliers.foreigner);

@@ -71,9 +73,5 @@ // Check to see if the check digit given is correct, If not, try next type of person

function _miscellaneousVAT(vat, rules) {
var total = 0;
// Finally, if not yet identified, see if it conforms to a miscellaneous VAT number
var total = _increase2(0, vat, 0, 9, rules.multipliers.miscellaneous);
for (var i = 0; i < 9; i++) {
total += +vat.charAt(i) * rules.multipliers.miscellaneous[i];
}
// Establish check digit.

@@ -134,5 +132,5 @@ total = 11 - total % 11;

},
regex: /^(BG)(\d{9,10})$/
regex: [/^(BG)(\d{9,10})$/]
}
};
})();

@@ -26,4 +26,4 @@ COUNTRIES.croatia = {

rules: {
regex: /^(HR)(\d{11})$/
regex: [/^(HR)(\d{11})$/]
}
};

@@ -46,4 +46,4 @@ COUNTRIES.cyprus = {

rules: {
regex: /^(CY)([0-59]\d{7}[A-Z])$/
regex: [/^(CY)([0-59]\d{7}[A-Z])$/]
}
};

@@ -90,3 +90,3 @@ COUNTRIES.czech_republic = (function () {

],
regex: /^(CZ)(\d{8,10})(\d{3})?$/,
regex: [/^(CZ)(\d{8,10})(\d{3})?$/],
additional: [

@@ -93,0 +93,0 @@ /^\d{8}$/,

@@ -22,4 +22,4 @@ COUNTRIES.denmark = {

],
regex: /^(DK)(\d{8})$/
regex: [/^(DK)(\d{8})$/]
}
};

@@ -30,4 +30,4 @@ COUNTRIES.estonia = {

],
regex: /^(EE)(10\d{7})$/
regex: [/^(EE)(10\d{7})$/]
}
};

@@ -8,5 +8,5 @@ COUNTRIES.europe = {

rules: {
regex: /^(EU)(\d{9})$/
regex: [/^(EU)(\d{9})$/]
}
}
;

@@ -29,4 +29,4 @@ COUNTRIES.finland = {

],
regex: /^(FI)(\d{8})$/
regex: [/^(FI)(\d{8})$/]
}
};

@@ -32,4 +32,4 @@ COUNTRIES.germany = {

rules: {
regex: /^(DE)([1-9]\d{8})$/
regex: [/^(DE)([1-9]\d{8})$/]
}
};

@@ -37,4 +37,4 @@ COUNTRIES.greece = {

],
regex: /^(EL)(\d{9})$/
regex: [/^(EL)(\d{9})$/]
}
};

@@ -29,4 +29,4 @@ COUNTRIES.hungary = {

],
regex: /^(HU)(\d{8})$/
regex: [/^(HU)(\d{8})$/]
}
};

@@ -49,4 +49,4 @@ COUNTRIES.italy = {

],
regex: /^(IT)(\d{11})$/
regex: [/^(IT)(\d{11})$/]
}
};

@@ -46,4 +46,4 @@ COUNTRIES.latvia = {

],
regex: /^(LV)(\d{11})$/
regex: [/^(LV)(\d{11})$/]
}
};

@@ -147,5 +147,5 @@ COUNTRIES.lithunia = (function () {

check: /^\d{10}1/,
regex: /^(LT)(\d{9}|\d{12})$/
regex: [/^(LT)(\d{9}|\d{12})$/]
}
};
}());

@@ -10,4 +10,4 @@ COUNTRIES.luxembourg = {

rules: {
regex: /^(LU)(\d{8})$/
regex: [/^(LU)(\d{8})$/]
}
};

@@ -27,4 +27,4 @@ COUNTRIES.malta = {

],
regex: /^(MT)([1-9]\d{7})$/
regex: [/^(MT)([1-9]\d{7})$/]
}
};

@@ -32,4 +32,4 @@ COUNTRIES.netherlands = {

],
regex: /^(NL)(\d{9})B\d{2}$/
regex: [/^(NL)(\d{9})B\d{2}$/]
}
};

@@ -36,4 +36,4 @@ COUNTRIES.norway = {

],
regex: /^(NO)(\d{9})$/
regex: [/^(NO)(\d{9})$/]
}
};

@@ -33,4 +33,4 @@ COUNTRIES.poland = {

],
regex: /^(PL)(\d{10})$/
regex: [/^(PL)(\d{10})$/]
}
};

@@ -32,4 +32,4 @@ COUNTRIES.portugal = {

],
regex: /^(PT)(\d{9})$/
regex: [/^(PT)(\d{9})$/]
}
};

@@ -34,4 +34,4 @@ COUNTRIES.romania = {

],
regex: /^(RO)([1-9]\d{1,9})$/
regex: [/^(RO)([1-9]\d{1,9})$/]
}
};

@@ -107,5 +107,5 @@ COUNTRIES.russia = (function () {

},
regex: /^(RU)(\d{10}|\d{12})$/
regex: [/^(RU)(\d{10}|\d{12})$/]
}
};
}());

@@ -25,4 +25,4 @@ COUNTRIES.serbia = {

rules: {
regex: /^(RS)(\d{9})$/
regex: [/^(RS)(\d{9})$/]
}
};

@@ -8,4 +8,4 @@ COUNTRIES.slovakia_republic = {

rules: {
regex: /^(SK)([1-9]\d[2346-9]\d{7})$/
regex: [/^(SK)([1-9]\d[2346-9]\d{7})$/]
}
};

@@ -32,4 +32,4 @@ COUNTRIES.slovenia = {

],
regex: /^(SI)([1-9]\d{7})$/
regex: [/^(SI)([1-9]\d{7})$/]
}
};

@@ -27,5 +27,5 @@ COUNTRIES.sweden = {

rules: {
regex: /^(SE)(\d{10}01)$/
regex: [/^(SE)(\d{10}01)$/]
}
}
;

@@ -28,4 +28,4 @@ COUNTRIES.switzerland = {

],
regex: /^(CHE)(\d{9})(MWST)?$/
regex: [/^(CHE)(\d{9})(MWST)?$/]
}
};

@@ -22,56 +22,41 @@ var COUNTRIES = {};

function getClearVAT(vat) {
function _getPureVAT(vat) {
vat = vat || '';
return vat.toString().toUpperCase().replace(/(\s|-|\.)+/g, '');
}
function _makeArr(regex) {
if (!Array.isArray(regex)) {
return [regex];
}
function _isCountryBlocked(config, countryName) {
if (!config || config.length === 0) return false;
return regex;
return config.indexOf(countryName) === -1;
}
function isCountryBlocked(config, countryName) {
if (!config || Object.keys(config).length === 0) return false;
var country = config[countryName];
return (country === null || country === null) ? true : !country;
function checkValidity(vat, countryName) {
var regexArr = COUNTRIES[countryName].rules.regex;
for (var i = 0; i < regexArr.length; i++) {
var isValid = _validate(vat, regexArr[i], countryName);
if (isValid) return isValid && !_isCountryBlocked(exports.config, countryName);
}
return false;
}
var exports = {
config: {},
checkVAT: function (vat, isDetailed) {
if (!vat) return false;
vat = getClearVAT(vat);
config: [],
checkVAT: function (vat) {
var result = {
value: _getPureVAT(vat),
isValid: false,
countries: []
country: null
};
if (!vat) return result;
for (var countryName in COUNTRIES) {
if (COUNTRIES.hasOwnProperty(countryName)) {
//Make sure country check not skipped in config
if (!isCountryBlocked(exports.config, countryName)) {
result.isValid = checkValidity(result.value, countryName);
var regexArr = _makeArr(COUNTRIES[countryName].rules.regex);
for (var i = 0; i < regexArr.length; i++) {
//If once become a true, shouldn't be a false any more
result.isValid = (_validate(vat, regexArr[i], countryName)) ? true : result.isValid;
if (!isDetailed && result.isValid) return result.isValid;
var isValidForCurrCountry = _validate(vat, regexArr[i], countryName);
if (isValidForCurrCountry) {
result.countries.push(countryName);
}
}
if (result.isValid) {
result.country = countryName;
return result;
}

@@ -81,5 +66,5 @@ }

return isDetailed ? result : result.isValid;
return result;
}
};

@@ -8,36 +8,35 @@ 'use strict';

countries.austria = require('./countries_vat_lists/austria.vat.js');
countries.belgium = require('./countries_vat_lists/belgium.vat.js');
countries.bulgaria = require('./countries_vat_lists/bulgaria.vat.js');
countries.croatia = require('./countries_vat_lists/croatia.vat.js');
countries.cyprus = require('./countries_vat_lists/cyprus.vat.js');
countries.czech_republic = require('./countries_vat_lists/czech_republic.vat.js');
countries.denmark = require('./countries_vat_lists/denmark.vat.js');
countries.estonia = require('./countries_vat_lists/estonia.vat.js');
countries.europe = require('./countries_vat_lists/europe.vat.js');
countries.finland = require('./countries_vat_lists/finland.vat.js');
countries.france = require('./countries_vat_lists/france.vat.js');
countries.germany = require('./countries_vat_lists/germany.vat.js');
countries.greece = require('./countries_vat_lists/greece.vat.js');
countries.hungary = require('./countries_vat_lists/hungary.vat.js');
countries.ireland = require('./countries_vat_lists/ireland.vat.js');
countries.italy = require('./countries_vat_lists/italy.vat.js');
countries.latvia = require('./countries_vat_lists/latvia.vat.js');
countries.lithunia = require('./countries_vat_lists/lithunia.vat.js');
countries.luxembourg = require('./countries_vat_lists/luxembourg.vat.js');
countries.malta = require('./countries_vat_lists/malta.vat.js');
countries.netherlands = require('./countries_vat_lists/netherlands.vat.js');
countries.norway = require('./countries_vat_lists/norway.vat.js');
countries.poland = require('./countries_vat_lists/poland.vat.js');
countries.portugal = require('./countries_vat_lists/portugal.vat.js');
countries.romania = require('./countries_vat_lists/romania.vat.js');
countries.russia = require('./countries_vat_lists/russia.vat.js');
countries.serbia = require('./countries_vat_lists/serbia.vat.js');
countries.slovakia_republic = require('./countries_vat_lists/slovakia.vat.js');
countries.slovenia = require('./countries_vat_lists/slovenia.vat.js');
countries.spain = require('./countries_vat_lists/spain.vat.js');
countries.sweden = require('./countries_vat_lists/sweden.vat.js');
countries.switzerland = require('./countries_vat_lists/switzerland.vat.js');
countries.united_kingdom = require('./countries_vat_lists/united_kingdom.vat.js');
// countries.belgium = require('./countries_vat_lists/belgium.vat.js');
// countries.bulgaria = require('./countries_vat_lists/bulgaria.vat.js');
// countries.croatia = require('./countries_vat_lists/croatia.vat.js');
// countries.cyprus = require('./countries_vat_lists/cyprus.vat.js');
// countries.czech_republic = require('./countries_vat_lists/czech_republic.vat.js');
// countries.denmark = require('./countries_vat_lists/denmark.vat.js');
// countries.estonia = require('./countries_vat_lists/estonia.vat.js');
// countries.europe = require('./countries_vat_lists/europe.vat.js');
// countries.finland = require('./countries_vat_lists/finland.vat.js');
// countries.france = require('./countries_vat_lists/france.vat.js');
// countries.germany = require('./countries_vat_lists/germany.vat.js');
// countries.greece = require('./countries_vat_lists/greece.vat.js');
// countries.hungary = require('./countries_vat_lists/hungary.vat.js');
// countries.ireland = require('./countries_vat_lists/ireland.vat.js');
// countries.italy = require('./countries_vat_lists/italy.vat.js');
// countries.latvia = require('./countries_vat_lists/latvia.vat.js');
// countries.lithunia = require('./countries_vat_lists/lithunia.vat.js');
// countries.luxembourg = require('./countries_vat_lists/luxembourg.vat.js');
// countries.malta = require('./countries_vat_lists/malta.vat.js');
// countries.netherlands = require('./countries_vat_lists/netherlands.vat.js');
// countries.norway = require('./countries_vat_lists/norway.vat.js');
// countries.poland = require('./countries_vat_lists/poland.vat.js');
// countries.portugal = require('./countries_vat_lists/portugal.vat.js');
// countries.romania = require('./countries_vat_lists/romania.vat.js');
// countries.russia = require('./countries_vat_lists/russia.vat.js');
// countries.serbia = require('./countries_vat_lists/serbia.vat.js');
// countries.slovakia_republic = require('./countries_vat_lists/slovakia.vat.js');
// countries.slovenia = require('./countries_vat_lists/slovenia.vat.js');
// countries.spain = require('./countries_vat_lists/spain.vat.js');
// countries.sweden = require('./countries_vat_lists/sweden.vat.js');
// countries.switzerland = require('./countries_vat_lists/switzerland.vat.js');
// countries.united_kingdom = require('./countries_vat_lists/united_kingdom.vat.js');
for (var countryName in countries) {

@@ -54,62 +53,34 @@ if (countries.hasOwnProperty(countryName)) {

describe('Valid VAT.', function () {
describe('Simple checks.', function () {
describe('Regular valid VAT.', function () {
utils.check(vatList.valid, 'Is VAT valid', true);
utils.check(vatList.valid, 'Is VAT valid', true, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT with \'-\' valid', true);
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, countryName);
});
describe('Valid VAT with space character.', function () {
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT with space valid', true);
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName);
});
});
describe('Deep checks.', function () {
describe('Regular valid VAT.', function () {
utils.detailedCheck(vatList.valid, 'Is VAT valid', true, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, countryName);
});
describe('Valid VAT with space character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName);
});
});
});
describe('Invalid VAT.', function () {
describe('Simple checks.', function () {
describe('Regular VAT.', function () {
utils.check(vatList.invalid, 'Is VAT valid', false);
});
describe('Invalid VAT with \'-\' character.', function () {
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT with \'-\' valid', false);
});
describe('Invalid VAT with space character.', function () {
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT with space valid', false);
});
});
describe('Deep checks.', function () {
describe('Regular valid VAT.', function () {
utils.detailedCheck(vatList.invalid, 'Is VAT valid', false, countryName);
utils.check(vatList.invalid, 'Is VAT valid', false, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName);
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName);
});
describe('Valid VAT with space character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName);
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName);
});
});

@@ -120,336 +91,220 @@ });

describe('Isolated VAT checks', function () {
describe('Isolated VAT checks.', function () {
describe('Config include current country.', function () {
before(function () {
jsvat.config = {};
jsvat.config[countryName] = true;
jsvat.config = [];
jsvat.config.push(countryName);
});
describe('Valid VAT.', function () {
describe('Simple checks.', function () {
describe('Regular valid VAT.', function () {
utils.check(vatList.valid, 'Is VAT valid', true);
utils.check(vatList.valid, 'Is VAT valid', true, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT with \'-\' valid', true);
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, countryName);
});
describe('Valid VAT with space character.', function () {
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT with space valid', true);
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName);
});
});
describe('Deep checks.', function () {
describe('Regular valid VAT.', function () {
utils.detailedCheck(vatList.valid, 'Is VAT valid', true, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, countryName);
});
describe('Valid VAT with space character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName);
});
});
});
describe('Invalid VAT.', function () {
describe('Simple checks.', function () {
describe('Regular VAT.', function () {
utils.check(vatList.invalid, 'Is VAT valid', false);
});
describe('Invalid VAT with \'-\' character.', function () {
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT with \'-\' valid', false);
});
describe('Invalid VAT with space character.', function () {
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT with space valid', false);
});
});
describe('Deep checks.', function () {
describe('Regular valid VAT.', function () {
utils.detailedCheck(vatList.invalid, 'Is VAT valid', false, countryName);
utils.check(vatList.invalid, 'Is VAT valid', false, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName);
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName);
});
describe('Valid VAT with space character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName);
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName);
});
});
});
after(function () {
jsvat.config = {};
jsvat.config = [];
});
});
describe('Config exclude current country.', function () {
before(function () {
jsvat.config = {};
jsvat.config[countryName] = false;
jsvat.config = [];
jsvat.config.push(countryName)
});
describe('Valid VAT.', function () {
describe('Simple checks.', function () {
describe('Regular valid VAT.', function () {
utils.check(vatList.valid, 'Is VAT valid', false);
utils.check(vatList.valid, 'Is VAT valid', true, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT with \'-\' valid', false);
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, countryName);
});
describe('Valid VAT with space character.', function () {
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT with space valid', false);
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName);
});
after(function () {
jsvat.config = {};
});
});
describe('Deep checks.', function () {
describe('Regular valid VAT.', function () {
utils.detailedCheck(vatList.valid, 'Is VAT valid', true, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, countryName);
});
describe('Valid VAT with space character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName);
});
});
});
describe('Invalid VAT.', function () {
describe('Simple checks.', function () {
describe('Regular VAT.', function () {
utils.check(vatList.invalid, 'Is VAT valid', false);
});
describe('Invalid VAT with \'-\' character.', function () {
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT with \'-\' valid', false);
});
describe('Invalid VAT with space character.', function () {
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT with space valid', false);
});
});
describe('Deep checks.', function () {
describe('Regular valid VAT.', function () {
utils.detailedCheck(vatList.invalid, 'Is VAT valid', false, countryName);
utils.check(vatList.invalid, 'Is VAT valid', false, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName);
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName);
});
describe('Valid VAT with space character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName);
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName);
});
});
});
after(function () {
jsvat.config = {};
jsvat.config = [];
});
});
describe('Config include other country.', function () {
before(function () {
var otherCountry = 'sweden';
jsvat.config = {};
jsvat.config = [];
if (countryName === 'sweden') {
otherCountry = 'austria';
}
jsvat.config[otherCountry] = true;
jsvat.config.push(otherCountry)
});
describe('Valid VAT.', function () {
describe('Simple checks.', function () {
describe('Regular valid VAT.', function () {
utils.check(vatList.valid, 'Is VAT valid', false);
utils.check(vatList.valid, 'Is VAT valid', false, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT with \'-\' valid', false);
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', false, countryName);
});
describe('Valid VAT with space character.', function () {
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT with space valid', false);
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', false, countryName);
});
after(function () {
jsvat.config = {};
});
});
describe('Deep checks.', function () {
describe('Regular valid VAT.', function () {
utils.detailedCheck(vatList.valid, 'Is VAT valid', true, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, countryName);
});
describe('Valid VAT with space character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName);
});
});
});
describe('Invalid VAT.', function () {
describe('Simple checks.', function () {
describe('Regular VAT.', function () {
utils.check(vatList.invalid, 'Is VAT valid', false);
});
describe('Invalid VAT with \'-\' character.', function () {
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT with \'-\' valid', false);
});
describe('Invalid VAT with space character.', function () {
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT with space valid', false);
});
});
describe('Deep checks.', function () {
describe('Regular valid VAT.', function () {
utils.detailedCheck(vatList.invalid, 'Is VAT valid', false, countryName);
utils.check(vatList.invalid, 'Is VAT valid', false, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName);
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName);
});
describe('Valid VAT with space character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName);
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName);
});
});
});
after(function () {
jsvat.config = {};
jsvat.config = [];
});
});
describe('Config include multiple countries VAT checks.', function () {
before(function () {
var otherCountries = ['sweden', 'russia', 'united_kingdom'];
jsvat.config = {};
jsvat.config = [];
if (countryName === 'sweden') otherCountries[0] = 'austria';
if (countryName === 'russia') otherCountries[1] = 'austria';
if (countryName === 'united_kingdom') otherCountries[2] = 'austria';
jsvat.config[otherCountries[0]] = true;
jsvat.config[otherCountries[1]] = false;
jsvat.config[otherCountries[2]] = true;
jsvat.config.push(otherCountries[0]);
jsvat.config.push(otherCountries[1]);
jsvat.config.push(otherCountries[2]);
});
describe('Valid VAT.', function () {
describe('Simple checks.', function () {
describe('Regular valid VAT.', function () {
utils.check(vatList.valid, 'Is VAT valid', false);
utils.check(vatList.valid, 'Is VAT valid', false, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT with \'-\' valid', false);
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', false, countryName);
});
describe('Valid VAT with space character.', function () {
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT with space valid', false);
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', false, countryName);
});
after(function () {
jsvat.config = {};
});
});
describe('Deep checks.', function () {
describe('Regular valid VAT.', function () {
utils.detailedCheck(vatList.valid, 'Is VAT valid', true, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT valid', true, countryName);
});
describe('Valid VAT with space character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName);
});
});
});
describe('Invalid VAT.', function () {
describe('Simple checks.', function () {
describe('Regular VAT.', function () {
utils.check(vatList.invalid, 'Is VAT valid', false);
});
describe('Invalid VAT with \'-\' character.', function () {
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT with \'-\' valid', false);
});
describe('Invalid VAT with space character.', function () {
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT with space valid', false);
});
});
describe('Deep checks.', function () {
describe('Regular valid VAT.', function () {
utils.detailedCheck(vatList.invalid, 'Is VAT valid', false, countryName);
utils.check(vatList.invalid, 'Is VAT valid', false, countryName);
});
describe('Valid VAT with \'-\' character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName);
utils.check(utils.addCharsToVals(vatList.invalid, '-'), 'Is VAT valid', false, countryName);
});
describe('Valid VAT with space character.', function () {
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName);
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName);
});
});
});
after(function () {
jsvat.config = {};
jsvat.config = [];
});
});
});

@@ -456,0 +311,0 @@

@@ -8,3 +8,3 @@ var expect = require('chai').expect;

module.exports = {
check: function (arr, msg, isTrue) {
check: function (arr, msg, isTrue, countryName) {
arr.forEach(function (item) {

@@ -15,23 +15,15 @@

return it(testMsg, function () {
var result = jsvat.checkVAT(item);
if (isTrue) {
return expect(jsvat.checkVAT(item)).to.be.true;
} else {
return expect(jsvat.checkVAT(item)).to.be.false;
}
});
});
},
detailedCheck: function (arr, msg, isTrue, countryName) {
arr.forEach(function (item) {
var testMsg = (argv.config !== noVerbose) ? msg + ': ' + item : 'test';
return it(testMsg, function () {
var result = jsvat.checkVAT(item, true);
if (isTrue) {
expect(result.value).to.be.equal(item.toString().toUpperCase().replace(/(\s|-|\.)+/g, ''));
expect(result.isValid).to.be.true;
expect(result.countries[0]).to.be.equal(countryName);
console.log(11111111111);
console.log(result.country);
console.log(countryName);
console.log(11111111111);
expect(result.country).to.be.equal(countryName);
} else {
expect(result.value).to.be.equal(item.toString().toUpperCase().replace(/(\s|-|\.)+/g, ''));
expect(result.isValid).to.be.false;
expect(result.countries.length).to.be.equal(0);
expect(result.country).to.be.null;
}

@@ -38,0 +30,0 @@ });

### TODOs
| Filename | line # | TODO
|:------|:------:|:------
| main.js | 27 | (S.Panfilov) this is not cross-browser check
|:------|:------:|:------

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

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