Skip to content

Commit

Permalink
commonjs now targets es5 + dependencies update
Browse files Browse the repository at this point in the history
  • Loading branch information
se-panfilov committed Oct 21, 2019
1 parent e6bd8e1 commit 3bf2c55
Show file tree
Hide file tree
Showing 37 changed files with 749 additions and 660 deletions.
4 changes: 2 additions & 2 deletions lib/commonjs/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const countries_1 = require("./lib/countries");
const countries = [
var countries_1 = require("./lib/countries");
var countries = [
countries_1.austria,
countries_1.belgium,
countries_1.bulgaria,
Expand Down
8 changes: 4 additions & 4 deletions lib/commonjs/lib/countries/austria.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.austria = {
name: 'Austria',
codes: ['AT', 'AUT', '040'],
calcFn: (vat) => {
let total = 0;
for (let i = 0; i < 7; i++) {
const temp = Number(vat.charAt(i)) * exports.austria.rules.multipliers.common[i];
calcFn: function (vat) {
var total = 0;
for (var i = 0; i < 7; i++) {
var temp = Number(vat.charAt(i)) * exports.austria.rules.multipliers.common[i];
if (temp > 9) {
total += Math.floor(temp / 10) + temp % 10;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/commonjs/lib/countries/belgium.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.belgium = {
name: 'Belgium',
codes: ['BE', 'BEL', '056'],
calcFn: (vat) => {
const newVat = (vat.length === 9) ? ('0' + vat) : vat;
calcFn: function (vat) {
var newVat = (vat.length === 9) ? ('0' + vat) : vat;
if (Number(newVat.slice(1, 2)) === 0)
return false;
const check = (97 - Number(newVat.slice(0, 8)) % 97);
var check = (97 - Number(newVat.slice(0, 8)) % 97);
return check === Number(newVat.slice(8, 10));
},
rules: {
Expand Down
28 changes: 14 additions & 14 deletions lib/commonjs/lib/countries/bulgaria.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.bulgaria = {
name: 'Bulgaria',
codes: ['BG', 'BGR', '100'],
calcFn: (vat) => {
calcFn: function (vat) {
if (vat.length === 9)
return _checkNineLengthVat(vat);
const { multipliers } = exports.bulgaria.rules;
var multipliers = exports.bulgaria.rules.multipliers;
return _isPhysicalPerson(vat, multipliers.physical) || _isForeigner(vat, multipliers) || _miscellaneousVAT(vat, multipliers);
},
rules: {
Expand All @@ -19,23 +19,23 @@ exports.bulgaria = {
}
};
function _increase(value, vat, from, to, incr) {
let result = value;
for (let i = from; i < to; i++) {
var result = value;
for (var i = from; i < to; i++) {
result += Number(vat.charAt(i)) * (i + incr);
}
return result;
}
function _increase2(value, vat, from, to, multipliers) {
let result = value;
for (let i = from; i < to; i++) {
var result = value;
for (var i = from; i < to; i++) {
result += Number(vat.charAt(i)) * multipliers[i];
}
return result;
}
function _checkNineLengthVat(vat) {
let total;
let temp = _increase(0, vat, 0, 8, 1);
const expect = Number(vat.slice(8));
var total;
var temp = _increase(0, vat, 0, 8, 1);
var expect = Number(vat.slice(8));
total = temp % 11;
if (total !== 10)
return total === expect;
Expand All @@ -49,9 +49,9 @@ function _isPhysicalPerson(vat, physicalMultipliers) {
// 10 digit VAT code - see if it relates to a standard physical person
if ((/^\d\d[0-5]\d[0-3]\d\d{4}$/).test(vat)) {
// Check month
const month = Number(vat.slice(2, 4));
var month = Number(vat.slice(2, 4));
if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
let total = _increase2(0, vat, 0, 9, physicalMultipliers);
var total = _increase2(0, vat, 0, 9, physicalMultipliers);
// Establish check digit.
total = total % 11;
if (total === 10)
Expand All @@ -65,20 +65,20 @@ function _isPhysicalPerson(vat, physicalMultipliers) {
}
function _isForeigner(vat, multipliers) {
// Extract the next digit and multiply by the counter.
const total = _increase2(0, vat, 0, 9, multipliers.foreigner);
var total = _increase2(0, vat, 0, 9, multipliers.foreigner);
// Check to see if the check digit given is correct, If not, try next type of person
return total % 10 === Number(vat.substr(9, 1));
}
function _miscellaneousVAT(vat, multipliers) {
// Finally, if not yet identified, see if it conforms to a miscellaneous VAT number
let total = _increase2(0, vat, 0, 9, multipliers.miscellaneous);
var total = _increase2(0, vat, 0, 9, multipliers.miscellaneous);
// Establish check digit.
total = 11 - total % 11;
if (total === 10)
return false;
if (total === 11)
total = 0;
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
const expect = Number(vat.substr(9, 1));
var expect = Number(vat.substr(9, 1));
return total === expect;
}
10 changes: 5 additions & 5 deletions lib/commonjs/lib/countries/croatiat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.croatia = {
name: 'Croatia',
codes: ['HR', 'HRV', '191'],
calcFn: (vat) => {
calcFn: function (vat) {
// Checks the check digits of a Croatian VAT number using ISO 7064, MOD 11-10 for check digit.
let product = 10;
let sum = 0;
for (let i = 0; i < 10; i++) {
var product = 10;
var sum = 0;
for (var i = 0; i < 10; i++) {
// Extract the next digit and implement the algorithm
sum = (Number(vat.charAt(i)) + product) % 10;
if (sum === 0) {
Expand All @@ -16,7 +16,7 @@ exports.croatia = {
product = (2 * sum) % 11;
}
// Now check that we have the right check digit
const expect = Number(vat.slice(10, 11));
var expect = Number(vat.slice(10, 11));
return (product + expect) % 10 === 1;
},
rules: {
Expand Down
12 changes: 6 additions & 6 deletions lib/commonjs/lib/countries/cyprus.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.cyprus = {
name: 'Cyprus',
codes: ['CY', 'CYP', '196'],
calcFn: (vat) => {
calcFn: function (vat) {
// Not allowed to start with '12'
if (Number(vat.slice(0, 2)) === 12)
return false;
// Extract the next digit and multiply by the counter.
let total = extractAndMultiplyByCounter(vat, 0);
var total = extractAndMultiplyByCounter(vat, 0);
// Establish check digit using modulus 26, and translate to char. equivalent.
total = total % 26;
total = String.fromCharCode(total + 65);
// Check to see if the check digit given is correct
const expect = vat.substr(8, 1);
var expect = vat.substr(8, 1);
return total === expect;
},
rules: {
Expand All @@ -22,9 +22,9 @@ exports.cyprus = {
}
};
function extractAndMultiplyByCounter(vat, total) {
let result = total;
for (let i = 0; i < 8; i++) {
let temp = Number(vat.charAt(i));
var result = total;
for (var i = 0; i < 8; i++) {
var temp = Number(vat.charAt(i));
if (i % 2 === 0) {
switch (temp) {
case 0:
Expand Down
22 changes: 11 additions & 11 deletions lib/commonjs/lib/countries/czechRepublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.czechRepublic = {
name: 'Czech Republic',
codes: ['CZ', 'CZE', '203'],
calcFn: (vat) => {
const { rules } = exports.czechRepublic;
const { multipliers, additional, lookup } = rules;
calcFn: function (vat) {
var rules = exports.czechRepublic.rules;
var multipliers = rules.multipliers, additional = rules.additional, lookup = rules.lookup;
if (!additional)
return false;
return isLegalEntities(vat, multipliers.common, additional)
Expand All @@ -28,10 +28,10 @@ exports.czechRepublic = {
}
};
function isLegalEntities(vat, multipliers, additional) {
let total = 0;
var total = 0;
if (additional[0].test(vat)) {
// Extract the next digit and multiply by the counter.
for (let i = 0; i < 7; i++) {
for (var i = 0; i < 7; i++) {
total += Number(vat.charAt(i)) * multipliers[i];
}
// Establish check digit.
Expand All @@ -41,7 +41,7 @@ function isLegalEntities(vat, multipliers, additional) {
if (total === 11)
total = 1;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
const expect = Number(vat.slice(7, 8));
var expect = Number(vat.slice(7, 8));
return total === expect;
}
return false;
Expand All @@ -53,10 +53,10 @@ function isIndividualType1(vat, additional) {
return false;
}
function isIndividualType2(vat, multipliers, additional, lookup) {
let total = 0;
var total = 0;
if (additional[2].test(vat)) {
// Extract the next digit and multiply by the counter.
for (let j = 0; j < 7; j++) {
for (var j = 0; j < 7; j++) {
total += Number(vat.charAt(j + 1)) * multipliers[j];
}
// Establish check digit.
Expand All @@ -66,7 +66,7 @@ function isIndividualType2(vat, multipliers, additional, lookup) {
if (total === 11)
total = 1;
// Convert calculated check digit according to a lookup table
const expect = Number(vat.slice(8, 9));
var expect = Number(vat.slice(8, 9));
if (!lookup)
return false;
return lookup[total - 1] === expect;
Expand All @@ -75,8 +75,8 @@ function isIndividualType2(vat, multipliers, additional, lookup) {
}
function isIndividualType3(vat, additional) {
if (additional[3].test(vat)) {
const temp = Number(vat.slice(0, 2)) + Number(vat.slice(2, 4)) + Number(vat.slice(4, 6)) + Number(vat.slice(6, 8)) + Number(vat.slice(8));
const expect = Number(vat) % 11 === 0;
var temp = Number(vat.slice(0, 2)) + Number(vat.slice(2, 4)) + Number(vat.slice(4, 6)) + Number(vat.slice(6, 8)) + Number(vat.slice(8));
var expect = Number(vat) % 11 === 0;
return !!(temp % 11 === 0 && expect);
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions lib/commonjs/lib/countries/denmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.denmark = {
name: 'Denmark',
codes: ['DK', 'DNK', '208'],
calcFn: (vat) => {
let total = 0;
for (let i = 0; i < 8; i++) {
calcFn: function (vat) {
var total = 0;
for (var i = 0; i < 8; i++) {
total += Number(vat.charAt(i)) * exports.denmark.rules.multipliers.common[i];
}
return total % 11 === 0;
Expand Down
8 changes: 4 additions & 4 deletions lib/commonjs/lib/countries/estonia.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.estonia = {
name: 'Estonia',
codes: ['EE', 'EST', '233'],
calcFn: (vat) => {
let total = 0;
let expect;
calcFn: function (vat) {
var total = 0;
var expect;
// Extract the next digit and multiply by the counter.
for (let i = 0; i < 8; i++) {
for (var i = 0; i < 8; i++) {
total += Number(vat.charAt(i)) * exports.estonia.rules.multipliers.common[i];
}
// Establish check digits using modulus 10.
Expand Down
2 changes: 1 addition & 1 deletion lib/commonjs/lib/countries/europe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.europe = {
name: 'Europe',
codes: ['EU', 'EUR', '000'],
calcFn: () => {
calcFn: function () {
// We know little about EU numbers apart from the fact that the first 3 digits represent the
// country, and that there are nine digits in total.
return true;
Expand Down
8 changes: 4 additions & 4 deletions lib/commonjs/lib/countries/finland.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.finland = {
name: 'Finland',
codes: ['FI', 'FIN', '246'],
calcFn: (vat) => {
let total = 0;
calcFn: function (vat) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (let i = 0; i < 7; i++)
for (var i = 0; i < 7; i++)
total += Number(vat.charAt(i)) * exports.finland.rules.multipliers.common[i];
// Establish check digit.
total = 11 - total % 11;
if (total > 9) {
total = 0;
}
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
const expect = Number(vat.slice(7, 8));
var expect = Number(vat.slice(7, 8));
return total === expect;
},
rules: {
Expand Down
6 changes: 3 additions & 3 deletions lib/commonjs/lib/countries/france.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.france = {
name: 'France',
codes: ['FR', 'FRA', '250'],
calcFn: (vat) => {
let total;
calcFn: function (vat) {
var total;
// Checks the check digits of a French VAT number.
if (!(/^\d{11}$/).test(vat))
return true;
Expand All @@ -13,7 +13,7 @@ exports.france = {
// Establish check digit.
total = (total * 100 + 12) % 97;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
const expect = Number(vat.slice(0, 2));
var expect = Number(vat.slice(0, 2));
return total === expect;
},
rules: {
Expand Down
12 changes: 6 additions & 6 deletions lib/commonjs/lib/countries/germany.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.germany = {
name: 'Germany',
codes: ['DE', 'DEU', '276'],
calcFn: (vat) => {
calcFn: function (vat) {
// Checks the check digits of a German VAT number.
let product = 10;
let sum = 0;
let checkDigit = 0;
let expect;
for (let i = 0; i < 8; i++) {
var product = 10;
var sum = 0;
var checkDigit = 0;
var expect;
for (var i = 0; i < 8; i++) {
// Extract the next digit and implement peculiar algorithm!.
sum = (Number(vat.charAt(i)) + product) % 10;
if (sum === 0) {
Expand Down
10 changes: 5 additions & 5 deletions lib/commonjs/lib/countries/greece.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.greece = {
name: 'Greece',
codes: ['GR', 'GRC', '300'],
calcFn: (vat) => {
let total = 0;
calcFn: function (vat) {
var total = 0;
// eight character numbers should be prefixed with an 0.
const newVat = (vat.length === 8) ? '0' + vat : vat;
var newVat = (vat.length === 8) ? '0' + vat : vat;
// Extract the next digit and multiply by the counter.
for (let i = 0; i < 8; i++) {
for (var i = 0; i < 8; i++) {
total += Number(newVat.charAt(i)) * exports.greece.rules.multipliers.common[i];
}
// Establish check digit.
total = total % 11;
total = (total > 9) ? 0 : total;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
const expect = Number(newVat.slice(8, 9));
var expect = Number(newVat.slice(8, 9));
return total === expect;
},
rules: {
Expand Down
8 changes: 4 additions & 4 deletions lib/commonjs/lib/countries/hungary.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.hungary = {
name: 'Hungary',
codes: ['HU', 'HUN', '348'],
calcFn: (vat) => {
let total = 0;
calcFn: function (vat) {
var total = 0;
// Extract the next digit and multiply by the counter.
for (let i = 0; i < 7; i++) {
for (var i = 0; i < 7; i++) {
total += Number(vat.charAt(i)) * exports.hungary.rules.multipliers.common[i];
}
// Establish check digit.
total = 10 - total % 10;
if (total === 10)
total = 0;
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
const expect = Number(vat.slice(7, 8));
var expect = Number(vat.slice(7, 8));
return total === expect;
},
rules: {
Expand Down
Loading

0 comments on commit 3bf2c55

Please sign in to comment.