diff --git a/types/card-validator/card-validator-tests.ts b/types/card-validator/card-validator-tests.ts new file mode 100644 index 0000000000..1b83ee8ecf --- /dev/null +++ b/types/card-validator/card-validator-tests.ts @@ -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); +} diff --git a/types/card-validator/index.d.ts b/types/card-validator/index.d.ts new file mode 100644 index 0000000000..9bafec3510 --- /dev/null +++ b/types/card-validator/index.d.ts @@ -0,0 +1,43 @@ +// Type definitions for card-validator 4.1 +// Project: https://github.com/braintree/card-validator +// Definitions by: Gregory Moore +// 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; diff --git a/types/card-validator/tsconfig.json b/types/card-validator/tsconfig.json new file mode 100644 index 0000000000..a3e4d160e5 --- /dev/null +++ b/types/card-validator/tsconfig.json @@ -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" + ] +} diff --git a/types/card-validator/tslint.json b/types/card-validator/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/card-validator/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }