DefinitelyTyped/types/payment/index.d.ts
Florian Barbare b883a3573a @types/payment Add formatCardNumber in the types (#28669)
I wanna use the `formatCardNumber` function standalone but it is not defined in the types yet, so there we go.
2018-09-11 08:27:22 -07:00

92 lines
2.5 KiB
TypeScript

// Type definitions for payment 2.1
// Project: https://github.com/jessepollak/payment#readme
// Definitions by: Alexandre Paré <https://github.com/apare>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface Fns {
/**
* Validates a card number:
* * Validates numbers
* * Validates Luhn algorithm
* * Validates length
*/
validateCardNumber(cardNumber: string): boolean;
/**
* Formats a card number
*/
formatCardNumber(cardNumber: string): string;
/**
* Validates a card expiry:
* * Validates numbers
* * Validates in the future
* * Supports year shorthand
* * Supports formatted as formatCardExpiry input value
*/
validateCardExpiry(monthYear: string, year?: string): boolean;
/**
* Validates a card CVC:
* * Validates number
* * Validates length to 4
*/
validateCardCVC(cvc: string, type?: string): boolean;
/**
* Returns a card type. Either:
* * visa
* * mastercard
* * discover
* * amex
* * jcb
* * dinersclub
* * maestro
* * laser
* * unionpay
* * elo
*
* The function will return null if the card type can't be determined.
*/
cardType(cardNumber: string): string;
/**
* Parses a credit card expiry in the form of MM/YYYY, returning an object containing the `month` and `year`.
* Shorthand years, such as `13` are also supported (and converted into the longhand, e.g. `2013`).
*/
cardExpiryVal(monthYear: string | HTMLInputElement): MonthYear;
}
interface MonthYear {
month: number;
year: number;
}
declare var Payment: {
/**
* Formats card numbers:
* * Includes a space between every 4 digits
* * Restricts input to numbers
* * Limits to 16 numbers
* * Supports American Express formatting
* * Adds a class of the card type (e.g. 'visa') to the input
*/
formatCardNumber(elem: HTMLInputElement): HTMLInputElement;
/**
* Formats card expiry:
* * Includes a / between the month and year
* * Restricts input to numbers
* * Restricts length
*/
formatCardExpiry(elem: HTMLInputElement): HTMLInputElement;
/**
* Formats card CVC:
* * Restricts length to 4 numbers
* * Restricts input to numbers
*/
formatCardCVC(elem: HTMLInputElement): HTMLInputElement;
/**
* General numeric input restriction.
*/
restrictNumeric(elem: HTMLInputElement): HTMLInputElement;
fns: Fns;
};
export = Payment;