CardInfo.js
CardInfo.js allows you to get the logo of the bank and brand, brand colors and etc. by card number. Use this data to make beautiful forms for bank cards. The database currently has 49 most popular Russian banks, soon will be added banks for United States, Canada, England, Australia and New Zealand. You can play with the example of the form on the demo page.
Документация на русском языке здесь.

Get Started
Download CardInfo.js, install via bowerbower install card-info
or npm npm install card-info
.Insert JS file with plugin to your html:
<script src="/bower_components/card-info/dist/card-info.min.js"></script>
Now you can use the class
CardInfo
in your code:
var cardInfo = new CardInfo('4377730000000000');
console.log('Bank name:', cardInfo.bankName);
// > Bank Name: Tinkoff Bank
console.log('Bank logo:', cardInfo.bankLogo);
// > Bank logo: /bower_components/card-info/dist/banks-logos/ru-tinkoff.svg
Constructor
new CardInfo(number)
new CardInfo(number, options)
number
card number, number or string, spaces are allowed in the string.options
the object with the settings.
Instance
If the first 6 digits of the card number failed to determine the bank details, then the fields bankAlias, bankName, bankNameEn, bankCountry, bankUrl, bankLogoPng, bankLogoSvg, bankLogo, bankLogoStyle, backgroundColor, backgroundColors, backgroundLightness, textColor, backgroundGradient will have a default value.If the first digits in the card number failed to determine the brand information, the fields brandAlias, brandName, brandLogoPng, brandLogoSvg, brandLogo, codeName, codeLength, numberLengths, numberGaps will have a default value.
bankAlias
by defaultnull
null
.bankName
by defaultnull
bankNameEn
by defaultnull
bankCountry
by defaultnull
'ru'
- Russia.bankUrl
by defaultnull
bankLogo
by defaultnull
dist/banks-logos
there is a logo in PNG format, for some, also in SVG. The name of the file is determined by the property of the instance of bankAlias
. The path to the file is determined by the property of the settings banksLogosPath
. The extension of the logo is determined by the property of the preferences preferredExt
. Example: for the bank "Tinkoff" the value will be '/bower_components/card-info/dist/banks-logos/ru-tinkoff.svg'
.bankLogoPng
by defaultnull
bankLogoSvg
by defaultnull
bankLogoStyle
by defaultnull
'black'
, if it is white, then 'white'
, if colored, 'colored'
.backgroundColor
by default'#eeeeee'
'#eeeeee'
.backgroundColors
by default['#eeeeee', '#dddddd']
['#eeeeee', '#dddddd']
.backgroundLightness
by default'light'
'light'
, otherwise 'dark'
.backgroundGradient
by defaultlinear-gradient(135deg, #eeeeee, #dddddd)
background
property, setting which, you will get a gradient from the colors specified in the field backgroundColors
. The angle can be specified in the property of the settings gradientDegrees
.textColor
by default'#000'
backgroundColor
property.brandAlias
by defaultnull
brandName
by defaultnull
brandLogo
by defaultnull
dist/brands-logos
there is a logo in PNG and SVG format and in three styles: black, white and color. The name of the file is determined by the property of the instance brandAlias
. The path to the file is determined by the properties of the brandsLogosPath
settings. The extension of the logo is determined by the property of the preferences preferredExt
. The style of the logo is determined by the property of the brandLogoPolicy
settings. Example: for the "Visa" brand, the value will be '/bower_components/card-info/dist/brands-logos/visa-colored.svg'
.brandLogoPng
by defaultnull
brandLogoSvg
by defaultnull
codeName
by defaultnull
codeLength
by defaultnull
numberMask
by default0000 0000 0000 0000000
maskDigitSymbol
and maskDelimiterSymbol
. Use the numberMask
property to apply a mask to the card number entry field.numberGaps
by default[4, 8, 12]
numberBlocks
by default[4, 4, 4, 7]
numberGaps
and the maximum number in numberLengths
.numberLengths
by default[12, 13, 14, 15, 16, 17, 18, 19]
numberNice
numberMask
. Example: 4377730000000000 → 4377 7300 0000 0000, 437773 → 4377 73.number
numberSource
options
Settings
Settings are transferred either when creating a new instance:var cardInfo = new CardInfo('4377730000000000', {
banksLogosPath: '/my/path/to/banks/logos',
brandsLogosPath: '/my/path/to/brands/logos'
});
Or, the default settings are set, which will be applied when creating all subsequent instances:
CardInfo.setDefaultOptions({
banksLogosPath: '/my/path/to/banks/logos',
brandsLogosPath: '/my/path/to/brands/logos'
});
banksLogosPath
by default'/bower_components/card-info/dist/banks-logos/'
brandsLogosPath
by default'/bower_components/card-info/dist/brands-logos/'
brandLogoPolicy
by default'auto'
'colored'
The brand logo will be colored
'black'
The brand logo will be black
'white'
The brand logo will be white
'mono'
The brand logo will be white, if the background (`backgroundLightness`) is dark (`'dark'`)
The brand logo will be black if the background (`backgroundLightness`) is light (`'light'`)
'auto'
The logo of the brand will be colored if the style of the bank logo (`bankLogoStyle`) is colored (`'colored'`)
The brand logo will be white if the bank logo style (`bankLogoStyle`) is white (`'white'`)
The brand logo will be black if the bank logo style (`bankLogoStyle`) is black (`'black'`)
The brand logo will be colored if the bank is not defined
preferredExt
by default'svg'
'png'
or 'svg'
.maskDigitSymbol
by default'0'
numberMask
.maskDelimiterSymbol
by default''
numberMask
instance.gradientDegrees
by default135
backgroundGradient
.Static methods
CardInfo.setDefaultOptions(options)
CardInfo.getBrands()
CardInfo.getBrands(options)
Array with all brands.
CardInfo.getBanks()
CardInfo.getBanks(options)
Array with all banks.
Ways of connecting
- Connect the main file. In this case, you download the entire database of banks.
<script src="/bower_components/card-info/dist/card-info.min.js"></script>
- Connect only the file with the logic, without the database, and the database for your country separately. Bases of banks for each country separately are located in the
dist/banks-and-prefixes
folder.
<script src="/bower_components/card-info/dist/card-info.core.min.js"></script>
<script src="/bower_components/card-info/dist/banks-and-prefixes/ru.min.js"></script>
- Connect as a module in your code
const CardInfo = require('card-info')
// or
import CardInfo from 'card-info'
Cutting Logos
All bank logos in the original size are stored in the foldersrc/banks-logos
. If you installed CardInfo.js in npm, you will be able to use the command npm run build-banks-logos
. After its call, all logos from the folder src/banks-logos
will be transformed into PNG format, reduced to 600 pixels in width and 200 in height, copied to the folder dist/banks-logos
. To change the settings for slicing logos, pass the settings when calling the command like this: npm run build-banks-logos -- -w 1000 -h 300
-w | --width
by default600
-h | --height
by default200
-n | --enlargement
is disabled by default
-e | --embed
is disabled by default
-w 200 -h 100
becomes 200×50. However, if you pass this option, the picture will become 200×100, and the empty space will be taken by a transparent area.All the information above also applies to brand logos. The command:
npm run build-brands-logos
. Source folder: src/brands-logos
. The destination folder is dist/brands-logos
. The default height is 60 pixels, and the width is not specified.Performance
The code is checked and works in all browsers, including Internet Explorer 6. To run the tests, run the commandnpm test
or open the file test/browser/main.html
in the browser.Thanks
Thanks to BIN Codes for the current database of prefixes for all banks.Thanks to Stuart Colville for brand logos.
Thanks to Evgeny Katyshev for the logo of the MIR payment system.