-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
98 lines (78 loc) · 2.69 KB
/
index.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
94
95
96
97
98
import BaseFormat from "./src/main";
class Format extends BaseFormat {
cpf(value: string): string {
return this.format(value, '###.###.###-##', {
onlyNumbers: true,
});
}
secretCpf(value: string): string {
return this.secretFor(value, {start: 3, end: 2, isVisible: false});
}
cnpj(value: string): string {
return this.format(value, '##.###.###/####-##', {
onlyNumbers: true,
});
}
secretCnpj(value: string): string {
return this.secretFor(value, {start: 4, end: 3});
}
phone(value: string): string {
const pattern = value.length === 11 ? '(##) # ####-####' : '(##) ####-####';
return this.format(value, pattern, {
onlyNumbers: true,
});
}
secretPhone(value: string): string {
return this.secretFor(value, {start: 0, end: 4});
}
cep(value: string): string {
return this.format(value, '#####-###', {
onlyNumbers: true,
});
}
secretCep(value: string): string {
return this.secretFor(value, {start: 0, end: 3});
}
realCurrency(value: string): string {
this.setOriginalValueBucket(value);
return Intl.NumberFormat(this.locale, {
style: 'currency',
currency: 'BRL'
}).format(Number(this.numeric(value)) / 100).replace(/\u00a0/g, ' ');
}
secretRealCurrency(value: string): string {
return this.secretFrom(value, {start: 1, escapeStart: 2, end: 3, isVisible: true})
}
percent(value: string): string {
this.setOriginalValueBucket(value);
value = this.numeric(value);
return Intl.NumberFormat(this.locale, {
style: 'percent',
minimumFractionDigits: 2
}).format((Number(value) / 10000));
}
secretPercent(value: string): string {
return this.secretFrom(value, {start: 0, end: 3, escapeEnd: 1});
}
cardNumber(value: string): string {
return this.format(value, '#### #### #### ####', {
onlyNumbers: true,
});
}
secretCardNumber(value: string): string {
return this.secretFor(value, {start: 0, end: 4});
}
secretEmail(value: string): string {
return this.special(value, {start: [2, 1], end: 0, specialCharacter: ['@', '.']});
}
oab(value: string): string {
return this.format(value, '###.###', {
uppercase: true,
});
}
secretOab(value: string): string {
return this.secretFor(value, {start: 2, end: 1});
}
}
export default Format;
export const format = new Format();