validation-br 2.0.1 → 2.6.0-beta.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 (126) hide show
  1. package/dist/cjs/_exceptions/ValidationBRError.d.ts +12 -0
  2. package/dist/cjs/_exceptions/ValidationBRError.js +30 -1
  3. package/dist/cjs/_helpers/pix-fields.d.ts +106 -0
  4. package/dist/cjs/_helpers/pix-fields.js +296 -0
  5. package/dist/cjs/_helpers/utils.d.ts +0 -1
  6. package/dist/cjs/_helpers/utils.js +0 -1
  7. package/dist/cjs/base.d.ts +14 -6
  8. package/dist/cjs/base.js +16 -0
  9. package/dist/cjs/boleto.d.ts +47 -7
  10. package/dist/cjs/boleto.js +67 -16
  11. package/dist/cjs/caepf.d.ts +41 -5
  12. package/dist/cjs/caepf.js +68 -21
  13. package/dist/cjs/carplate.d.ts +45 -7
  14. package/dist/cjs/carplate.js +68 -24
  15. package/dist/cjs/cep.d.ts +43 -11
  16. package/dist/cjs/cep.js +73 -28
  17. package/dist/cjs/certidao.d.ts +50 -2
  18. package/dist/cjs/certidao.js +76 -15
  19. package/dist/cjs/cib.d.ts +166 -0
  20. package/dist/cjs/cib.js +232 -0
  21. package/dist/cjs/cnh.d.ts +43 -6
  22. package/dist/cjs/cnh.js +71 -24
  23. package/dist/cjs/cnpj.d.ts +41 -5
  24. package/dist/cjs/cnpj.js +68 -21
  25. package/dist/cjs/cpf.d.ts +42 -8
  26. package/dist/cjs/cpf.js +69 -25
  27. package/dist/cjs/email.d.ts +47 -6
  28. package/dist/cjs/email.js +118 -20
  29. package/dist/cjs/index.d.ts +5 -2
  30. package/dist/cjs/index.js +27 -24
  31. package/dist/cjs/judicial-process.d.ts +42 -8
  32. package/dist/cjs/judicial-process.js +74 -26
  33. package/dist/cjs/nup17.d.ts +35 -9
  34. package/dist/cjs/nup17.js +62 -26
  35. package/dist/cjs/phone.d.ts +52 -14
  36. package/dist/cjs/phone.js +87 -35
  37. package/dist/cjs/pis-pasep.d.ts +41 -8
  38. package/dist/cjs/pis-pasep.js +68 -25
  39. package/dist/cjs/pix-copy-paste.d.ts +10 -0
  40. package/dist/cjs/pix-copy-paste.js +12 -0
  41. package/dist/cjs/pix-key.d.ts +63 -4
  42. package/dist/cjs/pix-key.js +103 -32
  43. package/dist/cjs/pix.d.ts +193 -0
  44. package/dist/cjs/pix.js +191 -0
  45. package/dist/cjs/postal-track-code.d.ts +42 -12
  46. package/dist/cjs/postal-track-code.js +68 -32
  47. package/dist/cjs/renavam.d.ts +38 -8
  48. package/dist/cjs/renavam.js +67 -28
  49. package/dist/cjs/standard-schema/create-schema.d.ts +5 -0
  50. package/dist/cjs/standard-schema/create-schema.js +87 -0
  51. package/dist/cjs/standard-schema/index.d.ts +48 -0
  52. package/dist/cjs/standard-schema/index.js +50 -0
  53. package/dist/cjs/standard-schema/types.d.ts +58 -0
  54. package/dist/cjs/standard-schema/types.js +2 -0
  55. package/dist/cjs/tituloEleitor.d.ts +43 -8
  56. package/dist/cjs/tituloEleitor.js +78 -27
  57. package/dist/cjs/uf.d.ts +35 -2
  58. package/dist/cjs/uf.js +61 -25
  59. package/dist/cjs/uuid.d.ts +42 -2
  60. package/dist/cjs/uuid.js +62 -14
  61. package/dist/esm/_exceptions/ValidationBRError.d.ts +12 -0
  62. package/dist/esm/_exceptions/ValidationBRError.js +26 -0
  63. package/dist/esm/_helpers/pix-fields.d.ts +106 -0
  64. package/dist/esm/_helpers/pix-fields.js +292 -0
  65. package/dist/esm/_helpers/utils.d.ts +0 -1
  66. package/dist/esm/_helpers/utils.js +0 -1
  67. package/dist/esm/base.d.ts +14 -6
  68. package/dist/esm/base.js +16 -0
  69. package/dist/esm/boleto.d.ts +47 -7
  70. package/dist/esm/boleto.js +67 -16
  71. package/dist/esm/caepf.d.ts +41 -5
  72. package/dist/esm/caepf.js +70 -23
  73. package/dist/esm/carplate.d.ts +45 -7
  74. package/dist/esm/carplate.js +68 -24
  75. package/dist/esm/cep.d.ts +43 -11
  76. package/dist/esm/cep.js +73 -28
  77. package/dist/esm/certidao.d.ts +50 -2
  78. package/dist/esm/certidao.js +76 -15
  79. package/dist/esm/cib.d.ts +166 -0
  80. package/dist/esm/cib.js +228 -0
  81. package/dist/esm/cnh.d.ts +43 -6
  82. package/dist/esm/cnh.js +73 -26
  83. package/dist/esm/cnpj.d.ts +41 -5
  84. package/dist/esm/cnpj.js +70 -23
  85. package/dist/esm/cpf.d.ts +42 -8
  86. package/dist/esm/cpf.js +71 -27
  87. package/dist/esm/email.d.ts +47 -6
  88. package/dist/esm/email.js +119 -19
  89. package/dist/esm/index.d.ts +5 -2
  90. package/dist/esm/index.js +25 -22
  91. package/dist/esm/judicial-process.d.ts +42 -8
  92. package/dist/esm/judicial-process.js +75 -27
  93. package/dist/esm/nup17.d.ts +35 -9
  94. package/dist/esm/nup17.js +64 -28
  95. package/dist/esm/phone.d.ts +52 -14
  96. package/dist/esm/phone.js +87 -35
  97. package/dist/esm/pis-pasep.d.ts +41 -8
  98. package/dist/esm/pis-pasep.js +70 -27
  99. package/dist/esm/pix-copy-paste.d.ts +10 -0
  100. package/dist/esm/pix-copy-paste.js +12 -0
  101. package/dist/esm/pix-key.d.ts +63 -4
  102. package/dist/esm/pix-key.js +103 -32
  103. package/dist/esm/pix.d.ts +193 -0
  104. package/dist/esm/pix.js +187 -0
  105. package/dist/esm/postal-track-code.d.ts +42 -12
  106. package/dist/esm/postal-track-code.js +69 -33
  107. package/dist/esm/renavam.d.ts +38 -8
  108. package/dist/esm/renavam.js +69 -30
  109. package/dist/esm/standard-schema/create-schema.d.ts +5 -0
  110. package/dist/esm/standard-schema/create-schema.js +50 -0
  111. package/dist/esm/standard-schema/index.d.ts +48 -0
  112. package/dist/esm/standard-schema/index.js +47 -0
  113. package/dist/esm/standard-schema/types.d.ts +58 -0
  114. package/dist/esm/standard-schema/types.js +1 -0
  115. package/dist/esm/tituloEleitor.d.ts +43 -8
  116. package/dist/esm/tituloEleitor.js +80 -29
  117. package/dist/esm/uf.d.ts +35 -2
  118. package/dist/esm/uf.js +62 -26
  119. package/dist/esm/uuid.d.ts +42 -2
  120. package/dist/esm/uuid.js +62 -11
  121. package/package.json +12 -3
  122. package/readme.md +158 -860
  123. package/dist/cjs/cbi_sinter.d.ts +0 -78
  124. package/dist/cjs/cbi_sinter.js +0 -123
  125. package/dist/esm/cbi_sinter.d.ts +0 -78
  126. package/dist/esm/cbi_sinter.js +0 -119
package/dist/cjs/cpf.js CHANGED
@@ -69,8 +69,15 @@ class CPF extends base_1.Base {
69
69
  super(_value);
70
70
  this._value = _value;
71
71
  this._mask = '000.000.000-00';
72
- this.normalize();
73
- if (!this.validate()) {
72
+ // O formato é conferido antes de qualquer limpeza, com o valor exatamente como chegou
73
+ if (!CPF._matches(this._value)) {
74
+ throw new ValidationBRError_1.InvalidFormatException();
75
+ }
76
+ this._value = CPF._normalize(this._value);
77
+ if ((0, utils_1.checkRepeatedSequence)(this._value)) {
78
+ throw new ValidationBRError_1.RepeatedSequenceException();
79
+ }
80
+ if (!CPF._check(this._value)) {
74
81
  throw new ValidationBRError_1.InvalidChecksumException();
75
82
  }
76
83
  }
@@ -80,42 +87,43 @@ class CPF extends base_1.Base {
80
87
  //
81
88
  //
82
89
  //
83
- normalize() {
84
- this._value = this._value.replace(/([.-])/g, '');
90
+ /**
91
+ * Oculta os 3 primeiros dígitos e os 2 dígitos verificadores (padrão Bacen / CGU),
92
+ * mantendo os 6 dígitos centrais.
93
+ * Ex.: `***.782.710-**`
94
+ */
95
+ redact() {
96
+ return `***.${this._value.slice(3, 6)}.${this._value.slice(6, 9)}-**`;
85
97
  }
86
98
  /**
87
- * validate()
88
- * Valida se um número é válido e
89
- * retorna uma exceção se não estiver
99
+ * isValid()
100
+ * Diz se um valor é válido, sem criar uma instância e sem lançar exceção.
101
+ * Faz os mesmos passos do construtor: formato, limpeza e dígito verificador.
90
102
  *
91
- * @param {String|Number} value Número a ser validado
92
- * @returns {Boolean}
103
+ * @example
104
+ * CPF.isValid('133.782.710-00') // -> true
105
+ * CPF.isValid(' 133.782.710-00') // -> false
106
+ * CPF.isValid('111.111.111-11') // -> false
93
107
  */
94
- validate() {
95
- const cpf = (0, utils_1.clearValue)(this._value, 11, {
96
- rejectEmpty: true,
97
- rejectIfLonger: true,
98
- rejectIfShorter: true,
99
- rejectEqualSequence: true,
100
- });
101
- return CPF.checksum(cpf.substring(0, 9)) === cpf.substring(9, 11);
108
+ static isValid(value) {
109
+ return CPF._matches(value) && CPF._check(CPF._normalize(value));
102
110
  }
103
- //
104
- //
105
- //
106
- //
107
- //
108
- //
109
111
  /**
110
- * fake()
112
+ * generate()
111
113
  * Gera um número válido
112
114
  *
113
115
  * @returns {String}
114
116
  */
115
- static fake() {
117
+ static generate() {
116
118
  const num = random_1.Random.number(9, true);
117
119
  return new CPF(`${num}${CPF.checksum(num)}`);
118
120
  }
121
+ /**
122
+ * @deprecated Use generate(). Será removido em uma versão futura.
123
+ */
124
+ static fake() {
125
+ return CPF.generate();
126
+ }
119
127
  /**
120
128
  * checksum()
121
129
  * Calcula o dígito verificador de um número SEM o dígito incluído
@@ -132,5 +140,41 @@ class CPF extends base_1.Base {
132
140
  const dv2 = (0, utils_1.sumToDV)(sum2);
133
141
  return `${dv1}${dv2}`;
134
142
  }
143
+ //
144
+ //
145
+ //
146
+ //
147
+ //
148
+ //
149
+ /**
150
+ * _matches()
151
+ * Confere se o valor segue o formato do CPF. Não aceita espaços nem barras.
152
+ * Usa a string original, por isso deve rodar antes do _normalize().
153
+ */
154
+ static _matches(value) {
155
+ return typeof value === 'string' && CPF._pattern.test(value);
156
+ }
157
+ /**
158
+ * _normalize()
159
+ * Remove os pontos e o hífen.
160
+ * Só deve receber um valor que já passou pelo _matches().
161
+ */
162
+ static _normalize(value) {
163
+ return value.replace(/[.-]/g, '');
164
+ }
165
+ /**
166
+ * _check()
167
+ * Rejeita sequências repetidas e compara os dígitos verificadores.
168
+ * Recebe o CPF normalizado, com 11 dígitos.
169
+ */
170
+ static _check(value) {
171
+ return (!(0, utils_1.checkRepeatedSequence)(value) &&
172
+ CPF.checksum(value.substring(0, 9)) === value.substring(9, 11));
173
+ }
135
174
  }
136
175
  exports.CPF = CPF;
176
+ /**
177
+ * Formato aceito: 11 dígitos, com ou sem os pontos e o hífen da máscara.
178
+ * Ex.: `123.456.789-09` ou `12345678909`
179
+ */
180
+ CPF._pattern = /^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/;
@@ -1,12 +1,53 @@
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
- protected normalize(): void;
9
- protected validate(): boolean;
10
- mask(): string;
8
+ get local(): string;
9
+ get domain(): string;
10
+ /**
11
+ * _matches()
12
+ * Confere o e-mail com as regras da isEmail(). Não aceita espaços, nem nas pontas.
13
+ * Usa a string original, por isso deve rodar antes do _normalize().
14
+ */
15
+ private static _matches;
16
+ /**
17
+ * _normalize()
18
+ * Converte para minúsculas. Só deve receber um valor que já passou pelo _matches().
19
+ */
20
+ private static _normalize;
21
+ /**
22
+ * Oculta parte do usuário (parte local) mantendo o domínio visível.
23
+ * Para local com até 2 caracteres exibe o 1º caractere + `***`;
24
+ * acima disso exibe os 2 primeiros + `***` + último caractere.
25
+ * Ex.: `fu***o@exemplo.com` / `a***@b.co`
26
+ */
27
+ redact(): string;
28
+ /**
29
+ * isValid()
30
+ * Diz se um valor é um e-mail válido, sem criar uma instância e sem lançar exceção.
31
+ * É o mesmo que a função isEmail().
32
+ *
33
+ * @example
34
+ * Email.isValid('fulano@exemplo.com') // -> true
35
+ * Email.isValid(' fulano@exemplo.com') // -> false
36
+ */
37
+ static isValid(value: string): boolean;
38
+ /**
39
+ * generate()
40
+ * Gera um e-mail válido aleatório.
41
+ */
42
+ static generate(): Email;
43
+ /**
44
+ * @deprecated Use generate(). Será removido em uma versão futura.
45
+ */
11
46
  static fake(): Email;
12
47
  }
48
+ /**
49
+ *
50
+ * Função base que verifica se um valor é e-mail
51
+ *
52
+ */
53
+ export declare function isEmail(value: string): boolean;
package/dist/cjs/email.js CHANGED
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Email = void 0;
7
- const ValidationBRError_1 = __importDefault(require("./_exceptions/ValidationBRError"));
4
+ exports.isEmail = isEmail;
5
+ const ValidationBRError_1 = require("./_exceptions/ValidationBRError");
8
6
  const random_1 = require("./_helpers/random");
9
7
  const base_1 = require("./base");
10
8
  class Email extends base_1.Base {
@@ -12,32 +10,132 @@ class Email extends base_1.Base {
12
10
  super(_value);
13
11
  this._value = _value;
14
12
  this._mask = null;
15
- this.normalize();
16
- if (!this.validate()) {
17
- throw new ValidationBRError_1.default('Email inválido');
13
+ this._local = '';
14
+ this._domain = '';
15
+ // O formato é conferido antes de qualquer limpeza, com o valor exatamente como chegou
16
+ if (!Email._matches(this._value)) {
17
+ throw new ValidationBRError_1.InvalidFormatException();
18
18
  }
19
+ this._value = Email._normalize(this._value);
20
+ const atIndex = this._value.indexOf('@');
21
+ this._local = this._value.slice(0, atIndex);
22
+ this._domain = this._value.slice(atIndex + 1);
19
23
  }
20
- get value() {
21
- return this._value;
24
+ get local() {
25
+ return this._local;
22
26
  }
23
- toString() {
24
- return this.value;
27
+ get domain() {
28
+ return this._domain;
25
29
  }
26
- normalize() {
27
- this._value = this._value.toLocaleLowerCase();
30
+ /**
31
+ * _matches()
32
+ * Confere o e-mail com as regras da isEmail(). Não aceita espaços, nem nas pontas.
33
+ * Usa a string original, por isso deve rodar antes do _normalize().
34
+ */
35
+ static _matches(value) {
36
+ return isEmail(value);
28
37
  }
29
- validate() {
30
- return /^[0-9a-z._+-]+@[0-9a-z._+-]+(\.[0-9a-z._+-]+)+$/i.test(this._value);
38
+ /**
39
+ * _normalize()
40
+ * Converte para minúsculas. Só deve receber um valor que já passou pelo _matches().
41
+ */
42
+ static _normalize(value) {
43
+ return value.toLowerCase();
31
44
  }
32
- mask() {
33
- throw new Error("Method not implemented.");
45
+ /**
46
+ * Oculta parte do usuário (parte local) mantendo o domínio visível.
47
+ * Para local com até 2 caracteres exibe o 1º caractere + `***`;
48
+ * acima disso exibe os 2 primeiros + `***` + último caractere.
49
+ * Ex.: `fu***o@exemplo.com` / `a***@b.co`
50
+ */
51
+ redact() {
52
+ if (this._local.length <= 2) {
53
+ return `${this._local[0]}***@${this._domain}`;
54
+ }
55
+ return `${this._local.slice(0, 2)}***${this._local.slice(-1)}@${this._domain}`;
34
56
  }
35
- //
57
+ //
36
58
  // STATIC
37
- //
38
- static fake() {
59
+ //
60
+ /**
61
+ * isValid()
62
+ * Diz se um valor é um e-mail válido, sem criar uma instância e sem lançar exceção.
63
+ * É o mesmo que a função isEmail().
64
+ *
65
+ * @example
66
+ * Email.isValid('fulano@exemplo.com') // -> true
67
+ * Email.isValid(' fulano@exemplo.com') // -> false
68
+ */
69
+ static isValid(value) {
70
+ return Email._matches(value);
71
+ }
72
+ /**
73
+ * generate()
74
+ * Gera um e-mail válido aleatório.
75
+ */
76
+ static generate() {
39
77
  const servers = ['gmail.com', 'hotmail.com'];
40
78
  return new Email(`${random_1.Random.alpha(10)}@${random_1.Random.fromArray(servers)}`);
41
79
  }
80
+ /**
81
+ * @deprecated Use generate(). Será removido em uma versão futura.
82
+ */
83
+ static fake() {
84
+ return Email.generate();
85
+ }
42
86
  }
43
87
  exports.Email = Email;
88
+ const ATEXT_PART = /^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+$/;
89
+ const DOMAIN_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
90
+ const TLD = /^(?:[a-z]{2,}|xn--[a-z0-9]{2,59})$/i;
91
+ /**
92
+ *
93
+ * Função base que verifica se um valor é e-mail
94
+ *
95
+ */
96
+ function isEmail(value) {
97
+ if (typeof value !== 'string')
98
+ return false;
99
+ // Sem trim(): espaço antes ou depois do e-mail o torna inválido (o laço abaixo rejeita)
100
+ const email = value;
101
+ if (email.length < 3 || email.length > 254)
102
+ return false;
103
+ for (let i = 0; i < email.length; i++) {
104
+ const code = email.charCodeAt(i);
105
+ if (code <= 32 || code === 127)
106
+ return false;
107
+ }
108
+ const atIndex = email.indexOf('@');
109
+ if (atIndex <= 0 || atIndex !== email.lastIndexOf('@'))
110
+ return false;
111
+ const local = email.slice(0, atIndex);
112
+ const domain = email.slice(atIndex + 1);
113
+ if (local.length < 1 || local.length > 64)
114
+ return false;
115
+ if (local.startsWith('.') || local.endsWith('.') || local.includes('..')) {
116
+ return false;
117
+ }
118
+ const localParts = local.split('.');
119
+ for (const part of localParts) {
120
+ if (!ATEXT_PART.test(part))
121
+ return false;
122
+ }
123
+ if (domain.length < 3 || domain.length > 253)
124
+ return false;
125
+ if (domain.startsWith('.') || domain.endsWith('.') || domain.includes('..')) {
126
+ return false;
127
+ }
128
+ const labels = domain.split('.');
129
+ if (labels.length < 2)
130
+ return false;
131
+ for (const label of labels) {
132
+ if (label.length < 1 || label.length > 63)
133
+ return false;
134
+ if (!DOMAIN_LABEL.test(label))
135
+ return false;
136
+ }
137
+ const tld = labels[labels.length - 1];
138
+ if (!TLD.test(tld))
139
+ return false;
140
+ return true;
141
+ }
@@ -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;
@@ -10,15 +11,17 @@ export declare function isNUP17(value: string): boolean;
10
11
  export declare function isPhone(value: string): boolean;
11
12
  export declare function isPIS(value: string): boolean;
12
13
  export declare function isPixKey(value: string): boolean;
14
+ /** @deprecated Use isPix(). Será removido em uma versão futura. */
13
15
  export declare function isPixCopyPaste(value: string): boolean;
16
+ export declare function isPix(value: string): boolean;
14
17
  export declare function isPostalTrackCode(value: string): boolean;
15
18
  export declare function isRenavam(value: string): boolean;
16
19
  export declare function isTituloEleitor(value: string): boolean;
17
- export declare function isEmail(value: string): boolean;
20
+ export { isEmail };
18
21
  export declare function isUUID(value: string): boolean;
19
22
  export declare function isBoleto(value: string): boolean;
20
23
  export declare function isCAEPF(value: string): boolean;
21
24
  export declare function isCEP(value: string): boolean;
22
25
  export declare function isCertidao(value: string): boolean;
23
- export declare function isCBISinter(value: string): boolean;
26
+ export declare function isCIB(value: string): boolean;
24
27
  export declare function isUF(value: string): boolean;
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CertidaoServico = exports.CertidaoTipoLivro = exports.PixKeys = void 0;
3
+ exports.isEmail = exports.CertidaoServico = exports.CertidaoTipoLivro = exports.PixKeys = void 0;
4
4
  exports.isCNH = isCNH;
5
5
  exports.isCNPJ = isCNPJ;
6
6
  exports.isCPF = isCPF;
@@ -11,16 +11,16 @@ exports.isPhone = isPhone;
11
11
  exports.isPIS = isPIS;
12
12
  exports.isPixKey = isPixKey;
13
13
  exports.isPixCopyPaste = isPixCopyPaste;
14
+ exports.isPix = isPix;
14
15
  exports.isPostalTrackCode = isPostalTrackCode;
15
16
  exports.isRenavam = isRenavam;
16
17
  exports.isTituloEleitor = isTituloEleitor;
17
- exports.isEmail = isEmail;
18
18
  exports.isUUID = isUUID;
19
19
  exports.isBoleto = isBoleto;
20
20
  exports.isCAEPF = isCAEPF;
21
21
  exports.isCEP = isCEP;
22
22
  exports.isCertidao = isCertidao;
23
- exports.isCBISinter = isCBISinter;
23
+ exports.isCIB = isCIB;
24
24
  exports.isUF = isUF;
25
25
  const cnh_1 = require("./cnh");
26
26
  const cnpj_1 = require("./cnpj");
@@ -33,18 +33,20 @@ const phone_1 = require("./phone");
33
33
  const pix_key_1 = require("./pix-key");
34
34
  Object.defineProperty(exports, "PixKeys", { enumerable: true, get: function () { return pix_key_1.PixKeys; } });
35
35
  const pix_copy_paste_1 = require("./pix-copy-paste");
36
+ const pix_1 = require("./pix");
36
37
  const judicial_process_1 = require("./judicial-process");
37
38
  const postal_track_code_1 = require("./postal-track-code");
38
39
  const tituloEleitor_1 = require("./tituloEleitor");
39
40
  const uuid_1 = require("./uuid");
40
41
  const email_1 = require("./email");
42
+ Object.defineProperty(exports, "isEmail", { enumerable: true, get: function () { return email_1.isEmail; } });
41
43
  const boleto_1 = require("./boleto");
42
44
  const caepf_1 = require("./caepf");
43
45
  const cep_1 = require("./cep");
44
46
  const certidao_1 = require("./certidao");
45
47
  Object.defineProperty(exports, "CertidaoTipoLivro", { enumerable: true, get: function () { return certidao_1.CertidaoTipoLivro; } });
46
48
  Object.defineProperty(exports, "CertidaoServico", { enumerable: true, get: function () { return certidao_1.CertidaoServico; } });
47
- const cbi_sinter_1 = require("./cbi_sinter");
49
+ const cib_1 = require("./cib");
48
50
  const uf_1 = require("./uf");
49
51
  function validate(fn) {
50
52
  try {
@@ -55,24 +57,25 @@ function validate(fn) {
55
57
  return false;
56
58
  }
57
59
  }
58
- function isCNH(value) { return validate(() => new cnh_1.CNH(value)); }
59
- function isCNPJ(value) { return validate(() => new cnpj_1.CNPJ(value)); }
60
- function isCPF(value) { return validate(() => new cpf_1.CPF(value)); }
61
- function isCarPlate(value) { return validate(() => new carplate_1.CarPlate(value)); }
62
- function isJudicialProcess(value) { return validate(() => new judicial_process_1.JudicialProcess(value)); }
63
- function isNUP17(value) { return validate(() => new nup17_1.NUP17(value)); }
64
- function isPhone(value) { return validate(() => new phone_1.Phone(value)); }
65
- function isPIS(value) { return validate(() => new pis_pasep_1.PIS(value)); }
66
- function isPixKey(value) { return validate(() => new pix_key_1.PixKey(value)); }
60
+ function isCNH(value) { return cnh_1.CNH.isValid(value); }
61
+ function isCNPJ(value) { return cnpj_1.CNPJ.isValid(value); }
62
+ function isCPF(value) { return cpf_1.CPF.isValid(value); }
63
+ function isCarPlate(value) { return carplate_1.CarPlate.isValid(value); }
64
+ function isJudicialProcess(value) { return judicial_process_1.JudicialProcess.isValid(value); }
65
+ function isNUP17(value) { return nup17_1.NUP17.isValid(value); }
66
+ function isPhone(value) { return phone_1.Phone.isValid(value); }
67
+ function isPIS(value) { return pis_pasep_1.PIS.isValid(value); }
68
+ function isPixKey(value) { return pix_key_1.PixKey.isValid(value); }
69
+ /** @deprecated Use isPix(). Será removido em uma versão futura. */
67
70
  function isPixCopyPaste(value) { return validate(() => new pix_copy_paste_1.PixCopyPaste(value)); }
68
- function isPostalTrackCode(value) { return validate(() => new postal_track_code_1.PostalTrackCode(value)); }
69
- function isRenavam(value) { return validate(() => new renavam_1.Renavam(value)); }
70
- function isTituloEleitor(value) { return validate(() => new tituloEleitor_1.TituloEleitor(value)); }
71
- function isEmail(value) { return validate(() => new email_1.Email(value)); }
72
- function isUUID(value) { return validate(() => new uuid_1.UUID(value)); }
73
- function isBoleto(value) { return validate(() => new boleto_1.Boleto(value)); }
74
- function isCAEPF(value) { return validate(() => new caepf_1.CAEPF(value)); }
75
- function isCEP(value) { return validate(() => new cep_1.CEP(value)); }
76
- function isCertidao(value) { return validate(() => new certidao_1.Certidao(value)); }
77
- function isCBISinter(value) { return validate(() => new cbi_sinter_1.CBISinter(value)); }
78
- function isUF(value) { return validate(() => new uf_1.UF(value)); }
71
+ function isPix(value) { return pix_1.Pix.isValid(value); }
72
+ function isPostalTrackCode(value) { return postal_track_code_1.PostalTrackCode.isValid(value); }
73
+ function isRenavam(value) { return renavam_1.Renavam.isValid(value); }
74
+ function isTituloEleitor(value) { return tituloEleitor_1.TituloEleitor.isValid(value); }
75
+ function isUUID(value) { return uuid_1.UUID.isValid(value); }
76
+ function isBoleto(value) { return boleto_1.Boleto.isValid(value); }
77
+ function isCAEPF(value) { return caepf_1.CAEPF.isValid(value); }
78
+ function isCEP(value) { return cep_1.CEP.isValid(value); }
79
+ function isCertidao(value) { return certidao_1.Certidao.isValid(value); }
80
+ function isCIB(value) { return cib_1.CIB.isValid(value); }
81
+ function isUF(value) { return uf_1.UF.isValid(value); }
@@ -87,6 +87,11 @@ export declare class JudicialProcess extends Base {
87
87
  _processNumber: string;
88
88
  _checksum: string;
89
89
  protected _mask: string;
90
+ /**
91
+ * Formato aceito: 20 dígitos, com ou sem o hífen e os pontos da máscara.
92
+ * Ex.: `0000001-80.2016.4.05.8400` ou `00000018020164058400`
93
+ */
94
+ private static readonly _pattern;
90
95
  constructor(_value: string);
91
96
  parse(): void;
92
97
  get processNumber(): string;
@@ -95,22 +100,32 @@ export declare class JudicialProcess extends Base {
95
100
  get court(): string;
96
101
  get subCourt(): string;
97
102
  get origin(): string;
98
- protected normalize(): void;
99
103
  /**
100
- * validate()
101
- * Valida se um número é válido e
102
- * retorna uma exceção se não estiver
104
+ * Oculta o número sequencial do processo e os dígitos verificadores,
105
+ * mantendo ano, segmento da justiça, tribunal e unidade de origem.
106
+ * Ex.: `*******-**.2016.4.05.8400`
107
+ */
108
+ redact(): string;
109
+ /**
110
+ * isValid()
111
+ * Diz se um valor é válido, sem criar uma instância e sem lançar exceção.
112
+ * Faz os mesmos passos do construtor: formato, limpeza e dígito verificador.
103
113
  *
104
- * @param {String|Number} value Número a ser validado
105
- * @returns {Boolean}
114
+ * @example
115
+ * JudicialProcess.isValid('6105283-83.2009.8.13.0024') // -> true
116
+ * JudicialProcess.isValid('6105283/83.2009.8.13.0024') // -> false
106
117
  */
107
- protected validate(): boolean;
118
+ static isValid(value: string): boolean;
108
119
  /**
109
- * fake()
120
+ * generate()
110
121
  * Gera um número válido
111
122
  *
112
123
  * @returns {String}
113
124
  */
125
+ static generate(options?: Partial<FakeOptions>): JudicialProcess;
126
+ /**
127
+ * @deprecated Use generate(). Será removido em uma versão futura.
128
+ */
114
129
  static fake(options?: Partial<FakeOptions>): JudicialProcess;
115
130
  /**
116
131
  * checksum()
@@ -140,6 +155,25 @@ export declare class JudicialProcess extends Base {
140
155
  private static validateSubCourt;
141
156
  private static validateOrigin;
142
157
  private static validateYear;
158
+ /**
159
+ * _matches()
160
+ * Confere se o valor segue o formato do processo judicial. Não aceita espaços nem barras.
161
+ * Usa a string original, por isso deve rodar antes do _normalize().
162
+ */
163
+ private static _matches;
164
+ /**
165
+ * _normalize()
166
+ * Remove o hífen e os pontos.
167
+ * Só deve receber um valor que já passou pelo _matches().
168
+ */
169
+ private static _normalize;
170
+ /**
171
+ * _check()
172
+ * Compara os dígitos verificadores (posições 8 e 9) com os calculados.
173
+ * Recebe o processo normalizado, com 20 dígitos.
174
+ * Lança erro se o código do órgão judiciário for 0.
175
+ */
176
+ private static _check;
143
177
  }
144
178
  interface FakeOptions {
145
179
  court?: string;