@sankhyalabs/core 7.0.5 → 7.0.6
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 +354 -354
- 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
|
"cep": "##.###-###",
|
|
@@ -123,7 +125,7 @@ export class MaskFormatter {
|
|
|
123
125
|
if (value === expectedFormattedValue) {
|
|
124
126
|
return value;
|
|
125
127
|
}
|
|
126
|
-
const maskPlaceholders = this.mask.match(/[
|
|
128
|
+
const maskPlaceholders = this.mask.match(/[UAZL#?*']/g) || [];
|
|
127
129
|
const placeholderCount = maskPlaceholders.length;
|
|
128
130
|
|
|
129
131
|
const validValue = value.split('').filter((char, index) => {
|
|
@@ -139,6 +141,8 @@ export class MaskFormatter {
|
|
|
139
141
|
return /[a-zA-Z]/.test(char);
|
|
140
142
|
case MaskFormatter.ALPHA_NUMERIC_KEY:
|
|
141
143
|
return /[a-zA-Z0-9]/.test(char);
|
|
144
|
+
case MaskFormatter.ALPHA_NUMERIC_UPPERCASE_KEY:
|
|
145
|
+
return /[A-Z0-9]/.test(char);
|
|
142
146
|
case MaskFormatter.CHARACTER_KEY:
|
|
143
147
|
return /[a-zA-Z]/.test(char);
|
|
144
148
|
case MaskFormatter.ANYTHING_KEY:
|
|
@@ -236,6 +240,9 @@ export class MaskFormatter {
|
|
|
236
240
|
case MaskFormatter.ALPHA_NUMERIC_KEY:
|
|
237
241
|
this._maskChars.push(new MaskFormatter.AlphaNumericCharacter(this, maskChar));
|
|
238
242
|
break;
|
|
243
|
+
case MaskFormatter.ALPHA_NUMERIC_UPPERCASE_KEY:
|
|
244
|
+
this._maskChars.push(new MaskFormatter.AlphaNumericUpperCaseCharacter(this, maskChar));
|
|
245
|
+
break;
|
|
239
246
|
case MaskFormatter.CHARACTER_KEY:
|
|
240
247
|
this._maskChars.push(new MaskFormatter.CharCharacter(this, maskChar));
|
|
241
248
|
break;
|
|
@@ -360,6 +367,7 @@ export class MaskFormatter {
|
|
|
360
367
|
message = 'um número';
|
|
361
368
|
break;
|
|
362
369
|
case MaskFormatter.ALPHA_NUMERIC_KEY:
|
|
370
|
+
case MaskFormatter.ALPHA_NUMERIC_UPPERCASE_KEY:
|
|
363
371
|
message = 'uma letra ou um número';
|
|
364
372
|
break;
|
|
365
373
|
default:
|
|
@@ -477,6 +485,24 @@ export class MaskFormatter {
|
|
|
477
485
|
}
|
|
478
486
|
}
|
|
479
487
|
|
|
488
|
+
private static AlphaNumericUpperCaseCharacter = class extends MaskFormatter.MaskCharacter {
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Valida se a string é uma letra do alfabeto (A-Z) ou um numero entre zero e nove.
|
|
492
|
+
*
|
|
493
|
+
* @param aChar - String passada para validação.
|
|
494
|
+
* @returns - Verdadeiro se a string passada for uma letra do alfabeto ou um numeral (de 0 a 9).
|
|
495
|
+
*/
|
|
496
|
+
public isValidCharacter(aChar: string): boolean {
|
|
497
|
+
//FIXME: talvez seja problema usar regex aqui... avaliar se existe forma mais barata.
|
|
498
|
+
return (/[a-zA-Z0-9]/.test(aChar)) && super.isValidCharacter(aChar);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
public getChar(aChar: string): string {
|
|
502
|
+
return aChar.toLocaleUpperCase();
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
480
506
|
private static CharCharacter = class extends MaskFormatter.MaskCharacter {
|
|
481
507
|
/**
|
|
482
508
|
* Valida se a string é uma letra do alfabeto (a-z).
|