kontonummer 1.4.1 → 3.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 +5 -278
  2. package/dist/cjs/banks.js +270 -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 +267 -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 → dist/types}/banks.d.ts +3 -3
  23. package/{dist-types → dist/types}/errors.d.ts +0 -0
  24. package/{dist-types → dist/types}/format.d.ts +0 -0
  25. package/{dist-types → dist/types}/index.d.ts +0 -0
  26. package/dist/types/validate.d.ts +6 -0
  27. package/package.json +35 -53
  28. package/CHANGELOG.md +0 -35
  29. package/dist-node/index.js +0 -924
  30. package/dist-node/index.js.map +0 -1
  31. package/dist-src/banks.js +0 -247
  32. package/dist-src/errors.js +0 -49
  33. package/dist-src/format.js +0 -102
  34. package/dist-src/index.js +0 -207
  35. package/dist-src/validate.js +0 -41
  36. package/dist-types/validate.d.ts +0 -5
  37. package/dist-web/index.bundled.js +0 -2
  38. package/dist-web/index.bundled.js.map +0 -1
  39. package/dist-web/index.js +0 -647
  40. package/dist-web/index.js.map +0 -1
package/README.md CHANGED
@@ -1,25 +1,20 @@
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
- ![test](https://github.com/svbeon/kontonummer/workflows/test/badge.svg)
7
- ![release](https://github.com/svbeon/kontonummer/workflows/release/badge.svg)
8
- [![codecov](https://codecov.io/gh/svbeon/kontonummer/branch/master/graph/badge.svg)](https://codecov.io/gh/svbeon/kontonummer)
4
+ ![test](https://github.com/swantzter/kontonummer/workflows/test/badge.svg)
5
+ ![release](https://github.com/swantzter/kontonummer/workflows/release/badge.svg)
6
+ [![codecov](https://codecov.io/gh/swantzter/kontonummer/branch/main/graph/badge.svg)](https://codecov.io/gh/swantzter/kontonummer)
9
7
 
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](/svbeon/kontonummer/blob/master/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
@@ -179,272 +174,4 @@ class Kontonummer {
179
174
 
180
175
  ## [Research](https://i.imgur.com/5wuurYD.png)
181
176
 
182
- ### Sorting Code
183
-
184
- Sorting codes are 4 digits long. (`SSSS`) However accounts in Swedbank that have
185
- a sorting code starting with 8 displays an extra 5'th check digit to the sorting
186
- code. (`SSSS-C`) The check digit is calculated using the mod-10 algorithm
187
- [[7]](#source-7), [[citation-needed]]() This means that in actual bank
188
- transactions the check digit is discarded for these accounts and only the first
189
- four "actually matter". A sorting code needs to be a number between 1000
190
- and 9999. [[3]](#source-3)
191
-
192
- The sorting code can be used to derive the account type (1 or 2) and the
193
- associated "comment" in a publication by Bankgirot. [[1]](#source-1)
194
-
195
- ### Account Number
196
-
197
- #### Type 1
198
-
199
- Type 1 accounts are the "standard" for swedish bank accounts. Swedish bankers'
200
- association are "actively working for increased standardisation on the Swedish
201
- market and only allows type 1 for new banks" [[9]](#source-9)
202
-
203
- A type 1 account number is 11 digits long, (4 digits for the sorting code and 7
204
- for the account number) the sorting code and check digit is part of the account
205
- number. [[1]](#source-1) The format is `SSSSAAAAAAC`, or with separation for
206
- readability `SSSS AA AAA AC`. [[5]](#source-5), [[9]](#source-9)
207
- Swedbank formats their type 1 account numbers in a different way `SSSS-AA-AAAAC`
208
- [[10]](#source-10)
209
-
210
- The check digit is calculated using a mod-11 algorithm which is either
211
- calculated on the whole sorting code and account number (`SSSSAAAAAA`) or, the
212
- last three digits of the sorting code and the whole account number
213
- (`SSSAAAAAA`) this varies by clearing number range and is referred to by
214
- "comment" in the documents from Bankgirot. [[1]](#source-1), [[8]](#source-8)
215
- Why does this differ? I have no idea!
216
-
217
- #### Type 2
218
-
219
- Type 2 accounts are the wild west of bank accounts. This is where you should go
220
- if you seek chaos.
221
-
222
- Type 2 accounts are the older account type and the sorting code is not part
223
- of the account number. This means that the sorting code is often only required
224
- for external transactions, i.e. to another bank than the account holder's.
225
- These accounts are mainly used by Handelsbanken, Nordea, Swedbank, and the
226
- independent savings banks. [[9]](#source-9)
227
-
228
- Type 2 account numbers are between 5 and 11 digits long without the sorting code
229
- [[9]](#source-9), or 2-11 digits long if PlusGirot numbers are counted.
230
- [[1]](#source-1) Worthy of note however is that PlusGirot "transaction accounts"
231
- are 10 digits long. This is mainly a different way of writing a PlusGirot
232
- account number. [[6]](#source-6)
233
-
234
- Some notable examples follow, for a full list see Bankgirot. [[1]](#source-1)
235
-
236
- ##### Swedbank and the independent savings banks
237
-
238
- Accounts with Swedbank and all the independent savings banks that have a sorting
239
- code starting with 8 are type 2 accounts. The sorting code is not part of the
240
- account number. As mentioned above, a 5'th digit is added to the sorting code
241
- for these Swedbank and independent savings banks' bank accounts to
242
- account for that. The account number (check digit included) is 10 digits long.
243
- [[1]](#source-1) [[10]](#source-10)
244
-
245
- The format for these account numbers is `AAAAAAAAAC`, or with separation
246
- for readability `AAA AAA AAA-C` when showing the sorting code
247
- in the latter format it is separated from the account number by a comma by
248
- Swedbank `SSSS-C, AAA AAA AAA-C`. [[10]](#source-10)
249
-
250
- The check digit are calculated using a mod-10 algorithm on the whole account
251
- number `AAAAAAAAA`. [[1]](#source-1)
252
-
253
- **!!NOTE!!** There exist very old Swedbank accounts without any check digit.
254
- There is no way to validate these account numbers. [[1]](#source-1)
255
- According to Swedbanks phone support these accounts also "lives" under the same
256
- sorting codes as other accounts with a check digit and they can have either a
257
- 4-digit or a 5-digit sorting code, so there is no way to distinguish them.
258
- [[13]](#source-13)
259
-
260
- ##### Handelsbanken
261
-
262
- Accounts with Handelsbanken are 8 or 9 digits long.
263
- [[1]](#source-1) [[14]](#source-14)
264
-
265
- The format for these account numbers are `AAAAAAAAC`, or with separation
266
- for readability `AAA AAA AAC`. As the sorting code is not part of the
267
- account number and not part of the check digit calculation. Account numbers that
268
- are shorter than 9 digits do not _need_ to be zero-padded because the sorting
269
- code is not part of the account number and should be entered separately,
270
- so `AA AAA AAC` is valid.
271
- The sorting code is separated from the account number using a dash in their
272
- mobile applications `SSSS - AAA AAA AAC`, but it seems reasonable to use a comma
273
- like Swedbank to separate sorting code and account number. [[citation-needed]]()
274
-
275
- The check digit are calculated using a mod-11 algorithm on the whole account
276
- number `AAAAAAAA`. [[1]](#source-1)
277
-
278
- ##### Nordea Personkonto
279
-
280
- These accounts have the holders personal identity number as their account
281
- number. They are 10 digits long. Traditionally these account numbers are written
282
- without their sorting code, but in actuality they have the sorting code 3300.
283
- [[1]](#source-1), [[11]](#source-11)
284
-
285
- No new Nordea Personkonto with the holders personal identity number as the
286
- account number are issued as of 2019-01-01. [[11]](#source-11)
287
-
288
- The format for these account numbers are `AAAAAAAAAC`. [[1]](#source-1)
289
- It stands to reason that the format with separation for readability is the same
290
- as for a personal identity number `AAAAAA-AAAC` but do note that only digits
291
- are significant in bank account numbers so the dash (or plus for people older
292
- than 100) cannot be used to differentiate bank accounts which may men there
293
- is a risk for collisions. [[citation-needed]]()
294
-
295
- The check digit are calculated using a mod-10 algorithm on the whole account
296
- number `AAAAAAAAA`. [[1]](#source-1) Same as for personal identity numbers.
297
- [[12]](#source-12)
298
-
299
- ##### Nordea PlusGirot Account
300
-
301
- **TODO**. There are some decisions to be made regarding this.
302
- Should the 2-8 digit format be allowed for validation or only the 10 digit
303
- longer form. this depends on Bankgirot implementation I think.
304
- Currently the 2-8 digit numbers do validate and the 10 digit ones do not.
305
-
306
- ##### Others
307
-
308
- The other type 2 accounts are 10 digits long. [[1]](#source-1)
309
-
310
- The format for these account numbers are `AAAAAAAAAC`. [[1]](#source-1)
311
- The format with separation for readability is not known at the time of writing
312
- [[citation-needed]]()
313
-
314
- The check digit are calculated using a mod-10 algorithm on the whole account
315
- number `AAAAAAAAA`. [[1]](#source-1)
316
-
317
- ### BankGirot and PlusGirot
318
-
319
- Bankgirot is just an "address" to an actual account number whereas PlusGirot
320
- (formerly PostGirot) is an actual account.
321
-
322
- **TODO** How to handle these? should there be a separate `Kontonummer.BgPg`
323
- class with a different API? Open for suggestions.
324
-
325
- #### PlusGirot
326
-
327
- The format for these are `AAAAAAAC`, or with separation for readability
328
- `AAA AA AA-C`. [[6]](#source-6) omit digits from the left if the number is
329
- shorter.
330
-
331
- The check digit are calculated using a mod-10 algorithm on the whole account
332
- number `AAAAAAA`. [[1]](#source-1)
333
-
334
- #### Bankgirot
335
-
336
- The format for these are `AAAAAAAC` or `AAAAAAC`, or with separation for
337
- readability `AAAA-AAAC` / `AAA-AAAC`. [[7]](#source-6)
338
-
339
- The check digit are calculated using a mod-10 algorithm on the whole
340
- number `AAAAAAA`. [[7]](#source-7)
341
-
342
- ### BIC (SWIFT) and IBAN
343
-
344
- **TODO**: research + implement.
345
-
346
- Im imagining a `readonly bic: string`property and a `.format('iban')`.
347
-
348
- Swedish IBAN numbers are 24 digits long and has the format
349
- `[SE]KK BBBA AAAA AAAA AAAA AAAA`
350
- (letters wrapped in `[]` are "escaped" i.e static and not a placeholder)
351
- [[4]](#source-4)
352
-
353
- The bank codes and BIC codes are assigned by the swedish bankers' association.
354
- [[2]](#source-2)
355
-
356
- The check digits are calculated using a mod-97 algorithm. [[4]](#source-4)
357
-
358
- ## Needs further research
359
-
360
- 1. <https://www.dbschenker.com/se-sv/haer-ser-du-hur-kontonumret-ska-skrivas-foer-olika-banker-481736>
361
- Claims about Danske Bank
362
- 2. PlusGirot vs PlusGirot Account (2-8 vs 14 digits)
363
- 3. BIC/IBAN
364
-
365
- ## Sources
366
-
367
- 1. <a id="source-1"></a>
368
- Bankgirot. (2019-10-22).
369
- _Bankernas kontonummer_.
370
- Stockholm: Bankgirocentralen BGC AB.
371
- [[pdf]](https://www.bankgirot.se/globalassets/dokument/anvandarmanualer/bankernaskontonummeruppbyggnad_anvandarmanual_sv.pdf),
372
- [[archived]](https://web.archive.org/web/20200412104139/https://www.bankgirot.se/globalassets/dokument/anvandarmanualer/bankernaskontonummeruppbyggnad_anvandarmanual_sv.pdf),
373
- [index](https://www.bankgirot.se/kundservice/handbocker/)
374
- 2. <a id="source-2"></a>
375
- Svenska Bankföreningen. (2019-05-23).
376
- _Swedish Bank ID Codes for IBAN_.
377
- Stockholm: Svenska Bankföreningen
378
- [[pdf]](https://www.swedishbankers.se/media/4223/bank_id_iban_bic.pdf),
379
- [[archived]](web.archive.org/web/20200412105327/https://www.swedishbankers.se/media/4223/bank_id_iban_bic.pdf),
380
- [index](https://www.swedishbankers.se/fraagor-vi-arbetar-med/clearingnummer/clearingnummer/)
381
- 3. <a id="source-3"></a>
382
- Svenska Bankföreningen. (2019-06-12).
383
- _Förteckning över av Bankföreningen tilldelade och reserverade clearingnummerserier_.
384
- Stockholm: Svenska Bankföreningen.
385
- [[pdf]](https://www.swedishbankers.se/media/4245/1906_clearingnummer-institut.pdf),
386
- [[archived]](https://web.archive.org/web/20200412105642/https://www.swedishbankers.se/media/4245/1906_clearingnummer-institut.pdf),
387
- [index](https://www.swedishbankers.se/fraagor-vi-arbetar-med/clearingnummer/clearingnummer/)
388
- 4. <a id="source-4"></a>
389
- _International Bank Account Number_. (2020-04-11).
390
- Retrieved from Wikipedia:
391
- [[permalink]](https://en.wikipedia.org/w/index.php?title=International_Bank_Account_Number&oldid=950326275)
392
- 5. <a id="source-5"></a>
393
- _Bankkonto_. (2019-05-28).
394
- Retrieved from Wikipedia:
395
- [[permalink]](https://sv.wikipedia.org/w/index.php?title=Bankkonto&oldid=45788136)
396
- 6. <a id="source-6"></a>
397
- _Transaktionskonto med PlusGironummer_.
398
- Retrieved 2020-04-12 from Nordea:
399
- [[web]](https://www.nordea.se/foretag/produkter/betala/transaktionskonto.html),
400
- [[archived]](https://web.archive.org/web/20200412110937/https://www.nordea.se/foretag/produkter/betala/transaktionskonto.html)
401
- 7. <a id="source-7"></a>
402
- Bankgirot. (2016-12-01).
403
- _Beräkning av kontrollsiffra 10-modulen_.
404
- Stockholm: Bankgirocentralen BGC AB.
405
- [[pdf]](https://www.bankgirot.se/globalassets/dokument/anvandarmanualer/10-modul.pdf),
406
- [[archived]](https://web.archive.org/web/20200412111510/https://www.bankgirot.se/globalassets/dokument/anvandarmanualer/10-modul.pdf),
407
- [index](https://www.bankgirot.se/kundservice/handbocker/)
408
- 8. <a id="source-8"></a>
409
- Bankgirot. (2016-12-01).
410
- _Beräkning av kontrollsiffra 11-modulen_.
411
- Stockholm: Bankgirocentralen BGC AB.
412
- [[pdf]](https://www.bankgirot.se/globalassets/dokument/anvandarmanualer/11-modul.pdf),
413
- [[archived]](https://web.archive.org/web/20200412111804/https://www.bankgirot.se/globalassets/dokument/anvandarmanualer/11-modul.pdf),
414
- [index](https://www.bankgirot.se/kundservice/handbocker/)
415
- 9. <a id="source-9"></a>
416
- _Clearingnummer_. (2019-02-19).
417
- Retrieved 2020-04-12 from Svenska Bankföreningen:
418
- [[web]](https://www.swedishbankers.se/fraagor-vi-arbetar-med/clearingnummer/clearingnummer/),
419
- [[archived]](https://web.archive.org/web/20200412115826/https://www.swedishbankers.se/fraagor-vi-arbetar-med/clearingnummer/clearingnummer/)
420
- 10. <a id="source-10"></a>
421
- _Clearingnummer_.
422
- Retrieved 2020-04-12 from Swedbank:
423
- [[web]](https://www.swedbank.se/privat/kort-och-betala/konton-for-in-och-utbetalningar/clearingnummer.html),
424
- [[archived]](https://web.archive.org/web/20200412124754/https://www.swedbank.se/privat/kort-och-betala/konton-for-in-och-utbetalningar/clearingnummer.html)
425
- 11. <a id="source-11"></a>
426
- _Frågor och svar konton och clearingnummer_.
427
- Retrieved 2020-04-12 from Nordea:
428
- [[web]](https://www.nordea.se/privat/kundservice/fragor-svar-konton-clearingnummer.html),
429
- [[archived]](https://web.archive.org/web/20200412130818/https://www.nordea.se/privat/kundservice/fragor-svar-konton-clearingnummer.html)
430
- 12. <a id="source-12"></a>
431
- Statistiska centralbyrån. (2016).
432
- _Befolknings- och välfärdsstatistik 2016:1, Personnummer_.
433
- SCB, avdelningen för befolkning och välfärd.
434
- Örebro: Statistiska centralbyrån.
435
- urn:nbn:se:scb-2016-be96br1601_pdf,
436
- ISSN 1654-4331.
437
- [[pdf]](https://www.scb.se/contentassets/8d9d985ca9c84c6e8d879cc89a8ae479/ov9999_2016a01_br_be96br1601.pdf),
438
- [[archived]](https://web.archive.org/web/20200412133141/https://www.scb.se/contentassets/8d9d985ca9c84c6e8d879cc89a8ae479/ov9999_2016a01_br_be96br1601.pdf),
439
- [index](https://www.scb.se/hitta-statistik/statistik-efter-amne/ovrigt/ovrigt/ovriga-publikationer-ej-statistik/pong/publikationer/personnummer/)
440
- 13. <a id="source-13"></a>
441
- Call with Swedbank regarding unverifiable account numbers.
442
- (2020-04-17)
443
- (Svante B, Interviewer)
444
- 14. <a id="source-14"></a>
445
- Vera B . (2020-04-17).
446
- Handelsbanken Chat: Question regarding length of account numbers in
447
- Handelsbanken.
448
- (Svante B, Interviewer)
449
- [[pdf]](https://swantzter.se/2020-04-17-SHB-chat.pdf)
450
- [[archived]](https://web.archive.org/web/20200417111535/https://swantzter.se/2020-04-17-SHB-chat.pdf)
177
+ **Moved** to [swantzter.se](https://swantzter.se/deep-dives/kontonummer) where I plan to publish research on other topics as well
@@ -0,0 +1,270 @@
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: 'Avanza Bank',
9
+ type: 1,
10
+ comment: 2,
11
+ ranges: [[9550, 9569]]
12
+ },
13
+ {
14
+ bankName: 'BlueStep Finans',
15
+ type: 1,
16
+ comment: 1,
17
+ ranges: [[9680, 9689]]
18
+ },
19
+ {
20
+ bankName: 'BNP Paribas SA.',
21
+ type: 1,
22
+ comment: 2,
23
+ ranges: [[9470, 9479]]
24
+ },
25
+ {
26
+ bankName: 'Citibank',
27
+ type: 1,
28
+ comment: 2,
29
+ ranges: [[9040, 9049]]
30
+ },
31
+ {
32
+ bankName: 'Danske Bank',
33
+ type: 1,
34
+ comment: 1,
35
+ ranges: [[1200, 1399], [2400, 2499]]
36
+ },
37
+ {
38
+ bankName: 'DNB Bank',
39
+ type: 1,
40
+ comment: 2,
41
+ ranges: [[9190, 9199], [9260, 9269]]
42
+ },
43
+ {
44
+ bankName: 'Ekobanken',
45
+ type: 1,
46
+ comment: 2,
47
+ ranges: [[9700, 9709]]
48
+ },
49
+ {
50
+ bankName: 'Erik Penser',
51
+ type: 1,
52
+ comment: 2,
53
+ ranges: [[9590, 9599]]
54
+ },
55
+ {
56
+ bankName: 'Ferratum Bank plc',
57
+ type: 1,
58
+ comment: 1,
59
+ ranges: [[9070, 9079]]
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: 'Lån & Spar Bank Sverige',
93
+ type: 1,
94
+ comment: 1,
95
+ ranges: [[9630, 9639]]
96
+ },
97
+ {
98
+ bankName: 'Länsförsäkringar Bank',
99
+ type: 1,
100
+ comment: 1,
101
+ ranges: [[3400, 3499], [9060, 9069]]
102
+ },
103
+ {
104
+ bankName: 'Länsförsäkringar Bank',
105
+ type: 1,
106
+ comment: 2,
107
+ ranges: [[9020, 9029]]
108
+ },
109
+ {
110
+ bankName: 'Marginalen Bank',
111
+ type: 1,
112
+ comment: 1,
113
+ ranges: [[9230, 9239]]
114
+ },
115
+ {
116
+ bankName: 'Nordax Bank',
117
+ type: 1,
118
+ comment: 2,
119
+ ranges: [[9640, 9649]]
120
+ },
121
+ {
122
+ bankName: 'Nordea',
123
+ type: 1,
124
+ comment: 1,
125
+ ranges: [[1100, 1199], [1400, 2099], [3000, 3299], [3301, 3399], [3410, 3781], [3783, 3999]]
126
+ },
127
+ {
128
+ bankName: 'Nordea',
129
+ type: 1,
130
+ comment: 2,
131
+ ranges: [[4000, 4999]]
132
+ },
133
+ {
134
+ bankName: 'Nordnet Bank',
135
+ type: 1,
136
+ comment: 2,
137
+ ranges: [[9100, 9109]]
138
+ },
139
+ {
140
+ bankName: 'Northmill Bank',
141
+ type: 1,
142
+ comment: 2,
143
+ ranges: [[9750, 9759]]
144
+ },
145
+ {
146
+ bankName: 'Resurs Bank',
147
+ type: 1,
148
+ comment: 1,
149
+ ranges: [[9280, 9289]]
150
+ },
151
+ {
152
+ bankName: 'Riksgälden',
153
+ type: 1,
154
+ comment: 2,
155
+ ranges: [[9880, 9889]]
156
+ },
157
+ {
158
+ bankName: 'Santander Consumer Bank',
159
+ type: 1,
160
+ comment: 1,
161
+ ranges: [[9460, 9469]]
162
+ },
163
+ {
164
+ bankName: 'SBAB',
165
+ type: 1,
166
+ comment: 1,
167
+ ranges: [[9250, 9259]]
168
+ },
169
+ {
170
+ bankName: 'SEB',
171
+ type: 1,
172
+ comment: 1,
173
+ ranges: [[5000, 5999], [9120, 9124], [9130, 9149]]
174
+ },
175
+ {
176
+ bankName: 'Skandiabanken',
177
+ type: 1,
178
+ comment: 2,
179
+ ranges: [[9150, 9169]]
180
+ },
181
+ {
182
+ bankName: 'Svea Bank',
183
+ type: 1,
184
+ comment: 2,
185
+ ranges: [[9660, 9669]]
186
+ },
187
+ {
188
+ bankName: 'Swedbank',
189
+ type: 1,
190
+ comment: 1,
191
+ ranges: [[7000, 7999]]
192
+ },
193
+ {
194
+ bankName: 'Ålandsbanken',
195
+ type: 1,
196
+ comment: 2,
197
+ ranges: [[2300, 2399]]
198
+ },
199
+ // Type 2 accounts - the messy ones
200
+ {
201
+ bankName: 'Danske Bank',
202
+ type: 2,
203
+ comment: 1,
204
+ ranges: [[9180, 9189]],
205
+ accountMinLength: 10,
206
+ accountMaxLength: 10
207
+ },
208
+ {
209
+ bankName: 'Handelsbanken',
210
+ type: 2,
211
+ comment: 2,
212
+ ranges: [[6000, 6999]],
213
+ accountMinLength: 8,
214
+ accountMaxLength: 9
215
+ },
216
+ {
217
+ bankName: 'Nordea',
218
+ type: 2,
219
+ comment: 1,
220
+ ranges: [[3300, 3300], [3782, 3782]],
221
+ accountMinLength: 10,
222
+ accountMaxLength: 10
223
+ },
224
+ {
225
+ bankName: 'Nordea Plusgirot',
226
+ type: 2,
227
+ comment: 3,
228
+ ranges: [[9500, 9549], [9960, 9969]],
229
+ accountMinLength: 2,
230
+ accountMaxLength: 8
231
+ },
232
+ {
233
+ bankName: 'Riksgälden',
234
+ type: 2,
235
+ comment: 1,
236
+ ranges: [[9890, 9899]],
237
+ accountMinLength: 10,
238
+ accountMaxLength: 10
239
+ },
240
+ {
241
+ bankName: 'Sparbanken Syd',
242
+ type: 2,
243
+ comment: 1,
244
+ ranges: [[9570, 9579]],
245
+ accountMinLength: 10,
246
+ accountMaxLength: 10
247
+ },
248
+ {
249
+ bankName: 'Swedbank',
250
+ type: 2,
251
+ comment: 3,
252
+ ranges: [[8000, 8999]],
253
+ accountMinLength: 10,
254
+ accountMaxLength: 11 // Allowing 11 here in case clearingnumber is sent as the first four instead of the first five
255
+ },
256
+ {
257
+ bankName: 'Swedbank',
258
+ type: 2,
259
+ comment: 1,
260
+ ranges: [[9300, 9349]],
261
+ accountMinLength: 10,
262
+ accountMaxLength: 10
263
+ }
264
+ ];
265
+ exports.default = (sortingCode) => exports.banks.find(bank => bank.ranges.some(([min, max]) => {
266
+ const sortingCodeNumber = Number(`${sortingCode}`.replace(/[^\d]/g, '').substring(0, 4));
267
+ return sortingCodeNumber >= min &&
268
+ sortingCodeNumber <= max;
269
+ }));
270
+ //# 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,aAAa;QACvB,IAAI,EAAE,CAAC;QACP,OAAO,EAAE,CAAC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V,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACtB,gBAAgB,EAAE,EAAE;QACpB,gBAAgB,EAAE,EAAE,CAAC,8FAA8F;KACpH;IACD;QACE,QAAQ,EAAE,UAAU;QACpB,IAAI,EAAE,CAAC;QACP,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACtB,gBAAgB,EAAE,EAAE;QACpB,gBAAgB,EAAE,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