Skip to content

Commit 92c3793

Browse files
authored
Merge pull request #51 from phuoc-ng/iban
Add IBAN generator
2 parents c30541a + bf40c79 commit 92c3793

File tree

11 files changed

+654
-29
lines changed

11 files changed

+654
-29
lines changed

README.md

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,45 +35,46 @@ const isValid = FakeNumbers.creditCard.check('given number').valid;
3535

3636
## Supported numbers
3737

38-
* [x] 01. ABN (_Australian Business Number_)
39-
* [x] 02. ACN (_Australian Company Number_)
38+
* [x] 01. ABN: Australian Business Number
39+
* [x] 02. ACN: Australian Company Number
4040
* [x] 03. ALV (_Arvonlisäveronumero_): Finnish VAT number
4141
* [x] 04. ANUM: Hungarian VAT number
42-
* [x] 05. BIC (_Business Identifier Code_)
42+
* [x] 05. BIC: Business Identifier Code
4343
* [x] 06. BN: Canadian Business Number
4444
* [x] 07. BTW: Belgian VAT number
4545
* [x] 08. CNPJ (_Cadastro Nacional da Pessoa Jurídica_): Brazilian company identifier
4646
* [x] 09. CPF (_Cadastro de Pessoas Físicas_): Brazilian identification number
4747
* [x] 10. Credit card number
4848
* [x] 11. CUSIP (_Committee on Uniform Security Identification Procedures_)
4949
* [x] 12. CVR: Danish VAT number
50-
* [x] 13. CVV (_Card Verification Value_)
50+
* [x] 13. CVV: Card Verification Value
5151
* [x] 14. DDV: Slovenian VAT number
52-
* [x] 15. EAN (_International Article Number_)
52+
* [x] 15. EAN: International Article Number
5353
* [x] 16. FPA: Greek VAT number
54-
* [x] 17. IMEI (_International Mobile Equipment Identity_)
55-
* [x] 18. IMO (_International Maritime Organization_)
56-
* [x] 19. ISBN (_International Standard Book Number_)
57-
* [x] 20. ISIN (_International Securities Identification Number_)
58-
* [x] 21. ISMN (_International Standard Music Number_)
59-
* [x] 22. ISSN (_International Standard Serial Number_)
60-
* [x] 23. NIF (_Numéro d'Immatriculation Fiscale_): French tax identification number
61-
* [x] 24. NPI (_National Provider Identifier_)
62-
* [x] 25. NRIC (_Singaporean National Registration Identity Card_)
63-
* [x] 26. PVM: Lithuanian VAT number
64-
* [x] 27. RIF (_Registro de Identificación Fiscal_): Venezuelan VAT number
65-
* [x] 28. RTN (_Routing Transit Number_)
66-
* [x] 29. SEDOL (_Stock Exchange Daily Official List_)
67-
* [x] 30. SIN (_Canadian Social Insurance Number_)
68-
* [x] 31. SIREN
69-
* [x] 32. SIRET (_Système d’Identification du Répertoire des Établissements_)
70-
* [x] 33. SSN (_Social Security number_)
71-
* [x] 34. SVNR: Austrian social insurance number
72-
* [x] 35. TFN: Australian Tax File Number
73-
* [x] 36. TRN: South African Tax Reference Number
74-
* [x] 37. UID (_Umsatzsteuer-Identifikationsnummer_): Austrian VAT number
75-
* [x] 38. VIN (_Vehicle Identification Number_): Support US only
76-
* [x] 39. VKN: Turkish tax identification number
54+
* [x] 17. IBAN: International Bank Account Number
55+
* [x] 18. IMEI: International Mobile Equipment Identity
56+
* [x] 19. IMO: International Maritime Organization
57+
* [x] 20. ISBN: International Standard Book Number
58+
* [x] 21. ISIN: International Securities Identification Number
59+
* [x] 22. ISMN: International Standard Music Number
60+
* [x] 23. ISSN: International Standard Serial Number
61+
* [x] 24. NIF (_Numéro d'Immatriculation Fiscale_): French tax identification number
62+
* [x] 25. NPI: National Provider Identifier
63+
* [x] 26. NRIC: Singaporean National Registration Identity Card
64+
* [x] 27. PVM: Lithuanian VAT number
65+
* [x] 28. RIF (_Registro de Identificación Fiscal_): Venezuelan VAT number
66+
* [x] 29. RTN: Routing Transit Number
67+
* [x] 30. SEDOL: Stock Exchange Daily Official List
68+
* [x] 31. SIN: Canadian Social Insurance Number
69+
* [x] 32. SIREN
70+
* [x] 33. SIRET (_Système d’Identification du Répertoire des Établissements_)
71+
* [x] 34. SSN: Social Security number
72+
* [x] 35. SVNR: Austrian social insurance number
73+
* [x] 36. TFN: Australian Tax File Number
74+
* [x] 37. TRN: South African Tax Reference Number
75+
* [x] 38. UID (_Umsatzsteuer-Identifikationsnummer_): Austrian VAT number
76+
* [x] 39. VIN: Vehicle Identification Number (Support US only)
77+
* [x] 40. VKN: Turkish tax identification number
7778

7879
## License
7980
Purchase a Commercial License at the [official website](https://fakenumbers.io)

dist/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const cvv: DefaultFakeCheck;
6262
export const ddv: DefaultFakeCheck;
6363
export const ean: DefaultFakeCheck;
6464
export const fpa: DefaultFakeCheck;
65+
export const iban: DefaultFakeCheck;
6566
export const imei: DefaultFakeCheck;
6667
export const imo: DefaultFakeCheck;
6768

dist/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"DDV", "Slovenian VAT number",
2929
"EAN", "International Article Number",
3030
"FPA", "Greek VAT number",
31+
"IBAN", "International Bank Account Number",
3132
"IMEI", "International Mobile Equipment Identity",
3233
"IMO", "International Maritime Organization",
3334
"ISBN", "International Standard Book Number",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"DDV", "Slovenian VAT number",
2929
"EAN", "International Article Number",
3030
"FPA", "Greek VAT number",
31+
"IBAN", "International Bank Account Number",
3132
"IMEI", "International Mobile Equipment Identity",
3233
"IMO", "International Maritime Organization",
3334
"ISBN", "International Standard Book Number",

src/CharSet.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
export const Digits = '0123456789';
1010
export const LowerCaseLetters = 'abcdefghijklmnopqrstuvwxyz';
1111
export const UpperCaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
12-
export const Letters = `${LowerCaseLetters}${UpperCaseLetters}`;
12+
13+
// Some combinations
1314
export const Hex = `${Digits}ABCDEF`;
15+
export const Letters = `${LowerCaseLetters}${UpperCaseLetters}`;
16+
export const UpperCaseDigits = `${UpperCaseLetters}${Digits}`;
1417
export const Words = `${LowerCaseLetters}${UpperCaseLetters}${Digits}`;

src/iban/check.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* Generate fake and valid numbers
3+
*
4+
* @see https://fakenumbers.io
5+
* @license https://fakenumbers.io/license
6+
* @copyright 2020 Nguyen Huu Phuoc <[email protected]>
7+
*/
8+
9+
import CheckResult from '../CheckResult';
10+
import { isValid } from '../utils/mod97And10';
11+
12+
const check = (input: string): CheckResult<{}> => {
13+
// http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
14+
// http://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
15+
const ibanPatterns = {
16+
AD: 'AD[0-9]{10}[A-Z0-9]{12}', // Andorra
17+
AE: 'AE[0-9]{21}', // United Arab Emirates
18+
AL: 'AL[0-9]{10}[A-Z0-9]{16}', // Albania
19+
AO: 'AO[0-9]{23}', // Angola
20+
AT: 'AT[0-9]{18}', // Austria
21+
AZ: 'AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}', // Azerbaijan
22+
BA: 'BA[0-9]{18}', // Bosnia and Herzegovina
23+
BE: 'BE[0-9]{14}', // Belgium
24+
BF: 'BF[0-9]{25}', // Burkina Faso
25+
BG: 'BG[0-9]{2}[A-Z]{4}[0-9]{6}[A-Z0-9]{8}', // Bulgaria
26+
BH: 'BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}', // Bahrain
27+
BI: 'BI[0-9]{14}', // Burundi
28+
BJ: 'BJ[0-9]{2}[A-Z]{1}[0-9]{23}', // Benin
29+
BR: 'BR[0-9]{25}[A-Z][A-Z0-9]', // Brazil
30+
CH: 'CH[0-9]{7}[A-Z0-9]{12}', // Switzerland
31+
CI: 'CI[0-9]{2}[A-Z]{1}[0-9]{23}', // Ivory Coast
32+
CM: 'CM[0-9]{25}', // Cameroon
33+
CR: 'CR[0-9]{20}', // Costa Rica
34+
CV: 'CV[0-9]{23}', // Cape Verde
35+
CY: 'CY[0-9]{10}[A-Z0-9]{16}', // Cyprus
36+
CZ: 'CZ[0-9]{22}', // Czech Republic
37+
DE: 'DE[0-9]{20}', // Germany
38+
DK: 'DK[0-9]{16}', // Denmark
39+
DO: 'DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}', // Dominican Republic
40+
DZ: 'DZ[0-9]{22}', // Algeria
41+
EE: 'EE[0-9]{18}', // Estonia
42+
ES: 'ES[0-9]{22}', // Spain
43+
FI: 'FI[0-9]{16}', // Finland
44+
FO: 'FO[0-9]{16}', // Faroe Islands
45+
FR: 'FR[0-9]{12}[A-Z0-9]{11}[0-9]{2}', // France
46+
GB: 'GB[0-9]{2}[A-Z]{4}[0-9]{14}', // United Kingdom
47+
GE: 'GE[0-9]{2}[A-Z]{2}[0-9]{16}', // Georgia
48+
GI: 'GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}', // Gibraltar
49+
GL: 'GL[0-9]{16}', // Greenland
50+
GR: 'GR[0-9]{9}[A-Z0-9]{16}', // Greece
51+
GT: 'GT[0-9]{2}[A-Z0-9]{24}', // Guatemala
52+
HR: 'HR[0-9]{19}', // Croatia
53+
HU: 'HU[0-9]{26}', // Hungary
54+
IE: 'IE[0-9]{2}[A-Z]{4}[0-9]{14}', // Ireland
55+
IL: 'IL[0-9]{21}', // Israel
56+
IR: 'IR[0-9]{23}', // Iran
57+
IS: 'IS[0-9]{24}', // Iceland
58+
IT: 'IT[0-9]{2}[A-Z]{1}[0-9]{10}[A-Z0-9]{12}', // Italy
59+
JO: 'JO[0-9]{2}[A-Z]{4}[0-9]{4}[0]{8}[A-Z0-9]{10}', // Jordan
60+
KW: 'KW[0-9]{2}[A-Z]{4}[0-9]{22}', // Kuwait
61+
KZ: 'KZ[0-9]{5}[A-Z0-9]{13}', // Kazakhstan
62+
LB: 'LB[0-9]{6}[A-Z0-9]{20}', // Lebanon
63+
LI: 'LI[0-9]{7}[A-Z0-9]{12}', // Liechtenstein
64+
LT: 'LT[0-9]{18}', // Lithuania
65+
LU: 'LU[0-9]{5}[A-Z0-9]{13}', // Luxembourg
66+
LV: 'LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}', // Latvia
67+
MC: 'MC[0-9]{12}[A-Z0-9]{11}[0-9]{2}', // Monaco
68+
MD: 'MD[0-9]{2}[A-Z0-9]{20}', // Moldova
69+
ME: 'ME[0-9]{20}', // Montenegro
70+
MG: 'MG[0-9]{25}', // Madagascar
71+
MK: 'MK[0-9]{5}[A-Z0-9]{10}[0-9]{2}', // Macedonia
72+
ML: 'ML[0-9]{2}[A-Z]{1}[0-9]{23}', // Mali
73+
MR: 'MR[0-9]{25}', // Mauritania
74+
MT: 'MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}', // Malta
75+
MU: 'MU[0-9]{2}[A-Z]{4}[0-9]{19}[A-Z]{3}', // Mauritius
76+
MZ: 'MZ[0-9]{23}', // Mozambique
77+
NL: 'NL[0-9]{2}[A-Z]{4}[0-9]{10}', // Netherlands
78+
NO: 'NO[0-9]{13}', // Norway
79+
PK: 'PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Pakistan
80+
PL: 'PL[0-9]{26}', // Poland
81+
PS: 'PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Palestinian
82+
PT: 'PT[0-9]{23}', // Portugal
83+
QA: 'QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Qatar
84+
RO: 'RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Romania
85+
RS: 'RS[0-9]{20}', // Serbia
86+
SA: 'SA[0-9]{4}[A-Z0-9]{18}', // Saudi Arabia
87+
SE: 'SE[0-9]{22}', // Sweden
88+
SI: 'SI[0-9]{17}', // Slovenia
89+
SK: 'SK[0-9]{22}', // Slovakia
90+
SM: 'SM[0-9]{2}[A-Z]{1}[0-9]{10}[A-Z0-9]{12}', // San Marino
91+
SN: 'SN[0-9]{2}[A-Z]{1}[0-9]{23}', // Senegal
92+
TL: 'TL[0-9]{21}', // East Timor
93+
TN: 'TN[0-9]{22}', // Tunisia
94+
TR: 'TR[0-9]{7}[A-Z0-9]{17}', // Turkey
95+
VG: 'VG[0-9]{2}[A-Z]{4}[0-9]{16}', // Virgin Islands, British
96+
XK: 'XK[0-9]{18}', // Republic of Kosovo
97+
};
98+
99+
const value = input.replace(/\s/g, '');
100+
const country = value.substr(0, 2);
101+
if (!ibanPatterns[country]) {
102+
return { valid: false };
103+
}
104+
105+
return {
106+
valid: isValid(`${value.substr(4)}${value.substr(0, 4)}`),
107+
};
108+
};
109+
110+
export default check;

0 commit comments

Comments
 (0)