From 0f5893da65a0533984560c7f37000b79ff667256 Mon Sep 17 00:00:00 2001 From: Josh Hunt <30400858+huntjosh@users.noreply.github.com> Date: Wed, 8 Apr 2020 10:21:22 +1200 Subject: [PATCH] Add types for text-mask-core and text-mask-addons (#43715) * Add text-mask-addons and text-mask-core types * Add Fix linting issues * Reconcile tsconfigs * Lint fixes Co-authored-by: josh --- types/text-mask-addons/index.d.ts | 12 ++++++ .../text-mask-addons-tests.ts | 9 +++++ types/text-mask-addons/tsconfig.json | 24 ++++++++++++ types/text-mask-addons/tslint.json | 1 + types/text-mask-core/index.d.ts | 29 +++++++++++++++ types/text-mask-core/text-mask-core-tests.ts | 37 +++++++++++++++++++ types/text-mask-core/tsconfig.json | 24 ++++++++++++ types/text-mask-core/tslint.json | 1 + 8 files changed, 137 insertions(+) create mode 100644 types/text-mask-addons/index.d.ts create mode 100644 types/text-mask-addons/text-mask-addons-tests.ts create mode 100644 types/text-mask-addons/tsconfig.json create mode 100644 types/text-mask-addons/tslint.json create mode 100644 types/text-mask-core/index.d.ts create mode 100644 types/text-mask-core/text-mask-core-tests.ts create mode 100644 types/text-mask-core/tsconfig.json create mode 100644 types/text-mask-core/tslint.json diff --git a/types/text-mask-addons/index.d.ts b/types/text-mask-addons/index.d.ts new file mode 100644 index 0000000000..7e9d0c8649 --- /dev/null +++ b/types/text-mask-addons/index.d.ts @@ -0,0 +1,12 @@ +// Type definitions for text-mask-addons 3.8 +// Project: https://github.com/text-mask/text-mask/tree/master/addons/#readme +// Definitions by: josh +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Pipe } from 'text-mask-core'; + +export interface DatePipeYears { + minYear: number; + maxYear: number; +} +export function createAutoCorrectedDatePipe(dateFormat?: string, validYears?: DatePipeYears): Pipe; diff --git a/types/text-mask-addons/text-mask-addons-tests.ts b/types/text-mask-addons/text-mask-addons-tests.ts new file mode 100644 index 0000000000..a7835de604 --- /dev/null +++ b/types/text-mask-addons/text-mask-addons-tests.ts @@ -0,0 +1,9 @@ +import { DatePipeYears, createAutoCorrectedDatePipe } from 'text-mask-addons'; + +function test() { + const datePipeYears: DatePipeYears = { minYear: 1, maxYear: 1 }; + createAutoCorrectedDatePipe(); + createAutoCorrectedDatePipe('dd-mm-yyy'); + createAutoCorrectedDatePipe('dd-mm-yyy', undefined); + createAutoCorrectedDatePipe('dd-mm-yyy', datePipeYears); +} diff --git a/types/text-mask-addons/tsconfig.json b/types/text-mask-addons/tsconfig.json new file mode 100644 index 0000000000..da4b3e36c3 --- /dev/null +++ b/types/text-mask-addons/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "text-mask-addons-tests.ts" + ] +} diff --git a/types/text-mask-addons/tslint.json b/types/text-mask-addons/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/text-mask-addons/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/text-mask-core/index.d.ts b/types/text-mask-core/index.d.ts new file mode 100644 index 0000000000..d255ca6f07 --- /dev/null +++ b/types/text-mask-core/index.d.ts @@ -0,0 +1,29 @@ +// Type definitions for text-mask-core 5.1 +// Project: https://github.com/text-mask/text-mask/core/#readme +// Definitions by: josh +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export type Mask = Array; + +export interface PipeAddResult { + value: string; + indexesOfPipedChars: number[]; +} +export type PipeResult = PipeAddResult | string | false; +export type Pipe = (conformedValue: string, config: any) => PipeResult; + +export interface CreateTextMaskConfig { + inputElement: HTMLInputElement; + mask: Mask; + guide?: string; + pipe?: Pipe; + placeholderChar?: string; + keepCharPositions?: boolean; + showMask?: boolean; +} + +export interface TextMaskInputElement { + update: (rawValue?: string) => void; +} + +export function createTextMaskInputElement(config: CreateTextMaskConfig): TextMaskInputElement; diff --git a/types/text-mask-core/text-mask-core-tests.ts b/types/text-mask-core/text-mask-core-tests.ts new file mode 100644 index 0000000000..de3320fdd1 --- /dev/null +++ b/types/text-mask-core/text-mask-core-tests.ts @@ -0,0 +1,37 @@ +import { + Mask, + PipeAddResult, + PipeResult, + Pipe, + CreateTextMaskConfig, + TextMaskInputElement, + createTextMaskInputElement, +} from 'text-mask-core'; + +function test() { + const mask: Mask = ['a']; + + const pipeAddResult: PipeAddResult = { value: 'abc', indexesOfPipedChars: [1] }; + + let pipeResult: PipeResult = pipeAddResult; + pipeResult = false; + pipeResult = 'abc'; + + const pipeFunc: Pipe = (value: string, config: any): PipeResult => { + return pipeAddResult; + }; + + const createTextMaskConfig: CreateTextMaskConfig = { + inputElement: {} as any, + mask, + guide: 'a', + keepCharPositions: true, + showMask: true, + }; + + const textMaskInputElement: TextMaskInputElement = { + update: (a?: string): void => {}, + }; + + createTextMaskInputElement(createTextMaskConfig); +} diff --git a/types/text-mask-core/tsconfig.json b/types/text-mask-core/tsconfig.json new file mode 100644 index 0000000000..3493cc81db --- /dev/null +++ b/types/text-mask-core/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "text-mask-core-tests.ts" + ] +} diff --git a/types/text-mask-core/tslint.json b/types/text-mask-core/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/text-mask-core/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }