Skip to content

Commit 3bf2c55

Browse files
committed
commonjs now targets es5 + dependencies update
1 parent e6bd8e1 commit 3bf2c55

37 files changed

+749
-660
lines changed

lib/commonjs/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
const countries_1 = require("./lib/countries");
4-
const countries = [
3+
var countries_1 = require("./lib/countries");
4+
var countries = [
55
countries_1.austria,
66
countries_1.belgium,
77
countries_1.bulgaria,

lib/commonjs/lib/countries/austria.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.austria = {
44
name: 'Austria',
55
codes: ['AT', 'AUT', '040'],
6-
calcFn: (vat) => {
7-
let total = 0;
8-
for (let i = 0; i < 7; i++) {
9-
const temp = Number(vat.charAt(i)) * exports.austria.rules.multipliers.common[i];
6+
calcFn: function (vat) {
7+
var total = 0;
8+
for (var i = 0; i < 7; i++) {
9+
var temp = Number(vat.charAt(i)) * exports.austria.rules.multipliers.common[i];
1010
if (temp > 9) {
1111
total += Math.floor(temp / 10) + temp % 10;
1212
}

lib/commonjs/lib/countries/belgium.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.belgium = {
44
name: 'Belgium',
55
codes: ['BE', 'BEL', '056'],
6-
calcFn: (vat) => {
7-
const newVat = (vat.length === 9) ? ('0' + vat) : vat;
6+
calcFn: function (vat) {
7+
var newVat = (vat.length === 9) ? ('0' + vat) : vat;
88
if (Number(newVat.slice(1, 2)) === 0)
99
return false;
10-
const check = (97 - Number(newVat.slice(0, 8)) % 97);
10+
var check = (97 - Number(newVat.slice(0, 8)) % 97);
1111
return check === Number(newVat.slice(8, 10));
1212
},
1313
rules: {

lib/commonjs/lib/countries/bulgaria.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.bulgaria = {
44
name: 'Bulgaria',
55
codes: ['BG', 'BGR', '100'],
6-
calcFn: (vat) => {
6+
calcFn: function (vat) {
77
if (vat.length === 9)
88
return _checkNineLengthVat(vat);
9-
const { multipliers } = exports.bulgaria.rules;
9+
var multipliers = exports.bulgaria.rules.multipliers;
1010
return _isPhysicalPerson(vat, multipliers.physical) || _isForeigner(vat, multipliers) || _miscellaneousVAT(vat, multipliers);
1111
},
1212
rules: {
@@ -19,23 +19,23 @@ exports.bulgaria = {
1919
}
2020
};
2121
function _increase(value, vat, from, to, incr) {
22-
let result = value;
23-
for (let i = from; i < to; i++) {
22+
var result = value;
23+
for (var i = from; i < to; i++) {
2424
result += Number(vat.charAt(i)) * (i + incr);
2525
}
2626
return result;
2727
}
2828
function _increase2(value, vat, from, to, multipliers) {
29-
let result = value;
30-
for (let i = from; i < to; i++) {
29+
var result = value;
30+
for (var i = from; i < to; i++) {
3131
result += Number(vat.charAt(i)) * multipliers[i];
3232
}
3333
return result;
3434
}
3535
function _checkNineLengthVat(vat) {
36-
let total;
37-
let temp = _increase(0, vat, 0, 8, 1);
38-
const expect = Number(vat.slice(8));
36+
var total;
37+
var temp = _increase(0, vat, 0, 8, 1);
38+
var expect = Number(vat.slice(8));
3939
total = temp % 11;
4040
if (total !== 10)
4141
return total === expect;
@@ -49,9 +49,9 @@ function _isPhysicalPerson(vat, physicalMultipliers) {
4949
// 10 digit VAT code - see if it relates to a standard physical person
5050
if ((/^\d\d[0-5]\d[0-3]\d\d{4}$/).test(vat)) {
5151
// Check month
52-
const month = Number(vat.slice(2, 4));
52+
var month = Number(vat.slice(2, 4));
5353
if ((month > 0 && month < 13) || (month > 20 && month < 33) || (month > 40 && month < 53)) {
54-
let total = _increase2(0, vat, 0, 9, physicalMultipliers);
54+
var total = _increase2(0, vat, 0, 9, physicalMultipliers);
5555
// Establish check digit.
5656
total = total % 11;
5757
if (total === 10)
@@ -65,20 +65,20 @@ function _isPhysicalPerson(vat, physicalMultipliers) {
6565
}
6666
function _isForeigner(vat, multipliers) {
6767
// Extract the next digit and multiply by the counter.
68-
const total = _increase2(0, vat, 0, 9, multipliers.foreigner);
68+
var total = _increase2(0, vat, 0, 9, multipliers.foreigner);
6969
// Check to see if the check digit given is correct, If not, try next type of person
7070
return total % 10 === Number(vat.substr(9, 1));
7171
}
7272
function _miscellaneousVAT(vat, multipliers) {
7373
// Finally, if not yet identified, see if it conforms to a miscellaneous VAT number
74-
let total = _increase2(0, vat, 0, 9, multipliers.miscellaneous);
74+
var total = _increase2(0, vat, 0, 9, multipliers.miscellaneous);
7575
// Establish check digit.
7676
total = 11 - total % 11;
7777
if (total === 10)
7878
return false;
7979
if (total === 11)
8080
total = 0;
8181
// Check to see if the check digit given is correct, If not, we have an error with the VAT number
82-
const expect = Number(vat.substr(9, 1));
82+
var expect = Number(vat.substr(9, 1));
8383
return total === expect;
8484
}

lib/commonjs/lib/countries/croatiat.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.croatia = {
44
name: 'Croatia',
55
codes: ['HR', 'HRV', '191'],
6-
calcFn: (vat) => {
6+
calcFn: function (vat) {
77
// Checks the check digits of a Croatian VAT number using ISO 7064, MOD 11-10 for check digit.
8-
let product = 10;
9-
let sum = 0;
10-
for (let i = 0; i < 10; i++) {
8+
var product = 10;
9+
var sum = 0;
10+
for (var i = 0; i < 10; i++) {
1111
// Extract the next digit and implement the algorithm
1212
sum = (Number(vat.charAt(i)) + product) % 10;
1313
if (sum === 0) {
@@ -16,7 +16,7 @@ exports.croatia = {
1616
product = (2 * sum) % 11;
1717
}
1818
// Now check that we have the right check digit
19-
const expect = Number(vat.slice(10, 11));
19+
var expect = Number(vat.slice(10, 11));
2020
return (product + expect) % 10 === 1;
2121
},
2222
rules: {

lib/commonjs/lib/countries/cyprus.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.cyprus = {
44
name: 'Cyprus',
55
codes: ['CY', 'CYP', '196'],
6-
calcFn: (vat) => {
6+
calcFn: function (vat) {
77
// Not allowed to start with '12'
88
if (Number(vat.slice(0, 2)) === 12)
99
return false;
1010
// Extract the next digit and multiply by the counter.
11-
let total = extractAndMultiplyByCounter(vat, 0);
11+
var total = extractAndMultiplyByCounter(vat, 0);
1212
// Establish check digit using modulus 26, and translate to char. equivalent.
1313
total = total % 26;
1414
total = String.fromCharCode(total + 65);
1515
// Check to see if the check digit given is correct
16-
const expect = vat.substr(8, 1);
16+
var expect = vat.substr(8, 1);
1717
return total === expect;
1818
},
1919
rules: {
@@ -22,9 +22,9 @@ exports.cyprus = {
2222
}
2323
};
2424
function extractAndMultiplyByCounter(vat, total) {
25-
let result = total;
26-
for (let i = 0; i < 8; i++) {
27-
let temp = Number(vat.charAt(i));
25+
var result = total;
26+
for (var i = 0; i < 8; i++) {
27+
var temp = Number(vat.charAt(i));
2828
if (i % 2 === 0) {
2929
switch (temp) {
3030
case 0:

lib/commonjs/lib/countries/czechRepublic.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.czechRepublic = {
44
name: 'Czech Republic',
55
codes: ['CZ', 'CZE', '203'],
6-
calcFn: (vat) => {
7-
const { rules } = exports.czechRepublic;
8-
const { multipliers, additional, lookup } = rules;
6+
calcFn: function (vat) {
7+
var rules = exports.czechRepublic.rules;
8+
var multipliers = rules.multipliers, additional = rules.additional, lookup = rules.lookup;
99
if (!additional)
1010
return false;
1111
return isLegalEntities(vat, multipliers.common, additional)
@@ -28,10 +28,10 @@ exports.czechRepublic = {
2828
}
2929
};
3030
function isLegalEntities(vat, multipliers, additional) {
31-
let total = 0;
31+
var total = 0;
3232
if (additional[0].test(vat)) {
3333
// Extract the next digit and multiply by the counter.
34-
for (let i = 0; i < 7; i++) {
34+
for (var i = 0; i < 7; i++) {
3535
total += Number(vat.charAt(i)) * multipliers[i];
3636
}
3737
// Establish check digit.
@@ -41,7 +41,7 @@ function isLegalEntities(vat, multipliers, additional) {
4141
if (total === 11)
4242
total = 1;
4343
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
44-
const expect = Number(vat.slice(7, 8));
44+
var expect = Number(vat.slice(7, 8));
4545
return total === expect;
4646
}
4747
return false;
@@ -53,10 +53,10 @@ function isIndividualType1(vat, additional) {
5353
return false;
5454
}
5555
function isIndividualType2(vat, multipliers, additional, lookup) {
56-
let total = 0;
56+
var total = 0;
5757
if (additional[2].test(vat)) {
5858
// Extract the next digit and multiply by the counter.
59-
for (let j = 0; j < 7; j++) {
59+
for (var j = 0; j < 7; j++) {
6060
total += Number(vat.charAt(j + 1)) * multipliers[j];
6161
}
6262
// Establish check digit.
@@ -66,7 +66,7 @@ function isIndividualType2(vat, multipliers, additional, lookup) {
6666
if (total === 11)
6767
total = 1;
6868
// Convert calculated check digit according to a lookup table
69-
const expect = Number(vat.slice(8, 9));
69+
var expect = Number(vat.slice(8, 9));
7070
if (!lookup)
7171
return false;
7272
return lookup[total - 1] === expect;
@@ -75,8 +75,8 @@ function isIndividualType2(vat, multipliers, additional, lookup) {
7575
}
7676
function isIndividualType3(vat, additional) {
7777
if (additional[3].test(vat)) {
78-
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));
79-
const expect = Number(vat) % 11 === 0;
78+
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));
79+
var expect = Number(vat) % 11 === 0;
8080
return !!(temp % 11 === 0 && expect);
8181
}
8282
return false;

lib/commonjs/lib/countries/denmark.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.denmark = {
44
name: 'Denmark',
55
codes: ['DK', 'DNK', '208'],
6-
calcFn: (vat) => {
7-
let total = 0;
8-
for (let i = 0; i < 8; i++) {
6+
calcFn: function (vat) {
7+
var total = 0;
8+
for (var i = 0; i < 8; i++) {
99
total += Number(vat.charAt(i)) * exports.denmark.rules.multipliers.common[i];
1010
}
1111
return total % 11 === 0;

lib/commonjs/lib/countries/estonia.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.estonia = {
44
name: 'Estonia',
55
codes: ['EE', 'EST', '233'],
6-
calcFn: (vat) => {
7-
let total = 0;
8-
let expect;
6+
calcFn: function (vat) {
7+
var total = 0;
8+
var expect;
99
// Extract the next digit and multiply by the counter.
10-
for (let i = 0; i < 8; i++) {
10+
for (var i = 0; i < 8; i++) {
1111
total += Number(vat.charAt(i)) * exports.estonia.rules.multipliers.common[i];
1212
}
1313
// Establish check digits using modulus 10.

lib/commonjs/lib/countries/europe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.europe = {
44
name: 'Europe',
55
codes: ['EU', 'EUR', '000'],
6-
calcFn: () => {
6+
calcFn: function () {
77
// We know little about EU numbers apart from the fact that the first 3 digits represent the
88
// country, and that there are nine digits in total.
99
return true;

lib/commonjs/lib/countries/finland.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.finland = {
44
name: 'Finland',
55
codes: ['FI', 'FIN', '246'],
6-
calcFn: (vat) => {
7-
let total = 0;
6+
calcFn: function (vat) {
7+
var total = 0;
88
// Extract the next digit and multiply by the counter.
9-
for (let i = 0; i < 7; i++)
9+
for (var i = 0; i < 7; i++)
1010
total += Number(vat.charAt(i)) * exports.finland.rules.multipliers.common[i];
1111
// Establish check digit.
1212
total = 11 - total % 11;
1313
if (total > 9) {
1414
total = 0;
1515
}
1616
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
17-
const expect = Number(vat.slice(7, 8));
17+
var expect = Number(vat.slice(7, 8));
1818
return total === expect;
1919
},
2020
rules: {

lib/commonjs/lib/countries/france.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.france = {
44
name: 'France',
55
codes: ['FR', 'FRA', '250'],
6-
calcFn: (vat) => {
7-
let total;
6+
calcFn: function (vat) {
7+
var total;
88
// Checks the check digits of a French VAT number.
99
if (!(/^\d{11}$/).test(vat))
1010
return true;
@@ -13,7 +13,7 @@ exports.france = {
1313
// Establish check digit.
1414
total = (total * 100 + 12) % 97;
1515
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
16-
const expect = Number(vat.slice(0, 2));
16+
var expect = Number(vat.slice(0, 2));
1717
return total === expect;
1818
},
1919
rules: {

lib/commonjs/lib/countries/germany.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.germany = {
44
name: 'Germany',
55
codes: ['DE', 'DEU', '276'],
6-
calcFn: (vat) => {
6+
calcFn: function (vat) {
77
// Checks the check digits of a German VAT number.
8-
let product = 10;
9-
let sum = 0;
10-
let checkDigit = 0;
11-
let expect;
12-
for (let i = 0; i < 8; i++) {
8+
var product = 10;
9+
var sum = 0;
10+
var checkDigit = 0;
11+
var expect;
12+
for (var i = 0; i < 8; i++) {
1313
// Extract the next digit and implement peculiar algorithm!.
1414
sum = (Number(vat.charAt(i)) + product) % 10;
1515
if (sum === 0) {

lib/commonjs/lib/countries/greece.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.greece = {
44
name: 'Greece',
55
codes: ['GR', 'GRC', '300'],
6-
calcFn: (vat) => {
7-
let total = 0;
6+
calcFn: function (vat) {
7+
var total = 0;
88
// eight character numbers should be prefixed with an 0.
9-
const newVat = (vat.length === 8) ? '0' + vat : vat;
9+
var newVat = (vat.length === 8) ? '0' + vat : vat;
1010
// Extract the next digit and multiply by the counter.
11-
for (let i = 0; i < 8; i++) {
11+
for (var i = 0; i < 8; i++) {
1212
total += Number(newVat.charAt(i)) * exports.greece.rules.multipliers.common[i];
1313
}
1414
// Establish check digit.
1515
total = total % 11;
1616
total = (total > 9) ? 0 : total;
1717
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
18-
const expect = Number(newVat.slice(8, 9));
18+
var expect = Number(newVat.slice(8, 9));
1919
return total === expect;
2020
},
2121
rules: {

lib/commonjs/lib/countries/hungary.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
exports.hungary = {
44
name: 'Hungary',
55
codes: ['HU', 'HUN', '348'],
6-
calcFn: (vat) => {
7-
let total = 0;
6+
calcFn: function (vat) {
7+
var total = 0;
88
// Extract the next digit and multiply by the counter.
9-
for (let i = 0; i < 7; i++) {
9+
for (var i = 0; i < 7; i++) {
1010
total += Number(vat.charAt(i)) * exports.hungary.rules.multipliers.common[i];
1111
}
1212
// Establish check digit.
1313
total = 10 - total % 10;
1414
if (total === 10)
1515
total = 0;
1616
// Compare it with the last character of the VAT number. If it's the same, then it's valid.
17-
const expect = Number(vat.slice(7, 8));
17+
var expect = Number(vat.slice(7, 8));
1818
return total === expect;
1919
},
2020
rules: {

0 commit comments

Comments
 (0)