mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add types for vanilla-masker (#36126)
This commit is contained in:
parent
8bc13c7029
commit
4d7cd124b6
50
types/vanilla-masker/index.d.ts
vendored
Normal file
50
types/vanilla-masker/index.d.ts
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
// Type definitions for vanilla-masker 1.2
|
||||
// Project: https://fleury.io/vanilla-masker/
|
||||
// Definitions by: BenLorantfy <https://github.com/BenLorantfy>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
interface MoneyOptions {
|
||||
// Decimal precision -> "90"
|
||||
precision?: number;
|
||||
|
||||
// Decimal separator -> ",90"
|
||||
separator?: string;
|
||||
|
||||
// Number delimiter -> "12.345.678"
|
||||
delimiter?: string;
|
||||
|
||||
// Money unit -> "R$ 12.345.678,90"
|
||||
unit?: string;
|
||||
|
||||
// Money unit -> "12.345.678,90 R$"
|
||||
suffixUnit?: string;
|
||||
|
||||
// Force type only number instead decimal,
|
||||
// masking decimals with ",00"
|
||||
// Zero cents -> "R$ 1.234.567.890,00"
|
||||
zeroCents?: boolean;
|
||||
}
|
||||
|
||||
interface PatternOptions {
|
||||
// Pattern to mask value against.
|
||||
pattern?: string;
|
||||
|
||||
// Placeholder option to represent remaining characters to be entered
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
declare const VMasker: {
|
||||
(el: Element|NodeListOf<Element>): {
|
||||
maskMoney: (options?: MoneyOptions) => void;
|
||||
maskNumber: () => void;
|
||||
maskAlphaNum: () => void;
|
||||
maskPattern: (pattern: string) => void;
|
||||
unMask: () => void;
|
||||
}
|
||||
toMoney: (value: string|number, options?: MoneyOptions) => string;
|
||||
toPattern: (value: string|number, options?: string|PatternOptions) => string;
|
||||
toNumber: (value: string|number) => string;
|
||||
toAlphaNumeric: (value: string|number) => string;
|
||||
};
|
||||
|
||||
export = VMasker;
|
||||
24
types/vanilla-masker/tsconfig.json
Normal file
24
types/vanilla-masker/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",
|
||||
"vanilla-masker-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/vanilla-masker/tslint.json
Normal file
1
types/vanilla-masker/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
52
types/vanilla-masker/vanilla-masker-tests.ts
Normal file
52
types/vanilla-masker/vanilla-masker-tests.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import * as VMasker from "vanilla-masker";
|
||||
|
||||
// Masking input element to money.
|
||||
const el = document.querySelector("data-js-input") as Element;
|
||||
const els = document.querySelectorAll("data-js-input");
|
||||
|
||||
VMasker(el).maskMoney();
|
||||
VMasker(el).maskMoney({});
|
||||
|
||||
// Masking input element to money with options.
|
||||
VMasker(el).maskMoney({
|
||||
// Decimal precision -> "90"
|
||||
precision: 2,
|
||||
// Decimal separator -> ",90"
|
||||
separator: ',',
|
||||
// Number delimiter -> "12.345.678"
|
||||
delimiter: '.',
|
||||
// Money unit -> "R$ 12.345.678,90"
|
||||
unit: 'R$',
|
||||
// Money unit -> "12.345.678,90 R$"
|
||||
suffixUnit: 'R$',
|
||||
// Force type only number instead decimal,
|
||||
// masking decimals with ",00"
|
||||
// Zero cents -> "R$ 1.234.567.890,00"
|
||||
zeroCents: true
|
||||
});
|
||||
|
||||
// Masking an array of input elements to money.
|
||||
VMasker(els).maskMoney();
|
||||
|
||||
// Converts number to money string
|
||||
VMasker.toMoney(1234); // -> R$ 1.234,00
|
||||
|
||||
// Masking input element to number.
|
||||
VMasker(el).maskNumber();
|
||||
|
||||
// Converts any string to number
|
||||
VMasker.toNumber("123ac34"); // -> 12334
|
||||
VMasker.toNumber("-123ac34"); // -> -12334
|
||||
VMasker.toAlphaNumeric("-123ac34");
|
||||
|
||||
// Listen the input element masking it to format with pattern.
|
||||
VMasker(el).maskPattern("(99) 9999-9999");
|
||||
|
||||
// Converts value to masked phone
|
||||
VMasker.toPattern(1099911111, "(99) 9999-9999"); // -> (10) 9991-1111
|
||||
|
||||
// Pass in an optional placeholder option to represent remaining characters to be entered
|
||||
VMasker.toPattern('4', {pattern: "(999) 999-9999", placeholder: "x"}); // -> (4xx) xxx-xxxx
|
||||
|
||||
// unmask!
|
||||
VMasker(el).unMask();
|
||||
Loading…
Reference in New Issue
Block a user