Banks DB (Bankcard BIN Database)

0.23.0 · active · verified Wed Apr 22

The `banks-db` library provides a client-side database of bank identification numbers (BINs) to retrieve bank names and associated brand colors based on a bankcard prefix. Its primary function is to enhance user experience on billing pages, for example, by dynamically displaying a bank's logo or changing background colors as a user types their card number. It is crucial to understand that this database is community-driven and explicitly warns against its use for any billing logic, fraud detection, or security-sensitive operations due to potential inaccuracies or incompleteness. The current stable version is 0.23.0, and the package maintains a relatively active release cadence, with minor version updates typically occurring every few weeks to months, often reflecting database updates or small feature enhancements. A key differentiator is its dual approach: offering a comprehensive global dataset through the main export, alongside the ability to selectively load country-specific data for optimized bundle sizes, with direct integration examples for PostCSS and CSS-in-JS environments.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use the `banks-db` library to retrieve bank information and card type from a given card number prefix, showing how to access properties like bank code, name, type, and brand color. It also illustrates how to access the raw database.

import banksDB from 'banks-db';

// Simulate a card number input field
const cardNumberField = { value: '5275940000000000' };
// In a real application, you'd get this from an input element:
// const cardNumberField = document.getElementById('cardNumberInput');

const bank = banksDB(cardNumberField.value);

if (bank.code) {
  console.log('Bank found!');
  console.log(`Bank Code: ${bank.code}`); // e.g., 'ru-citibank'
  console.log(`Bank Name (EN): ${bank.engTitle}`); // e.g., 'Citibank'
  console.log(`Card Type: ${bank.type}`); // e.g., 'mastercard'
  console.log(`Brand Color: ${bank.color}`); // e.g., '#F8C220'
  console.log(`Country: ${bank.country}`); // e.g., 'ru'
  // Example of applying styles based on bank data
  // document.body.style.backgroundColor = bank.color;
} else if (bank.type) {
  console.log('Bank not found in DB, but card type identified: ' + bank.type);
} else {
  console.log('No bank or card type identified for this prefix.');
}

// To see the raw data (for debugging or custom processing)
// console.log('\nFull Banks DB Data:');
// for (const b of banksDB.data) {
//   console.log(b.code, b.engTitle);
//   if (b.code === 'ru-citibank') break; // Limit output for brevity
// }

view raw JSON →