braintree / credit-card-type

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

add getCreditCardType function to use in RequireJS #85

Closed wuestkamp closed 5 years ago

wuestkamp commented 5 years ago

Hey!

I know this has already been discussed in other tickets, but what speaks against adding this method:

creditCardType.getCreditCardType = function (cardNumber) {
    return clone(creditCardType(cardNumber));
};

So that its possible to access this when (for example) loaded via RequireJS? Then I can do this in RequireJS:

requirejs.config({
    paths: {
        creditcardtype: '../vendor/credit-card-type/dist/js/app.built'
    }
}
define(['jquery', 'creditcardtype'], function ($, CreditCardType) {
    var cardType = CreditCardType.getCreditCardType('4111');
}

Where credi

Thanks a lot! Kim

crookedneighbor commented 5 years ago

I don't think I understand what you need. Why can't you call CreditCardType() directly?

wuestkamp commented 5 years ago

Well, this one doesn't seem to be accessible:

console.log(CreditCardType.CreditCardType('4111')); console: Uncaught TypeError: CreditCardType.CreditCardType is not a function

console.log(CreditCardType.creditCardType('4111')); console: Uncaught TypeError: CreditCardType.creditCardType is not a function

Just those methods defined using creditCardType.X are available.

Thanks! Kim

jackellenberger commented 5 years ago

When credit-card-type is loaded, the api should just be

> var creditCardType = require('credit-card-type');
> creditCardType('4111');
[ { niceType: 'Visa',
    type: 'visa',
    patterns: [ 4 ],
    gaps: [ 4, 8, 12 ],
    lengths: [ 16, 18, 19 ],
    code: { name: 'CVV', size: 3 },
    matchStrength: 1 } ]

There's no need to index into the module to find a method named "creditCardType".

If you are still having trouble, could you post a command line example of what you're trying to do with requirejs?