ibantools 4.1.6 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/build/ibantools.d.ts +9 -0
- package/build/ibantools.js +38 -28
- package/jsnext/ibantools.js +36 -27
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -86,6 +86,18 @@ If you are using tools that support `jsnext`, like a [rollup](https://github.com
|
|
|
86
86
|
|
|
87
87
|
Install library/module using npm. Package bundles type definitions and if you are on TypeScript 2.0 or above `tsc` will access those automatically. If not, check your `tsconfig.json` file.
|
|
88
88
|
|
|
89
|
+
### Extension
|
|
90
|
+
|
|
91
|
+
Country specifications can be extended with national BBAN validations by calling `setCountryBBANValidation`.
|
|
92
|
+
|
|
93
|
+
For example, to fully syntactically check German IBAN, you can install [IBANTools-Germany](https://github.com/baumerdev/ibantools-germany) and add this with
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
const ibantools = require('ibantools');
|
|
97
|
+
const ibantoolsGermany = require("ibantools-germany");
|
|
98
|
+
ibantools.setCountryBBANValidation("DE", ibantoolsGermany.isValidBBAN);
|
|
99
|
+
```
|
|
100
|
+
|
|
89
101
|
## Contributing
|
|
90
102
|
|
|
91
103
|
This project adheres to the Contributor Covenant [code of conduct](https://github.com/Simplify/ibantools/blob/master/.github/CODE_OF_CONDUCT.md).
|
package/build/ibantools.d.ts
CHANGED
|
@@ -224,6 +224,8 @@ export interface CountryMap {
|
|
|
224
224
|
}
|
|
225
225
|
/**
|
|
226
226
|
* Interface for IBAN Country Specification
|
|
227
|
+
*
|
|
228
|
+
* @ignore
|
|
227
229
|
*/
|
|
228
230
|
interface CountrySpecInternal {
|
|
229
231
|
chars?: number;
|
|
@@ -238,6 +240,13 @@ interface CountrySpecInternal {
|
|
|
238
240
|
interface CountryMapInternal {
|
|
239
241
|
[code: string]: CountrySpecInternal;
|
|
240
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Set custom BBAN validation function for country.
|
|
245
|
+
*
|
|
246
|
+
* If `bban_validation_func` already exists for the corresponding country,
|
|
247
|
+
* it will be overwritten.
|
|
248
|
+
*/
|
|
249
|
+
export declare const setCountryBBANValidation: (country: string, func: (bban: string) => boolean) => boolean;
|
|
241
250
|
/**
|
|
242
251
|
* Country specifications
|
|
243
252
|
*/
|
package/build/ibantools.js
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
* @package Documentation
|
|
9
9
|
* @author Saša Jovanić
|
|
10
10
|
* @module ibantools
|
|
11
|
-
* @version 4.1
|
|
11
|
+
* @version 4.2.1
|
|
12
12
|
* @license MPL-2.0
|
|
13
13
|
* @preferred
|
|
14
14
|
*/
|
|
15
15
|
'use strict';
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.countrySpecs = exports.extractBIC = exports.validateBIC = exports.ValidationErrorsBIC = exports.isValidBIC = exports.getCountrySpecifications = exports.friendlyFormatIBAN = exports.electronicFormatIBAN = exports.extractIBAN = exports.composeIBAN = exports.isSEPACountry = exports.isValidBBAN = exports.validateIBAN = exports.ValidationErrorsIBAN = exports.isValidIBAN = void 0;
|
|
17
|
+
exports.countrySpecs = exports.setCountryBBANValidation = exports.extractBIC = exports.validateBIC = exports.ValidationErrorsBIC = exports.isValidBIC = exports.getCountrySpecifications = exports.friendlyFormatIBAN = exports.electronicFormatIBAN = exports.extractIBAN = exports.composeIBAN = exports.isSEPACountry = exports.isValidBBAN = exports.validateIBAN = exports.ValidationErrorsIBAN = exports.isValidIBAN = void 0;
|
|
18
18
|
/**
|
|
19
19
|
* Validate IBAN
|
|
20
20
|
* ```
|
|
@@ -567,11 +567,11 @@ var checkCroatianBBAN = function (bban) {
|
|
|
567
567
|
return checkMod1110(bankBranch, controlBankBranch) && checkMod1110(account, controlAccount);
|
|
568
568
|
};
|
|
569
569
|
/**
|
|
570
|
-
* Czech (CZ) BBAN check
|
|
570
|
+
* Czech (CZ) and Slowak (SK) BBAN check
|
|
571
571
|
*
|
|
572
572
|
* @ignore
|
|
573
573
|
*/
|
|
574
|
-
var
|
|
574
|
+
var checkCzechAndSlovakBBAN = function (bban) {
|
|
575
575
|
var weightsPrefix = [10, 5, 8, 4, 2, 1];
|
|
576
576
|
var weightsSuffix = [6, 3, 7, 9, 10, 5, 8, 4, 2, 1];
|
|
577
577
|
var controlPrefix = parseInt(bban.charAt(9), 10);
|
|
@@ -615,34 +615,24 @@ var checkEstonianBBAN = function (bban) {
|
|
|
615
615
|
* @ignore
|
|
616
616
|
*/
|
|
617
617
|
var checkFinlandBBAN = function (bban) {
|
|
618
|
-
var
|
|
619
|
-
var weightsMethod2 = [0, 0, 0, 0, 0, 0, 0, 1, 3, 7, 1, 3, 7];
|
|
618
|
+
var weights = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2];
|
|
620
619
|
var controlDigit = parseInt(bban.charAt(13), 10);
|
|
621
620
|
var toCheck = bban.substring(0, 13);
|
|
622
621
|
var sum = 0;
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
sum += parseInt(toCheck.charAt(index), 10) *
|
|
622
|
+
for (var index = 0; index < toCheck.length; index++) {
|
|
623
|
+
if (weights[index] === 1) {
|
|
624
|
+
sum += parseInt(toCheck.charAt(index), 10) * weights[index];
|
|
626
625
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
else {
|
|
631
|
-
for (var index = 0; index < toCheck.length; index++) {
|
|
632
|
-
if (weightsMethod1[index] === 1) {
|
|
633
|
-
sum += parseInt(toCheck.charAt(index), 10) * weightsMethod1[index];
|
|
634
|
-
}
|
|
635
|
-
else {
|
|
636
|
-
var value = parseInt(toCheck.charAt(index), 10) * weightsMethod1[index];
|
|
637
|
-
sum += Math.floor(value / 10) + (value % 10);
|
|
638
|
-
}
|
|
626
|
+
else {
|
|
627
|
+
var value = parseInt(toCheck.charAt(index), 10) * weights[index];
|
|
628
|
+
sum += Math.floor(value / 10) + (value % 10);
|
|
639
629
|
}
|
|
640
|
-
var extraSum = sum + controlDigit;
|
|
641
|
-
var multiDigit = Math.floor(extraSum / 10);
|
|
642
|
-
var result = multiDigit * 10;
|
|
643
|
-
var remainder = result - sum;
|
|
644
|
-
return remainder === controlDigit;
|
|
645
630
|
}
|
|
631
|
+
var extraSum = sum + controlDigit;
|
|
632
|
+
var multiDigit = Math.floor(extraSum / 10);
|
|
633
|
+
var result = multiDigit * 10;
|
|
634
|
+
var remainder = result - sum;
|
|
635
|
+
return remainder === controlDigit;
|
|
646
636
|
};
|
|
647
637
|
/**
|
|
648
638
|
* Check French (FR) BBAN
|
|
@@ -744,6 +734,20 @@ var checkHungarianBBAN = function (bban) {
|
|
|
744
734
|
return controlDigitAccount === (remainder_2 === 0 ? 0 : 10 - remainder_2);
|
|
745
735
|
}
|
|
746
736
|
};
|
|
737
|
+
/**
|
|
738
|
+
* Set custom BBAN validation function for country.
|
|
739
|
+
*
|
|
740
|
+
* If `bban_validation_func` already exists for the corresponding country,
|
|
741
|
+
* it will be overwritten.
|
|
742
|
+
*/
|
|
743
|
+
var setCountryBBANValidation = function (country, func) {
|
|
744
|
+
if (typeof exports.countrySpecs[country] === 'undefined') {
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
exports.countrySpecs[country].bban_validation_func = func;
|
|
748
|
+
return true;
|
|
749
|
+
};
|
|
750
|
+
exports.setCountryBBANValidation = setCountryBBANValidation;
|
|
747
751
|
/**
|
|
748
752
|
* Country specifications
|
|
749
753
|
*/
|
|
@@ -892,7 +896,7 @@ exports.countrySpecs = {
|
|
|
892
896
|
CZ: {
|
|
893
897
|
chars: 24,
|
|
894
898
|
bban_regexp: '^[0-9]{20}$',
|
|
895
|
-
bban_validation_func:
|
|
899
|
+
bban_validation_func: checkCzechAndSlovakBBAN,
|
|
896
900
|
IBANRegistry: true,
|
|
897
901
|
SEPA: true,
|
|
898
902
|
},
|
|
@@ -1318,7 +1322,13 @@ exports.countrySpecs = {
|
|
|
1318
1322
|
SEPA: true,
|
|
1319
1323
|
},
|
|
1320
1324
|
SJ: {},
|
|
1321
|
-
SK: {
|
|
1325
|
+
SK: {
|
|
1326
|
+
chars: 24,
|
|
1327
|
+
bban_regexp: '^[0-9]{20}$',
|
|
1328
|
+
bban_validation_func: checkCzechAndSlovakBBAN,
|
|
1329
|
+
IBANRegistry: true,
|
|
1330
|
+
SEPA: true,
|
|
1331
|
+
},
|
|
1322
1332
|
SL: {},
|
|
1323
1333
|
SM: {
|
|
1324
1334
|
chars: 27,
|
package/jsnext/ibantools.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @package Documentation
|
|
9
9
|
* @author Saša Jovanić
|
|
10
10
|
* @module ibantools
|
|
11
|
-
* @version 4.1
|
|
11
|
+
* @version 4.2.1
|
|
12
12
|
* @license MPL-2.0
|
|
13
13
|
* @preferred
|
|
14
14
|
*/
|
|
@@ -553,11 +553,11 @@ var checkCroatianBBAN = function (bban) {
|
|
|
553
553
|
return checkMod1110(bankBranch, controlBankBranch) && checkMod1110(account, controlAccount);
|
|
554
554
|
};
|
|
555
555
|
/**
|
|
556
|
-
* Czech (CZ) BBAN check
|
|
556
|
+
* Czech (CZ) and Slowak (SK) BBAN check
|
|
557
557
|
*
|
|
558
558
|
* @ignore
|
|
559
559
|
*/
|
|
560
|
-
var
|
|
560
|
+
var checkCzechAndSlovakBBAN = function (bban) {
|
|
561
561
|
var weightsPrefix = [10, 5, 8, 4, 2, 1];
|
|
562
562
|
var weightsSuffix = [6, 3, 7, 9, 10, 5, 8, 4, 2, 1];
|
|
563
563
|
var controlPrefix = parseInt(bban.charAt(9), 10);
|
|
@@ -601,34 +601,24 @@ var checkEstonianBBAN = function (bban) {
|
|
|
601
601
|
* @ignore
|
|
602
602
|
*/
|
|
603
603
|
var checkFinlandBBAN = function (bban) {
|
|
604
|
-
var
|
|
605
|
-
var weightsMethod2 = [0, 0, 0, 0, 0, 0, 0, 1, 3, 7, 1, 3, 7];
|
|
604
|
+
var weights = [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2];
|
|
606
605
|
var controlDigit = parseInt(bban.charAt(13), 10);
|
|
607
606
|
var toCheck = bban.substring(0, 13);
|
|
608
607
|
var sum = 0;
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
sum += parseInt(toCheck.charAt(index), 10) *
|
|
608
|
+
for (var index = 0; index < toCheck.length; index++) {
|
|
609
|
+
if (weights[index] === 1) {
|
|
610
|
+
sum += parseInt(toCheck.charAt(index), 10) * weights[index];
|
|
612
611
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
else {
|
|
617
|
-
for (var index = 0; index < toCheck.length; index++) {
|
|
618
|
-
if (weightsMethod1[index] === 1) {
|
|
619
|
-
sum += parseInt(toCheck.charAt(index), 10) * weightsMethod1[index];
|
|
620
|
-
}
|
|
621
|
-
else {
|
|
622
|
-
var value = parseInt(toCheck.charAt(index), 10) * weightsMethod1[index];
|
|
623
|
-
sum += Math.floor(value / 10) + (value % 10);
|
|
624
|
-
}
|
|
612
|
+
else {
|
|
613
|
+
var value = parseInt(toCheck.charAt(index), 10) * weights[index];
|
|
614
|
+
sum += Math.floor(value / 10) + (value % 10);
|
|
625
615
|
}
|
|
626
|
-
var extraSum = sum + controlDigit;
|
|
627
|
-
var multiDigit = Math.floor(extraSum / 10);
|
|
628
|
-
var result = multiDigit * 10;
|
|
629
|
-
var remainder = result - sum;
|
|
630
|
-
return remainder === controlDigit;
|
|
631
616
|
}
|
|
617
|
+
var extraSum = sum + controlDigit;
|
|
618
|
+
var multiDigit = Math.floor(extraSum / 10);
|
|
619
|
+
var result = multiDigit * 10;
|
|
620
|
+
var remainder = result - sum;
|
|
621
|
+
return remainder === controlDigit;
|
|
632
622
|
};
|
|
633
623
|
/**
|
|
634
624
|
* Check French (FR) BBAN
|
|
@@ -730,6 +720,19 @@ var checkHungarianBBAN = function (bban) {
|
|
|
730
720
|
return controlDigitAccount === (remainder_2 === 0 ? 0 : 10 - remainder_2);
|
|
731
721
|
}
|
|
732
722
|
};
|
|
723
|
+
/**
|
|
724
|
+
* Set custom BBAN validation function for country.
|
|
725
|
+
*
|
|
726
|
+
* If `bban_validation_func` already exists for the corresponding country,
|
|
727
|
+
* it will be overwritten.
|
|
728
|
+
*/
|
|
729
|
+
export var setCountryBBANValidation = function (country, func) {
|
|
730
|
+
if (typeof countrySpecs[country] === 'undefined') {
|
|
731
|
+
return false;
|
|
732
|
+
}
|
|
733
|
+
countrySpecs[country].bban_validation_func = func;
|
|
734
|
+
return true;
|
|
735
|
+
};
|
|
733
736
|
/**
|
|
734
737
|
* Country specifications
|
|
735
738
|
*/
|
|
@@ -878,7 +881,7 @@ export var countrySpecs = {
|
|
|
878
881
|
CZ: {
|
|
879
882
|
chars: 24,
|
|
880
883
|
bban_regexp: '^[0-9]{20}$',
|
|
881
|
-
bban_validation_func:
|
|
884
|
+
bban_validation_func: checkCzechAndSlovakBBAN,
|
|
882
885
|
IBANRegistry: true,
|
|
883
886
|
SEPA: true,
|
|
884
887
|
},
|
|
@@ -1304,7 +1307,13 @@ export var countrySpecs = {
|
|
|
1304
1307
|
SEPA: true,
|
|
1305
1308
|
},
|
|
1306
1309
|
SJ: {},
|
|
1307
|
-
SK: {
|
|
1310
|
+
SK: {
|
|
1311
|
+
chars: 24,
|
|
1312
|
+
bban_regexp: '^[0-9]{20}$',
|
|
1313
|
+
bban_validation_func: checkCzechAndSlovakBBAN,
|
|
1314
|
+
IBANRegistry: true,
|
|
1315
|
+
SEPA: true,
|
|
1316
|
+
},
|
|
1308
1317
|
SL: {},
|
|
1309
1318
|
SM: {
|
|
1310
1319
|
chars: 27,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ibantools",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Validation, extraction and creation of IBAN, BBAN, BIC/SWIFT numbers plus some other helpful stuff like ISO 3136-1 alpha 2 country list",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"IBAN",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
},
|
|
51
51
|
"license": "MPL-2.0",
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
54
|
-
"@typescript-eslint/parser": "^
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
54
|
+
"@typescript-eslint/parser": "^5.0.0",
|
|
55
55
|
"chai": "^4.3.4",
|
|
56
56
|
"coveralls": "^3.1.1",
|
|
57
57
|
"docdash": "^1.2.0",
|
|
58
|
-
"eslint": "^
|
|
58
|
+
"eslint": "^8.0.0",
|
|
59
59
|
"eslint-config-prettier": "^8.3.0",
|
|
60
60
|
"eslint-plugin-prettier": "^4.0.0",
|
|
61
61
|
"gulp": "^4.0.2",
|