kontonummer 5.0.1 → 6.0.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 +2 -1
- package/dist/cjs/errors.js +1 -4
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.js +30 -35
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/banks.js +5 -2
- package/dist/esm/banks.js.map +1 -1
- package/dist/esm/errors.js +6 -5
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/format.js +14 -10
- package/dist/esm/format.js.map +1 -1
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +85 -50
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/validate.js +12 -7
- package/dist/esm/validate.js.map +1 -1
- package/eslint.config.mjs +7 -0
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -74,7 +74,8 @@ class Kontonummer {
|
|
|
74
74
|
- `strict` should validate sorting code, account number length and account
|
|
75
75
|
number check digit. Should throw if any of these checks fail.
|
|
76
76
|
- `semi` should do strict checks for type 1 account numbers (4+7) but lax
|
|
77
|
-
checks for type 2 account numbers.
|
|
77
|
+
checks for type 2 account numbers. Account numbers that are valid if
|
|
78
|
+
padded are also considered valid.
|
|
78
79
|
- `lax` should not throw if the check digit of the account number cannot be
|
|
79
80
|
validated. Should instead set the `valid` property to false if the check
|
|
80
81
|
digit or length is invalid. Should still throw for invalid sorting codes.
|
package/dist/cjs/errors.js
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.KontonummerError = void 0;
|
|
4
4
|
class KontonummerError extends Error {
|
|
5
|
-
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.name = 'KontonummerError';
|
|
8
|
-
}
|
|
5
|
+
name = 'KontonummerError';
|
|
9
6
|
}
|
|
10
7
|
exports.KontonummerError = KontonummerError;
|
|
11
8
|
//# sourceMappingURL=errors.js.map
|
package/dist/cjs/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,gBAAiB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,gBAAiB,SAAQ,KAAK;IACzC,IAAI,GAAG,kBAAkB,CAAA;CAC1B;AAFD,4CAEC"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { type Format } from './format.js';
|
|
2
2
|
import type { BankName, SortingCodeInfo } from './banks.js';
|
|
3
3
|
interface InitOptions {
|
|
4
|
+
/**
|
|
5
|
+
* - `strict` validates sorting code, account number length and account
|
|
6
|
+
* number check digit.
|
|
7
|
+
* - `semi` performs strict checks for type 1 account numbers (4+7) but lax
|
|
8
|
+
* checks for type 2 account numbers. Account numbers that are valid if
|
|
9
|
+
* padded are also considered valid.
|
|
10
|
+
* - `lax` does not throw if the check digit of the account number cannot be
|
|
11
|
+
* validated. Instead, sets the `valid` property to false if the check
|
|
12
|
+
* digit or length is invalid.
|
|
13
|
+
*/
|
|
4
14
|
mode: 'strict' | 'semi' | 'lax';
|
|
5
15
|
}
|
|
6
16
|
export default class Kontonummer {
|
package/dist/cjs/index.js
CHANGED
|
@@ -32,21 +32,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
36
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
37
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
38
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
39
|
-
};
|
|
40
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
41
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
42
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
43
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
44
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
45
|
-
};
|
|
46
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
47
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
48
37
|
};
|
|
49
|
-
var _Kontonummer_bankName, _Kontonummer_sortingCode, _Kontonummer_accountNumber, _Kontonummer_type, _Kontonummer_comment, _Kontonummer_valid;
|
|
50
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
39
|
exports.valid = exports.parse = void 0;
|
|
52
40
|
const banks_js_1 = __importDefault(require("./banks.js"));
|
|
@@ -54,19 +42,19 @@ const errors_js_1 = require("./errors.js");
|
|
|
54
42
|
const validate_js_1 = __importStar(require("./validate.js"));
|
|
55
43
|
const format_js_1 = __importDefault(require("./format.js"));
|
|
56
44
|
class Kontonummer {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
45
|
+
#bankName;
|
|
46
|
+
#sortingCode;
|
|
47
|
+
#accountNumber;
|
|
48
|
+
#type;
|
|
49
|
+
#comment;
|
|
50
|
+
#valid; // only relevant in `lax` mode
|
|
51
|
+
get bankName() { return this.#bankName; }
|
|
52
|
+
get sortingCode() { return this.#sortingCode; }
|
|
53
|
+
get accountNumber() { return this.#accountNumber; }
|
|
54
|
+
get type() { return this.#type; }
|
|
55
|
+
get comment() { return this.#comment; }
|
|
56
|
+
get valid() { return this.#valid; }
|
|
63
57
|
constructor(sortingCodeWithOrWithoutAccountNumber, accountOrOptions, optionsArg) {
|
|
64
|
-
_Kontonummer_bankName.set(this, void 0);
|
|
65
|
-
_Kontonummer_sortingCode.set(this, void 0);
|
|
66
|
-
_Kontonummer_accountNumber.set(this, void 0);
|
|
67
|
-
_Kontonummer_type.set(this, void 0);
|
|
68
|
-
_Kontonummer_comment.set(this, void 0);
|
|
69
|
-
_Kontonummer_valid.set(this, void 0); // only relevant in `lax` mode
|
|
70
58
|
let accountNumber;
|
|
71
59
|
let options = {
|
|
72
60
|
mode: 'strict',
|
|
@@ -99,17 +87,24 @@ class Kontonummer {
|
|
|
99
87
|
throw new errors_js_1.KontonummerError('Invalid account number');
|
|
100
88
|
}
|
|
101
89
|
const bank = Kontonummer.getSortingCodeInfo(sortingCode);
|
|
102
|
-
const
|
|
103
|
-
|
|
90
|
+
const accountMaxLength = bank.type === 2 ? bank.accountMaxLength ?? 7 : 7;
|
|
91
|
+
const accountMinLength = bank.type === 2 ? bank.accountMinLength ?? 2 : (typeof accountOrOptions === 'object' ? 7 : 2);
|
|
92
|
+
const lengthValid = accountNumber.length <= accountMaxLength && accountNumber.length >= accountMinLength;
|
|
93
|
+
if (!lengthValid && options.mode === 'strict')
|
|
94
|
+
throw new errors_js_1.KontonummerError('Invalid account number');
|
|
95
|
+
if (!lengthValid && bank.type === 1 && options.mode === 'semi')
|
|
96
|
+
throw new errors_js_1.KontonummerError('Invalid account number');
|
|
97
|
+
const checksumValid = (0, validate_js_1.default)(bank.type, bank.comment, sortingCode, accountNumber);
|
|
98
|
+
if (!checksumValid && options.mode === 'strict')
|
|
104
99
|
throw new errors_js_1.KontonummerError('Invalid account number');
|
|
105
|
-
if (!
|
|
100
|
+
if (!checksumValid && bank.type === 1 && options.mode === 'semi')
|
|
106
101
|
throw new errors_js_1.KontonummerError('Invalid account number');
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
102
|
+
this.#bankName = bank.bankName;
|
|
103
|
+
this.#type = bank.type;
|
|
104
|
+
this.#comment = bank.comment;
|
|
105
|
+
this.#sortingCode = sortingCode;
|
|
106
|
+
this.#accountNumber = accountNumber;
|
|
107
|
+
this.#valid = checksumValid && (options.mode === 'strict' ? lengthValid : true);
|
|
113
108
|
}
|
|
114
109
|
format(format) {
|
|
115
110
|
return (0, format_js_1.default)(this.sortingCode, this.accountNumber, Kontonummer.getSortingCodeInfo(this.sortingCode), format);
|
|
@@ -121,7 +116,7 @@ class Kontonummer {
|
|
|
121
116
|
return new Kontonummer(sortingCodeWithOrWithoutAccountNumber, accountOrOptions);
|
|
122
117
|
}
|
|
123
118
|
static valid(sortingCodeWithOrWithoutAccountNumber, accountNumber) {
|
|
124
|
-
if (accountNumber && (typeof accountNumber
|
|
119
|
+
if (accountNumber && !(typeof accountNumber === 'string' || typeof accountNumber === 'number'))
|
|
125
120
|
throw new errors_js_1.KontonummerError('Kontonummer.valid() does not accept an options argument');
|
|
126
121
|
try {
|
|
127
122
|
if (accountNumber)
|
|
@@ -150,7 +145,7 @@ class Kontonummer {
|
|
|
150
145
|
valid: this.valid,
|
|
151
146
|
};
|
|
152
147
|
}
|
|
153
|
-
[
|
|
148
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
154
149
|
return this.toJSON();
|
|
155
150
|
}
|
|
156
151
|
}
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA2C;AAC3C,2CAA8C;AAC9C,6DAAyD;AACzD,4DAAoD;AAiBpD,MAAqB,WAAW;IAC9B,SAAS,CAAU;IACnB,YAAY,CAAQ;IACpB,cAAc,CAAQ;IACt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ACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAA;IACH,CAAC;IAED,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAA;IACtB,CAAC;CACF;AAzHD,8BAyHC;AAEY,QAAA,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;AAC3C,QAAA,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA"}
|
package/dist/esm/banks.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.banks = void 0;
|
|
4
|
+
exports.banks = [
|
|
2
5
|
// Type 1 accounts. Always 11 digits long sortingCode included.
|
|
3
6
|
// SSSSAAAAAAC
|
|
4
7
|
{
|
|
@@ -271,7 +274,7 @@ export const banks = [
|
|
|
271
274
|
accountMaxLength: 10,
|
|
272
275
|
},
|
|
273
276
|
];
|
|
274
|
-
|
|
277
|
+
exports.default = (sortingCode) => exports.banks.find(bank => bank.ranges.some(([min, max]) => {
|
|
275
278
|
const sortingCodeNumber = Number(`${sortingCode}`.replace(/[^\d]/g, '').substring(0, 4));
|
|
276
279
|
return sortingCodeNumber >= min &&
|
|
277
280
|
sortingCodeNumber <= max;
|
package/dist/esm/banks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"banks.js","sourceRoot":"","sources":["../../src/banks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"banks.js","sourceRoot":"","sources":["../../src/banks.ts"],"names":[],"mappings":";;;AA8Ba,QAAA,KAAK,GAAsB;IACtC,+DAA+D;IAC/D,cAAc;IACd;QACE,QAAQ,EAAE,WAAW;QACrB,IAAI,EAAE,CAAC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
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KontonummerError = void 0;
|
|
4
|
+
class KontonummerError extends Error {
|
|
5
|
+
name = 'KontonummerError';
|
|
6
6
|
}
|
|
7
|
+
exports.KontonummerError = KontonummerError;
|
|
7
8
|
//# sourceMappingURL=errors.js.map
|
package/dist/esm/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,gBAAiB,SAAQ,KAAK;IACzC,IAAI,GAAG,kBAAkB,CAAA;CAC1B;AAFD,4CAEC"}
|
package/dist/esm/format.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatter = void 0;
|
|
4
|
+
const formatter = (sortingCode, accountNumber, mask, pad = false) => {
|
|
2
5
|
// we need to split these because sortingCode goes ltr and accountNumber goes rtl
|
|
3
6
|
const accountNumberMask = mask.substring(mask.lastIndexOf('S') + 1);
|
|
4
7
|
const sortingCodeMask = mask.substring(0, mask.lastIndexOf('S') + 1);
|
|
@@ -49,7 +52,8 @@ export const formatter = (sortingCode, accountNumber, mask, pad = false) => {
|
|
|
49
52
|
}
|
|
50
53
|
return `${sortingCodeResult.join('')}${accountNumberResult.join('')}`;
|
|
51
54
|
};
|
|
52
|
-
|
|
55
|
+
exports.formatter = formatter;
|
|
56
|
+
exports.default = (sortingCode, accountNumber, sortingCodeInfo, format = 'numeric') => {
|
|
53
57
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
54
58
|
sortingCode = `${sortingCode ?? ''}`;
|
|
55
59
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -57,29 +61,29 @@ export default (sortingCode, accountNumber, sortingCodeInfo, format = 'numeric')
|
|
|
57
61
|
const { bankName, type } = sortingCodeInfo;
|
|
58
62
|
if (format === 'pretty') {
|
|
59
63
|
if (type === 1 && bankName === 'Swedbank') {
|
|
60
|
-
return formatter(sortingCode, accountNumber, 'SSSS-AA-AAAAA', true);
|
|
64
|
+
return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS-AA-AAAAA', true);
|
|
61
65
|
}
|
|
62
66
|
else if (type === 1) {
|
|
63
|
-
return formatter(sortingCode, accountNumber, 'SSSS AA AAA AA', true);
|
|
67
|
+
return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS AA AAA AA', true);
|
|
64
68
|
}
|
|
65
69
|
else if (bankName === 'Swedbank') {
|
|
66
|
-
return formatter(sortingCode, accountNumber, 'SSSS-S, AAA AAA AAA-A');
|
|
70
|
+
return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS-S, AAA AAA AAA-A');
|
|
67
71
|
}
|
|
68
72
|
else if (bankName === 'Handelsbanken') {
|
|
69
|
-
return formatter(sortingCode, accountNumber, 'SSSS, AAA AAA AAA');
|
|
73
|
+
return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS, AAA AAA AAA');
|
|
70
74
|
}
|
|
71
75
|
else if (bankName === 'Nordea Plusgirot') {
|
|
72
|
-
return formatter(sortingCode, accountNumber, 'SSSS, AAA AA AA-A');
|
|
76
|
+
return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS, AAA AA AA-A');
|
|
73
77
|
}
|
|
74
78
|
else if (bankName === 'Nordea') {
|
|
75
|
-
return formatter(sortingCode, accountNumber, 'SSSS, AAAAAA-AAAA');
|
|
79
|
+
return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS, AAAAAA-AAAA');
|
|
76
80
|
}
|
|
77
81
|
else {
|
|
78
|
-
return formatter(sortingCode, accountNumber, 'SSSS-S, AA AAAA AAAA');
|
|
82
|
+
return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS-S, AA AAAA AAAA');
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
85
|
else {
|
|
82
|
-
return formatter(sortingCode, accountNumber, 'SSSSS' + new Array(sortingCodeInfo.accountMinLength ?? 7).fill('A').join(''), true);
|
|
86
|
+
return (0, exports.formatter)(sortingCode, accountNumber, 'SSSSS' + new Array(sortingCodeInfo.accountMinLength ?? 7).fill('A').join(''), true);
|
|
83
87
|
}
|
|
84
88
|
};
|
|
85
89
|
//# sourceMappingURL=format.js.map
|
package/dist/esm/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":";;;AAMO,MAAM,SAAS,GAAa,CAAC,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,GAAG,KAAK,EAAE,EAAE;IACnF,iFAAiF;IACjF,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IACnE,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IAEpE,MAAM,iBAAiB,GAAa,EAAE,CAAA;IACtC,MAAM,mBAAmB,GAAa,EAAE,CAAA;IAExC,MAAM,gBAAgB,GAAG,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAC9C,MAAM,kBAAkB,GAAG,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAElD;;;;OAIG;IACH,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;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CAAC;YAC3C,OAAO,IAAA,iBAAS,EAAC,WAAW,EAAE,aAAa,EAAE,mBAAmB,CAAC,CAAA;QACnE,CAAC;aAAM,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACjC,OAAO,IAAA,iBAAS,EAAC,WAAW,EAAE,aAAa,EAAE,mBAAmB,CAAC,CAAA;QACnE,CAAC;aAAM,CAAC;YACN,OAAO,IAAA,iBAAS,EAAC,WAAW,EAAE,aAAa,EAAE,sBAAsB,CAAC,CAAA;QACtE,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,IAAA,iBAAS,EAAC,WAAW,EAAE,aAAa,EAAE,OAAO,GAAG,IAAI,KAAK,CAAE,eAAgC,CAAC,gBAAgB,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;IACrJ,CAAC;AACH,CAAC,CAAA"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { type Format } from './format.js';
|
|
2
2
|
import type { BankName, SortingCodeInfo } from './banks.js';
|
|
3
3
|
interface InitOptions {
|
|
4
|
+
/**
|
|
5
|
+
* - `strict` validates sorting code, account number length and account
|
|
6
|
+
* number check digit.
|
|
7
|
+
* - `semi` performs strict checks for type 1 account numbers (4+7) but lax
|
|
8
|
+
* checks for type 2 account numbers. Account numbers that are valid if
|
|
9
|
+
* padded are also considered valid.
|
|
10
|
+
* - `lax` does not throw if the check digit of the account number cannot be
|
|
11
|
+
* validated. Instead, sets the `valid` property to false if the check
|
|
12
|
+
* digit or length is invalid.
|
|
13
|
+
*/
|
|
4
14
|
mode: 'strict' | 'semi' | 'lax';
|
|
5
15
|
}
|
|
6
16
|
export default class Kontonummer {
|
package/dist/esm/index.js
CHANGED
|
@@ -1,33 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
37
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.valid = exports.parse = void 0;
|
|
40
|
+
const banks_js_1 = __importDefault(require("./banks.js"));
|
|
41
|
+
const errors_js_1 = require("./errors.js");
|
|
42
|
+
const validate_js_1 = __importStar(require("./validate.js"));
|
|
43
|
+
const format_js_1 = __importDefault(require("./format.js"));
|
|
44
|
+
class Kontonummer {
|
|
45
|
+
#bankName;
|
|
46
|
+
#sortingCode;
|
|
47
|
+
#accountNumber;
|
|
48
|
+
#type;
|
|
49
|
+
#comment;
|
|
50
|
+
#valid; // only relevant in `lax` mode
|
|
51
|
+
get bankName() { return this.#bankName; }
|
|
52
|
+
get sortingCode() { return this.#sortingCode; }
|
|
53
|
+
get accountNumber() { return this.#accountNumber; }
|
|
54
|
+
get type() { return this.#type; }
|
|
55
|
+
get comment() { return this.#comment; }
|
|
56
|
+
get valid() { return this.#valid; }
|
|
24
57
|
constructor(sortingCodeWithOrWithoutAccountNumber, accountOrOptions, optionsArg) {
|
|
25
|
-
_Kontonummer_bankName.set(this, void 0);
|
|
26
|
-
_Kontonummer_sortingCode.set(this, void 0);
|
|
27
|
-
_Kontonummer_accountNumber.set(this, void 0);
|
|
28
|
-
_Kontonummer_type.set(this, void 0);
|
|
29
|
-
_Kontonummer_comment.set(this, void 0);
|
|
30
|
-
_Kontonummer_valid.set(this, void 0); // only relevant in `lax` mode
|
|
31
58
|
let accountNumber;
|
|
32
59
|
let options = {
|
|
33
60
|
mode: 'strict',
|
|
@@ -53,27 +80,34 @@ export default class Kontonummer {
|
|
|
53
80
|
options = optionsArg;
|
|
54
81
|
}
|
|
55
82
|
// validate arguments
|
|
56
|
-
if (sortingCode.length < 4 || (sortingCode.length > 4 ? !mod10(sortingCode) : false)) {
|
|
57
|
-
throw new KontonummerError('Invalid sorting code');
|
|
83
|
+
if (sortingCode.length < 4 || (sortingCode.length > 4 ? !(0, validate_js_1.mod10)(sortingCode) : false)) {
|
|
84
|
+
throw new errors_js_1.KontonummerError('Invalid sorting code');
|
|
58
85
|
}
|
|
59
86
|
if (accountNumber.length < 2) {
|
|
60
|
-
throw new KontonummerError('Invalid account number');
|
|
87
|
+
throw new errors_js_1.KontonummerError('Invalid account number');
|
|
61
88
|
}
|
|
62
89
|
const bank = Kontonummer.getSortingCodeInfo(sortingCode);
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (!
|
|
67
|
-
throw new KontonummerError('Invalid account number');
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
90
|
+
const accountMaxLength = bank.type === 2 ? bank.accountMaxLength ?? 7 : 7;
|
|
91
|
+
const accountMinLength = bank.type === 2 ? bank.accountMinLength ?? 2 : (typeof accountOrOptions === 'object' ? 7 : 2);
|
|
92
|
+
const lengthValid = accountNumber.length <= accountMaxLength && accountNumber.length >= accountMinLength;
|
|
93
|
+
if (!lengthValid && options.mode === 'strict')
|
|
94
|
+
throw new errors_js_1.KontonummerError('Invalid account number');
|
|
95
|
+
if (!lengthValid && bank.type === 1 && options.mode === 'semi')
|
|
96
|
+
throw new errors_js_1.KontonummerError('Invalid account number');
|
|
97
|
+
const checksumValid = (0, validate_js_1.default)(bank.type, bank.comment, sortingCode, accountNumber);
|
|
98
|
+
if (!checksumValid && options.mode === 'strict')
|
|
99
|
+
throw new errors_js_1.KontonummerError('Invalid account number');
|
|
100
|
+
if (!checksumValid && bank.type === 1 && options.mode === 'semi')
|
|
101
|
+
throw new errors_js_1.KontonummerError('Invalid account number');
|
|
102
|
+
this.#bankName = bank.bankName;
|
|
103
|
+
this.#type = bank.type;
|
|
104
|
+
this.#comment = bank.comment;
|
|
105
|
+
this.#sortingCode = sortingCode;
|
|
106
|
+
this.#accountNumber = accountNumber;
|
|
107
|
+
this.#valid = checksumValid && (options.mode === 'strict' ? lengthValid : true);
|
|
74
108
|
}
|
|
75
109
|
format(format) {
|
|
76
|
-
return
|
|
110
|
+
return (0, format_js_1.default)(this.sortingCode, this.accountNumber, Kontonummer.getSortingCodeInfo(this.sortingCode), format);
|
|
77
111
|
}
|
|
78
112
|
static parse(sortingCodeWithOrWithoutAccountNumber, accountOrOptions, options) {
|
|
79
113
|
if (typeof accountOrOptions === 'string' || typeof accountOrOptions === 'number')
|
|
@@ -82,8 +116,8 @@ export default class Kontonummer {
|
|
|
82
116
|
return new Kontonummer(sortingCodeWithOrWithoutAccountNumber, accountOrOptions);
|
|
83
117
|
}
|
|
84
118
|
static valid(sortingCodeWithOrWithoutAccountNumber, accountNumber) {
|
|
85
|
-
if (accountNumber && (typeof accountNumber
|
|
86
|
-
throw new KontonummerError('Kontonummer.valid() does not accept an options argument');
|
|
119
|
+
if (accountNumber && !(typeof accountNumber === 'string' || typeof accountNumber === 'number'))
|
|
120
|
+
throw new errors_js_1.KontonummerError('Kontonummer.valid() does not accept an options argument');
|
|
87
121
|
try {
|
|
88
122
|
if (accountNumber)
|
|
89
123
|
new Kontonummer(sortingCodeWithOrWithoutAccountNumber, accountNumber); // eslint-disable-line no-new
|
|
@@ -96,9 +130,9 @@ export default class Kontonummer {
|
|
|
96
130
|
}
|
|
97
131
|
}
|
|
98
132
|
static getSortingCodeInfo(sortingCode) {
|
|
99
|
-
const bank =
|
|
133
|
+
const bank = (0, banks_js_1.default)(sortingCode);
|
|
100
134
|
if (typeof bank === 'undefined')
|
|
101
|
-
throw new KontonummerError(`No Bank found with sorting code ${sortingCode}`);
|
|
135
|
+
throw new errors_js_1.KontonummerError(`No Bank found with sorting code ${sortingCode}`);
|
|
102
136
|
return bank;
|
|
103
137
|
}
|
|
104
138
|
toJSON() {
|
|
@@ -111,10 +145,11 @@ export default class Kontonummer {
|
|
|
111
145
|
valid: this.valid,
|
|
112
146
|
};
|
|
113
147
|
}
|
|
114
|
-
[
|
|
148
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
115
149
|
return this.toJSON();
|
|
116
150
|
}
|
|
117
151
|
}
|
|
118
|
-
|
|
119
|
-
|
|
152
|
+
exports.default = Kontonummer;
|
|
153
|
+
exports.parse = Kontonummer.parse.bind(Kontonummer);
|
|
154
|
+
exports.valid = Kontonummer.valid.bind(Kontonummer);
|
|
120
155
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA2C;AAC3C,2CAA8C;AAC9C,6DAAyD;AACzD,4DAAoD;AAiBpD,MAAqB,WAAW;IAC9B,SAAS,CAAU;IACnB,YAAY,CAAQ;IACpB,cAAc,CAAQ;IACtB,KAAK,CAAO;IACZ,QAAQ,CAAW;IACnB,MAAM,CAAS,CAAC,8BAA8B;IAE9C,IAAI,QAAQ,KAAM,OAAO,IAAI,CAAC,SAAS,CAAA,CAAC,CAAC;IACzC,IAAI,WAAW,KAAM,OAAO,IAAI,CAAC,YAAY,CAAA,CAAC,CAAC;IAC/C,IAAI,aAAa,KAAM,OAAO,IAAI,CAAC,cAAc,CAAA,CAAC,CAAC;IACnD,IAAI,IAAI,KAAM,OAAO,IAAI,CAAC,KAAK,CAAA,CAAC,CAAC;IACjC,IAAI,OAAO,KAAM,OAAO,IAAI,CAAC,QAAQ,CAAA,CAAC,CAAC;IACvC,IAAI,KAAK,KAAM,OAAO,IAAI,CAAC,MAAM,CAAA,CAAC,CAAC;IAInC,YAAa,qCAAsD,EAAE,gBAAgD,EAAE,UAAwB;QAC7I,IAAI,aAAqB,CAAA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CAAC,CAAA;QACrL,IAAI,CAAC;YACH,IAAI,aAAa;gBAAE,IAAI,WAAW,CAAC,qCAAqC,EAAE,aAAa,CAAC,CAAA,CAAC,6BAA6B;;gBACjH,IAAI,WAAW,CAAC,qCAAqC,CAAC,CAAA,CAAC,6BAA6B;YACzF,OAAO,IAAI,CAAA;QACb,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAAE,WAA4B;QAC5D,MAAM,IAAI,GAAG,IAAA,kBAAkB,EAAC,WAAW,CAAC,CAAA;QAC5C,IAAI,OAAO,IAAI,KAAK,WAAW;YAAE,MAAM,IAAI,4BAAgB,CAAC,mCAAmC,WAAW,EAAE,CAAC,CAAA;QAC7G,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM;QACJ,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAA;IACH,CAAC;IAED,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAA;IACtB,CAAC;CACF;AAzHD,8BAyHC;AAEY,QAAA,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;AAC3C,QAAA,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA"}
|
package/dist/esm/validate.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mod11 = exports.mod10 = void 0;
|
|
4
|
+
const mod10 = (number) => {
|
|
2
5
|
number = `${number}`;
|
|
3
6
|
let len = number.length;
|
|
4
7
|
let bit = 1;
|
|
@@ -13,7 +16,8 @@ export const mod10 = (number) => {
|
|
|
13
16
|
}
|
|
14
17
|
return !!sum && sum % 10 === 0;
|
|
15
18
|
};
|
|
16
|
-
|
|
19
|
+
exports.mod10 = mod10;
|
|
20
|
+
const mod11 = (number) => {
|
|
17
21
|
number = `${number}`;
|
|
18
22
|
let len = number.length;
|
|
19
23
|
let sum = 0;
|
|
@@ -27,17 +31,18 @@ export const mod11 = (number) => {
|
|
|
27
31
|
}
|
|
28
32
|
return !!sum && sum % 11 === 0;
|
|
29
33
|
};
|
|
30
|
-
|
|
34
|
+
exports.mod11 = mod11;
|
|
35
|
+
exports.default = (type, comment, sortingCode, accountNumber) => {
|
|
31
36
|
// 1:1 => mod11 on 3 last of clearing + whole account number
|
|
32
37
|
if (type === 1 && comment === 1)
|
|
33
|
-
return mod11(`${sortingCode.substring(1)}${accountNumber.padStart(7, '0')}`);
|
|
38
|
+
return (0, exports.mod11)(`${sortingCode.substring(1)}${accountNumber.padStart(7, '0')}`);
|
|
34
39
|
// 1:2 => mod 11 on whole clearing + whole account number
|
|
35
40
|
if (type === 1 && comment === 2)
|
|
36
|
-
return mod11(`${sortingCode}${accountNumber.padStart(7, '0')}`);
|
|
41
|
+
return (0, exports.mod11)(`${sortingCode}${accountNumber.padStart(7, '0')}`);
|
|
37
42
|
// 2:2 => mod11 on whole account number (SHB) 9 digits
|
|
38
43
|
if (type === 2 && comment === 2)
|
|
39
|
-
return mod11(accountNumber.padStart(9, '0'));
|
|
44
|
+
return (0, exports.mod11)(accountNumber.padStart(9, '0'));
|
|
40
45
|
// 2:1 & 2:3 => mod10 on whole account number
|
|
41
|
-
return mod10(accountNumber.padStart(10, '0'));
|
|
46
|
+
return (0, exports.mod10)(accountNumber.padStart(10, '0'));
|
|
42
47
|
};
|
|
43
48
|
//# sourceMappingURL=validate.js.map
|
package/dist/esm/validate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/validate.ts"],"names":[],"mappings":";;;AAGO,MAAM,KAAK,GAAgB,CAAC,MAAM,EAAE,EAAE;IAC3C,MAAM,GAAG,GAAG,MAAM,EAAE,CAAA;IAEpB,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAA;IACvB,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,IAAI,GAAW,CAAA;IACf,MAAM,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAE1C,OAAO,GAAG,EAAE,CAAC;QACX,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;QACxC,GAAG,IAAI,CAAC,CAAA;QACR,oEAAoE;QACpE,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,CAAC,CAAC,GAAG,CAAA;IAC9B,CAAC;IAED,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,EAAE,KAAK,CAAC,CAAA;AAChC,CAAC,CAAA;AAjBY,QAAA,KAAK,SAiBjB;AAEM,MAAM,KAAK,GAAgB,CAAC,MAAM,EAAE,EAAE;IAC3C,MAAM,GAAG,GAAG,MAAM,EAAE,CAAA;IAEpB,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAA;IACvB,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,IAAI,GAAW,CAAA;IACf,MAAM,OAAO,GAAG,CAAC,CAAC,EAAE,EAAE,EA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CAAC,CAAC,CAAA;IAC7E,6CAA6C;IAC7C,OAAO,IAAA,aAAK,EAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAA;AAC/C,CAAC,CAAA"}
|
package/eslint.config.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import neostandard, { resolveIgnoresFromGitignore } from 'neostandard'
|
|
2
2
|
import eslint from '@eslint/js'
|
|
3
3
|
import tseslint from 'typescript-eslint'
|
|
4
|
+
import globals from 'globals'
|
|
4
5
|
|
|
5
6
|
export default [
|
|
6
7
|
...neostandard({
|
|
@@ -17,6 +18,7 @@ export default [
|
|
|
17
18
|
parserOptions: {
|
|
18
19
|
projectService: {
|
|
19
20
|
allowDefaultProject: ['*.js', '.*.js', '*.mjs'],
|
|
21
|
+
defaultProject: 'tsconfig.json',
|
|
20
22
|
},
|
|
21
23
|
tsconfigRootDir: process.cwd(),
|
|
22
24
|
},
|
|
@@ -49,6 +51,11 @@ export default [
|
|
|
49
51
|
{
|
|
50
52
|
name: 'swantzter/tests',
|
|
51
53
|
files: ['**/*.test.ts', '**/*.test.js'],
|
|
54
|
+
languageOptions: {
|
|
55
|
+
globals: {
|
|
56
|
+
...globals.mocha,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
52
59
|
rules: {
|
|
53
60
|
'@typescript-eslint/ban-ts-comment': ['error', {
|
|
54
61
|
'ts-expect-error': false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kontonummer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "A validator for swedish banking numbers",
|
|
5
5
|
"author": "Svante Bengtson <svante@swantzter.se> (https://swantzter.se)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,12 +37,13 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/mocha": "^10.0.10",
|
|
40
|
-
"@types/node": "^
|
|
41
|
-
"c8": "^
|
|
42
|
-
"eslint": "^9.39.
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
40
|
+
"@types/node": "^22.19.19",
|
|
41
|
+
"c8": "^11.0.0",
|
|
42
|
+
"eslint": "^9.39.3",
|
|
43
|
+
"globals": "^17.6.0",
|
|
44
|
+
"mocha": "^11.7.6",
|
|
45
|
+
"neostandard": "^0.13.0",
|
|
46
|
+
"tsx": "^4.22.3",
|
|
46
47
|
"typescript": "^5.9.3"
|
|
47
48
|
},
|
|
48
49
|
"keywords": [
|