fn
findCardBrand
v0.0.5Detect a payment-card brand from a number's digits by its IIN/BIN
pattern. Returns the brand whose pattern matches the most leading digits (so it
narrows down as the user types), or undefined if none match. Pure.
Example
ts
findCardBrand('4111111111111111')?.brand; // 'visa'
findCardBrand('371449635398431')?.brand; // 'american-express'
findCardBrand('2200123412341234')?.brand; // 'mir'Signature
ts
export function findCardBrand(
digits: string,
brands: readonly CardBrand[] = CARD_BRANDS,
): CardBrand | undefined{ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
digits | string | The card number's digits (no separators) |
brands? | readonly CardBrand[] | The brand list |
Returns
CardBrand | undefinedThe detected brand, or undefined