Comparing version 0.9.0 to 1.0.0
{ | ||
"name": "jsvat", | ||
"version": "0.9.0", | ||
"version": "1.0.0", | ||
"description": "Check the validity of the format of an EU VAT number", | ||
@@ -5,0 +5,0 @@ "main": "./dist/jsvat.js", |
@@ -9,14 +9,14 @@ "use strict"; | ||
const config = { | ||
dest: DEST, | ||
projectName: PROJECT_NAME, | ||
js: { | ||
src: [ | ||
SRC + '/**/*.js' | ||
] | ||
}, | ||
tests: { | ||
src: [TESTS_SRC] | ||
} | ||
dest: DEST, | ||
projectName: PROJECT_NAME, | ||
js: { | ||
src: [ | ||
SRC + '/**/*.js' | ||
] | ||
}, | ||
tests: { | ||
src: [TESTS_SRC] | ||
} | ||
}; | ||
module.exports = config; |
@@ -5,20 +5,21 @@ "use strict"; | ||
const config = require('../config'); | ||
const gzip = require('gulp-gzip'); | ||
const notify = require('gulp-notify'); | ||
const plumber = require('gulp-plumber'); | ||
gulp.task('gzip', function () { | ||
const config = require('../config'); | ||
const gzip = require('gulp-gzip'); | ||
const notify = require('gulp-notify'); | ||
const plumber = require('gulp-plumber'); | ||
return gulp.src(config.dest + '/**/*.js') | ||
.pipe(plumber({ | ||
errorHandler: notify.onError(function (err) { | ||
return { | ||
title: 'GZIP JS', | ||
message: err.message | ||
}; | ||
}) | ||
})) | ||
.pipe(gzip()) | ||
.pipe(gulp.dest(config.dest)); | ||
return gulp.src(config.dest + '/**/*.js') | ||
.pipe(plumber({ | ||
errorHandler: notify.onError(function (err) { | ||
return { | ||
title: 'GZIP JS', | ||
message: err.message | ||
}; | ||
}) | ||
})) | ||
.pipe(gzip()) | ||
.pipe(gulp.dest(config.dest)); | ||
}); | ||
@@ -5,14 +5,14 @@ "use strict"; | ||
const config = require('../config'); | ||
const sourcemaps = require('gulp-sourcemaps'); | ||
const uglify = require('gulp-uglify'); | ||
const concat = require('gulp-concat'); | ||
const rename = require('gulp-rename'); | ||
const notify = require('gulp-notify'); | ||
const plumber = require('gulp-plumber'); | ||
const beautify = require('gulp-beautify'); | ||
const wrap = require('gulp-wrap'); | ||
gulp.task('js', function () { | ||
const config = require('../config'); | ||
const sourcemaps = require('gulp-sourcemaps'); | ||
const uglify = require('gulp-uglify'); | ||
const concat = require('gulp-concat'); | ||
const rename = require('gulp-rename'); | ||
const notify = require('gulp-notify'); | ||
const plumber = require('gulp-plumber'); | ||
const beautify = require('gulp-beautify'); | ||
const wrap = require('gulp-wrap'); | ||
const moduleWrap = | ||
@@ -19,0 +19,0 @@ 'var jsvat = (function () {' + |
@@ -5,18 +5,20 @@ "use strict"; | ||
const config = require('../config'); | ||
const jshint = require('gulp-jshint'); | ||
const jshintReporter = jshint.reporter('jshint-stylish'); | ||
gulp.task('lint', function () { | ||
const config = require('../../config'); | ||
const jshint = require('gulp-jshint'); | ||
const jshintReporter = jshint.reporter('jshint-stylish'); | ||
return gulp.src(config.js.src) | ||
.pipe(jshint({ | ||
globalstrict: true, | ||
strict: false, | ||
globals: { | ||
angular: true, | ||
localStorage: true, | ||
console: true | ||
} | ||
})) | ||
.pipe(jshintReporter); | ||
return gulp.src(config.js.src) | ||
.pipe(jshint({ | ||
globalstrict: true, | ||
strict: false, | ||
globals: { | ||
angular: true, | ||
localStorage: true, | ||
console: true | ||
} | ||
})) | ||
.pipe(jshintReporter); | ||
}); |
@@ -5,11 +5,13 @@ "use strict"; | ||
const config = require('../config'); | ||
const buddyjs = require('gulp-buddy.js'); | ||
gulp.task('magic_numbers', function () { | ||
const config = require('../../config'); | ||
const buddyjs = require('gulp-buddy.js'); | ||
return gulp.src(config.js.src) | ||
.pipe(buddyjs({ | ||
ignore: [0, 1], | ||
reporter: 'detailed' | ||
})); | ||
return gulp.src(config.js.src) | ||
.pipe(buddyjs({ | ||
ignore: [0, 1], | ||
reporter: 'detailed' | ||
})); | ||
}); |
"use strict"; | ||
const gulp = require('gulp'); | ||
const runSequence = require('run-sequence').use(gulp); | ||
const config = require('../config'); | ||
gulp.task('make', function () { | ||
const runSequence = require('run-sequence').use(gulp); | ||
const config = require('../config'); | ||
return runSequence( | ||
'js', | ||
'gzip' | ||
); | ||
return runSequence( | ||
'js', | ||
'gzip' | ||
); | ||
}); |
@@ -5,5 +5,6 @@ "use strict"; | ||
const size = require('gulp-size'); | ||
gulp.task('sizes', function () { | ||
var size = require('gulp-size'); | ||
return gulp.src([ | ||
@@ -10,0 +11,0 @@ 'dist/**/*.js', |
"use strict"; | ||
const gulp = require('gulp'); | ||
const config = require('../config'); | ||
const todo = require('gulp-todo'); | ||
gulp.task('todo', function () { | ||
const config = require('../config'); | ||
const todo = require('gulp-todo'); | ||
const src = config.js.src.concat([config.tests.src[0] + '/**/*.js']).concat(['tasks/**/*.js']); | ||
const src = config.js.src.concat([config.tests.src[0] + '/**/*.js']).concat(['tasks/**/*.js']); | ||
return gulp.src(src) | ||
.pipe(todo()) | ||
.pipe(gulp.dest('./')); | ||
return gulp.src(src) | ||
.pipe(todo()) | ||
.pipe(gulp.dest('./')); | ||
}); |
@@ -31,3 +31,2 @@ var jsvat = (function() { | ||
function _makeArr(regex) { | ||
//TODO (S.Panfilov) this is not cross-browser check | ||
if (!Array.isArray(regex)) { | ||
@@ -41,7 +40,7 @@ return [regex]; | ||
function isCountryBlocked(config, countryName) { | ||
if (!config || Object.keys(config).length === 0) return false; //TODO (S.Panfilov) Object.keys didn't supports by old browsers | ||
if (!config || Object.keys(config).length === 0) return false; | ||
var country = config[countryName]; | ||
return (country === null || country === undefined) ? true : !country; | ||
return (country === null || country === null) ? true : !country; | ||
} | ||
@@ -81,12 +80,2 @@ | ||
} | ||
// if (result.isValid) { | ||
// //If not detailed just return bool and exit | ||
// if (!isDetailed) { | ||
// return result.isValid | ||
// } | ||
// else { | ||
// //if detailed, should fill array of countries | ||
// result.push(countryName); | ||
// } | ||
} | ||
@@ -106,10 +95,11 @@ | ||
var temp; | ||
var expect; | ||
for (var i = 0; i < 7; i++) { | ||
temp = vat.charAt(i) * this.rules.multipliers[i]; | ||
if (temp > 9) | ||
if (temp > 9) { | ||
total += Math.floor(temp / 10) + temp % 10; | ||
else | ||
} else { | ||
total += temp; | ||
} | ||
} | ||
@@ -120,5 +110,3 @@ | ||
expect = +vat.slice(7, 8); | ||
return total === expect; | ||
return total === +vat.slice(7, 8); | ||
}, | ||
@@ -140,4 +128,2 @@ rules: { | ||
calcs: function(vat) { | ||
var expect; | ||
if (vat.length === 9) { | ||
@@ -150,4 +136,3 @@ vat = '0' + vat; | ||
var check = (97 - +vat.slice(0, 8) % 97); | ||
expect = +vat.slice(8, 10); | ||
return check === expect; | ||
return check === +vat.slice(8, 10); | ||
}, | ||
@@ -163,3 +148,3 @@ rules: { | ||
var temp = 0; | ||
var expect; | ||
var expect = +vat.slice(8); | ||
@@ -172,3 +157,2 @@ for (var i = 0; i < 8; i++) { | ||
if (total !== 10) { | ||
expect = +vat.slice(8); | ||
return total === expect; | ||
@@ -184,3 +168,2 @@ } | ||
if (total === 10) total = 0; | ||
expect = +vat.slice(8); | ||
@@ -446,3 +429,3 @@ return total === expect; | ||
], | ||
"lookup": [ | ||
lookup: [ | ||
8, | ||
@@ -468,4 +451,4 @@ 7, | ||
} | ||
} | ||
})(); | ||
}; | ||
}()); | ||
COUNTRIES.denmark = { | ||
@@ -528,3 +511,3 @@ calcs: function(vat) { | ||
COUNTRIES.europe = { | ||
calcs: function(vat) { | ||
calcs: function() { | ||
// We know little about EU numbers apart from the fact that the first 3 digits represent the | ||
@@ -870,3 +853,3 @@ // country, and that there are nine digits in total. | ||
for (var i = 0; i < 8; i++) { | ||
total += _extractDigit(vat, rules.multipliers.short, i) | ||
total += _extractDigit(vat, rules.multipliers.short, i); | ||
} | ||
@@ -920,3 +903,3 @@ } | ||
for (var k = 0; k < 11; k++) { | ||
total += _extractDigit(vat, rules.multipliers.med, k) | ||
total += _extractDigit(vat, rules.multipliers.med, k); | ||
} | ||
@@ -930,3 +913,3 @@ return total; | ||
for (var l = 0; l < 11; l++) { | ||
total += _extractDigit(vat, rules.multipliers.alt, l) | ||
total += _extractDigit(vat, rules.multipliers.alt, l); | ||
} | ||
@@ -970,3 +953,3 @@ } | ||
multipliers: { | ||
"short": [ | ||
short: [ | ||
3, | ||
@@ -981,3 +964,3 @@ 4, | ||
], | ||
"med": [ | ||
med: [ | ||
1, | ||
@@ -995,3 +978,3 @@ 2, | ||
], | ||
"alt": [ | ||
alt: [ | ||
3, | ||
@@ -1014,3 +997,3 @@ 4, | ||
}; | ||
})(); | ||
}()); | ||
COUNTRIES.luxembourg = { | ||
@@ -1301,3 +1284,3 @@ calcs: function(vat) { | ||
multipliers: { | ||
"m_1": [ | ||
m_1: [ | ||
2, | ||
@@ -1314,3 +1297,3 @@ 4, | ||
], | ||
"m_2": [ | ||
m_2: [ | ||
7, | ||
@@ -1328,3 +1311,3 @@ 2, | ||
], | ||
"m_3": [ | ||
m_3: [ | ||
3, | ||
@@ -1347,3 +1330,3 @@ 7, | ||
}; | ||
})(); | ||
}()); | ||
COUNTRIES.serbia = { | ||
@@ -1350,0 +1333,0 @@ calcs: function(vat) { |
@@ -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||void 0===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,i=0,s=0;7>s;s++)e=r.charAt(s)*this.rules.multipliers[s],i+=e>9?Math.floor(e/10)+e%10:e;return i=10-(i+4)%10,10===i&&(i=0),t=+r.slice(7,8),i===t},rules:{multipliers:[1,2,1,2,1,2,1],regex:/^(AT)U(\d{8})$/}},u.belgium={calcs:function(r){var e;if(9===r.length&&(r="0"+r),0===+r.slice(1,2))return!1;var t=97-+r.slice(0,8)%97;return e=+r.slice(8,10),t===e},rules:{regex:/^(BE)(0?\d{9})$/}},u.bulgaria=function(){function r(r){for(var e,t,i=0,s=0;8>s;s++)i+=+r.charAt(s)*(s+1);if(e=i%11,10!==e)return t=+r.slice(8),e===t;i=0;for(var l=0;8>l;l++)i+=+r.charAt(l)*(l+3);return e=i%11,10===e&&(e=0),t=+r.slice(8),e===t}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(r){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.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}(); | ||
//# sourceMappingURL=jsvat.min.js.map |
{ | ||
"name": "jsvat", | ||
"version": "0.9.0", | ||
"version": "1.0.0", | ||
"description": "Check the validity of the format of an EU VAT number", | ||
@@ -58,2 +58,3 @@ "main": "./dist/jsvat.js", | ||
"jshint-stylish": "^2.1.0", | ||
"minimist": "^1.2.0", | ||
"mocha": "^2.4.5", | ||
@@ -60,0 +61,0 @@ "require-dir": "^0.3.0", |
@@ -1,4 +0,1 @@ | ||
[![Codacy Badge](https://api.codacy.com/project/badge/grade/874e7dce623149e18807bdc0a02671c2)](https://www.codacy.com/app/se-panfilov/jsvat) | ||
@@ -31,2 +28,36 @@ [![bitHound Overall Score](https://www.bithound.io/github/se-panfilov/jsvat/badges/score.svg)](https://www.bithound.io/github/se-panfilov/jsvat) [![bitHound Code](https://www.bithound.io/github/se-panfilov/jsvat/badges/code.svg)](https://www.bithound.io/github/se-panfilov/jsvat) | ||
What jsvat can? | ||
-------- | ||
Several things: | ||
1. Say is VAT number valid or not: | ||
``` | ||
jsvat.checkVAT('BG131134023'); //true | ||
``` | ||
``` | ||
jsvat.checkVAT('BG0433170001'); //false | ||
``` | ||
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.checkVAT('BG131134023'); //valid VAT, but result would be 'false' | ||
``` | ||
Installation | ||
@@ -47,2 +78,23 @@ ---------- | ||
4. Just use `jsvat.chcekVat(vat, isDetailed)` from global scope. | ||
If you didn't like global scope - wrap it' | ||
How to use jsvat? | ||
----- | ||
It's simple: | ||
``` | ||
jsvat.chcekVat(vat, isDetailed); | ||
``` | ||
- `vat` param means VAT number (`string`), like "BG0433170001". | ||
`vat` can be passed with '-' (`BG0-4331-70001`) or ' ' (space, like `BG 0433 17 0001`) characters; | ||
- `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? | ||
@@ -77,4 +129,3 @@ --------- | ||
... | ||
(unknown yet, but modern browsers should support it as well) | ||
Support all browsers down to IE9 (including IE9). | ||
@@ -81,0 +132,0 @@ List of supported Countries: |
@@ -5,10 +5,11 @@ COUNTRIES.austria = { | ||
var temp; | ||
var expect; | ||
for (var i = 0; i < 7; i++) { | ||
temp = vat.charAt(i) * this.rules.multipliers[i]; | ||
if (temp > 9) | ||
if (temp > 9) { | ||
total += Math.floor(temp / 10) + temp % 10; | ||
else | ||
} else { | ||
total += temp; | ||
} | ||
} | ||
@@ -19,5 +20,3 @@ | ||
expect = +vat.slice(7, 8); | ||
return total === expect; | ||
return total === +vat.slice(7, 8); | ||
}, | ||
@@ -24,0 +23,0 @@ rules: { |
COUNTRIES.belgium = { | ||
calcs: function (vat) { | ||
var expect; | ||
if (vat.length === 9) { | ||
@@ -12,4 +10,3 @@ vat = '0' + vat; | ||
var check = (97 - +vat.slice(0, 8) % 97); | ||
expect = +vat.slice(8, 10); | ||
return check === expect; | ||
return check === +vat.slice(8, 10); | ||
}, | ||
@@ -16,0 +13,0 @@ rules: { |
@@ -6,3 +6,3 @@ COUNTRIES.bulgaria = (function () { | ||
var temp = 0; | ||
var expect; | ||
var expect = +vat.slice(8); | ||
@@ -15,3 +15,2 @@ for (var i = 0; i < 8; i++) { | ||
if (total !== 10) { | ||
expect = +vat.slice(8); | ||
return total === expect; | ||
@@ -27,3 +26,2 @@ } | ||
if (total === 10) total = 0; | ||
expect = +vat.slice(8); | ||
@@ -30,0 +28,0 @@ return total === expect; |
@@ -77,3 +77,3 @@ COUNTRIES.czech_republic = (function () { | ||
], | ||
"lookup": [ | ||
lookup: [ | ||
8, | ||
@@ -99,3 +99,3 @@ 7, | ||
} | ||
} | ||
})(); | ||
}; | ||
}()); |
COUNTRIES.europe = { | ||
calcs: function (vat) { | ||
calcs: function () { | ||
// We know little about EU numbers apart from the fact that the first 3 digits represent the | ||
@@ -4,0 +4,0 @@ // country, and that there are nine digits in total. |
@@ -12,3 +12,3 @@ COUNTRIES.lithunia = (function () { | ||
for (var i = 0; i < 8; i++) { | ||
total += _extractDigit(vat, rules.multipliers.short, i) | ||
total += _extractDigit(vat, rules.multipliers.short, i); | ||
} | ||
@@ -62,3 +62,3 @@ } | ||
for (var k = 0; k < 11; k++) { | ||
total += _extractDigit(vat, rules.multipliers.med, k) | ||
total += _extractDigit(vat, rules.multipliers.med, k); | ||
} | ||
@@ -72,3 +72,3 @@ return total; | ||
for (var l = 0; l < 11; l++) { | ||
total += _extractDigit(vat, rules.multipliers.alt, l) | ||
total += _extractDigit(vat, rules.multipliers.alt, l); | ||
} | ||
@@ -112,3 +112,3 @@ } | ||
multipliers: { | ||
"short": [ | ||
short: [ | ||
3, | ||
@@ -123,3 +123,3 @@ 4, | ||
], | ||
"med": [ | ||
med: [ | ||
1, | ||
@@ -137,3 +137,3 @@ 2, | ||
], | ||
"alt": [ | ||
alt: [ | ||
3, | ||
@@ -156,2 +156,2 @@ 4, | ||
}; | ||
})(); | ||
}()); |
@@ -67,3 +67,3 @@ COUNTRIES.russia = (function () { | ||
multipliers: { | ||
"m_1": [ | ||
m_1: [ | ||
2, | ||
@@ -80,3 +80,3 @@ 4, | ||
], | ||
"m_2": [ | ||
m_2: [ | ||
7, | ||
@@ -94,3 +94,3 @@ 2, | ||
], | ||
"m_3": [ | ||
m_3: [ | ||
3, | ||
@@ -113,2 +113,2 @@ 7, | ||
}; | ||
})(); | ||
}()); |
@@ -27,3 +27,2 @@ var COUNTRIES = {}; | ||
function _makeArr(regex) { | ||
//TODO (S.Panfilov) this is not cross-browser check | ||
if (!Array.isArray(regex)) { | ||
@@ -37,7 +36,7 @@ return [regex]; | ||
function isCountryBlocked(config, countryName) { | ||
if (!config || Object.keys(config).length === 0) return false; //TODO (S.Panfilov) Object.keys didn't supports by old browsers | ||
if (!config || Object.keys(config).length === 0) return false; | ||
var country = config[countryName]; | ||
return (country === null || country === undefined) ? true : !country; | ||
return (country === null || country === null) ? true : !country; | ||
} | ||
@@ -77,12 +76,2 @@ | ||
} | ||
// if (result.isValid) { | ||
// //If not detailed just return bool and exit | ||
// if (!isDetailed) { | ||
// return result.isValid | ||
// } | ||
// else { | ||
// //if detailed, should fill array of countries | ||
// result.push(countryName); | ||
// } | ||
} | ||
@@ -89,0 +78,0 @@ |
@@ -53,6 +53,8 @@ module.exports = { | ||
], | ||
invalid: [ //TODO (S.Panfilov) add more invalid | ||
invalid: [ | ||
'CZ699001237', | ||
'CZ600001234', | ||
'CZ60000123456', | ||
'CZ0123' | ||
] | ||
}; |
@@ -6,5 +6,8 @@ module.exports = { | ||
], | ||
invalid: [ //TODO (S.Panfilov) add more invalid | ||
invalid: [ | ||
'EU123456', | ||
'EU1234567', | ||
'EU826001142123', | ||
'EU0123' | ||
] | ||
}; |
@@ -51,5 +51,8 @@ module.exports = { | ||
], | ||
invalid: [ //TODO (S.Panfilov) add more invalid | ||
invalid: [ | ||
'LV90001234567', | ||
'LV12345234567', | ||
'LV123452345672', | ||
'LV0123' | ||
] | ||
}; |
@@ -61,5 +61,8 @@ module.exports = { | ||
], | ||
invalid: [ //TODO (S.Panfilov) add more invalid | ||
invalid: [ | ||
'LT123456789', | ||
'LT1234567890', | ||
'LT530091413111', | ||
'LT0123' | ||
] | ||
}; |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -45,3 +45,3 @@ var jsvat = require('../../dist/jsvat.js'); | ||
var vatList = countries[countryName]; | ||
makeTests(vatList, countryName) | ||
makeTests(vatList, countryName); | ||
} | ||
@@ -51,30 +51,30 @@ } | ||
function makeTests(vatList, countryName) { | ||
describe(countryName + " VAT.", function () { | ||
describe("Common checks.", function () { | ||
describe("Valid VAT.", function () { | ||
describe("Simple checks.", function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.check(vatList.valid, "Is VAT valid", true); | ||
describe(countryName + ' VAT.', function () { | ||
describe('Common checks.', function () { | ||
describe('Valid VAT.', function () { | ||
describe('Simple checks.', function () { | ||
describe('Regular valid VAT.', function () { | ||
utils.check(vatList.valid, 'Is VAT valid', true); | ||
}); | ||
describe("Valid VAT with \'-\' character.", function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, '-'), "Is VAT with \'-\' valid", true); | ||
describe('Valid VAT with \'-\' character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT with \'-\' valid', true); | ||
}); | ||
describe("Valid VAT with space character.", function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, ' '), "Is VAT with space valid", true); | ||
describe('Valid VAT with space character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT with space valid', true); | ||
}); | ||
}); | ||
describe("Deep checks.", function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.detailedCheck(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 \'-\' 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('Valid VAT with space character.', function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName); | ||
}); | ||
@@ -84,15 +84,15 @@ }); | ||
describe("Invalid VAT.", function () { | ||
describe("Simple checks.", function () { | ||
describe('Invalid VAT.', function () { | ||
describe('Simple checks.', function () { | ||
describe("Regular VAT.", function () { | ||
utils.check(vatList.invalid, "Is VAT valid", false); | ||
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 \'-\' 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('Invalid VAT with space character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT with space valid', false); | ||
}); | ||
@@ -102,14 +102,14 @@ | ||
describe("Deep checks.", function () { | ||
describe('Deep checks.', function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.detailedCheck(vatList.invalid, "Is VAT valid", false, countryName); | ||
describe('Regular valid VAT.', function () { | ||
utils.detailedCheck(vatList.invalid, 'Is VAT valid', false, countryName); | ||
}); | ||
describe("Valid VAT with \'-\' character.", function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, '-'), "Is VAT valid", false, countryName); | ||
describe('Valid VAT with \'-\' character.', function () { | ||
utils.detailedCheck(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); | ||
describe('Valid VAT with space character.', function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName); | ||
}); | ||
@@ -122,5 +122,5 @@ | ||
describe("Isolated VAT checks", function () { | ||
describe('Isolated VAT checks', function () { | ||
describe("Config include current country.", function () { | ||
describe('Config include current country.', function () { | ||
@@ -132,29 +132,29 @@ before(function () { | ||
describe("Valid VAT.", function () { | ||
describe("Simple checks.", function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.check(vatList.valid, "Is VAT valid", true); | ||
describe('Valid VAT.', function () { | ||
describe('Simple checks.', function () { | ||
describe('Regular valid VAT.', function () { | ||
utils.check(vatList.valid, 'Is VAT valid', true); | ||
}); | ||
describe("Valid VAT with \'-\' character.", function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, '-'), "Is VAT with \'-\' valid", true); | ||
describe('Valid VAT with \'-\' character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT with \'-\' valid', true); | ||
}); | ||
describe("Valid VAT with space character.", function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, ' '), "Is VAT with space valid", true); | ||
describe('Valid VAT with space character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT with space valid', true); | ||
}); | ||
}); | ||
describe("Deep checks.", function () { | ||
describe('Deep checks.', function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.detailedCheck(vatList.valid, "Is VAT valid", true, countryName); | ||
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 \'-\' 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('Valid VAT with space character.', function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName); | ||
}); | ||
@@ -165,29 +165,29 @@ | ||
describe("Invalid VAT.", function () { | ||
describe("Simple checks.", function () { | ||
describe("Regular VAT.", function () { | ||
utils.check(vatList.invalid, "Is VAT valid", false); | ||
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 \'-\' 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('Invalid VAT with space character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT with space valid', false); | ||
}); | ||
}); | ||
describe("Deep checks.", function () { | ||
describe('Deep checks.', function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.detailedCheck(vatList.invalid, "Is VAT valid", false, countryName); | ||
describe('Regular valid VAT.', function () { | ||
utils.detailedCheck(vatList.invalid, 'Is VAT valid', false, countryName); | ||
}); | ||
describe("Valid VAT with \'-\' character.", function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, '-'), "Is VAT valid", false, countryName); | ||
describe('Valid VAT with \'-\' character.', function () { | ||
utils.detailedCheck(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); | ||
describe('Valid VAT with space character.', function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName); | ||
}); | ||
@@ -204,3 +204,3 @@ | ||
describe("Config exclude current country.", function () { | ||
describe('Config exclude current country.', function () { | ||
@@ -212,14 +212,14 @@ before(function () { | ||
describe("Valid VAT.", function () { | ||
describe("Simple checks.", function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.check(vatList.valid, "Is VAT valid", false); | ||
describe('Valid VAT.', function () { | ||
describe('Simple checks.', function () { | ||
describe('Regular valid VAT.', function () { | ||
utils.check(vatList.valid, 'Is VAT valid', false); | ||
}); | ||
describe("Valid VAT with \'-\' character.", function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, '-'), "Is VAT with \'-\' valid", false); | ||
describe('Valid VAT with \'-\' character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT with \'-\' valid', false); | ||
}); | ||
describe("Valid VAT with space character.", function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, ' '), "Is VAT with space valid", false); | ||
describe('Valid VAT with space character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT with space valid', false); | ||
}); | ||
@@ -232,14 +232,14 @@ | ||
describe("Deep checks.", function () { | ||
describe('Deep checks.', function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.detailedCheck(vatList.valid, "Is VAT valid", true, countryName); | ||
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 \'-\' 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('Valid VAT with space character.', function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName); | ||
}); | ||
@@ -250,29 +250,29 @@ | ||
describe("Invalid VAT.", function () { | ||
describe("Simple checks.", function () { | ||
describe("Regular VAT.", function () { | ||
utils.check(vatList.invalid, "Is VAT valid", false); | ||
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 \'-\' 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('Invalid VAT with space character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT with space valid', false); | ||
}); | ||
}); | ||
describe("Deep checks.", function () { | ||
describe('Deep checks.', function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.detailedCheck(vatList.invalid, "Is VAT valid", false, countryName); | ||
describe('Regular valid VAT.', function () { | ||
utils.detailedCheck(vatList.invalid, 'Is VAT valid', false, countryName); | ||
}); | ||
describe("Valid VAT with \'-\' character.", function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, '-'), "Is VAT valid", false, countryName); | ||
describe('Valid VAT with \'-\' character.', function () { | ||
utils.detailedCheck(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); | ||
describe('Valid VAT with space character.', function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName); | ||
}); | ||
@@ -289,3 +289,3 @@ | ||
describe("Config include other country.", function () { | ||
describe('Config include other country.', function () { | ||
@@ -302,14 +302,14 @@ before(function () { | ||
describe("Valid VAT.", function () { | ||
describe("Simple checks.", function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.check(vatList.valid, "Is VAT valid", false); | ||
describe('Valid VAT.', function () { | ||
describe('Simple checks.', function () { | ||
describe('Regular valid VAT.', function () { | ||
utils.check(vatList.valid, 'Is VAT valid', false); | ||
}); | ||
describe("Valid VAT with \'-\' character.", function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, '-'), "Is VAT with \'-\' valid", false); | ||
describe('Valid VAT with \'-\' character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT with \'-\' valid', false); | ||
}); | ||
describe("Valid VAT with space character.", function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, ' '), "Is VAT with space valid", false); | ||
describe('Valid VAT with space character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT with space valid', false); | ||
}); | ||
@@ -322,14 +322,14 @@ | ||
describe("Deep checks.", function () { | ||
describe('Deep checks.', function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.detailedCheck(vatList.valid, "Is VAT valid", true, countryName); | ||
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 \'-\' 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('Valid VAT with space character.', function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName); | ||
}); | ||
@@ -340,29 +340,29 @@ | ||
describe("Invalid VAT.", function () { | ||
describe("Simple checks.", function () { | ||
describe("Regular VAT.", function () { | ||
utils.check(vatList.invalid, "Is VAT valid", false); | ||
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 \'-\' 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('Invalid VAT with space character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT with space valid', false); | ||
}); | ||
}); | ||
describe("Deep checks.", function () { | ||
describe('Deep checks.', function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.detailedCheck(vatList.invalid, "Is VAT valid", false, countryName); | ||
describe('Regular valid VAT.', function () { | ||
utils.detailedCheck(vatList.invalid, 'Is VAT valid', false, countryName); | ||
}); | ||
describe("Valid VAT with \'-\' character.", function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, '-'), "Is VAT valid", false, countryName); | ||
describe('Valid VAT with \'-\' character.', function () { | ||
utils.detailedCheck(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); | ||
describe('Valid VAT with space character.', function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName); | ||
}); | ||
@@ -378,3 +378,3 @@ | ||
describe("Config include multiple countries VAT checks.", function () { | ||
describe('Config include multiple countries VAT checks.', function () { | ||
@@ -395,14 +395,14 @@ before(function () { | ||
describe("Valid VAT.", function () { | ||
describe("Simple checks.", function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.check(vatList.valid, "Is VAT valid", false); | ||
describe('Valid VAT.', function () { | ||
describe('Simple checks.', function () { | ||
describe('Regular valid VAT.', function () { | ||
utils.check(vatList.valid, 'Is VAT valid', false); | ||
}); | ||
describe("Valid VAT with \'-\' character.", function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, '-'), "Is VAT with \'-\' valid", false); | ||
describe('Valid VAT with \'-\' character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, '-'), 'Is VAT with \'-\' valid', false); | ||
}); | ||
describe("Valid VAT with space character.", function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, ' '), "Is VAT with space valid", false); | ||
describe('Valid VAT with space character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT with space valid', false); | ||
}); | ||
@@ -415,14 +415,14 @@ | ||
describe("Deep checks.", function () { | ||
describe('Deep checks.', function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.detailedCheck(vatList.valid, "Is VAT valid", true, countryName); | ||
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 \'-\' 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('Valid VAT with space character.', function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.valid, ' '), 'Is VAT valid', true, countryName); | ||
}); | ||
@@ -433,29 +433,29 @@ | ||
describe("Invalid VAT.", function () { | ||
describe("Simple checks.", function () { | ||
describe("Regular VAT.", function () { | ||
utils.check(vatList.invalid, "Is VAT valid", false); | ||
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 \'-\' 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('Invalid VAT with space character.', function () { | ||
utils.check(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT with space valid', false); | ||
}); | ||
}); | ||
describe("Deep checks.", function () { | ||
describe('Deep checks.', function () { | ||
describe("Regular valid VAT.", function () { | ||
utils.detailedCheck(vatList.invalid, "Is VAT valid", false, countryName); | ||
describe('Regular valid VAT.', function () { | ||
utils.detailedCheck(vatList.invalid, 'Is VAT valid', false, countryName); | ||
}); | ||
describe("Valid VAT with \'-\' character.", function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, '-'), "Is VAT valid", false, countryName); | ||
describe('Valid VAT with \'-\' character.', function () { | ||
utils.detailedCheck(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); | ||
describe('Valid VAT with space character.', function () { | ||
utils.detailedCheck(utils.addCharsToVals(vatList.invalid, ' '), 'Is VAT valid', false, countryName); | ||
}); | ||
@@ -462,0 +462,0 @@ |
var expect = require('chai').expect; | ||
var jsvat = require('../dist/jsvat.js'); | ||
var argv = require('minimist')(process.argv.slice(2)); | ||
var noVerbose = "noverbose"; | ||
module.exports = { | ||
check: function (arr, msg, isTrue) { | ||
arr.forEach(function (item) { | ||
return it(msg + ": " + item, function () { | ||
var testMsg = (argv.config !== noVerbose) ? msg + ': ' + item : 'test'; | ||
return it(testMsg, function () { | ||
if (isTrue) { | ||
@@ -18,3 +24,6 @@ return expect(jsvat.checkVAT(item)).to.be.true; | ||
arr.forEach(function (item) { | ||
return it(msg + ": " + item, function () { | ||
var testMsg = (argv.config !== noVerbose) ? msg + ': ' + item : 'test'; | ||
return it(testMsg, function () { | ||
var result = jsvat.checkVAT(item, true); | ||
@@ -21,0 +30,0 @@ if (isTrue) { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
99
1
175
2
303149
22
5552