ibantools 4.2.2 → 4.3.0

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 CHANGED
@@ -52,7 +52,7 @@ See [full documentation](http://simplify.github.io/ibantools) with examples on G
52
52
 
53
53
  ```js
54
54
  const ibantools = require('ibantools');
55
- const iban = electronicFormatIBAN('NL91 ABNA 0517 1643 00'); // 'NL91ABNA0517164300'
55
+ const iban = electronicFormatIBAN('NL91 ABNA 0417 1643 00'); // 'NL91ABNA0517164300'
56
56
  ibantools.isValidIBAN(iban);
57
57
 
58
58
  // If you want to know reason why IBAN is invalid
@@ -67,7 +67,7 @@ ibantools.isValidBIC('ABNANL2A');
67
67
 
68
68
  ```js
69
69
  require(["ibantools"], function(ibantools) {
70
- console.log(ibantools.isValidIBAN('NL91 ABNA 0517 1643 00'));
70
+ console.log(ibantools.isValidIBAN('NL91 ABNA 0417 1643 00'));
71
71
  console.log(ibantools.isValidBIC('ABNANL2A'));
72
72
  });
73
73
  ```
@@ -3,18 +3,32 @@
3
3
  * This Source Code Form is subject to the terms of the Mozilla Public
4
4
  * License, v. 2.0. If a copy of the MPL was not distributed with this
5
5
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
+ /**
7
+ * Interface for validation options
8
+ */
9
+ export interface ValidateIBANOptions {
10
+ allowQRIBAN: boolean;
11
+ }
6
12
  /**
7
13
  * Validate IBAN
8
14
  * ```
9
15
  * // returns true
10
- * ibantools.isValidIBAN("NL91ABNA0517164300");
16
+ * ibantools.isValidIBAN("NL91ABNA0417164300");
11
17
  * ```
12
18
  * ```
13
19
  * // returns false
14
20
  * ibantools.isValidIBAN("NL92ABNA0517164300");
15
21
  * ```
22
+ * ```
23
+ * // returns true
24
+ * ibantools.isValidIBAN('CH4431999123000889012');
25
+ * ```
26
+ * ```
27
+ * // returns false
28
+ * ibantools.isValidIBAN('CH4431999123000889012', { allowQRIBAN: false });
29
+ * ```
16
30
  */
17
- export declare function isValidIBAN(iban: string): boolean;
31
+ export declare function isValidIBAN(iban: string, validationOptions?: ValidateIBANOptions): boolean;
18
32
  /**
19
33
  * IBAM validation errors
20
34
  */
@@ -25,7 +39,8 @@ export declare enum ValidationErrorsIBAN {
25
39
  WrongBBANFormat = 3,
26
40
  ChecksumNotNumber = 4,
27
41
  WrongIBANChecksum = 5,
28
- WrongAccountBankBranchChecksum = 6
42
+ WrongAccountBankBranchChecksum = 6,
43
+ QRIBANNotAllowed = 7
29
44
  }
30
45
  /**
31
46
  * Interface for ValidateIBAN result
@@ -40,14 +55,23 @@ export interface ValidateIBANResult {
40
55
  * // returns {errorCodes: [], valid: true}
41
56
  * ibantools.validateIBAN("NL91ABNA0417164300");
42
57
  * ```
58
+ * ```
59
+ * ```
60
+ * // returns {errorCodes: [], valid: true}
61
+ * ibantools.validateIBAN('CH4431999123000889012');
62
+ * ```
63
+ * ```
64
+ * // returns {errorCodes: [7], valid: false}
65
+ * ibantools.validateIBAN('CH4431999123000889012', { allowQRIBAN: false });
66
+ * ```
43
67
  */
44
- export declare function validateIBAN(iban?: string): ValidateIBANResult;
68
+ export declare function validateIBAN(iban?: string, validationOptions?: ValidateIBANOptions): ValidateIBANResult;
45
69
  /**
46
70
  * Validate BBAN
47
71
  *
48
72
  * ```
49
73
  * // returns true
50
- * ibantools.isValidBBAN("ABNA0517164300", "NL");
74
+ * ibantools.isValidBBAN("ABNA0417164300", "NL");
51
75
  * ```
52
76
  * ```
53
77
  * // returns false
@@ -67,6 +91,18 @@ export declare function isValidBBAN(bban?: string, countryCode?: string): boolea
67
91
  * ```
68
92
  */
69
93
  export declare function isSEPACountry(countryCode: string): boolean;
94
+ /**
95
+ * Check if IBAN is QR-IBAN
96
+ * ```
97
+ * // returns true
98
+ * ibantools.isQRIBAN("CH4431999123000889012");
99
+ * ```
100
+ * ```
101
+ * // returns false
102
+ * ibantools.isQRIBAN("NL92ABNA0517164300");
103
+ * ```
104
+ */
105
+ export declare function isQRIBAN(iban: string): boolean;
70
106
  /**
71
107
  * Interface for ComposeIBAN parameteres
72
108
  */
@@ -8,35 +8,46 @@
8
8
  * @package Documentation
9
9
  * @author Saša Jovanić
10
10
  * @module ibantools
11
- * @version 4.2.2
11
+ * @version 4.3.0
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.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;
17
+ exports.countrySpecs = exports.setCountryBBANValidation = exports.extractBIC = exports.validateBIC = exports.ValidationErrorsBIC = exports.isValidBIC = exports.getCountrySpecifications = exports.friendlyFormatIBAN = exports.electronicFormatIBAN = exports.extractIBAN = exports.composeIBAN = exports.isQRIBAN = exports.isSEPACountry = exports.isValidBBAN = exports.validateIBAN = exports.ValidationErrorsIBAN = exports.isValidIBAN = void 0;
18
18
  /**
19
19
  * Validate IBAN
20
20
  * ```
21
21
  * // returns true
22
- * ibantools.isValidIBAN("NL91ABNA0517164300");
22
+ * ibantools.isValidIBAN("NL91ABNA0417164300");
23
23
  * ```
24
24
  * ```
25
25
  * // returns false
26
26
  * ibantools.isValidIBAN("NL92ABNA0517164300");
27
27
  * ```
28
+ * ```
29
+ * // returns true
30
+ * ibantools.isValidIBAN('CH4431999123000889012');
31
+ * ```
32
+ * ```
33
+ * // returns false
34
+ * ibantools.isValidIBAN('CH4431999123000889012', { allowQRIBAN: false });
35
+ * ```
28
36
  */
29
- function isValidIBAN(iban) {
37
+ function isValidIBAN(iban, validationOptions) {
38
+ if (validationOptions === void 0) { validationOptions = { allowQRIBAN: true }; }
30
39
  if (iban === undefined || iban === null)
31
40
  return false;
32
41
  var reg = new RegExp('^[0-9]{2}$', '');
33
- var spec = exports.countrySpecs[iban.slice(0, 2)];
42
+ var countryCode = iban.slice(0, 2);
43
+ var spec = exports.countrySpecs[countryCode];
34
44
  if (spec === undefined || spec.bban_regexp === undefined || spec.bban_regexp === null || spec.chars === undefined)
35
45
  return false;
36
46
  return (spec.chars === iban.length &&
37
47
  reg.test(iban.slice(2, 4)) &&
38
- isValidBBAN(iban.slice(4), iban.slice(0, 2)) &&
39
- isValidIBANChecksum(iban));
48
+ isValidBBAN(iban.slice(4), countryCode) &&
49
+ isValidIBANChecksum(iban) &&
50
+ (validationOptions.allowQRIBAN || !isQRIBAN(iban)));
40
51
  }
41
52
  exports.isValidIBAN = isValidIBAN;
42
53
  /**
@@ -51,6 +62,7 @@ var ValidationErrorsIBAN;
51
62
  ValidationErrorsIBAN[ValidationErrorsIBAN["ChecksumNotNumber"] = 4] = "ChecksumNotNumber";
52
63
  ValidationErrorsIBAN[ValidationErrorsIBAN["WrongIBANChecksum"] = 5] = "WrongIBANChecksum";
53
64
  ValidationErrorsIBAN[ValidationErrorsIBAN["WrongAccountBankBranchChecksum"] = 6] = "WrongAccountBankBranchChecksum";
65
+ ValidationErrorsIBAN[ValidationErrorsIBAN["QRIBANNotAllowed"] = 7] = "QRIBANNotAllowed";
54
66
  })(ValidationErrorsIBAN = exports.ValidationErrorsIBAN || (exports.ValidationErrorsIBAN = {}));
55
67
  /**
56
68
  * validateIBAN
@@ -58,8 +70,18 @@ var ValidationErrorsIBAN;
58
70
  * // returns {errorCodes: [], valid: true}
59
71
  * ibantools.validateIBAN("NL91ABNA0417164300");
60
72
  * ```
73
+ * ```
74
+ * ```
75
+ * // returns {errorCodes: [], valid: true}
76
+ * ibantools.validateIBAN('CH4431999123000889012');
77
+ * ```
78
+ * ```
79
+ * // returns {errorCodes: [7], valid: false}
80
+ * ibantools.validateIBAN('CH4431999123000889012', { allowQRIBAN: false });
81
+ * ```
61
82
  */
62
- function validateIBAN(iban) {
83
+ function validateIBAN(iban, validationOptions) {
84
+ if (validationOptions === void 0) { validationOptions = { allowQRIBAN: true }; }
63
85
  var result = { errorCodes: [], valid: true };
64
86
  if (iban !== undefined && iban !== null && iban !== '') {
65
87
  var spec = exports.countrySpecs[iban.slice(0, 2)];
@@ -89,6 +111,10 @@ function validateIBAN(iban) {
89
111
  result.valid = false;
90
112
  result.errorCodes.push(ValidationErrorsIBAN.WrongIBANChecksum);
91
113
  }
114
+ if (!validationOptions.allowQRIBAN && isQRIBAN(iban)) {
115
+ result.valid = false;
116
+ result.errorCodes.push(ValidationErrorsIBAN.QRIBANNotAllowed);
117
+ }
92
118
  }
93
119
  else {
94
120
  result.valid = false;
@@ -102,7 +128,7 @@ exports.validateIBAN = validateIBAN;
102
128
  *
103
129
  * ```
104
130
  * // returns true
105
- * ibantools.isValidBBAN("ABNA0517164300", "NL");
131
+ * ibantools.isValidBBAN("ABNA0417164300", "NL");
106
132
  * ```
107
133
  * ```
108
134
  * // returns false
@@ -150,6 +176,28 @@ function isSEPACountry(countryCode) {
150
176
  return false;
151
177
  }
152
178
  exports.isSEPACountry = isSEPACountry;
179
+ /**
180
+ * Check if IBAN is QR-IBAN
181
+ * ```
182
+ * // returns true
183
+ * ibantools.isQRIBAN("CH4431999123000889012");
184
+ * ```
185
+ * ```
186
+ * // returns false
187
+ * ibantools.isQRIBAN("NL92ABNA0517164300");
188
+ * ```
189
+ */
190
+ function isQRIBAN(iban) {
191
+ if (iban === undefined || iban === null)
192
+ return false;
193
+ var countryCode = iban.slice(0, 2);
194
+ var QRIBANCountries = ['LX', 'CH'];
195
+ if (!QRIBANCountries.includes(countryCode))
196
+ return false;
197
+ var reg = new RegExp('^3[0-1]{1}[0-9]{3}$', '');
198
+ return reg.test(iban.slice(4, 9));
199
+ }
200
+ exports.isQRIBAN = isQRIBAN;
153
201
  /**
154
202
  * composeIBAN
155
203
  *
@@ -8,7 +8,7 @@
8
8
  * @package Documentation
9
9
  * @author Saša Jovanić
10
10
  * @module ibantools
11
- * @version 4.2.2
11
+ * @version 4.3.0
12
12
  * @license MPL-2.0
13
13
  * @preferred
14
14
  */
@@ -17,24 +17,35 @@
17
17
  * Validate IBAN
18
18
  * ```
19
19
  * // returns true
20
- * ibantools.isValidIBAN("NL91ABNA0517164300");
20
+ * ibantools.isValidIBAN("NL91ABNA0417164300");
21
21
  * ```
22
22
  * ```
23
23
  * // returns false
24
24
  * ibantools.isValidIBAN("NL92ABNA0517164300");
25
25
  * ```
26
+ * ```
27
+ * // returns true
28
+ * ibantools.isValidIBAN('CH4431999123000889012');
29
+ * ```
30
+ * ```
31
+ * // returns false
32
+ * ibantools.isValidIBAN('CH4431999123000889012', { allowQRIBAN: false });
33
+ * ```
26
34
  */
27
- export function isValidIBAN(iban) {
35
+ export function isValidIBAN(iban, validationOptions) {
36
+ if (validationOptions === void 0) { validationOptions = { allowQRIBAN: true }; }
28
37
  if (iban === undefined || iban === null)
29
38
  return false;
30
39
  var reg = new RegExp('^[0-9]{2}$', '');
31
- var spec = countrySpecs[iban.slice(0, 2)];
40
+ var countryCode = iban.slice(0, 2);
41
+ var spec = countrySpecs[countryCode];
32
42
  if (spec === undefined || spec.bban_regexp === undefined || spec.bban_regexp === null || spec.chars === undefined)
33
43
  return false;
34
44
  return (spec.chars === iban.length &&
35
45
  reg.test(iban.slice(2, 4)) &&
36
- isValidBBAN(iban.slice(4), iban.slice(0, 2)) &&
37
- isValidIBANChecksum(iban));
46
+ isValidBBAN(iban.slice(4), countryCode) &&
47
+ isValidIBANChecksum(iban) &&
48
+ (validationOptions.allowQRIBAN || !isQRIBAN(iban)));
38
49
  }
39
50
  /**
40
51
  * IBAM validation errors
@@ -48,6 +59,7 @@ export var ValidationErrorsIBAN;
48
59
  ValidationErrorsIBAN[ValidationErrorsIBAN["ChecksumNotNumber"] = 4] = "ChecksumNotNumber";
49
60
  ValidationErrorsIBAN[ValidationErrorsIBAN["WrongIBANChecksum"] = 5] = "WrongIBANChecksum";
50
61
  ValidationErrorsIBAN[ValidationErrorsIBAN["WrongAccountBankBranchChecksum"] = 6] = "WrongAccountBankBranchChecksum";
62
+ ValidationErrorsIBAN[ValidationErrorsIBAN["QRIBANNotAllowed"] = 7] = "QRIBANNotAllowed";
51
63
  })(ValidationErrorsIBAN || (ValidationErrorsIBAN = {}));
52
64
  /**
53
65
  * validateIBAN
@@ -55,8 +67,18 @@ export var ValidationErrorsIBAN;
55
67
  * // returns {errorCodes: [], valid: true}
56
68
  * ibantools.validateIBAN("NL91ABNA0417164300");
57
69
  * ```
70
+ * ```
71
+ * ```
72
+ * // returns {errorCodes: [], valid: true}
73
+ * ibantools.validateIBAN('CH4431999123000889012');
74
+ * ```
75
+ * ```
76
+ * // returns {errorCodes: [7], valid: false}
77
+ * ibantools.validateIBAN('CH4431999123000889012', { allowQRIBAN: false });
78
+ * ```
58
79
  */
59
- export function validateIBAN(iban) {
80
+ export function validateIBAN(iban, validationOptions) {
81
+ if (validationOptions === void 0) { validationOptions = { allowQRIBAN: true }; }
60
82
  var result = { errorCodes: [], valid: true };
61
83
  if (iban !== undefined && iban !== null && iban !== '') {
62
84
  var spec = countrySpecs[iban.slice(0, 2)];
@@ -86,6 +108,10 @@ export function validateIBAN(iban) {
86
108
  result.valid = false;
87
109
  result.errorCodes.push(ValidationErrorsIBAN.WrongIBANChecksum);
88
110
  }
111
+ if (!validationOptions.allowQRIBAN && isQRIBAN(iban)) {
112
+ result.valid = false;
113
+ result.errorCodes.push(ValidationErrorsIBAN.QRIBANNotAllowed);
114
+ }
89
115
  }
90
116
  else {
91
117
  result.valid = false;
@@ -98,7 +124,7 @@ export function validateIBAN(iban) {
98
124
  *
99
125
  * ```
100
126
  * // returns true
101
- * ibantools.isValidBBAN("ABNA0517164300", "NL");
127
+ * ibantools.isValidBBAN("ABNA0417164300", "NL");
102
128
  * ```
103
129
  * ```
104
130
  * // returns false
@@ -144,6 +170,27 @@ export function isSEPACountry(countryCode) {
144
170
  }
145
171
  return false;
146
172
  }
173
+ /**
174
+ * Check if IBAN is QR-IBAN
175
+ * ```
176
+ * // returns true
177
+ * ibantools.isQRIBAN("CH4431999123000889012");
178
+ * ```
179
+ * ```
180
+ * // returns false
181
+ * ibantools.isQRIBAN("NL92ABNA0517164300");
182
+ * ```
183
+ */
184
+ export function isQRIBAN(iban) {
185
+ if (iban === undefined || iban === null)
186
+ return false;
187
+ var countryCode = iban.slice(0, 2);
188
+ var QRIBANCountries = ['LX', 'CH'];
189
+ if (!QRIBANCountries.includes(countryCode))
190
+ return false;
191
+ var reg = new RegExp('^3[0-1]{1}[0-9]{3}$', '');
192
+ return reg.test(iban.slice(4, 9));
193
+ }
147
194
  /**
148
195
  * composeIBAN
149
196
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ibantools",
3
- "version": "4.2.2",
3
+ "version": "4.3.0",
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",
@@ -36,13 +36,17 @@
36
36
  "url": "https://github.com/Simplify/ibantools.git"
37
37
  },
38
38
  "scripts": {
39
- "build": "rm -rf dist && rm -rf jsnext && rm -rf build && gulp all",
40
- "test": "gulp test-it",
41
- "karma": "gulp karma",
42
- "coverage": "gulp coverage",
43
- "lint": "gulp lint",
44
- "prepare": "npm run build",
45
- "docs": "gulp docs"
39
+ "build": "npm run build-node && npm run build-bower && npm run build-module",
40
+ "build-node": "rm -rf build && npx tsc src/*.ts --declaration --target es5 --module commonjs --outDir ./build/",
41
+ "build-bower": "rm -rf dist && npx tsc src/*.ts --declaration --target es5 --module amd --outDir ./dist/",
42
+ "build-module": "rm -rf jsnext && npx tsc src/*.ts --target es5 --module es2015 --outDir ./jsnext/",
43
+ "test": "npm run build && mocha 'test/**/*.js'",
44
+ "karma": "karma start --single-run",
45
+ "coverage": "nyc mocha && nyc report --reporter=text-lcov | coveralls",
46
+ "lint": "eslint 'src/**/*.ts' 'test/**/*.js'",
47
+ "prepare": "npm run build-node",
48
+ "docs": "typedoc src/ibantools.ts",
49
+ "all": "npm run test && npm run lint && npm run karma && npm run docs"
46
50
  },
47
51
  "author": {
48
52
  "name": "Saša Jovanić",
@@ -58,23 +62,18 @@
58
62
  "eslint": "^8.0.0",
59
63
  "eslint-config-prettier": "^8.3.0",
60
64
  "eslint-plugin-prettier": "^4.0.0",
61
- "gulp": "^4.0.2",
62
- "gulp-rename": "^2.0",
63
- "gulp-shell": "^0.8.0",
64
- "gulp-typescript": "^5.0",
65
65
  "jasmine-core": "^4.0.0",
66
66
  "karma": "^6.3.4",
67
67
  "karma-chrome-launcher": "^3.1",
68
68
  "karma-jasmine": "^5.0",
69
69
  "karma-requirejs": "^1.1",
70
- "merge2": "^1.4.1",
71
70
  "mocha": "^10.0.0",
72
71
  "mocha-lcov-reporter": "^1.2.0",
73
72
  "nyc": "^15.1.0",
74
73
  "prettier": "^2.3.2",
75
74
  "requirejs": "^2.3.6",
76
- "typedoc": "^0.23.1",
77
- "typescript": "^4.3.5"
75
+ "typedoc": "^0.24.1",
76
+ "typescript": "^5.0.2"
78
77
  },
79
78
  "resolutions": {
80
79
  "source-map": "^0.8.0-beta.0"