braintree / credit-card-type

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

Allow numbers to be passed in #36

Closed andynoelker closed 7 years ago

andynoelker commented 7 years ago

This library requires that a string be passed in as input. I see no reason why this shouldn't be allowed:

var visaCards = creditCardType(4111);
console.log(visaCards[0].type);  // 'visa'

This would be helpful in instances where this library is used internally within app logic and not receiving direct user input.

I'm happy to submit a PR to add this in. As I see the project uses string properties such as length, my PR would essentially cast a numerical input to a string first.

EvanHahn commented 7 years ago

This is something we considered when building the library, but decided against it for two reasons.

We don't want to allow numbers to be passed in because credit card numbers can, in theory, start with 0. We also have to convert everything to a string anyway because we need to match things against regular expressions.

andynoelker commented 7 years ago

@EvanHahn Fair enough. It looked to me like the library simply returns an empty array for anything that is not a string rather than convert like you just mentioned. Maybe throwing some kind of descriptive warning would be good? Probably not too big of a deal.