-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
366 lines (347 loc) · 7.43 KB
/
index.js
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
const banks = [
{
nickname: 'ayandeh',
name: 'Ayandeh Bank',
persianName: 'بانک آینده',
code: '636214',
},
{
nickname: 'eghtesad-novin',
name: 'Eghtesad Novin Bank',
persianName: 'بانک اقتصاد نوین',
code: '627412',
},
{
nickname: 'ansar',
name: 'Ansar Bank',
persianName: 'بانک انصار',
code: '627381',
},
{
nickname: 'iran-zamin',
name: 'Iran Zamin Bank',
persianName: 'بانک ایران زمین',
code: '505785',
},
{
nickname: 'parsian',
name: 'Parsian Bank',
persianName: 'بانک پارسیان',
code: '622106',
},
{
nickname: 'parsian',
name: 'Parsian Bank',
persianName: 'بانک پارسیان',
code: '627884',
},
{
nickname: 'pasargad',
name: 'Pasargad Bank',
persianName: 'بانک پاسارگاد',
code: '502229',
},
{
nickname: 'pasargad',
name: 'Pasargad Bank',
persianName: 'بانک پاسارگاد',
code: '639347',
},
{
nickname: 'post',
name: 'Post Bank',
persianName: 'پست بانک ایران',
code: '627760',
},
{
nickname: 'tejarat',
name: 'Tejarat Bank',
persianName: 'بانک تجارت',
code: '585983',
},
{
nickname: 'tejarat',
name: 'Tejarat Bank',
persianName: 'بانک تجارت',
code: '627353',
},
{
nickname: 'tosee-taavon',
name: 'Tose Taavon Bank',
persianName: 'بانک توسعه تعاون',
code: '502908',
},
{
nickname: 'tosee-saderat',
name: 'Tose Saderat Bank',
persianName: 'بانک توسعه صادرات',
code: '207177',
},
{
nickname: 'tosee-saderat',
name: 'Tose Saderat Bank',
persianName: 'بانک توسعه صادرات',
code: '627648',
},
{
nickname: 'hekmat-iranian',
name: 'Hekmat Iranian Bank',
persianName: 'بانک حکمت ایرانیان',
code: '636949',
},
{
nickname: 'middle-east',
name: 'Middle East Bank',
persianName: 'بانک خاورمیانه',
code: '585949',
},
{
nickname: 'dey',
name: 'Dey Bank',
persianName: 'بانک دی',
code: '502938',
},
{
nickname: 'resalat',
name: 'Resalat Bank',
persianName: 'بانک رسالت',
code: '504172',
},
{
nickname: 'refah',
name: 'Refah Bank',
persianName: 'بانک رفاه کارگران',
code: '589463',
},
{
nickname: 'saman',
name: 'Saman Bank',
persianName: 'بانک سامان',
code: '621986',
},
{
nickname: 'sepah',
name: 'Sepah Bank',
persianName: 'بانک سپه',
code: '589210',
},
{
nickname: 'sarmayeh',
name: 'Sarmayeh Bank',
persianName: 'بانک سرمایه',
code: '639607',
},
{
nickname: 'sina',
name: 'Sina Bank',
persianName: 'بانک سینا',
code: '639346',
},
{
nickname: 'shahr',
name: 'City Bank',
persianName: 'بانک شهر',
code: '502806',
},
{
nickname: 'shahr',
name: 'City Bank',
persianName: 'بانک شهر',
code: '504706',
},
{
nickname: 'saderat',
name: 'Saderat Bank',
persianName: 'بانک صادرات ایران',
code: '603769',
},
{
nickname: 'saderat',
name: 'Saderat Bank',
persianName: 'بانک صادرات ایران',
code: '903769',
},
{
nickname: 'sanat-o-madan',
name: 'Sanat O Madan Bank',
persianName: 'بانک صنعت و معدن',
code: '627961',
},
{
nickname: 'gharzolhasane-mehr',
name: 'Gharzolhasaneh Mehr Bank',
persianName: 'بانک قرض الحسنه مهر',
code: '639370',
},
{
nickname: 'ghavamin',
name: 'Ghavamin Bank',
persianName: 'بانک قوامین',
code: '639599',
},
{
nickname: 'karafarin',
name: 'Karafarin Bank',
persianName: 'بانک کارآفرین',
code: '627488',
},
{
nickname: 'keshavarzi',
name: 'Keshavarzi',
persianName: 'بانک کشاورزی',
code: '603770',
},
{
nickname: 'keshavarzi',
name: 'Keshavarzi',
persianName: 'بانک کشاورزی',
code: '639217',
},
{
nickname: 'gardeshgari',
name: 'Gardeshgari',
persianName: 'بانک گردشگری',
code: '505416',
},
{
nickname: 'gardeshgari',
name: 'Gardeshgari',
persianName: 'بانک گردشگری',
code: '505426',
},
{
nickname: 'central',
name: 'Central Bank of Iran',
persianName: 'بانک مرکزی ایران',
code: '636797',
},
{
nickname: 'maskan',
name: 'Maskan Bank',
persianName: 'بانک مسکن',
code: '628023',
},
{
nickname: 'mellat',
name: 'Mellat Bank',
persianName: 'بانک ملت',
code: '610433',
},
{
nickname: 'mellat',
name: 'Mellat Bank',
persianName: 'بانک ملت',
code: '991975',
},
{
nickname: 'melli',
name: 'Melli',
persianName: 'بانک ملی ایران',
code: '170019',
},
{
nickname: 'melli',
name: 'Melli',
persianName: 'بانک ملی ایران',
code: '603799',
},
{
nickname: 'mehr-iran',
name: 'Mehr Iran Bank',
persianName: 'بانک مهر ایران',
code: '606373',
},
{
nickname: 'kousar',
name: 'Kousar Institution',
persianName: 'موسسه کوثر',
code: '505801',
},
{
nickname: 'mellal-credit',
name: 'Mellal Credit Institution',
persianName: 'موسسه اعتباری ملل',
code: '606256',
},
{
nickname: 'tose-financial',
name: 'Tose Financial Institution',
persianName: '',
code: '628157',
},
];
var banksHash = {};
var banksOutput = [];
for (var i = 0; i < banks.length; i++) {
banksHash[banks[i].code] = banks[i];
banksOutput.push({
nickname: banks[i].nickname,
name: banks[i].name,
persianName: banks[i].persianName,
code: banks[i].code,
accountNumberAvailable: banks[i].accountNumberAvailable,
});
}
const pattern = /[0-9]{16}/;
const pattern_code = /([0-9]{6})[0-9]{10}/;
module.exports.banks = banksOutput;
/*
function iso7064Mod97_10(card) {
var remainder = card,
block;
while (remainder.length > 2) {
block = remainder.slice(0, 9);
remainder = (parseInt(block, 10) % 97) + remainder.slice(block.length);
}
return parseInt(remainder, 10) % 97;
}
*/
const validate = function(str) {
str = str.replace(/-/g, '');
str = str.replace(/ /g, '');
if (str.length !== 16) {
return false;
}
if (!pattern.test(str)) {
return false;
}
var nCheck = 0,
bEven = false;
str = str.replace(/\D/g, '');
for (var n = str.length - 1; n >= 0; n--) {
var cDigit = str.charAt(n),
nDigit = parseInt(cDigit, 10);
if (bEven) {
if ((nDigit *= 2) > 9) nDigit -= 9;
}
nCheck += nDigit;
bEven = !bEven;
}
return nCheck % 10 == 0;
};
module.exports.isValid = validate;
module.exports.recognize = function(str) {
str = str.replace(/-/g, '');
str = str.replace(/ /g, '');
if (!validate(str)) {
return false;
}
var res = pattern_code.exec(str);
var code = res[1];
if (!banksHash[code]) {
return false;
}
var bank = banksHash[code];
var result = {
nickname: bank.nickname,
name: bank.name,
persianName: bank.persianName,
code: bank.code,
};
if (bank.accountNumberAvailable) {
var data = bank.process(str);
result.accountNumber = data.normal;
result.formattedAccountNumber = data.formatted;
}
return result;
};