Gathering detailed insights and metrics for creditcards-types
Gathering detailed insights and metrics for creditcards-types
Gathering detailed insights and metrics for creditcards-types
Gathering detailed insights and metrics for creditcards-types
npm install creditcards-types
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (95.87%)
TypeScript (4.13%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
72 Stars
143 Commits
20 Forks
3 Watchers
6 Branches
12 Contributors
Updated on May 28, 2025
Latest Version
4.0.0
Package Id
creditcards-types@4.0.0
Unpacked Size
26.43 kB
Size
9.22 kB
File Count
63
NPM Version
10.2.4
Node Version
20.11.1
Published on
May 14, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Card type definitions in JavaScript modules
This library powers creditcards, a higher level tool for parsing/formatting/validating card data. This repository focuses on tests and documentation. Card types are primarily represented by static values and regular expressions.
Visa Electron cards will validate and match as regular Visa cards.
Card data can be required individually by type. The main module includes all defined card types. You may want to select specific cards that your customers will use to save bytes or avoid confusion.
The main types in this library have unique patterns that map to major card networks. In some locales, companies issue co-branded with other card networks within the major partner's BIN range. This library includes these types as modules but does not include co-branded types in the main export. Custom types include:
Similar to using custom types, you can prepend optional types to the main list. Cards that previously matched as a major issuer will instead match the custom type if applicable.
1var types = [ require('creditcards-types/types/mada') ].concat(require('creditcards-types'))
Open an issue or a PR if you'd like to contribute documentation/code for a type that's missing.
Some processors (e.g. Stripe) support fake card numbers used for testing payments. In some cases, these test card numbers do not fall within the actual issuing range. For example, 6011 1111 1111 1117
is provided as a Discover test card, but falls outside of the documented range. If you need to match these cards, you'll need to handle them outside this library or add a custom type.
1npm install --save creditcards-types
1// finding 2var types = require('creditcards-types') 3var type = types.find(type => type.test('4', true)) 4// type.name => Visa 5 6// specific types 7var visa = require('creditcards-types/types/visa') 8visa.test('4242424242424242') // true 9 10// creating custom types 11var Type = require('creditcards-types/type') 12var myCard = Type({ 13 name: 'My Card', 14 pattern: /^999\d{13}$/ 15 eagerPattern: /^999/, 16 luhn: false 17}) 18 19var myTypes = types.concat(myCard) // myCard gets lowest priority
new Type(data)
-> type
Creates a new card type.
1var Type = require('creditcards-types/type') 2var type = Type(data)
Required
Type: object
The type configuration, containing the following properties:
pattern
true
regexp
eagerPattern
true
regexp
groupPattern
regexp
/(\d{1,4})(\d{1,4})?(\d{1,4})?(\d{1,4})?/
cvcLength
number
3
luhn
boolean
true
type.test(number, [eager])
-> boolean
Check whether a card number matches the type.
Required
Type: string
The card number to test.
Type: Boolean
Default: false
When false
, the full card pattern is used. When true
, the eager pattern is tested instead.
1var visa = require('creditcards-types/types/visa') 2 3// Strict type validation 4visa.test('4242424242424242') // => true 5 6// Eager type checking 7visa.test('42', true) // => true
type.group(number)
-> array[string]
Separates the card number into formatting groups.
Required
Type: string
The card number to group. This may be a complete or partial card number. Any digits past the type's maximum length will be discarded.
This repository is designed to support a large volume of automated testing. There are two types of tests.
Traditional regression tests are included in the test/
folder. These tests describe the regular expressions and make assertions about a few possible card patterns. Each type tests checks that expedcted eager matches for that type do not also match another card type. There's also a coverage check that will fail the test run if any type module is missing an identically named test file.
As an additional check, npm test
downloads range data from binlist. The binlist tests:
This data is not guaranteed to be accurate but provides a valuable external check against the validity of the type definitions with far more assertions than could ever be written by hand.
MIT © Ben Drucker
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 5/14 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More