ramoona / banks-db

Community driven database to get bank info (name, brand color etc.) by bankcard prefix (BIN)
https://ramoona.github.io/banks-db-demo/
720 stars 109 forks source link

Rewrite on es modules with compile into commonjs #177

Closed romanlex closed 5 years ago

romanlex commented 5 years ago

May be rewrite lib to es modules? We can compile es modules to commonjs with rollup for example

ai commented 5 years ago

For what reason?

romanlex commented 5 years ago

use this base in the browser

ai commented 5 years ago

Why you can’t use CommonJS modules in the same way in browser?

romanlex commented 5 years ago

Example I want use only RU banks or RU and BY Now I import to project all banks from all countries

ai commented 5 years ago

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?

ramoona commented 5 years ago

@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

ramoona commented 5 years ago

v0.15.0 with feature to pick specific banks arrived 💫details on API