validation-br 2.0.1 → 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 +6 -0
  29. package/dist/cjs/phone.js +9 -0
  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 +6 -0
  80. package/dist/esm/phone.js +9 -0
  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 +9 -1
  104. package/readme.md +55 -5
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()
@@ -91,6 +91,12 @@ export declare class Phone extends Base {
91
91
  *
92
92
  */
93
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;
94
100
  /**
95
101
  * Devolve o checksum
96
102
  *
package/dist/esm/phone.js CHANGED
@@ -119,6 +119,15 @@ export class Phone extends Base {
119
119
  mask(config) {
120
120
  return `${(config === null || config === void 0 ? void 0 : config.withCountry) ? '+55 ' : ''}${this._ddd} ${this._phone}`;
121
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
+ }
122
131
  /**
123
132
  * Devolve o checksum
124
133
  *
@@ -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>;
@@ -0,0 +1,44 @@
1
+ import { Boleto } from '../boleto.js';
2
+ import { CAEPF } from '../caepf.js';
3
+ import { CarPlate } from '../carplate.js';
4
+ import { CBISinter } from '../cbi_sinter.js';
5
+ import { CEP } from '../cep.js';
6
+ import { Certidao } from '../certidao.js';
7
+ import { CNH } from '../cnh.js';
8
+ import { CNPJ } from '../cnpj.js';
9
+ import { CPF } from '../cpf.js';
10
+ import { Email } from '../email.js';
11
+ import { JudicialProcess } from '../judicial-process.js';
12
+ import { NUP17 } from '../nup17.js';
13
+ import { Phone } from '../phone.js';
14
+ import { PIS } from '../pis-pasep.js';
15
+ import { PixCopyPaste } from '../pix-copy-paste.js';
16
+ import { PixKey } from '../pix-key.js';
17
+ import { PostalTrackCode } from '../postal-track-code.js';
18
+ import { Renavam } from '../renavam.js';
19
+ import { TituloEleitor } from '../tituloEleitor.js';
20
+ import { UF } from '../uf.js';
21
+ import { UUID } from '../uuid.js';
22
+ import { bindSchema, createSchema } from './create-schema.js';
23
+ export { createSchema };
24
+ export const boletoSchema = /*#__PURE__*/ bindSchema(Boleto);
25
+ export const caepfSchema = /*#__PURE__*/ bindSchema(CAEPF);
26
+ export const carPlateSchema = /*#__PURE__*/ bindSchema(CarPlate);
27
+ export const cbiSinterSchema = /*#__PURE__*/ bindSchema(CBISinter);
28
+ export const cepSchema = /*#__PURE__*/ bindSchema(CEP);
29
+ export const certidaoSchema = /*#__PURE__*/ bindSchema(Certidao);
30
+ export const cnhSchema = /*#__PURE__*/ bindSchema(CNH);
31
+ export const cnpjSchema = /*#__PURE__*/ bindSchema(CNPJ);
32
+ export const cpfSchema = /*#__PURE__*/ bindSchema(CPF);
33
+ export const emailSchema = /*#__PURE__*/ bindSchema(Email);
34
+ export const judicialProcessSchema = /*#__PURE__*/ bindSchema(JudicialProcess);
35
+ export const nup17Schema = /*#__PURE__*/ bindSchema(NUP17);
36
+ export const phoneSchema = /*#__PURE__*/ bindSchema(Phone);
37
+ export const pisSchema = /*#__PURE__*/ bindSchema(PIS);
38
+ export const pixCopyPasteSchema = /*#__PURE__*/ bindSchema(PixCopyPaste);
39
+ export const pixKeySchema = /*#__PURE__*/ bindSchema(PixKey);
40
+ export const postalTrackCodeSchema = /*#__PURE__*/ bindSchema(PostalTrackCode);
41
+ export const renavamSchema = /*#__PURE__*/ bindSchema(Renavam);
42
+ export const tituloEleitorSchema = /*#__PURE__*/ bindSchema(TituloEleitor);
43
+ export const ufSchema = /*#__PURE__*/ bindSchema(UF);
44
+ export const uuidSchema = /*#__PURE__*/ bindSchema(UUID);
@@ -0,0 +1,58 @@
1
+ import type ValidationBRError from '../_exceptions/ValidationBRError';
2
+ import type { Base } from '../base';
3
+ /**
4
+ * Interface oficial do contrato Standard Schema v1.
5
+ * Definida localmente (sem dependência de runtime) para compatibilidade estrutural
6
+ * com `@standard-schema/spec`.
7
+ *
8
+ * @see https://standardschema.dev/
9
+ */
10
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
11
+ readonly '~standard': StandardSchemaV1Props<Input, Output>;
12
+ }
13
+ export interface StandardSchemaV1Props<Input = unknown, Output = Input> {
14
+ readonly version: 1;
15
+ readonly vendor: string;
16
+ readonly validate: (value: unknown) => StandardSchemaV1Result<Output> | Promise<StandardSchemaV1Result<Output>>;
17
+ readonly types?: StandardSchemaV1Types<Input, Output> | undefined;
18
+ }
19
+ export type StandardSchemaV1Result<Output> = StandardSchemaV1SuccessResult<Output> | StandardSchemaV1FailureResult;
20
+ export interface StandardSchemaV1SuccessResult<Output> {
21
+ readonly value: Output;
22
+ readonly issues?: undefined;
23
+ }
24
+ export interface StandardSchemaV1FailureResult {
25
+ readonly issues: ReadonlyArray<StandardSchemaV1Issue>;
26
+ }
27
+ export interface StandardSchemaV1Issue {
28
+ readonly message: string;
29
+ readonly path?: ReadonlyArray<PropertyKey | StandardSchemaV1PathSegment> | undefined;
30
+ }
31
+ export interface StandardSchemaV1PathSegment {
32
+ readonly key: PropertyKey;
33
+ }
34
+ export interface StandardSchemaV1Types<Input = unknown, Output = Input> {
35
+ readonly input: Input;
36
+ readonly output: Output;
37
+ }
38
+ export type DocumentConstructor<T extends Base> = new (value: string) => T;
39
+ export type SchemaOutputMode = 'value' | 'masked' | 'object';
40
+ export type SchemaMessageResolver = string | ((error: ValidationBRError) => string);
41
+ export interface SchemaOptions<O extends SchemaOutputMode = SchemaOutputMode> {
42
+ /**
43
+ * Formato do valor retornado quando a validação é bem-sucedida:
44
+ * - `'value'` (padrão): string normalizada (`instance.value`)
45
+ * - `'masked'`: string formatada com máscara (`instance.mask()`)
46
+ * - `'object'`: instância do Value Object (`CPF`, `CNPJ`, etc.)
47
+ */
48
+ readonly output?: O;
49
+ /**
50
+ * Mensagem de erro customizada ou função que recebe o `ValidationBRError`
51
+ * lançado pelo documento. Quando omitida, utiliza a mensagem original do erro.
52
+ */
53
+ readonly message?: SchemaMessageResolver;
54
+ }
55
+ export interface SchemaFactory<T extends Base> {
56
+ (options?: SchemaOptions<'value' | 'masked'>): StandardSchemaV1<string, string>;
57
+ (options: SchemaOptions<'object'>): StandardSchemaV1<string, T>;
58
+ }
@@ -0,0 +1 @@
1
+ export {};