@sankhyalabs/core 7.1.0-dev.7 → 7.1.0-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/classes/MaskFormatter.md +52 -31
- package/.docs/namespaces/MaskFormatter/type-aliases/MaskCharacter.md +1 -1
- package/.docs/namespaces/MaskFormatter/variables/MaskCharacter.md +1 -1
- package/dist/utils/MaskFormatter.d.ts +11 -8
- package/dist/utils/MaskFormatter.js +33 -10
- package/dist/utils/MaskFormatter.js.map +1 -1
- package/package.json +1 -1
- package/reports/test-report.xml +308 -308
- package/src/utils/MaskFormatter.ts +36 -10
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* | U | Qualquer letra. Transforma letras minúsculas em maiúsculas. |
|
|
15
15
|
* | L | Qualquer letra. Transforma letras maiúsculas em minúsculas. |
|
|
16
16
|
* | A | Qualquer letra ou número. |
|
|
17
|
+
* | Z | Qualquer letra ou número. Transforma letras minúsculas em maiúsculas. |
|
|
17
18
|
* | ? | Qualquer letra. Preserva maiúsculas e minúsculas. |
|
|
18
19
|
* | * | Qualquer caractere. |
|
|
19
20
|
*
|
|
@@ -34,14 +35,14 @@
|
|
|
34
35
|
* resultaria na string '123-____'.
|
|
35
36
|
*
|
|
36
37
|
* ##Veja mais alguns exemplos:
|
|
37
|
-
* |Padrão |Máscara |Entrada |Saída
|
|
38
|
-
*
|
|
39
|
-
* |Telefone |(##) ####-#### |3432192515 |(34) 3219-2515
|
|
40
|
-
* |CPF |###.###.###-## |12345678901 |123.456.789-01
|
|
41
|
-
* |CNPJ
|
|
42
|
-
* |CEP |##.###-### |12345678 |12.345-678
|
|
43
|
-
* |PLACA (veículo) |UUU-#### |abc1234 |ABC-1234
|
|
44
|
-
* |Cor RGB |'#AAAAAA
|
|
38
|
+
* |Padrão |Máscara |Entrada |Saída |
|
|
39
|
+
* |----------------|------------------|--------------|-------------------|
|
|
40
|
+
* |Telefone |(##) ####-#### |3432192515 |(34) 3219-2515 |
|
|
41
|
+
* |CPF |###.###.###-## |12345678901 |123.456.789-01 |
|
|
42
|
+
* |CNPJ |ZZ.ZZZ.ZZZ/ZZZZ-##|1a3B5c7D9e1F31|1A.3B5.C7D9/E1F3-31|
|
|
43
|
+
* |CEP |##.###-### |12345678 |12.345-678 |
|
|
44
|
+
* |PLACA (veículo) |UUU-#### |abc1234 |ABC-1234 |
|
|
45
|
+
* |Cor RGB |'#AAAAAA |00000F0 |#0000F0 |
|
|
45
46
|
*
|
|
46
47
|
*/
|
|
47
48
|
export class MaskFormatter {
|
|
@@ -51,11 +52,12 @@ export class MaskFormatter {
|
|
|
51
52
|
private static UPPERCASE_KEY: string = "U";
|
|
52
53
|
private static LOWERCASE_KEY: string = "L";
|
|
53
54
|
private static ALPHA_NUMERIC_KEY: string = "A";
|
|
55
|
+
private static ALPHA_NUMERIC_UPPERCASE_KEY: string = "Z";
|
|
54
56
|
private static CHARACTER_KEY: string = "?";
|
|
55
57
|
private static ANYTHING_KEY: string = "*";
|
|
56
58
|
|
|
57
59
|
public static DEFAULT_MASKS: any = {
|
|
58
|
-
"cnpj": "
|
|
60
|
+
"cnpj": "ZZ.ZZZ.ZZZ/ZZZZ-##",
|
|
59
61
|
"cpf": "###.###.###-##",
|
|
60
62
|
"phone": "(##) ####-####",
|
|
61
63
|
"phone_mobile": "(##) #####-####",
|
|
@@ -124,7 +126,7 @@ export class MaskFormatter {
|
|
|
124
126
|
if (value === expectedFormattedValue) {
|
|
125
127
|
return value;
|
|
126
128
|
}
|
|
127
|
-
const maskPlaceholders = this.mask.match(/[
|
|
129
|
+
const maskPlaceholders = this.mask.match(/[UAZL#?*']/g) || [];
|
|
128
130
|
const placeholderCount = maskPlaceholders.length;
|
|
129
131
|
|
|
130
132
|
const validValue = value.split('').filter((char, index) => {
|
|
@@ -140,6 +142,8 @@ export class MaskFormatter {
|
|
|
140
142
|
return /[a-zA-Z]/.test(char);
|
|
141
143
|
case MaskFormatter.ALPHA_NUMERIC_KEY:
|
|
142
144
|
return /[a-zA-Z0-9]/.test(char);
|
|
145
|
+
case MaskFormatter.ALPHA_NUMERIC_UPPERCASE_KEY:
|
|
146
|
+
return /[A-Z0-9]/.test(char);
|
|
143
147
|
case MaskFormatter.CHARACTER_KEY:
|
|
144
148
|
return /[a-zA-Z]/.test(char);
|
|
145
149
|
case MaskFormatter.ANYTHING_KEY:
|
|
@@ -237,6 +241,9 @@ export class MaskFormatter {
|
|
|
237
241
|
case MaskFormatter.ALPHA_NUMERIC_KEY:
|
|
238
242
|
this._maskChars.push(new MaskFormatter.AlphaNumericCharacter(this, maskChar));
|
|
239
243
|
break;
|
|
244
|
+
case MaskFormatter.ALPHA_NUMERIC_UPPERCASE_KEY:
|
|
245
|
+
this._maskChars.push(new MaskFormatter.AlphaNumericUpperCaseCharacter(this, maskChar));
|
|
246
|
+
break;
|
|
240
247
|
case MaskFormatter.CHARACTER_KEY:
|
|
241
248
|
this._maskChars.push(new MaskFormatter.CharCharacter(this, maskChar));
|
|
242
249
|
break;
|
|
@@ -361,6 +368,7 @@ export class MaskFormatter {
|
|
|
361
368
|
message = 'um número';
|
|
362
369
|
break;
|
|
363
370
|
case MaskFormatter.ALPHA_NUMERIC_KEY:
|
|
371
|
+
case MaskFormatter.ALPHA_NUMERIC_UPPERCASE_KEY:
|
|
364
372
|
message = 'uma letra ou um número';
|
|
365
373
|
break;
|
|
366
374
|
default:
|
|
@@ -478,6 +486,24 @@ export class MaskFormatter {
|
|
|
478
486
|
}
|
|
479
487
|
}
|
|
480
488
|
|
|
489
|
+
private static AlphaNumericUpperCaseCharacter = class extends MaskFormatter.MaskCharacter {
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Valida se a string é uma letra do alfabeto (A-Z) ou um numero entre zero e nove.
|
|
493
|
+
*
|
|
494
|
+
* @param aChar - String passada para validação.
|
|
495
|
+
* @returns - Verdadeiro se a string passada for uma letra do alfabeto ou um numeral (de 0 a 9).
|
|
496
|
+
*/
|
|
497
|
+
public isValidCharacter(aChar: string): boolean {
|
|
498
|
+
//FIXME: talvez seja problema usar regex aqui... avaliar se existe forma mais barata.
|
|
499
|
+
return (/[a-zA-Z0-9]/.test(aChar)) && super.isValidCharacter(aChar);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
public getChar(aChar: string): string {
|
|
503
|
+
return aChar.toLocaleUpperCase();
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
481
507
|
private static CharCharacter = class extends MaskFormatter.MaskCharacter {
|
|
482
508
|
/**
|
|
483
509
|
* Valida se a string é uma letra do alfabeto (a-z).
|