Closed romanlex closed 5 years ago
For what reason?
use this base in the browser
Why you can’t use CommonJS modules in the same way in browser?
Example I want use only RU banks or RU and BY Now I import to project all banks from all countries
ES Modules will not help you with it. You need to:
var ruData = require('./banks/ru')
var banks = [];
ruData.forEach(function (item) {
banks = banks.concat(item);
});
banks.forEach(function (bank) {
bank.code = bank.country + '-' + bank.name;
bank.prefixes.forEach(function (prefix) {
prefixes[prefix] = bank;
});
});
module.exports = function findBank(cardNumber) {
cardNumber = cardNumber || '';
var card = cardNumber.toString().replace(/[^\d]/g, '');
var first5 = card.substr(0, 5);
var first6 = card.substr(0, 6);
var bank = prefixes[first6] || prefixes[first5];
var result = {
type: type(card)
};
if (bank) {
for (var el in bank) {
result[el] = bank[el];
}
}
return result;
};
@ramoona maybe we should move findBank
function to separated file and add instructions to docs about partial import?
@ai as I remember the initial idea was that you never know what card will be used so there's no point to select country :) but ok separating findBank
sounds good, I'll do that in a few days
v0.15.0 with feature to pick specific banks arrived 💫details on API
May be rewrite lib to es modules? We can compile es modules to commonjs with rollup for example