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 <joshua.hunt@vista.co>
This commit is contained in:
Josh Hunt 2020-04-08 10:21:22 +12:00 committed by GitHub
parent d8a951cec2
commit 0f5893da65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 137 additions and 0 deletions

12
types/text-mask-addons/index.d.ts vendored Normal file
View File

@ -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 <https://github.com/huntjosh>
// 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;

View File

@ -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);
}

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

29
types/text-mask-core/index.d.ts vendored Normal file
View File

@ -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 <https://github.com/huntjosh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export type Mask = Array<string | RegExp>;
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;

View File

@ -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);
}

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }