-
Notifications
You must be signed in to change notification settings - Fork 9
/
fake.ts
304 lines (297 loc) · 12.8 KB
/
fake.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/**
* Generate fake and valid numbers
*
* @see https://fakenumbers.io
* @license https://fakenumbers.io/license
* @copyright 2020 Nguyen Huu Phuoc <me@phuoc.ng>
*/
import { UpperCaseDigits, UpperCaseLetters } from '../CharSet';
import randomFromArray from '../utils/randomFromArray';
import randomNumbers from '../utils/randomNumbers';
import randomString from '../utils/randomString';
import { getCheckDigits } from '../utils/mod97And10';
/**
* Generate a random IBAN
*
* @returns string
*/
const fake = (countryCode?: string): string => {
const supportedCountries = [
'AD', 'AE', 'AL', 'AO', 'AT', 'AZ',
'BA', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BR',
'CH', 'CI', 'CM', 'CR', 'CV', 'CY', 'CZ',
'DE', 'DK', 'DO', 'DZ',
'EE', 'ES',
'FI', 'FO', 'FR',
'GB', 'GE', 'GI', 'GL', 'GR', 'GT',
'HR', 'HU',
'IE', 'IL', 'IR', 'IS', 'IT',
'JO',
'KW', 'KZ',
'LB', 'LI', 'LT', 'LU', 'LV',
'MC', 'MD', 'ME', 'MG', 'MK', 'ML', 'MR', 'MT', 'MU', 'MZ',
'NL', 'NO',
'PK', 'PL', 'PS', 'PT',
'QA',
'RO', 'RS',
'SA', 'SE', 'SI', 'SK', 'SM', 'SN',
'TL', 'TN', 'TR',
'VG',
'XK',
];
const country = countryCode || randomFromArray(supportedCountries);
if (supportedCountries.indexOf(country) === -1) {
throw new Error(`The ${country} isn't supported`);
}
let partial;
switch (country) {
case 'AD': // Andorra
partial = `AD${randomNumbers(10).join('')}${randomString(12, UpperCaseDigits)}`;
break;
case 'AE': // United Arab Emirates
partial = `AE${randomNumbers(21).join('')}`;
break;
case 'AL': // Albania
partial = `AL${randomNumbers(10).join('')}${randomString(16, UpperCaseDigits)}`;
break;
case 'AO': // Angola
partial = `AO${randomNumbers(23).join('')}`;
break;
case 'AT': // Austria
partial = `AT${randomNumbers(18).join('')}`;
break;
case 'AZ': // Azerbaijan
partial = `AZ${randomNumbers(6).join('')}${randomString(20, UpperCaseDigits)}`;
break;
case 'BA': // Bosnia and Herzegovina
partial = `BA${randomNumbers(18).join('')}`;
break;
case 'BE': // Belgium
partial = `BE${randomNumbers(14).join('')}`;
break;
case 'BF': // Burkina Faso
partial = `BF${randomNumbers(25).join('')}`;
break;
case 'BG': // Bulgaria
partial = `BG${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomNumbers(6).join('')}${randomString(8, UpperCaseDigits)}`;
break;
case 'BH': // Bahrain
partial = `BH${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomString(14, UpperCaseDigits)}`;
break;
case 'BI': // Burundi
partial = `BI${randomNumbers(14).join('')}`;
break;
case 'BJ': // Benin
partial = `BJ${randomNumbers(2).join('')}${randomString(1, UpperCaseLetters)}${randomNumbers(23).join('')}`;
break;
case 'BR': // Brazil
partial = `BR${randomNumbers(25).join('')}${randomString(1, UpperCaseLetters)}${randomString(1, UpperCaseDigits)}`;
break;
case 'CH': // Switzerland
partial = `CH${randomNumbers(7).join('')}${randomString(12, UpperCaseDigits)}`;
break;
case 'CI': // Ivory Coast
partial = `CI${randomNumbers(2).join('')}${randomString(1, UpperCaseLetters)}${randomNumbers(23).join('')}`;
break;
case 'CM': // Cameroon
partial = `CM${randomNumbers(25).join('')}`;
break;
case 'CR': // Costa Rica
partial = `CR${randomNumbers(29).join('')}`;
break;
case 'CV': // Cape Verde
partial = `CV${randomNumbers(23).join('')}`;
break;
case 'CY': // Cyprus
partial = `CY${randomNumbers(10).join('')}${randomString(16, UpperCaseDigits)}`;
break;
case 'CZ': // Czech Republic
partial = `CZ${randomNumbers(22).join('')}`;
break;
case 'DE': // Germany
partial = `DE${randomNumbers(20).join('')}`;
break;
case 'DK': // Denmark
partial = `DK${randomNumbers(16).join('')}`;
break;
case 'DO': // Dominican Republic
partial = `DO${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomNumbers(20).join('')}`;
break;
case 'DZ': // Algeria
partial = `DZ${randomNumbers(22).join('')}`;
break;
case 'EE': // Estonia
partial = `EE${randomNumbers(18).join('')}`;
break;
case 'ES': // Spain
partial = `ES${randomNumbers(22).join('')}`;
break;
case 'FI': // Finland
partial = `FI${randomNumbers(16).join('')}`;
break;
case 'FO': // Faroe Islands
partial = `FO${randomNumbers(16).join('')}`;
break;
case 'FR': // France
partial = `FR${randomNumbers(12).join('')}${randomString(11, UpperCaseDigits)}${randomNumbers(2).join('')}`;
break;
case 'GB': // United Kingdom
partial = `GB${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomNumbers(14).join('')}`;
break;
case 'GE': // Georgia
partial = `GE${randomNumbers(2).join('')}${randomString(2, UpperCaseLetters)}${randomNumbers(16).join('')}`;
break;
case 'GI': // Gibraltar
partial = `GI${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomString(15, UpperCaseDigits)}`;
break;
case 'GL': // Greenland
partial = `GL${randomNumbers(16).join('')}`;
break;
case 'GR': // Greece
partial = `GR${randomNumbers(9).join('')}${randomString(16, UpperCaseDigits)}`;
break;
case 'GT': // Guatemala
partial = `GT${randomNumbers(2).join('')}${randomString(24, UpperCaseDigits)}`;
break;
case 'HR': // Croatia
partial = `HR${randomNumbers(19).join('')}`;
break;
case 'HU': // Hungary
partial = `HU${randomNumbers(26).join('')}`;
break;
case 'IE': // Ireland
partial = `IE${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomNumbers(14).join('')}`;
break;
case 'IL': // Israel
partial = `IL${randomNumbers(21).join('')}`;
break;
case 'IR': // Iran
partial = `IR${randomNumbers(24).join('')}`;
break;
case 'IS': // Iceland
partial = `IS${randomNumbers(24).join('')}`;
break;
case 'IT': // Italy
partial = `IT${randomNumbers(2).join('')}${randomString(1, UpperCaseLetters)}${randomNumbers(10).join('')}${randomString(12, UpperCaseDigits)}`;
break;
case 'JO': // Jordan
partial = `JO${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomNumbers(4).join('')}${randomString(8, '0')}${randomString(10, UpperCaseDigits)}`;
break;
case 'KW': // Kuwait
partial = `KW${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomNumbers(22).join('')}`;
break;
case 'KZ': // Kazakhstan
partial = `KZ${randomNumbers(5).join('')}${randomString(13, UpperCaseDigits)}`;
break;
case 'LB': // Lebanon
partial = `LB${randomNumbers(6).join('')}${randomString(20, UpperCaseDigits)}`;
break;
case 'LI': // Liechtenstein
partial = `LI${randomNumbers(7).join('')}${randomString(12, UpperCaseDigits)}`;
break;
case 'LT': // Lithuania
partial = `LT${randomNumbers(18).join('')}`;
break;
case 'LU': // Luxembourg
partial = `LU${randomNumbers(5).join('')}${randomString(13, UpperCaseDigits)}`;
break;
case 'LV': // Latvia
partial = `LV${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomString(13, UpperCaseDigits)}`;
break;
case 'MC': // Monaco
partial = `MC${randomNumbers(12).join('')}${randomString(11, UpperCaseDigits)}${randomNumbers(2).join('')}`;
break;
case 'MD': // Moldova
partial = `MD${randomNumbers(2).join('')}${randomString(20, UpperCaseDigits)}`;
break;
case 'ME': // Montenegro
partial = `ME${randomNumbers(20).join('')}`;
break;
case 'MG': // Madagascar
partial = `MG${randomNumbers(25).join('')}`;
break;
case 'MK': // Macedonia
partial = `MK${randomNumbers(5).join('')}${randomString(10, UpperCaseDigits)}${randomNumbers(2).join('')}`;
break;
case 'ML': // Mali
partial = `ML${randomNumbers(2).join('')}${randomString(1, UpperCaseLetters)}${randomNumbers(23).join('')}`;
break;
case 'MR': // Mauritania
partial = `MR${randomNumbers(25).join('')}`;
break;
case 'MT': // Malta
partial = `MT${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomNumbers(5).join('')}${randomString(18, UpperCaseDigits)}`;
break;
case 'MU': // Mauritius
partial = `MU${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomNumbers(19).join('')}${randomString(3, UpperCaseLetters)}`;
break;
case 'MZ': // Mozambique
partial = `MZ${randomNumbers(23).join('')}`;
break;
case 'NL': // Netherlands
partial = `NL${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomNumbers(10).join('')}`;
break;
case 'NO': // Norway
partial = `NO${randomNumbers(13).join('')}`;
break;
case 'PK': // Pakistan
partial = `PK${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomString(16, UpperCaseDigits)}`;
break;
case 'PL': // Poland
partial = `PL${randomNumbers(26).join('')}`;
break;
case 'PS': // Palestinian
partial = `PS${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomString(21, UpperCaseDigits)}`;
break;
case 'PT': // Portugal
partial = `PT${randomNumbers(23).join('')}`;
break;
case 'QA': // Qatar
partial = `QA${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomString(21, UpperCaseDigits)}`;
break;
case 'RO': // Romania
partial = `RO${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomString(16, UpperCaseDigits)}`;
break;
case 'RS': // Serbia
partial = `RS${randomNumbers(20).join('')}`;
break;
case 'SA': // Saudi Arabia
partial = `SA${randomNumbers(4).join('')}${randomString(18, UpperCaseDigits)}`;
break;
case 'SE': // Sweden
partial = `SE${randomNumbers(22).join('')}`;
break;
case 'SI': // Slovenia
partial = `SI${randomNumbers(17).join('')}`;
break;
case 'SK': // Slovakia
partial = `SK${randomNumbers(22).join('')}`;
break;
case 'SM': // San Marino
partial = `SM${randomNumbers(2).join('')}${randomString(1, UpperCaseLetters)}${randomNumbers(10).join('')}${randomString(12, UpperCaseDigits)}`;
break;
case 'SN': // Senegal
partial = `SN${randomNumbers(2).join('')}${randomString(1, UpperCaseLetters)}${randomNumbers(23).join('')}`;
break;
case 'TL': // East Timor
partial = `TL${randomNumbers(21).join('')}`;
break;
case 'TN': // Tunisia
partial = `TN${randomNumbers(22).join('')}`;
break;
case 'TR': // Turkey
partial = `TR${randomNumbers(7).join('')}${randomString(17, UpperCaseDigits)}`;
break;
case 'VG': // Virgin Islands, British
partial = `VG${randomNumbers(2).join('')}${randomString(4, UpperCaseLetters)}${randomNumbers(16).join('')}`;
break;
case 'XK': // Republic of Kosovo
partial = `XK${randomNumbers(18).join('')}`;
break;
}
const value = `${partial.substr(4)}${partial.substr(0, 2)}`;
const cd = getCheckDigits(value);
const checkDigits = cd < 10 ? `0${cd}` : `${cd}`;
return `${partial.substr(0, 2)}${checkDigits}${partial.substr(4)}`;
};
export default fake;