diia-open-source / be-pkg-utils

European Union Public License 1.2
14 stars 10 forks source link

IBAN validation multiple issues #9

Open tshemsedinov opened 3 months ago

tshemsedinov commented 3 months ago

https://github.com/diia-open-source/be-pkg-utils/blob/e969374fb769e59ab6bbdb709caeba0199e14a8c/src/applicationUtils.ts#L240-L253

  1. Magic numbers: 3, 2, 2, 55...
  2. Regular expressions are not needed here
  3. Supports only UA ibans so rename to validateIbanUA or better move country to arguments and get universal solution
Amice13 commented 3 months ago

According to ISO 7064 each letter in the IBAN string must be replaced with two digits, where A = 10, B = 11, ..., Z = 35.

Is there any way to replace charCodeAt and 55 to avoid magic number, but keep is short?

I've added other countries to the validator as well:

https://github.com/diia-open-source/be-pkg-utils/pull/30

tshemsedinov commented 3 months ago

Is there any way to replace charCodeAt and 55 to avoid magic number, but keep is short?

To make code understandable all constants should have names and if there are series of constants (for example certain places in BLOB or code, like we have in this place) it should be represented as collection and offsets (see implementation of IP packet parsing or any other binary data structure representation parser).