mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
parent
130f8c921f
commit
aee5331d05
87
payment/index.d.ts
vendored
Normal file
87
payment/index.d.ts
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
// 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;
|
||||
/**
|
||||
* 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;
|
||||
16
payment/payment-tests.ts
Normal file
16
payment/payment-tests.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import * as Payment from "payment";
|
||||
|
||||
var input = document.getElementById('input') as HTMLInputElement;
|
||||
|
||||
Payment.restrictNumeric(input);
|
||||
Payment.formatCardNumber(input);
|
||||
Payment.formatCardExpiry(input);
|
||||
Payment.formatCardCVC(input);
|
||||
|
||||
var card = "1234 5678 9012 3456";
|
||||
|
||||
var cardType = Payment.fns.cardType(card);
|
||||
Payment.fns.validateCardNumber(card);
|
||||
Payment.fns.validateCardExpiry("1 / 20");
|
||||
Payment.fns.validateCardExpiry("1", "20");
|
||||
Payment.fns.validateCardCVC("123", cardType);
|
||||
20
payment/tsconfig.json
Normal file
20
payment/tsconfig.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"payment-tests.ts"
|
||||
]
|
||||
}
|
||||
1
payment/tslint.json
Normal file
1
payment/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Loading…
Reference in New Issue
Block a user