creditcard/identifier

Credit Card BIN validation using bin-cc data

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 1

Forks: 18

Open Issues: 0

Language:JavaScript

pkg:composer/creditcard/identifier

dev-master 2026-01-15 00:52 UTC

This package is auto-updated.

Last update: 2026-01-15 00:52:37 UTC


README

This is a data file project similar to tzdata, providing credit card BIN (Bank Identification Number) patterns as a source of truth for other libraries.

This repository contains authoritative data about credit card BIN patterns for validation and brand identification, along with reference implementations in multiple programming languages.

The original idea came from this gist by Erik Henrique.

After a JavaScript-only creditcard version, I found myself looking for this in other languages. With a bit of vibe coding style, I created libs for all languages I need (come contribute with more!). The idea is to generate from a source of truth in JSON to language-specific native code, avoiding the overhead of loading JSON files at runtime.

๐Ÿ“ Project Structure

bin-cc/
โ”œโ”€โ”€ data/                    # Credit card BIN data
โ”‚   โ”œโ”€โ”€ sources/            # Source data files (editable)
โ”‚   โ”‚   โ”œโ”€โ”€ visa/          # Subfolder for complex brands
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ base.json
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ bins-*.json
โ”‚   โ”‚   โ”œโ”€โ”€ mastercard.json
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ compiled/           # Compiled output formats
โ”‚   โ”‚   โ”œโ”€โ”€ cards.json      # Simplified regex format
โ”‚   โ”‚   โ””โ”€โ”€ cards-detailed.json  # Full detailed format
โ”‚   โ”œโ”€โ”€ SCHEMA.md           # Data schema documentation
โ”‚   โ””โ”€โ”€ README.md           # Data usage guide
โ”‚
โ”œโ”€โ”€ scripts/                # Build and validation tools
โ”‚   โ”œโ”€โ”€ build.js           # Compiles source โ†’ compiled data
โ”‚   โ”œโ”€โ”€ validate.js        # Standalone validation CLI
โ”‚   โ”œโ”€โ”€ create-card.js     # Interactive card creation CLI
โ”‚   โ””โ”€โ”€ lib/               # Shared modules
โ”‚
โ”œโ”€โ”€ libs/                   # Reference implementations
โ”‚   โ”œโ”€โ”€ javascript/        # Each lib includes example.{ext}
โ”‚   โ”œโ”€โ”€ python/
โ”‚   โ”œโ”€โ”€ ruby/
โ”‚   โ”œโ”€โ”€ elixir/
โ”‚   โ”œโ”€โ”€ dotnet/
โ”‚   โ”œโ”€โ”€ java/
โ”‚   โ”œโ”€โ”€ rust/
โ”‚   โ”œโ”€โ”€ go/
โ”‚   โ””โ”€โ”€ php/
โ”‚
โ”œโ”€โ”€ CONTRIBUTING.md         # Contribution guidelines
โ”œโ”€โ”€ LICENSE                 # MIT License
โ””โ”€โ”€ package.json            # Build scripts

๐ŸŽฏ Data Source

The authoritative data follows a build system similar to browserslist:

Building the Data

npm run build

This compiles source files into both detailed and simplified formats with validation.

Validating Data

# Validate all sources
node scripts/validate.js

# Validate specific file or directory
node scripts/validate.js data/sources/visa
node scripts/validate.js data/sources/amex.json

Creating New Card Schemes

node scripts/create-card.js

Interactive CLI to create new card scheme source files.

๐Ÿ“š Library Implementations

All libraries provide the same core functionality for credit card BIN validation and brand identification.

JavaScript/Node.js

Complete implementation in libs/javascript/

npm install creditcard-identifier
const cc = require('creditcard-identifier');
console.log(cc.findBrand('4012001037141112')); // 'visa'

Python

Complete implementation in libs/python/

pip install creditcard-identifier
from creditcard_identifier import find_brand
print(find_brand('4012001037141112'))  # 'visa'

Ruby

Complete implementation in libs/ruby/

gem install creditcard-identifier
require 'creditcard_identifier'
puts CreditcardIdentifier.find_brand('4012001037141112')  # 'visa'

Elixir

Complete implementation in libs/elixir/

# mix.exs
{:creditcard_identifier, "~> 1.0"}

# usage
CreditcardIdentifier.find_brand("4012001037141112")  # "visa"

.NET/C#

Complete implementation in libs/dotnet/

dotnet add package CreditCardIdentifier
using CreditCardIdentifier;
CreditCard.FindBrand("4012001037141112");  // "visa"

Java

Complete implementation in libs/java/

<!-- Maven -->
<dependency>
    <groupId>br.com.s2n.creditcard</groupId>
    <artifactId>creditcard-identifier</artifactId>
    <version>2.1.0</version>
</dependency>
import br.com.s2n.creditcard.identifier.CreditCardValidator;

CreditCardValidator validator = new CreditCardValidator();
validator.findBrand("4012001037141112");  // "visa"

Rust

Complete implementation in libs/rust/

# Cargo.toml
[dependencies]
creditcard-identifier = "2.1.0"
use creditcard_identifier::*;
find_brand("4012001037141112");  // Some("visa")

Go

Complete implementation in libs/go/

go get github.com/renatovico/bin-cc/libs/go
import creditcard "github.com/renatovico/bin-cc/libs/go"

brand := creditcard.FindBrand("4012001037141112")  // "visa"

PHP

Complete implementation in libs/php/

composer require creditcard/identifier
use CreditCard\Identifier\CreditCardValidator;

$validator = new CreditCardValidator();
$validator->findBrand('4012001037141112');  // "visa"

๐ŸŽด Supported Card Brands

See data/compiled/BRANDS.md for the auto-generated list of supported card brands.

๐Ÿค Contributing

Contributions are welcome! This project follows a source โ†’ build โ†’ compiled workflow:

  1. Data updates: Edit source files in data/sources/
  2. Build: Run npm run build to compile and validate
  3. Test: Ensure npm test passes
  4. Document: Cite sources in your PR description

See CONTRIBUTING.md for detailed guidelines.

Quick Start for Contributors

# Create a new card scheme interactively
node scripts/create-card.js

# Or edit a source file manually
vim data/sources/visa/base.json

# Build and validate
npm run build

# Test
npm test

# Commit changes (both source and generated files)
git add data/
git commit -m "Update Visa BIN patterns"

๐Ÿ“ฆ Publishing Libraries

All libraries are published to their respective package registries for easy installation:

Language Registry Installation Command
JavaScript npm npm install creditcard-identifier
Python PyPI pip install creditcard-identifier
Ruby RubyGems gem install creditcard-identifier
Elixir Hex.pm {:creditcard_identifier, "~> 2.1"}
.NET/C# NuGet dotnet add package CreditCardIdentifier
Java Maven Central See libs/java
Rust crates.io cargo add creditcard-identifier
Go pkg.go.dev go get github.com/renatovico/bin-cc/libs/go
PHP Packagist composer require creditcard/identifier

For Library Maintainers

To publish new versions of the libraries, see the RELEASE.md guide. Each library also has its own PUBLISH.md file with detailed instructions:

All new libraries support automated publishing via GitHub Actions when you create a release with the appropriate tag format (e.g., java-v2.1.0).

๐Ÿ“ License

MIT License