kontonummer 2.0.0 → 4.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.
Files changed (40) hide show
  1. package/README.md +1 -6
  2. package/dist/cjs/banks.js +282 -0
  3. package/dist/cjs/banks.js.map +1 -0
  4. package/dist/cjs/errors.js +11 -0
  5. package/dist/cjs/errors.js.map +1 -0
  6. package/dist/cjs/format.js +84 -0
  7. package/dist/cjs/format.js.map +1 -0
  8. package/dist/cjs/index.js +150 -0
  9. package/dist/cjs/index.js.map +1 -0
  10. package/dist/cjs/validate.js +46 -0
  11. package/dist/cjs/validate.js.map +1 -0
  12. package/dist/esm/banks.js +279 -0
  13. package/dist/esm/banks.js.map +1 -0
  14. package/dist/esm/errors.js +7 -0
  15. package/dist/esm/errors.js.map +1 -0
  16. package/dist/esm/format.js +80 -0
  17. package/dist/esm/format.js.map +1 -0
  18. package/dist/esm/index.js +120 -0
  19. package/dist/esm/index.js.map +1 -0
  20. package/dist/esm/validate.js +41 -0
  21. package/dist/esm/validate.js.map +1 -0
  22. package/dist/types/banks.d.ts +19 -0
  23. package/{dist-types → dist/types}/format.d.ts +2 -2
  24. package/{dist-types → dist/types}/index.d.ts +1 -1
  25. package/{dist-types → dist/types}/validate.d.ts +2 -2
  26. package/package.json +35 -54
  27. package/CHANGELOG.md +0 -49
  28. package/dist-node/index.js +0 -927
  29. package/dist-node/index.js.map +0 -1
  30. package/dist-src/banks.js +0 -247
  31. package/dist-src/errors.js +0 -49
  32. package/dist-src/format.js +0 -102
  33. package/dist-src/index.js +0 -208
  34. package/dist-src/validate.js +0 -41
  35. package/dist-types/banks.d.ts +0 -19
  36. package/dist-web/index.bundled.js +0 -2
  37. package/dist-web/index.bundled.js.map +0 -1
  38. package/dist-web/index.js +0 -648
  39. package/dist-web/index.js.map +0 -1
  40. /package/{dist-types → dist/types}/errors.d.ts +0 -0
package/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Kontonummer
2
2
 
3
3
  [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
4
- [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
5
- [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
6
4
  ![test](https://github.com/swantzter/kontonummer/workflows/test/badge.svg)
7
5
  ![release](https://github.com/swantzter/kontonummer/workflows/release/badge.svg)
8
6
  [![codecov](https://codecov.io/gh/swantzter/kontonummer/branch/main/graph/badge.svg)](https://codecov.io/gh/swantzter/kontonummer)
@@ -10,16 +8,13 @@
10
8
  This is a reimagination of [jop-io/kontonummer.js](https://github.com/jop-io/kontonummer.js)
11
9
  with some additional goals:
12
10
 
13
- - Provide an npm package with cjs and esm modules for easy use with node and
14
- bundlers.
15
- - Provide TypeScript definitions
16
11
  - Provide a similar API to [Personnummer](https://personnummer.dev)
17
12
  - Stretch goal: Calculate IBAN (and BIC/SWIFT-code)
18
13
  - Stretch goal: Handle BankGirot and PlusGirot numbers
19
14
 
20
15
  Some Code (c) [Jonas Persson](https://github.com/jop-io) and
21
16
  [Tobbe Lundberg](https://github.com/Tobbe) which they have gracefully released
22
- under a MIT license. See [LICENCE](/swantzter/kontonummer/blob/main/LICENSE)
17
+ under a MIT license. See [LICENCE](LICENSE)
23
18
 
24
19
  This implementation is written in TypeScript but the following specification
25
20
  should be applicable to other languages as well. But some language specific
@@ -0,0 +1,282 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.banks = void 0;
4
+ exports.banks = [
5
+ // Type 1 accounts. Always 11 digits long sortingCode included.
6
+ // SSSSAAAAAAC
7
+ {
8
+ bankName: 'Aion Bank',
9
+ type: 1,
10
+ comment: 1,
11
+ ranges: [[9580, 9589]]
12
+ },
13
+ {
14
+ bankName: 'Avanza Bank',
15
+ type: 1,
16
+ comment: 2,
17
+ ranges: [[9550, 9569]]
18
+ },
19
+ {
20
+ bankName: 'BlueStep Finans',
21
+ type: 1,
22
+ comment: 1,
23
+ ranges: [[9680, 9689]]
24
+ },
25
+ {
26
+ bankName: 'BNP Paribas',
27
+ type: 1,
28
+ comment: 2,
29
+ ranges: [[9470, 9479]]
30
+ },
31
+ {
32
+ bankName: 'Citibank',
33
+ type: 1,
34
+ comment: 2,
35
+ ranges: [[9040, 9049]]
36
+ },
37
+ {
38
+ bankName: 'Danske Bank',
39
+ type: 1,
40
+ comment: 1,
41
+ ranges: [[1200, 1399], [2400, 2499]]
42
+ },
43
+ {
44
+ bankName: 'DNB Bank',
45
+ type: 1,
46
+ comment: 2,
47
+ ranges: [[9190, 9199], [9260, 9269]]
48
+ },
49
+ {
50
+ bankName: 'Ekobanken',
51
+ type: 1,
52
+ comment: 2,
53
+ ranges: [[9700, 9709]]
54
+ },
55
+ {
56
+ bankName: 'Erik Penser',
57
+ type: 1,
58
+ comment: 2,
59
+ ranges: [[9590, 9599]]
60
+ },
61
+ {
62
+ bankName: 'ICA Banken',
63
+ type: 1,
64
+ comment: 1,
65
+ ranges: [[9270, 9279]]
66
+ },
67
+ {
68
+ bankName: 'IKANO Bank',
69
+ type: 1,
70
+ comment: 1,
71
+ ranges: [[9170, 9179]]
72
+ },
73
+ {
74
+ bankName: 'JAK Medlemsbank',
75
+ type: 1,
76
+ comment: 2,
77
+ ranges: [[9670, 9679]]
78
+ },
79
+ {
80
+ bankName: 'Klarna Bank',
81
+ type: 1,
82
+ comment: 2,
83
+ ranges: [[9780, 9789]]
84
+ },
85
+ {
86
+ bankName: 'Landshypotek',
87
+ type: 1,
88
+ comment: 2,
89
+ ranges: [[9390, 9399]]
90
+ },
91
+ {
92
+ bankName: 'Lunar Bank',
93
+ type: 1,
94
+ comment: 2,
95
+ ranges: [[9710, 9719]]
96
+ },
97
+ {
98
+ bankName: 'Lån & Spar Bank Sverige',
99
+ type: 1,
100
+ comment: 1,
101
+ ranges: [[9630, 9639]]
102
+ },
103
+ {
104
+ bankName: 'Länsförsäkringar Bank',
105
+ type: 1,
106
+ comment: 1,
107
+ ranges: [[3400, 3499], [9060, 9069]]
108
+ },
109
+ {
110
+ bankName: 'Länsförsäkringar Bank',
111
+ type: 1,
112
+ comment: 2,
113
+ ranges: [[9020, 9029]]
114
+ },
115
+ {
116
+ bankName: 'Marginalen Bank',
117
+ type: 1,
118
+ comment: 1,
119
+ ranges: [[9230, 9239]]
120
+ },
121
+ {
122
+ bankName: 'Multitude Bank',
123
+ type: 1,
124
+ comment: 1,
125
+ ranges: [[9070, 9079]]
126
+ },
127
+ {
128
+ bankName: 'Nordax Bank',
129
+ type: 1,
130
+ comment: 2,
131
+ ranges: [[9640, 9649]]
132
+ },
133
+ {
134
+ bankName: 'Nordea',
135
+ type: 1,
136
+ comment: 1,
137
+ ranges: [[1100, 1199], [1400, 2099], [3000, 3299], [3301, 3399], [3410, 3781], [3783, 3999]]
138
+ },
139
+ {
140
+ bankName: 'Nordea',
141
+ type: 1,
142
+ comment: 2,
143
+ ranges: [[4000, 4999]]
144
+ },
145
+ {
146
+ bankName: 'Nordnet Bank',
147
+ type: 1,
148
+ comment: 2,
149
+ ranges: [[9100, 9109]]
150
+ },
151
+ {
152
+ bankName: 'Northmill Bank',
153
+ type: 1,
154
+ comment: 2,
155
+ ranges: [[9750, 9759]]
156
+ },
157
+ {
158
+ bankName: 'Resurs Bank',
159
+ type: 1,
160
+ comment: 1,
161
+ ranges: [[9280, 9289]]
162
+ },
163
+ {
164
+ bankName: 'Riksgälden',
165
+ type: 1,
166
+ comment: 2,
167
+ ranges: [[9880, 9889]]
168
+ },
169
+ {
170
+ bankName: 'Santander Consumer Bank',
171
+ type: 1,
172
+ comment: 1,
173
+ ranges: [[9460, 9469]]
174
+ },
175
+ {
176
+ bankName: 'SBAB',
177
+ type: 1,
178
+ comment: 1,
179
+ ranges: [[9250, 9259]]
180
+ },
181
+ {
182
+ bankName: 'SEB',
183
+ type: 1,
184
+ comment: 1,
185
+ ranges: [[5000, 5999], [9120, 9124], [9130, 9149]]
186
+ },
187
+ {
188
+ bankName: 'Skandiabanken',
189
+ type: 1,
190
+ comment: 2,
191
+ ranges: [[9150, 9169]]
192
+ },
193
+ {
194
+ bankName: 'Svea Bank',
195
+ type: 1,
196
+ comment: 2,
197
+ ranges: [[9660, 9669]]
198
+ },
199
+ {
200
+ bankName: 'Swedbank',
201
+ type: 1,
202
+ comment: 1,
203
+ ranges: [[7000, 7999]]
204
+ },
205
+ {
206
+ bankName: 'Ålandsbanken',
207
+ type: 1,
208
+ comment: 2,
209
+ ranges: [[2300, 2399]]
210
+ },
211
+ // Type 2 accounts - the messy ones
212
+ {
213
+ bankName: 'Danske Bank',
214
+ type: 2,
215
+ comment: 1,
216
+ ranges: [[9180, 9189]],
217
+ accountMinLength: 10,
218
+ accountMaxLength: 10
219
+ },
220
+ {
221
+ bankName: 'Handelsbanken',
222
+ type: 2,
223
+ comment: 2,
224
+ ranges: [[6000, 6999]],
225
+ accountMinLength: 8,
226
+ accountMaxLength: 9
227
+ },
228
+ {
229
+ bankName: 'Nordea',
230
+ type: 2,
231
+ comment: 1,
232
+ ranges: [[3300, 3300], [3782, 3782]],
233
+ accountMinLength: 10,
234
+ accountMaxLength: 10
235
+ },
236
+ {
237
+ bankName: 'Nordea Plusgirot',
238
+ type: 2,
239
+ comment: 3,
240
+ ranges: [[9500, 9549], [9960, 9969]],
241
+ accountMinLength: 2,
242
+ accountMaxLength: 8
243
+ },
244
+ {
245
+ bankName: 'Riksgälden',
246
+ type: 2,
247
+ comment: 1,
248
+ ranges: [[9890, 9899]],
249
+ accountMinLength: 10,
250
+ accountMaxLength: 10
251
+ },
252
+ {
253
+ bankName: 'Sparbanken Syd',
254
+ type: 2,
255
+ comment: 1,
256
+ ranges: [[9570, 9579]],
257
+ accountMinLength: 10,
258
+ accountMaxLength: 10
259
+ },
260
+ {
261
+ bankName: 'Swedbank',
262
+ type: 2,
263
+ comment: 3,
264
+ ranges: [[8000, 8999]],
265
+ accountMinLength: 10,
266
+ accountMaxLength: 11 // Allowing 11 here in case clearingnumber is sent as the first four instead of the first five
267
+ },
268
+ {
269
+ bankName: 'Swedbank',
270
+ type: 2,
271
+ comment: 1,
272
+ ranges: [[9300, 9349]],
273
+ accountMinLength: 10,
274
+ accountMaxLength: 10
275
+ }
276
+ ];
277
+ exports.default = (sortingCode) => exports.banks.find(bank => bank.ranges.some(([min, max]) => {
278
+ const sortingCodeNumber = Number(`${sortingCode}`.replace(/[^\d]/g, '').substring(0, 4));
279
+ return sortingCodeNumber >= min &&
280
+ sortingCodeNumber <= max;
281
+ }));
282
+ //# sourceMappingURL=banks.js.map
@@ -0,0 +1 @@
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;QACP,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;KACvB;IACD;QACE,QAAQ,EAAE,aAAa;QACvB,IAAI,EAAE,CAAC;QACP,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;KACvB;IACD;QACE,QAAQ,EAAE,iBAAiB;QAC3B,IAAI,EAAE,CAAC;QACP,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;KACvB;IACD;QACE,QAAQ,EAAE,aAAa;QACvB,IAAI,EAAE,CAAC;QACP,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;KACvB;IACD;QACE,QAAQ,EAAE,UAAU;QACpB,IAAI,EAAE,CAAC;QACP,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,CAA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,EAAE;KACrB;CACF,CAAA;AAED,kBAAe,CAAC,WAA4B,EAA+B,EAAE,CAC3E,aAAK,CAAC,IAAI,CACR,IAAI,CAAC,EAAE,CACL,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE;IACb,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,WAAW,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACxF,OAAO,iBAAiB,IAAI,GAAG;QAC7B,iBAAiB,IAAI,GAAG,CAAA;AAC5B,CAAC,CACF,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KontonummerError = void 0;
4
+ class KontonummerError extends Error {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.name = 'KontonummerError';
8
+ }
9
+ }
10
+ exports.KontonummerError = KontonummerError;
11
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,gBAAiB,SAAQ,KAAK;IAA3C;;QACE,SAAI,GAAG,kBAAkB,CAAA;IAC3B,CAAC;CAAA;AAFD,4CAEC"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatter = void 0;
4
+ const formatter = (sortingCode, accountNumber, mask, pad = false) => {
5
+ // we need to split these because sortingCode goes ltr and accountNumber goes rtl
6
+ const accountNumberMask = mask.substring(mask.lastIndexOf('S') + 1);
7
+ const sortingCodeMask = mask.substring(0, mask.lastIndexOf('S') + 1);
8
+ const sortingCodeResult = [];
9
+ const accountNumberResult = [];
10
+ const sortingCodeChars = sortingCode.split('');
11
+ const accountNumberChars = accountNumber.split('');
12
+ /*
13
+ * Here's what will happen we'll go through the mask and replace every 'S' with the next
14
+ * character in the sorting code. if there's no mask for that character we output the character
15
+ * If there's no more characters we end the loop.
16
+ */
17
+ for (let idx = 0; idx < Math.max(sortingCodeMask.length, sortingCodeChars.length); idx++) {
18
+ if (sortingCodeMask[idx] === 'S' || sortingCodeMask[idx] === undefined) {
19
+ sortingCodeResult.push(sortingCodeChars.shift() ?? '');
20
+ }
21
+ else {
22
+ sortingCodeResult.push(sortingCodeMask[idx]);
23
+ }
24
+ if (sortingCodeChars.length === 0)
25
+ break;
26
+ }
27
+ /*
28
+ * for the account number we do a similar thing to the sorting code, except that we start
29
+ * from the right. Why? Because we might want to zero-pad the number based on the mask, and we
30
+ * always want the zero padding to the left/the start of the number
31
+ */
32
+ for (let idx = accountNumberMask.length - 1; idx >= 0; idx--) {
33
+ if (accountNumberMask[idx] === 'A') {
34
+ accountNumberResult.unshift(accountNumberChars.pop() ?? (pad ? '0' : ''));
35
+ }
36
+ else {
37
+ accountNumberResult.unshift(accountNumberMask[idx]);
38
+ }
39
+ // if we have more account number than we have mask we just dump it at the start
40
+ if (idx === accountNumberMask.indexOf('A') && accountNumberChars.length > 0) {
41
+ while (accountNumberChars.length) {
42
+ accountNumberResult.unshift(accountNumberChars.pop() ?? '');
43
+ }
44
+ }
45
+ if (accountNumberChars.length === 0 && !pad) {
46
+ accountNumberResult.unshift(...accountNumberMask.slice(0, accountNumberMask.indexOf('A')));
47
+ break;
48
+ }
49
+ }
50
+ return `${sortingCodeResult.join('')}${accountNumberResult.join('')}`;
51
+ };
52
+ exports.formatter = formatter;
53
+ exports.default = (sortingCode, accountNumber, sortingCodeInfo, format = 'numeric') => {
54
+ sortingCode = `${sortingCode ?? ''}`;
55
+ accountNumber = `${accountNumber ?? ''}`;
56
+ const { bankName, type } = sortingCodeInfo;
57
+ if (format === 'pretty') {
58
+ if (type === 1 && bankName === 'Swedbank') {
59
+ return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS-AA-AAAAA', true);
60
+ }
61
+ else if (type === 1) {
62
+ return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS AA AAA AA', true);
63
+ }
64
+ else if (bankName === 'Swedbank') {
65
+ return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS-S, AAA AAA AAA-A');
66
+ }
67
+ else if (bankName === 'Handelsbanken') {
68
+ return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS, AAA AAA AAA');
69
+ }
70
+ else if (bankName === 'Nordea Plusgirot') {
71
+ return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS, AAA AA AA-A');
72
+ }
73
+ else if (bankName === 'Nordea') {
74
+ return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS, AAAAAA-AAAA');
75
+ }
76
+ else {
77
+ return (0, exports.formatter)(sortingCode, accountNumber, 'SSSS-S, AA AAAA AAAA');
78
+ }
79
+ }
80
+ else {
81
+ return (0, exports.formatter)(sortingCode, accountNumber, 'SSSSS' + new Array(sortingCodeInfo.accountMinLength ?? 7).fill('A').join(''), true);
82
+ }
83
+ };
84
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
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,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AkB,EAAE;YAC1C,OAAO,IAAA,iBAAS,EAAC,WAAW,EAAE,aAAa,EAAE,mBAAmB,CAAC,CAAA;SAClE;aAAM,IAAI,QAAQ,KAAK,QAAQ,EAAE;YAChC,OAAO,IAAA,iBAAS,EAAC,WAAW,EAAE,aAAa,EAAE,mBAAmB,CAAC,CAAA;SAClE;aAAM;YACL,OAAO,IAAA,iBAAS,EAAC,WAAW,EAAE,aAAa,EAAE,sBAAsB,CAAC,CAAA;SACrE;KACF;SAAM;QACL,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;KACpJ;AACH,CAAC,CAAA"}
@@ -0,0 +1,150 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
26
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
27
+ 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");
28
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
29
+ };
30
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
31
+ if (kind === "m") throw new TypeError("Private method is not writable");
32
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
33
+ 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");
34
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ var _Kontonummer_bankName, _Kontonummer_sortingCode, _Kontonummer_accountNumber, _Kontonummer_type, _Kontonummer_comment, _Kontonummer_valid;
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.valid = exports.parse = void 0;
42
+ const banks_1 = __importDefault(require("./banks"));
43
+ const errors_1 = require("./errors");
44
+ const validate_1 = __importStar(require("./validate"));
45
+ const format_1 = __importDefault(require("./format"));
46
+ class Kontonummer {
47
+ get bankName() { return __classPrivateFieldGet(this, _Kontonummer_bankName, "f"); }
48
+ get sortingCode() { return __classPrivateFieldGet(this, _Kontonummer_sortingCode, "f"); }
49
+ get accountNumber() { return __classPrivateFieldGet(this, _Kontonummer_accountNumber, "f"); }
50
+ get type() { return __classPrivateFieldGet(this, _Kontonummer_type, "f"); }
51
+ get comment() { return __classPrivateFieldGet(this, _Kontonummer_comment, "f"); }
52
+ get valid() { return __classPrivateFieldGet(this, _Kontonummer_valid, "f"); }
53
+ constructor(sortingCodeWithOrWithoutAccountNumber, accountOrOptions, optionsArg) {
54
+ _Kontonummer_bankName.set(this, void 0);
55
+ _Kontonummer_sortingCode.set(this, void 0);
56
+ _Kontonummer_accountNumber.set(this, void 0);
57
+ _Kontonummer_type.set(this, void 0);
58
+ _Kontonummer_comment.set(this, void 0);
59
+ _Kontonummer_valid.set(this, void 0); // only relevant in `lax` mode
60
+ let accountNumber;
61
+ let options = {
62
+ mode: 'strict'
63
+ };
64
+ // parse params
65
+ // sortingCode
66
+ sortingCodeWithOrWithoutAccountNumber = `${sortingCodeWithOrWithoutAccountNumber}`.replace(/[^\d]/g, '');
67
+ // Swedbank 8xxx-x have 5 digits
68
+ const sortingCode = sortingCodeWithOrWithoutAccountNumber.substring(0, sortingCodeWithOrWithoutAccountNumber.startsWith('8') ? 5 : 4);
69
+ // accountNumber
70
+ if (typeof accountOrOptions === 'object') {
71
+ options = accountOrOptions;
72
+ accountNumber = sortingCodeWithOrWithoutAccountNumber.substring(sortingCodeWithOrWithoutAccountNumber.startsWith('8') ? 5 : 4);
73
+ }
74
+ else if (typeof accountOrOptions === 'string' || typeof accountOrOptions === 'number') {
75
+ accountNumber = `${accountOrOptions}`.replace(/[^\d]/g, '');
76
+ }
77
+ else {
78
+ accountNumber = sortingCodeWithOrWithoutAccountNumber.substring(sortingCodeWithOrWithoutAccountNumber.startsWith('8') ? 5 : 4);
79
+ }
80
+ // optionsArg
81
+ if (typeof optionsArg === 'object') {
82
+ options = optionsArg;
83
+ }
84
+ // validate arguments
85
+ if (sortingCode.length < 4 || (sortingCode.length > 4 ? !(0, validate_1.mod10)(sortingCode) : false)) {
86
+ throw new errors_1.KontonummerError('Invalid sorting code');
87
+ }
88
+ if (accountNumber.length < 2) {
89
+ throw new errors_1.KontonummerError('Invalid account number');
90
+ }
91
+ const bank = Kontonummer.getSortingCodeInfo(sortingCode);
92
+ const valid = (0, validate_1.default)(bank.type, bank.comment, sortingCode, accountNumber);
93
+ if (!valid && options.mode === 'strict')
94
+ throw new errors_1.KontonummerError('Invalid account number');
95
+ if (!valid && bank.type === 1 && options.mode === 'semi')
96
+ throw new errors_1.KontonummerError('Invalid account number');
97
+ __classPrivateFieldSet(this, _Kontonummer_bankName, bank.bankName, "f");
98
+ __classPrivateFieldSet(this, _Kontonummer_type, bank.type, "f");
99
+ __classPrivateFieldSet(this, _Kontonummer_comment, bank.comment, "f");
100
+ __classPrivateFieldSet(this, _Kontonummer_sortingCode, sortingCode, "f");
101
+ __classPrivateFieldSet(this, _Kontonummer_accountNumber, accountNumber, "f");
102
+ __classPrivateFieldSet(this, _Kontonummer_valid, valid, "f");
103
+ }
104
+ format(format) {
105
+ return (0, format_1.default)(this.sortingCode, this.accountNumber, Kontonummer.getSortingCodeInfo(this.sortingCode), format);
106
+ }
107
+ static parse(sortingCodeWithOrWithoutAccountNumber, accountOrOptions, options) {
108
+ if (typeof accountOrOptions === 'string' || typeof accountOrOptions === 'number')
109
+ return new Kontonummer(sortingCodeWithOrWithoutAccountNumber, accountOrOptions, options);
110
+ else
111
+ return new Kontonummer(sortingCodeWithOrWithoutAccountNumber, accountOrOptions);
112
+ }
113
+ static valid(sortingCodeWithOrWithoutAccountNumber, accountNumber) {
114
+ if (accountNumber && (typeof accountNumber !== 'string' || typeof accountNumber !== 'number'))
115
+ throw new errors_1.KontonummerError('Kontonummer.valid() does not accept an options argument');
116
+ try {
117
+ if (accountNumber)
118
+ new Kontonummer(sortingCodeWithOrWithoutAccountNumber, accountNumber); // eslint-disable-line no-new
119
+ else
120
+ new Kontonummer(sortingCodeWithOrWithoutAccountNumber); // eslint-disable-line no-new
121
+ return true;
122
+ }
123
+ catch {
124
+ return false;
125
+ }
126
+ }
127
+ static getSortingCodeInfo(sortingCode) {
128
+ const bank = (0, banks_1.default)(sortingCode);
129
+ if (typeof bank === 'undefined')
130
+ throw new errors_1.KontonummerError(`No Bank found with sorting code ${sortingCode}`);
131
+ return bank;
132
+ }
133
+ toJSON() {
134
+ return {
135
+ bankName: this.bankName,
136
+ sortingCode: this.sortingCode,
137
+ accountNumber: this.accountNumber,
138
+ type: this.type,
139
+ comment: this.comment,
140
+ valid: this.valid
141
+ };
142
+ }
143
+ [(_Kontonummer_bankName = new WeakMap(), _Kontonummer_sortingCode = new WeakMap(), _Kontonummer_accountNumber = new WeakMap(), _Kontonummer_type = new WeakMap(), _Kontonummer_comment = new WeakMap(), _Kontonummer_valid = new WeakMap(), Symbol.for('nodejs.util.inspect.custom'))]() {
144
+ return this.toJSON();
145
+ }
146
+ }
147
+ exports.default = Kontonummer;
148
+ exports.parse = Kontonummer.parse;
149
+ exports.valid = Kontonummer.valid;
150
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAwC;AACxC,qCAA2C;AAC3C,uDAAsD;AACtD,sDAAiD;AAOjD,MAAqB,WAAW;IAQ9B,IAAI,QAAQ,KAAM,OAAO,uBAAA,IAAI,6BAAU,CAAA,CAAC,CAAC;IACzC,IAAI,WAAW,KAAM,OAAO,uBAAA,IAAI,gCAAa,CAAA,CAAC,CAAC;IAC/C,IAAI,aAAa,KAAM,OAAO,uBAAA,IAAI,kCAAe,CAAA,CAAC,CAAC;IACnD,IAAI,IAAI,KAAM,OAAO,uBAAA,IAAI,yBAAM,CAAA,CAAC,CAAC;IACjC,IAAI,OAAO,KAAM,OAAO,uBAAA,IAAI,4BAAS,CAAA,CAAC,CAAC;IACvC,IAAI,KAAK,KAAM,OAAO,uBAAA,IAAI,0BAAO,CAAA,CAAC,CAAC;IAInC,YAAa,qCAAsD,EAAE,gBAAgD,EAAE,UAAwB;QAhB/I,wCAAmB;QACnB,2CAAoB;QACpB,6CAAsB;QACtB,oCAAY;QACZ,uCAAmB;QACnB,qCAAe,CAAC,8BAA8B;QAY5C,IAAI,aAAqB,CAAA;QACzB,IAAI,OAAO,GAAgB;YACzB,IAAI,EAAE,QAAQ;SACf,CAAA;Q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,QAAA,KAAK,GAAG,WAAW,CAAC,KAAK,CAAA"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mod11 = exports.mod10 = void 0;
4
+ const mod10 = (number) => {
5
+ number = `${number}`;
6
+ let len = number.length;
7
+ let bit = 1;
8
+ let sum = 0;
9
+ let val;
10
+ const arr = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9];
11
+ while (len) {
12
+ val = parseInt(number.charAt(--len), 10);
13
+ bit ^= 1;
14
+ sum += bit ? arr[val] : val;
15
+ }
16
+ return !!sum && sum % 10 === 0;
17
+ };
18
+ exports.mod10 = mod10;
19
+ const mod11 = (number) => {
20
+ number = `${number}`;
21
+ let len = number.length;
22
+ let sum = 0;
23
+ let val;
24
+ const weights = [1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
25
+ const arr = weights.splice(weights.length - len, weights.length - (weights.length - len));
26
+ while (len) {
27
+ val = parseInt(number.charAt(--len), 10);
28
+ sum += arr[len] * val;
29
+ }
30
+ return !!sum && sum % 11 === 0;
31
+ };
32
+ exports.mod11 = mod11;
33
+ exports.default = (type, comment, sortingCode, accountNumber) => {
34
+ // 1:1 => mod11 on 3 last of clearing + whole account number
35
+ if (type === 1 && comment === 1)
36
+ return (0, exports.mod11)(`${sortingCode.substring(1)}${accountNumber.padStart(7, '0')}`);
37
+ // 1:2 => mod 11 on whole clearing + whole account number
38
+ if (type === 1 && comment === 2)
39
+ return (0, exports.mod11)(`${sortingCode}${accountNumber.padStart(7, '0')}`);
40
+ // 2:2 => mod11 on whole account number (SHB) 9 digits
41
+ if (type === 2 && comment === 2)
42
+ return (0, exports.mod11)(`${accountNumber.padStart(9, '0')}`);
43
+ // 2:1 & 2:3 => mod10 on whole account number
44
+ return (0, exports.mod10)(accountNumber.padStart(10, '0'));
45
+ };
46
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":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