validation-br 2.0.0 → 2.2.0

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.
Files changed (104) hide show
  1. package/dist/cjs/base.d.ts +4 -0
  2. package/dist/cjs/boleto.d.ts +6 -0
  3. package/dist/cjs/boleto.js +9 -0
  4. package/dist/cjs/caepf.d.ts +6 -0
  5. package/dist/cjs/caepf.js +8 -0
  6. package/dist/cjs/carplate.d.ts +5 -0
  7. package/dist/cjs/carplate.js +7 -0
  8. package/dist/cjs/cbi_sinter.d.ts +6 -0
  9. package/dist/cjs/cbi_sinter.js +8 -0
  10. package/dist/cjs/cep.d.ts +6 -0
  11. package/dist/cjs/cep.js +8 -0
  12. package/dist/cjs/certidao.d.ts +6 -0
  13. package/dist/cjs/certidao.js +8 -0
  14. package/dist/cjs/cnh.d.ts +6 -0
  15. package/dist/cjs/cnh.js +8 -0
  16. package/dist/cjs/cnpj.d.ts +6 -0
  17. package/dist/cjs/cnpj.js +8 -0
  18. package/dist/cjs/cpf.d.ts +6 -0
  19. package/dist/cjs/cpf.js +8 -0
  20. package/dist/cjs/email.d.ts +13 -4
  21. package/dist/cjs/email.js +76 -10
  22. package/dist/cjs/index.d.ts +2 -1
  23. package/dist/cjs/index.js +2 -3
  24. package/dist/cjs/judicial-process.d.ts +6 -0
  25. package/dist/cjs/judicial-process.js +8 -0
  26. package/dist/cjs/nup17.d.ts +1 -0
  27. package/dist/cjs/nup17.js +6 -0
  28. package/dist/cjs/phone.d.ts +13 -1
  29. package/dist/cjs/phone.js +20 -3
  30. package/dist/cjs/pis-pasep.d.ts +6 -0
  31. package/dist/cjs/pis-pasep.js +8 -0
  32. package/dist/cjs/pix-copy-paste.d.ts +6 -0
  33. package/dist/cjs/pix-copy-paste.js +8 -0
  34. package/dist/cjs/pix-key.d.ts +5 -0
  35. package/dist/cjs/pix-key.js +18 -0
  36. package/dist/cjs/postal-track-code.d.ts +6 -0
  37. package/dist/cjs/postal-track-code.js +8 -0
  38. package/dist/cjs/renavam.d.ts +6 -0
  39. package/dist/cjs/renavam.js +8 -0
  40. package/dist/cjs/standard-schema/create-schema.d.ts +5 -0
  41. package/dist/cjs/standard-schema/create-schema.js +87 -0
  42. package/dist/cjs/standard-schema/index.d.ts +45 -0
  43. package/dist/cjs/standard-schema/index.js +47 -0
  44. package/dist/cjs/standard-schema/types.d.ts +58 -0
  45. package/dist/cjs/standard-schema/types.js +2 -0
  46. package/dist/cjs/tituloEleitor.d.ts +6 -0
  47. package/dist/cjs/tituloEleitor.js +8 -0
  48. package/dist/cjs/uf.d.ts +5 -0
  49. package/dist/cjs/uf.js +7 -0
  50. package/dist/cjs/uuid.d.ts +6 -0
  51. package/dist/cjs/uuid.js +8 -0
  52. package/dist/esm/base.d.ts +4 -0
  53. package/dist/esm/boleto.d.ts +6 -0
  54. package/dist/esm/boleto.js +9 -0
  55. package/dist/esm/caepf.d.ts +6 -0
  56. package/dist/esm/caepf.js +8 -0
  57. package/dist/esm/carplate.d.ts +5 -0
  58. package/dist/esm/carplate.js +7 -0
  59. package/dist/esm/cbi_sinter.d.ts +6 -0
  60. package/dist/esm/cbi_sinter.js +8 -0
  61. package/dist/esm/cep.d.ts +6 -0
  62. package/dist/esm/cep.js +8 -0
  63. package/dist/esm/certidao.d.ts +6 -0
  64. package/dist/esm/certidao.js +8 -0
  65. package/dist/esm/cnh.d.ts +6 -0
  66. package/dist/esm/cnh.js +8 -0
  67. package/dist/esm/cnpj.d.ts +6 -0
  68. package/dist/esm/cnpj.js +8 -0
  69. package/dist/esm/cpf.d.ts +6 -0
  70. package/dist/esm/cpf.js +8 -0
  71. package/dist/esm/email.d.ts +13 -4
  72. package/dist/esm/email.js +78 -13
  73. package/dist/esm/index.d.ts +2 -1
  74. package/dist/esm/index.js +2 -2
  75. package/dist/esm/judicial-process.d.ts +6 -0
  76. package/dist/esm/judicial-process.js +8 -0
  77. package/dist/esm/nup17.d.ts +1 -0
  78. package/dist/esm/nup17.js +6 -0
  79. package/dist/esm/phone.d.ts +13 -1
  80. package/dist/esm/phone.js +20 -3
  81. package/dist/esm/pis-pasep.d.ts +6 -0
  82. package/dist/esm/pis-pasep.js +8 -0
  83. package/dist/esm/pix-copy-paste.d.ts +6 -0
  84. package/dist/esm/pix-copy-paste.js +8 -0
  85. package/dist/esm/pix-key.d.ts +5 -0
  86. package/dist/esm/pix-key.js +18 -0
  87. package/dist/esm/postal-track-code.d.ts +6 -0
  88. package/dist/esm/postal-track-code.js +8 -0
  89. package/dist/esm/renavam.d.ts +6 -0
  90. package/dist/esm/renavam.js +8 -0
  91. package/dist/esm/standard-schema/create-schema.d.ts +5 -0
  92. package/dist/esm/standard-schema/create-schema.js +50 -0
  93. package/dist/esm/standard-schema/index.d.ts +45 -0
  94. package/dist/esm/standard-schema/index.js +44 -0
  95. package/dist/esm/standard-schema/types.d.ts +58 -0
  96. package/dist/esm/standard-schema/types.js +1 -0
  97. package/dist/esm/tituloEleitor.d.ts +6 -0
  98. package/dist/esm/tituloEleitor.js +8 -0
  99. package/dist/esm/uf.d.ts +5 -0
  100. package/dist/esm/uf.js +7 -0
  101. package/dist/esm/uuid.d.ts +6 -0
  102. package/dist/esm/uuid.js +8 -0
  103. package/package.json +16 -3
  104. package/readme.md +56 -7
@@ -89,6 +89,12 @@ export declare class CNPJ extends Base {
89
89
  *
90
90
  */
91
91
  protected validate(): boolean;
92
+ /**
93
+ * Oculta os 5 primeiros dígitos da raiz e os 2 dígitos verificadores,
94
+ * mantendo os 3 últimos dígitos da raiz e o número da filial.
95
+ * Ex.: `**.***.333/0001-**`
96
+ */
97
+ redact(): string;
92
98
  /**
93
99
  * checksum()
94
100
  * Calcula o dígito verificador de um número SEM o dígito incluído
package/dist/esm/cnpj.js CHANGED
@@ -117,6 +117,14 @@ export class CNPJ extends Base {
117
117
  //
118
118
  //
119
119
  //
120
+ /**
121
+ * Oculta os 5 primeiros dígitos da raiz e os 2 dígitos verificadores,
122
+ * mantendo os 3 últimos dígitos da raiz e o número da filial.
123
+ * Ex.: `**.***.333/0001-**`
124
+ */
125
+ redact() {
126
+ return `**.***.${this._value.slice(5, 8)}/${this._value.slice(8, 12)}-**`;
127
+ }
120
128
  /**
121
129
  * checksum()
122
130
  * Calcula o dígito verificador de um número SEM o dígito incluído
package/dist/esm/cpf.d.ts CHANGED
@@ -72,6 +72,12 @@ export declare class CPF extends Base {
72
72
  * @returns {Boolean}
73
73
  */
74
74
  protected validate(): boolean;
75
+ /**
76
+ * Oculta os 3 primeiros dígitos e os 2 dígitos verificadores (padrão Bacen / CGU),
77
+ * mantendo os 6 dígitos centrais.
78
+ * Ex.: `***.782.710-**`
79
+ */
80
+ redact(): string;
75
81
  /**
76
82
  * fake()
77
83
  * Gera um número válido
package/dist/esm/cpf.js CHANGED
@@ -103,6 +103,14 @@ export class CPF extends Base {
103
103
  //
104
104
  //
105
105
  //
106
+ /**
107
+ * Oculta os 3 primeiros dígitos e os 2 dígitos verificadores (padrão Bacen / CGU),
108
+ * mantendo os 6 dígitos centrais.
109
+ * Ex.: `***.782.710-**`
110
+ */
111
+ redact() {
112
+ return `***.${this._value.slice(3, 6)}.${this._value.slice(6, 9)}-**`;
113
+ }
106
114
  /**
107
115
  * fake()
108
116
  * Gera um número válido
@@ -1,12 +1,21 @@
1
- import { Base } from "./base";
1
+ import { Base } from './base';
2
2
  export declare class Email extends Base {
3
3
  protected _value: string;
4
4
  protected _mask: null;
5
+ private _local;
6
+ private _domain;
5
7
  constructor(_value: string);
6
- get value(): string;
7
- toString(): string;
8
+ get local(): string;
9
+ get domain(): string;
8
10
  protected normalize(): void;
9
11
  protected validate(): boolean;
10
- mask(): string;
12
+ /**
13
+ * Oculta parte do usuário (parte local) mantendo o domínio visível.
14
+ * Para local com até 2 caracteres exibe o 1º caractere + `***`;
15
+ * acima disso exibe os 2 primeiros + `***` + último caractere.
16
+ * Ex.: `kl***o@gmail.com` / `a***@b.co`
17
+ */
18
+ redact(): string;
11
19
  static fake(): Email;
12
20
  }
21
+ export declare function isEmail(value: string): boolean;
package/dist/esm/email.js CHANGED
@@ -1,36 +1,101 @@
1
- import ValidationBRError from "./_exceptions/ValidationBRError.js";
2
- import { Random } from "./_helpers/random.js";
3
- import { Base } from "./base.js";
1
+ import ValidationBRError from './_exceptions/ValidationBRError.js';
2
+ import { Random } from './_helpers/random.js';
3
+ import { Base } from './base.js';
4
4
  export class Email extends Base {
5
5
  constructor(_value) {
6
6
  super(_value);
7
7
  this._value = _value;
8
8
  this._mask = null;
9
+ this._local = '';
10
+ this._domain = '';
11
+ if (typeof _value !== 'string') {
12
+ throw new ValidationBRError('Email inválido');
13
+ }
9
14
  this.normalize();
10
15
  if (!this.validate()) {
11
16
  throw new ValidationBRError('Email inválido');
12
17
  }
18
+ const atIndex = this._value.indexOf('@');
19
+ this._local = this._value.slice(0, atIndex);
20
+ this._domain = this._value.slice(atIndex + 1);
13
21
  }
14
- get value() {
15
- return this._value;
22
+ get local() {
23
+ return this._local;
16
24
  }
17
- toString() {
18
- return this.value;
25
+ get domain() {
26
+ return this._domain;
19
27
  }
20
28
  normalize() {
21
- this._value = this._value.toLocaleLowerCase();
29
+ this._value = this._value.trim().toLowerCase();
22
30
  }
23
31
  validate() {
24
- return /^[0-9a-z._+-]+@[0-9a-z._+-]+(\.[0-9a-z._+-]+)+$/i.test(this._value);
32
+ return isEmail(this._value);
25
33
  }
26
- mask() {
27
- throw new Error("Method not implemented.");
34
+ /**
35
+ * Oculta parte do usuário (parte local) mantendo o domínio visível.
36
+ * Para local com até 2 caracteres exibe o 1º caractere + `***`;
37
+ * acima disso exibe os 2 primeiros + `***` + último caractere.
38
+ * Ex.: `kl***o@gmail.com` / `a***@b.co`
39
+ */
40
+ redact() {
41
+ if (this._local.length <= 2) {
42
+ return `${this._local[0]}***@${this._domain}`;
43
+ }
44
+ return `${this._local.slice(0, 2)}***${this._local.slice(-1)}@${this._domain}`;
28
45
  }
29
- //
46
+ //
30
47
  // STATIC
31
- //
48
+ //
32
49
  static fake() {
33
50
  const servers = ['gmail.com', 'hotmail.com'];
34
51
  return new Email(`${Random.alpha(10)}@${Random.fromArray(servers)}`);
35
52
  }
36
53
  }
54
+ const ATEXT_PART = /^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+$/;
55
+ const DOMAIN_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
56
+ const TLD = /^(?:[a-z]{2,}|xn--[a-z0-9]{2,59})$/i;
57
+ export function isEmail(value) {
58
+ if (typeof value !== 'string')
59
+ return false;
60
+ const trimmed = value.trim();
61
+ if (trimmed.length < 3 || trimmed.length > 254)
62
+ return false;
63
+ for (let i = 0; i < trimmed.length; i++) {
64
+ const code = trimmed.charCodeAt(i);
65
+ if (code <= 32 || code === 127)
66
+ return false;
67
+ }
68
+ const atIndex = trimmed.indexOf('@');
69
+ if (atIndex <= 0 || atIndex !== trimmed.lastIndexOf('@'))
70
+ return false;
71
+ const local = trimmed.slice(0, atIndex);
72
+ const domain = trimmed.slice(atIndex + 1);
73
+ if (local.length < 1 || local.length > 64)
74
+ return false;
75
+ if (local.startsWith('.') || local.endsWith('.') || local.includes('..')) {
76
+ return false;
77
+ }
78
+ const localParts = local.split('.');
79
+ for (const part of localParts) {
80
+ if (!ATEXT_PART.test(part))
81
+ return false;
82
+ }
83
+ if (domain.length < 3 || domain.length > 253)
84
+ return false;
85
+ if (domain.startsWith('.') || domain.endsWith('.') || domain.includes('..')) {
86
+ return false;
87
+ }
88
+ const labels = domain.split('.');
89
+ if (labels.length < 2)
90
+ return false;
91
+ for (const label of labels) {
92
+ if (label.length < 1 || label.length > 63)
93
+ return false;
94
+ if (!DOMAIN_LABEL.test(label))
95
+ return false;
96
+ }
97
+ const tld = labels[labels.length - 1];
98
+ if (!TLD.test(tld))
99
+ return false;
100
+ return true;
101
+ }
@@ -1,4 +1,5 @@
1
1
  import { PixKeys } from './pix-key';
2
+ import { isEmail } from './email';
2
3
  import { CertidaoTipoLivro, CertidaoServico } from './certidao';
3
4
  export { PixKeys, CertidaoTipoLivro, CertidaoServico };
4
5
  export declare function isCNH(value: string): boolean;
@@ -14,7 +15,7 @@ export declare function isPixCopyPaste(value: string): boolean;
14
15
  export declare function isPostalTrackCode(value: string): boolean;
15
16
  export declare function isRenavam(value: string): boolean;
16
17
  export declare function isTituloEleitor(value: string): boolean;
17
- export declare function isEmail(value: string): boolean;
18
+ export { isEmail };
18
19
  export declare function isUUID(value: string): boolean;
19
20
  export declare function isBoleto(value: string): boolean;
20
21
  export declare function isCAEPF(value: string): boolean;
package/dist/esm/index.js CHANGED
@@ -12,7 +12,7 @@ import { JudicialProcess } from './judicial-process.js';
12
12
  import { PostalTrackCode } from './postal-track-code.js';
13
13
  import { TituloEleitor } from './tituloEleitor.js';
14
14
  import { UUID } from './uuid.js';
15
- import { Email } from './email.js';
15
+ import { isEmail } from './email.js';
16
16
  import { Boleto } from './boleto.js';
17
17
  import { CAEPF } from './caepf.js';
18
18
  import { CEP } from './cep.js';
@@ -42,7 +42,7 @@ export function isPixCopyPaste(value) { return validate(() => new PixCopyPaste(v
42
42
  export function isPostalTrackCode(value) { return validate(() => new PostalTrackCode(value)); }
43
43
  export function isRenavam(value) { return validate(() => new Renavam(value)); }
44
44
  export function isTituloEleitor(value) { return validate(() => new TituloEleitor(value)); }
45
- export function isEmail(value) { return validate(() => new Email(value)); }
45
+ export { isEmail };
46
46
  export function isUUID(value) { return validate(() => new UUID(value)); }
47
47
  export function isBoleto(value) { return validate(() => new Boleto(value)); }
48
48
  export function isCAEPF(value) { return validate(() => new CAEPF(value)); }
@@ -105,6 +105,12 @@ export declare class JudicialProcess extends Base {
105
105
  * @returns {Boolean}
106
106
  */
107
107
  protected validate(): boolean;
108
+ /**
109
+ * Oculta o número sequencial do processo e os dígitos verificadores,
110
+ * mantendo ano, segmento da justiça, tribunal e unidade de origem.
111
+ * Ex.: `*******-**.2016.4.05.8400`
112
+ */
113
+ redact(): string;
108
114
  /**
109
115
  * fake()
110
116
  * Gera um número válido
@@ -151,6 +151,14 @@ export class JudicialProcess extends Base {
151
151
  //
152
152
  //
153
153
  //
154
+ /**
155
+ * Oculta o número sequencial do processo e os dígitos verificadores,
156
+ * mantendo ano, segmento da justiça, tribunal e unidade de origem.
157
+ * Ex.: `*******-**.2016.4.05.8400`
158
+ */
159
+ redact() {
160
+ return `*******-**.${this._value.slice(9, 13)}.${this._value.slice(13, 14)}.${this._value.slice(14, 16)}.${this._value.slice(16, 20)}`;
161
+ }
154
162
  /**
155
163
  * fake()
156
164
  * Gera um número válido
@@ -76,6 +76,7 @@ export declare class NUP17 extends Base {
76
76
  *
77
77
  */
78
78
  protected validate(): boolean;
79
+ redact(): string;
79
80
  /**
80
81
  *
81
82
  * fake()
package/dist/esm/nup17.js CHANGED
@@ -106,6 +106,12 @@ export class NUP17 extends Base {
106
106
  //
107
107
  //
108
108
  //
109
+ // Oculta o número sequencial e os 2 dígitos verificadores do protocolo,
110
+ // mantendo o código do órgão protocolizador e o ano.
111
+ // Ex.: `23037.******/2021-**`
112
+ redact() {
113
+ return `${this._value.slice(0, 5)}.******/${this._value.slice(11, 15)}-**`;
114
+ }
109
115
  /**
110
116
  *
111
117
  * fake()
@@ -15,8 +15,14 @@
15
15
  * new Phone('8440043214').validate()
16
16
  * // -> true
17
17
  *
18
+ * new Phone('(21) 2345-6789').validate()
19
+ * // -> true (fixos iniciam de 2 a 6)
20
+ *
21
+ * new Phone('(11) 7555-1234').validate()
22
+ * // -> throws error (fixo iniciado em 7 é reserva técnica)
23
+ *
18
24
  * new Phone('(23) 4004-3214').validate()
19
- * // -> throws error
25
+ * // -> throws error (DDD 23 não existe)
20
26
  *
21
27
  * new Phone('(13) 6 6321-875').validate()
22
28
  * // -> throws error
@@ -85,6 +91,12 @@ export declare class Phone extends Base {
85
91
  *
86
92
  */
87
93
  mask(config?: Partial<MaskSettings>): string;
94
+ /**
95
+ * Oculta 6 dígitos do telefone, mantendo DDI, DDD, dígito `9` (em celulares)
96
+ * e os 2 últimos dígitos.
97
+ * Ex.: `+55 84 9****-**56` (celular) / `+55 84 ****-**54` (fixo)
98
+ */
99
+ redact(): string;
88
100
  /**
89
101
  * Devolve o checksum
90
102
  *
package/dist/esm/phone.js CHANGED
@@ -15,8 +15,14 @@
15
15
  * new Phone('8440043214').validate()
16
16
  * // -> true
17
17
  *
18
+ * new Phone('(21) 2345-6789').validate()
19
+ * // -> true (fixos iniciam de 2 a 6)
20
+ *
21
+ * new Phone('(11) 7555-1234').validate()
22
+ * // -> throws error (fixo iniciado em 7 é reserva técnica)
23
+ *
18
24
  * new Phone('(23) 4004-3214').validate()
19
- * // -> throws error
25
+ * // -> throws error (DDD 23 não existe)
20
26
  *
21
27
  * new Phone('(13) 6 6321-875').validate()
22
28
  * // -> throws error
@@ -44,7 +50,9 @@ export class Phone extends Base {
44
50
  super(_value);
45
51
  this._value = _value;
46
52
  this._mask = null;
47
- this._regex = /^(?<ddi>\+55)?(?<ddd>\d{2})(?<phone>9\d{8}|[34]\d{7})$/;
53
+ // Fixos (STFC/SCM): 8 dígitos iniciados em 2 a 6 — Resolução Anatel nº 749/2022, art. 11, I, "a".
54
+ // Celulares (SMP): 9 dígitos iniciados em 9.
55
+ this._regex = /^(?<ddi>\+55)?(?<ddd>\d{2})(?<phone>9\d{8}|[2-6]\d{7})$/;
48
56
  this._ddd = '';
49
57
  this._phone = '';
50
58
  this._ddi = '';
@@ -111,6 +119,15 @@ export class Phone extends Base {
111
119
  mask(config) {
112
120
  return `${(config === null || config === void 0 ? void 0 : config.withCountry) ? '+55 ' : ''}${this._ddd} ${this._phone}`;
113
121
  }
122
+ /**
123
+ * Oculta 6 dígitos do telefone, mantendo DDI, DDD, dígito `9` (em celulares)
124
+ * e os 2 últimos dígitos.
125
+ * Ex.: `+55 84 9****-**56` (celular) / `+55 84 ****-**54` (fixo)
126
+ */
127
+ redact() {
128
+ const prefix = this._isMobile ? `${this._phone[0]}****` : '****';
129
+ return `${this._ddi} ${this._ddd} ${prefix}-**${this._phone.slice(-2)}`;
130
+ }
114
131
  /**
115
132
  * Devolve o checksum
116
133
  *
@@ -133,7 +150,7 @@ export class Phone extends Base {
133
150
  const ddd = (_a = config === null || config === void 0 ? void 0 : config.ddd) !== null && _a !== void 0 ? _a : Random.fromArray(Phone._ddds);
134
151
  // Prefixos
135
152
  const mobilePrefixes = ['99', '98', '97'];
136
- const landLinePrefixes = ['3', '4'];
153
+ const landLinePrefixes = ['2', '3', '4', '5', '6'];
137
154
  // Se não informar se quer mobile ou fixo, gere o tipo
138
155
  let firstPart;
139
156
  if (config === null || config === void 0 ? void 0 : config.isMobile)
@@ -53,6 +53,12 @@ export declare class PIS extends Base {
53
53
  * @returns {Boolean}
54
54
  */
55
55
  protected validate(): boolean;
56
+ /**
57
+ * Oculta os 6 primeiros dígitos e o dígito verificador do PIS/PASEP,
58
+ * mantendo os 4 dígitos finais antes do traço.
59
+ * Ex.: `***.***49.96-*`
60
+ */
61
+ redact(): string;
56
62
  /**
57
63
  * fake()
58
64
  * Gera um número válido
@@ -84,6 +84,14 @@ export class PIS extends Base {
84
84
  //
85
85
  //
86
86
  //
87
+ /**
88
+ * Oculta os 6 primeiros dígitos e o dígito verificador do PIS/PASEP,
89
+ * mantendo os 4 dígitos finais antes do traço.
90
+ * Ex.: `***.***49.96-*`
91
+ */
92
+ redact() {
93
+ return `***.***${this._value.slice(6, 8)}.${this._value.slice(8, 10)}-*`;
94
+ }
87
95
  /**
88
96
  * fake()
89
97
  * Gera um número válido
@@ -3,6 +3,12 @@ export declare class PixCopyPaste extends Base {
3
3
  protected _value: string;
4
4
  protected _mask: null;
5
5
  constructor(_value: string);
6
+ /**
7
+ * Oculta o miolo do payload EMV (chave Pix, nome do recebedor, cidade e valor),
8
+ * mantendo os 12 primeiros caracteres (cabeçalho) e os 8 últimos (tag CRC `6304XXXX`).
9
+ * Ex.: `000201010212...***...6304FF60`
10
+ */
11
+ redact(): string;
6
12
  protected validate(): boolean;
7
13
  protected normalize(): void;
8
14
  }
@@ -9,6 +9,14 @@ export class PixCopyPaste extends Base {
9
9
  this.normalize();
10
10
  this.validate();
11
11
  }
12
+ /**
13
+ * Oculta o miolo do payload EMV (chave Pix, nome do recebedor, cidade e valor),
14
+ * mantendo os 12 primeiros caracteres (cabeçalho) e os 8 últimos (tag CRC `6304XXXX`).
15
+ * Ex.: `000201010212...***...6304FF60`
16
+ */
17
+ redact() {
18
+ return `${this._value.slice(0, 12)}...***...${this._value.slice(-8)}`;
19
+ }
12
20
  //
13
21
  //
14
22
  // static
@@ -17,6 +17,11 @@ export declare class PixKey extends Base {
17
17
  private _type?;
18
18
  constructor(_value: string);
19
19
  get type(): PixKeys | undefined;
20
+ /**
21
+ * Delega a ocultação para a classe correspondente ao tipo identificado da chave Pix
22
+ * (`CPF`, `CNPJ`, `Email`, `Phone` ou `UUID`).
23
+ */
24
+ redact(): string;
20
25
  /**
21
26
  * Gera uma chave fake
22
27
  */
@@ -33,6 +33,24 @@ export class PixKey extends Base {
33
33
  get type() {
34
34
  return this._type;
35
35
  }
36
+ /**
37
+ * Delega a ocultação para a classe correspondente ao tipo identificado da chave Pix
38
+ * (`CPF`, `CNPJ`, `Email`, `Phone` ou `UUID`).
39
+ */
40
+ redact() {
41
+ switch (this._type) {
42
+ case PixKeys.cpf:
43
+ return new CPF(this._value).redact();
44
+ case PixKeys.cnpj:
45
+ return new CNPJ(this._value).redact();
46
+ case PixKeys.email:
47
+ return new Email(this._value).redact();
48
+ case PixKeys.phone:
49
+ return new Phone(this._value).redact();
50
+ default:
51
+ return new UUID(this._value).redact();
52
+ }
53
+ }
36
54
  //
37
55
  //
38
56
  // STATIC
@@ -60,6 +60,12 @@ export declare class PostalTrackCode extends Base {
60
60
  * @returns {Boolean}
61
61
  */
62
62
  protected validate(): boolean;
63
+ /**
64
+ * Oculta os 6 primeiros dígitos da numeração sequencial,
65
+ * mantendo o tipo do objeto (2 letras iniciais), os 3 últimos dígitos e o código do país.
66
+ * Ex.: `PN******423BR`
67
+ */
68
+ redact(): string;
63
69
  /**
64
70
  * fake()
65
71
  * Gera um número válido
@@ -91,6 +91,14 @@ export class PostalTrackCode extends Base {
91
91
  //
92
92
  //
93
93
  //
94
+ /**
95
+ * Oculta os 6 primeiros dígitos da numeração sequencial,
96
+ * mantendo o tipo do objeto (2 letras iniciais), os 3 últimos dígitos e o código do país.
97
+ * Ex.: `PN******423BR`
98
+ */
99
+ redact() {
100
+ return `${this._value.slice(0, 2)}******${this._value.slice(8, 11)}${this._value.slice(11, 13)}`;
101
+ }
94
102
  /**
95
103
  * fake()
96
104
  * Gera um número válido
@@ -16,6 +16,12 @@ export declare class Renavam extends Base {
16
16
  *
17
17
  */
18
18
  protected validate(): boolean;
19
+ /**
20
+ * Oculta os 6 primeiros dígitos e o dígito verificador do RENAVAM,
21
+ * mantendo os 4 dígitos finais antes do traço.
22
+ * Ex.: `******8837-*`
23
+ */
24
+ redact(): string;
19
25
  /**
20
26
  *
21
27
  * Gera um número válido
@@ -83,6 +83,14 @@ export class Renavam extends Base {
83
83
  //
84
84
  //
85
85
  //
86
+ /**
87
+ * Oculta os 6 primeiros dígitos e o dígito verificador do RENAVAM,
88
+ * mantendo os 4 dígitos finais antes do traço.
89
+ * Ex.: `******8837-*`
90
+ */
91
+ redact() {
92
+ return `******${this._value.slice(6, 10)}-*`;
93
+ }
86
94
  /**
87
95
  *
88
96
  * Gera um número válido
@@ -0,0 +1,5 @@
1
+ import type { Base } from '../base';
2
+ import type { DocumentConstructor, SchemaFactory, SchemaOptions, StandardSchemaV1 } from './types';
3
+ export declare function createSchema<T extends Base>(DocumentClass: DocumentConstructor<T>, options?: SchemaOptions<'value' | 'masked'>): StandardSchemaV1<string, string>;
4
+ export declare function createSchema<T extends Base>(DocumentClass: DocumentConstructor<T>, options: SchemaOptions<'object'>): StandardSchemaV1<string, T>;
5
+ export declare function bindSchema<T extends Base>(DocumentClass: DocumentConstructor<T>): SchemaFactory<T>;
@@ -0,0 +1,50 @@
1
+ import ValidationBRError, { InvalidFormatException, } from '../_exceptions/ValidationBRError.js';
2
+ function resolveMessage(error, customMessage) {
3
+ if (typeof customMessage === 'string') {
4
+ return customMessage;
5
+ }
6
+ if (error instanceof ValidationBRError) {
7
+ return customMessage ? customMessage(error) : error.message;
8
+ }
9
+ if (error instanceof Error && error.message) {
10
+ return error.message;
11
+ }
12
+ return 'Valor inválido';
13
+ }
14
+ export function createSchema(DocumentClass, options) {
15
+ var _a;
16
+ const output = (_a = options === null || options === void 0 ? void 0 : options.output) !== null && _a !== void 0 ? _a : 'value';
17
+ const customMessage = options === null || options === void 0 ? void 0 : options.message;
18
+ return {
19
+ '~standard': {
20
+ version: 1,
21
+ vendor: 'validation-br',
22
+ validate(value) {
23
+ if (typeof value !== 'string') {
24
+ const error = new InvalidFormatException();
25
+ return {
26
+ issues: [{ message: resolveMessage(error, customMessage) }],
27
+ };
28
+ }
29
+ try {
30
+ const instance = new DocumentClass(value);
31
+ if (output === 'object') {
32
+ return { value: instance };
33
+ }
34
+ if (output === 'masked') {
35
+ return { value: instance.mask() };
36
+ }
37
+ return { value: instance.value };
38
+ }
39
+ catch (error) {
40
+ return {
41
+ issues: [{ message: resolveMessage(error, customMessage) }],
42
+ };
43
+ }
44
+ },
45
+ },
46
+ };
47
+ }
48
+ export function bindSchema(DocumentClass) {
49
+ return ((options) => createSchema(DocumentClass, options));
50
+ }
@@ -0,0 +1,45 @@
1
+ import { Boleto } from '../boleto';
2
+ import { CAEPF } from '../caepf';
3
+ import { CarPlate } from '../carplate';
4
+ import { CBISinter } from '../cbi_sinter';
5
+ import { CEP } from '../cep';
6
+ import { Certidao } from '../certidao';
7
+ import { CNH } from '../cnh';
8
+ import { CNPJ } from '../cnpj';
9
+ import { CPF } from '../cpf';
10
+ import { Email } from '../email';
11
+ import { JudicialProcess } from '../judicial-process';
12
+ import { NUP17 } from '../nup17';
13
+ import { Phone } from '../phone';
14
+ import { PIS } from '../pis-pasep';
15
+ import { PixCopyPaste } from '../pix-copy-paste';
16
+ import { PixKey } from '../pix-key';
17
+ import { PostalTrackCode } from '../postal-track-code';
18
+ import { Renavam } from '../renavam';
19
+ import { TituloEleitor } from '../tituloEleitor';
20
+ import { UF } from '../uf';
21
+ import { UUID } from '../uuid';
22
+ import { createSchema } from './create-schema';
23
+ export { createSchema };
24
+ export type { DocumentConstructor, SchemaFactory, SchemaMessageResolver, SchemaOptions, SchemaOutputMode, StandardSchemaV1, StandardSchemaV1FailureResult, StandardSchemaV1Issue, StandardSchemaV1PathSegment, StandardSchemaV1Props, StandardSchemaV1Result, StandardSchemaV1SuccessResult, StandardSchemaV1Types, } from './types';
25
+ export declare const boletoSchema: import("./types").SchemaFactory<Boleto>;
26
+ export declare const caepfSchema: import("./types").SchemaFactory<CAEPF>;
27
+ export declare const carPlateSchema: import("./types").SchemaFactory<CarPlate>;
28
+ export declare const cbiSinterSchema: import("./types").SchemaFactory<CBISinter>;
29
+ export declare const cepSchema: import("./types").SchemaFactory<CEP>;
30
+ export declare const certidaoSchema: import("./types").SchemaFactory<Certidao>;
31
+ export declare const cnhSchema: import("./types").SchemaFactory<CNH>;
32
+ export declare const cnpjSchema: import("./types").SchemaFactory<CNPJ>;
33
+ export declare const cpfSchema: import("./types").SchemaFactory<CPF>;
34
+ export declare const emailSchema: import("./types").SchemaFactory<Email>;
35
+ export declare const judicialProcessSchema: import("./types").SchemaFactory<JudicialProcess>;
36
+ export declare const nup17Schema: import("./types").SchemaFactory<NUP17>;
37
+ export declare const phoneSchema: import("./types").SchemaFactory<Phone>;
38
+ export declare const pisSchema: import("./types").SchemaFactory<PIS>;
39
+ export declare const pixCopyPasteSchema: import("./types").SchemaFactory<PixCopyPaste>;
40
+ export declare const pixKeySchema: import("./types").SchemaFactory<PixKey>;
41
+ export declare const postalTrackCodeSchema: import("./types").SchemaFactory<PostalTrackCode>;
42
+ export declare const renavamSchema: import("./types").SchemaFactory<Renavam>;
43
+ export declare const tituloEleitorSchema: import("./types").SchemaFactory<TituloEleitor>;
44
+ export declare const ufSchema: import("./types").SchemaFactory<UF>;
45
+ export declare const uuidSchema: import("./types").SchemaFactory<UUID>;