braintree / credit-card-type

A library for determining credit card type
MIT License
980 stars 154 forks source link

Resolve wrong credit card #79

Closed Ridermansb closed 6 years ago

Ridermansb commented 6 years ago

General information

Issue description

I added custom brand... (Hipercard) but is resolving any random data as Hipercard...

const creditCardType = require("credit-card-type");

creditCardType.addCard({
  niceType: "Hipercard",
  type: "hipercard",
  // exactPattern: /^(606282\d{10}(\d{3})?)|(3841(0|4|6)0\d{13})$/,
  exactPattern: /^(606282\d{10}(\d{3})?)|(3841\d{15})$/,
  prefixPattern: / /,
  gaps: [4, 8, 12],
  lengths: [16, 19],
  code: { name: "CVC", size: 3 }
});

const [cardDetected] = creditCardType("lorem ip");
const brand = cardDetected ? cardDetected.type : undefined;

console.log(brand); // hipercard .... why ???
quinnjn commented 6 years ago

You have an empty prefixPattern in the snippet. When I added one lorem ip was no longer detected as hipercard.

const creditCardType = require("credit-card-type");

creditCardType.addCard({
  niceType: "Hipercard",
  type: "hipercard",
  exactPattern: /^(606282\d{10}(\d{3})?)|(3841\d{15})$/,
  prefixPattern: /^(6|3)/,
  gaps: [4, 8, 12],
  lengths: [16, 19],
  code: { name: "CVC", size: 3 }
});

const [cardDetected] = creditCardType("lorem ip");
console.log(cardDetected); // undefined