mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
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:
parent
d8a951cec2
commit
0f5893da65
12
types/text-mask-addons/index.d.ts
vendored
Normal file
12
types/text-mask-addons/index.d.ts
vendored
Normal 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;
|
||||
9
types/text-mask-addons/text-mask-addons-tests.ts
Normal file
9
types/text-mask-addons/text-mask-addons-tests.ts
Normal 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);
|
||||
}
|
||||
24
types/text-mask-addons/tsconfig.json
Normal file
24
types/text-mask-addons/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/text-mask-addons/tslint.json
Normal file
1
types/text-mask-addons/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
29
types/text-mask-core/index.d.ts
vendored
Normal file
29
types/text-mask-core/index.d.ts
vendored
Normal 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;
|
||||
37
types/text-mask-core/text-mask-core-tests.ts
Normal file
37
types/text-mask-core/text-mask-core-tests.ts
Normal 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);
|
||||
}
|
||||
24
types/text-mask-core/tsconfig.json
Normal file
24
types/text-mask-core/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/text-mask-core/tslint.json
Normal file
1
types/text-mask-core/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user