mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-04 19:42:46 +08:00
Merge pull request #19731 from ChanceM/feature/card-validator
Add card-validator definitions
This commit is contained in:
35
types/card-validator/card-validator-tests.ts
Normal file
35
types/card-validator/card-validator-tests.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import valid = require('card-validator');
|
||||
|
||||
const numberValidation = valid.number('4111');
|
||||
|
||||
if (!numberValidation.isPotentiallyValid && numberValidation.card) {
|
||||
numberValidation.card.type;
|
||||
}
|
||||
|
||||
valid.expirationDate('10/19');
|
||||
const dateTest2 = valid.expirationDate({month: '1', year: '2019'});
|
||||
if (dateTest2.isPotentiallyValid) {
|
||||
dateTest2.month;
|
||||
}
|
||||
|
||||
const expirationMonthCheck = valid.expirationMonth('10');
|
||||
if (expirationMonthCheck.isPotentiallyValid) {
|
||||
expirationMonthCheck.isValidForThisYear;
|
||||
}
|
||||
|
||||
const expirationYearCheck = valid.expirationYear('10');
|
||||
if (expirationYearCheck.isPotentiallyValid) {
|
||||
expirationYearCheck.isCurrentYear;
|
||||
}
|
||||
|
||||
let postalCodeCheck = valid.postalCode('123');
|
||||
|
||||
if (postalCodeCheck.isValid) {
|
||||
postalCodeCheck = valid.postalCode('123', {});
|
||||
postalCodeCheck = valid.postalCode('123', {minLength: 5});
|
||||
}
|
||||
|
||||
const cvvCeck = valid.cvv('1234');
|
||||
if (cvvCeck.isValid) {
|
||||
valid.cvv('12345', 4);
|
||||
}
|
||||
43
types/card-validator/index.d.ts
vendored
Normal file
43
types/card-validator/index.d.ts
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
// Type definitions for card-validator 4.1
|
||||
// Project: https://github.com/braintree/card-validator
|
||||
// Definitions by: Gregory Moore <https://github.com/ChanceM>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export interface Card {
|
||||
niceType: string;
|
||||
type: string;
|
||||
pattern: string;
|
||||
isAmex: boolean;
|
||||
gaps: number[];
|
||||
lengths: number[];
|
||||
code: {name: string, size: number};
|
||||
}
|
||||
|
||||
export interface valid {
|
||||
isPotentiallyValid: boolean;
|
||||
isValid: boolean;
|
||||
}
|
||||
|
||||
export interface validNumber extends valid {
|
||||
card: Card | null;
|
||||
}
|
||||
|
||||
export interface validExpirationDate extends valid {
|
||||
month: string | null;
|
||||
year: string | null;
|
||||
}
|
||||
|
||||
export interface validExpirationMonth extends valid {
|
||||
isValidForThisYear: boolean;
|
||||
}
|
||||
|
||||
export interface validExpirationYear extends valid {
|
||||
isCurrentYear: boolean;
|
||||
}
|
||||
|
||||
export function number(value: string): validNumber;
|
||||
export function expirationDate(value: string | {month: string, year: string}): validExpirationDate;
|
||||
export function expirationMonth(value: string): validExpirationMonth;
|
||||
export function expirationYear(value: string): validExpirationYear;
|
||||
export function cvv(value: string, maxLength?: number): valid;
|
||||
export function postalCode(value: string, options?: {minLength?: number}): valid;
|
||||
22
types/card-validator/tsconfig.json
Normal file
22
types/card-validator/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"card-validator-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/card-validator/tslint.json
Normal file
1
types/card-validator/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user