-
Notifications
You must be signed in to change notification settings - Fork 20
/
getMaskOptions.ts
93 lines (88 loc) · 1.69 KB
/
getMaskOptions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { Mask, Options } from '../types';
export const getMaskOptions = (mask?: Mask, _options?: Options): Options => {
const options: Options = {
jitMasking: false,
..._options,
};
if (!mask) return options;
const masks: Record<string, Inputmask.Options> = {
datetime: {
alias: 'datetime',
...options,
},
email: {
alias: 'email',
placeholder: '',
...options,
},
numeric: {
alias: 'numeric',
placeholder: '',
...options,
},
currency: {
alias: 'currency',
prefix: '$ ',
placeholder: '',
...options,
},
decimal: {
alias: 'decimal',
placeholder: '',
...options,
},
integer: {
alias: 'integer',
placeholder: '',
...options,
},
percentage: {
alias: 'percentage',
placeholder: ' %',
suffix: ' %',
...options,
},
url: {
alias: 'url',
placeholder: 'https://',
...options,
},
ip: {
alias: 'ip',
...options,
},
mac: {
alias: 'mac',
...options,
},
ssn: {
alias: 'ssn',
...options,
},
// alias for brazilians <3
'brl-currency': {
alias: 'currency',
prefix: 'R$ ',
placeholder: '0,00',
displayFormat: 'currency',
radixPoint: ',',
autoUnmask: true,
...options,
},
cpf: {
mask: '999.999.999-99',
placeholder: '___.___.___-__',
...options,
},
cnpj: {
mask: '99.999.999/9999-99',
placeholder: '__.___.___/____-__',
...options,
},
};
if (typeof mask === 'string' && masks[mask]) return masks[mask];
return {
mask,
...options,
};
};