validation-br 2.2.0 → 2.6.0-beta.1

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 (118) 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 +12 -8
  8. package/dist/cjs/base.js +16 -0
  9. package/dist/cjs/boleto.d.ts +41 -7
  10. package/dist/cjs/boleto.js +58 -16
  11. package/dist/cjs/caepf.d.ts +36 -6
  12. package/dist/cjs/caepf.js +64 -25
  13. package/dist/cjs/carplate.d.ts +40 -7
  14. package/dist/cjs/carplate.js +61 -24
  15. package/dist/cjs/cbi_sinter.d.ts +9 -81
  16. package/dist/cjs/cbi_sinter.js +7 -127
  17. package/dist/cjs/cep.d.ts +39 -13
  18. package/dist/cjs/cep.js +73 -36
  19. package/dist/cjs/certidao.d.ts +44 -2
  20. package/dist/cjs/certidao.js +68 -15
  21. package/dist/cjs/cib.d.ts +166 -0
  22. package/dist/cjs/cib.js +232 -0
  23. package/dist/cjs/cnh.d.ts +37 -6
  24. package/dist/cjs/cnh.js +67 -28
  25. package/dist/cjs/cnpj.d.ts +37 -7
  26. package/dist/cjs/cnpj.js +65 -26
  27. package/dist/cjs/cpf.d.ts +38 -10
  28. package/dist/cjs/cpf.js +66 -30
  29. package/dist/cjs/email.d.ts +35 -3
  30. package/dist/cjs/email.js +56 -24
  31. package/dist/cjs/index.d.ts +4 -0
  32. package/dist/cjs/index.js +27 -20
  33. package/dist/cjs/judicial-process.d.ts +39 -11
  34. package/dist/cjs/judicial-process.js +71 -31
  35. package/dist/cjs/nup17.d.ts +35 -10
  36. package/dist/cjs/nup17.js +61 -31
  37. package/dist/cjs/phone.d.ts +48 -16
  38. package/dist/cjs/phone.js +81 -38
  39. package/dist/cjs/pis-pasep.d.ts +37 -10
  40. package/dist/cjs/pis-pasep.js +65 -30
  41. package/dist/cjs/pix-copy-paste.d.ts +4 -0
  42. package/dist/cjs/pix-copy-paste.js +4 -0
  43. package/dist/cjs/pix-key.d.ts +58 -4
  44. package/dist/cjs/pix-key.js +97 -44
  45. package/dist/cjs/pix.d.ts +193 -0
  46. package/dist/cjs/pix.js +191 -0
  47. package/dist/cjs/postal-track-code.d.ts +39 -15
  48. package/dist/cjs/postal-track-code.js +63 -35
  49. package/dist/cjs/renavam.d.ts +36 -12
  50. package/dist/cjs/renavam.js +64 -33
  51. package/dist/cjs/standard-schema/index.d.ts +7 -2
  52. package/dist/cjs/standard-schema/index.js +8 -3
  53. package/dist/cjs/tituloEleitor.d.ts +39 -10
  54. package/dist/cjs/tituloEleitor.js +74 -31
  55. package/dist/cjs/uf.d.ts +30 -2
  56. package/dist/cjs/uf.js +54 -25
  57. package/dist/cjs/uuid.d.ts +36 -2
  58. package/dist/cjs/uuid.js +56 -16
  59. package/dist/esm/_exceptions/ValidationBRError.d.ts +12 -0
  60. package/dist/esm/_exceptions/ValidationBRError.js +26 -0
  61. package/dist/esm/_helpers/pix-fields.d.ts +106 -0
  62. package/dist/esm/_helpers/pix-fields.js +292 -0
  63. package/dist/esm/_helpers/utils.d.ts +0 -1
  64. package/dist/esm/_helpers/utils.js +0 -1
  65. package/dist/esm/base.d.ts +12 -8
  66. package/dist/esm/base.js +16 -0
  67. package/dist/esm/boleto.d.ts +41 -7
  68. package/dist/esm/boleto.js +58 -16
  69. package/dist/esm/caepf.d.ts +36 -6
  70. package/dist/esm/caepf.js +66 -27
  71. package/dist/esm/carplate.d.ts +40 -7
  72. package/dist/esm/carplate.js +61 -24
  73. package/dist/esm/cbi_sinter.d.ts +9 -81
  74. package/dist/esm/cbi_sinter.js +5 -124
  75. package/dist/esm/cep.d.ts +39 -13
  76. package/dist/esm/cep.js +73 -36
  77. package/dist/esm/certidao.d.ts +44 -2
  78. package/dist/esm/certidao.js +68 -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 +37 -6
  82. package/dist/esm/cnh.js +69 -30
  83. package/dist/esm/cnpj.d.ts +37 -7
  84. package/dist/esm/cnpj.js +67 -28
  85. package/dist/esm/cpf.d.ts +38 -10
  86. package/dist/esm/cpf.js +68 -32
  87. package/dist/esm/email.d.ts +35 -3
  88. package/dist/esm/email.js +56 -21
  89. package/dist/esm/index.d.ts +4 -0
  90. package/dist/esm/index.js +25 -20
  91. package/dist/esm/judicial-process.d.ts +39 -11
  92. package/dist/esm/judicial-process.js +72 -32
  93. package/dist/esm/nup17.d.ts +35 -10
  94. package/dist/esm/nup17.js +63 -33
  95. package/dist/esm/phone.d.ts +48 -16
  96. package/dist/esm/phone.js +81 -38
  97. package/dist/esm/pis-pasep.d.ts +37 -10
  98. package/dist/esm/pis-pasep.js +67 -32
  99. package/dist/esm/pix-copy-paste.d.ts +4 -0
  100. package/dist/esm/pix-copy-paste.js +4 -0
  101. package/dist/esm/pix-key.d.ts +58 -4
  102. package/dist/esm/pix-key.js +97 -44
  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 +39 -15
  106. package/dist/esm/postal-track-code.js +64 -36
  107. package/dist/esm/renavam.d.ts +36 -12
  108. package/dist/esm/renavam.js +66 -35
  109. package/dist/esm/standard-schema/index.d.ts +7 -2
  110. package/dist/esm/standard-schema/index.js +7 -2
  111. package/dist/esm/tituloEleitor.d.ts +39 -10
  112. package/dist/esm/tituloEleitor.js +76 -33
  113. package/dist/esm/uf.d.ts +30 -2
  114. package/dist/esm/uf.js +55 -26
  115. package/dist/esm/uuid.d.ts +36 -2
  116. package/dist/esm/uuid.js +56 -13
  117. package/package.json +4 -2
  118. package/readme.md +166 -918
package/dist/cjs/cnpj.js CHANGED
@@ -88,8 +88,15 @@ class CNPJ extends base_1.Base {
88
88
  super(_value);
89
89
  this._value = _value;
90
90
  this._mask = '00.000.000/0000-00';
91
- this.normalize();
92
- if (!this.validate()) {
91
+ // O formato é conferido antes de qualquer limpeza, com o valor exatamente como chegou
92
+ if (!CNPJ._matches(this._value)) {
93
+ throw new ValidationBRError_1.InvalidFormatException();
94
+ }
95
+ this._value = CNPJ._normalize(this._value);
96
+ if ((0, utils_1.checkRepeatedSequence)(this._value)) {
97
+ throw new ValidationBRError_1.RepeatedSequenceException();
98
+ }
99
+ if (!CNPJ._check(this._value)) {
93
100
  throw new ValidationBRError_1.InvalidChecksumException();
94
101
  }
95
102
  }
@@ -97,29 +104,6 @@ class CNPJ extends base_1.Base {
97
104
  //
98
105
  //
99
106
  //
100
- //
101
- normalize() {
102
- this._value = this._value.replace(/[/.-]/g, '');
103
- }
104
- /**
105
- * validate()
106
- * Valida se um número é válido e
107
- * retorna uma exceção se não estiver
108
- *
109
- */
110
- validate() {
111
- const cnpj = (0, utils_1.clearValue)(this._value, 14, {
112
- rejectEmpty: true,
113
- rejectIfLonger: true,
114
- rejectIfShorter: true,
115
- rejectEqualSequence: true,
116
- });
117
- return CNPJ.checksum(cnpj.substring(0, 12)) === cnpj.substring(12, 14);
118
- }
119
- //
120
- //
121
- //
122
- //
123
107
  /**
124
108
  * Oculta os 5 primeiros dígitos da raiz e os 2 dígitos verificadores,
125
109
  * mantendo os 3 últimos dígitos da raiz e o número da filial.
@@ -128,6 +112,18 @@ class CNPJ extends base_1.Base {
128
112
  redact() {
129
113
  return `**.***.${this._value.slice(5, 8)}/${this._value.slice(8, 12)}-**`;
130
114
  }
115
+ /**
116
+ * isValid()
117
+ * Diz se um valor é válido, sem criar uma instância e sem lançar exceção.
118
+ * Faz os mesmos passos do construtor: formato, limpeza e dígito verificador.
119
+ *
120
+ * @example
121
+ * CNPJ.isValid('11.222.333/0001-81') // -> true
122
+ * CNPJ.isValid('11.222.333/0001-80') // -> false
123
+ */
124
+ static isValid(value) {
125
+ return CNPJ._matches(value) && CNPJ._check(CNPJ._normalize(value));
126
+ }
131
127
  /**
132
128
  * checksum()
133
129
  * Calcula o dígito verificador de um número SEM o dígito incluído
@@ -148,14 +144,57 @@ class CNPJ extends base_1.Base {
148
144
  *
149
145
  *
150
146
  */
151
- static fake(options = {}) {
147
+ static generate(options = {}) {
152
148
  var _a;
153
149
  const num = random_1.Random.number(8, true, (_a = options === null || options === void 0 ? void 0 : options.alphanumeric) !== null && _a !== void 0 ? _a : false);
154
150
  const fullNumber = `${num}0001`;
155
151
  return new CNPJ(`${fullNumber}${CNPJ.checksum(fullNumber)}`);
156
152
  }
153
+ /**
154
+ * @deprecated Use generate(). Será removido em uma versão futura.
155
+ */
156
+ static fake(options = {}) {
157
+ return CNPJ.generate(options);
158
+ }
159
+ //
160
+ //
161
+ //
162
+ //
163
+ //
164
+ //
165
+ /**
166
+ * _matches()
167
+ * Confere se o valor segue o formato do CNPJ. Não aceita espaços.
168
+ * Usa a string original, por isso deve rodar antes do _normalize().
169
+ */
170
+ static _matches(value) {
171
+ return typeof value === 'string' && CNPJ._pattern.test(value);
172
+ }
173
+ /**
174
+ * _normalize()
175
+ * Remove os pontos, a barra e o hífen e converte para maiúsculas.
176
+ * Só deve receber um valor que já passou pelo _matches().
177
+ */
178
+ static _normalize(value) {
179
+ return value.replace(/[./-]/g, '').toUpperCase();
180
+ }
181
+ /**
182
+ * _check()
183
+ * Rejeita sequências repetidas e compara o dígito verificador informado com o calculado.
184
+ * Recebe o valor normalizado, com 14 caracteres.
185
+ */
186
+ static _check(value) {
187
+ return (!(0, utils_1.checkRepeatedSequence)(value) &&
188
+ CNPJ.checksum(value.substring(0, 12)) === value.substring(12, 14));
189
+ }
157
190
  }
158
191
  exports.CNPJ = CNPJ;
192
+ /**
193
+ * 14 caracteres, com ou sem os pontos, a barra e o hífen da máscara.
194
+ * Os 12 primeiros podem ter letras (CNPJ alfanumérico); a flag `i` aceita minúsculas.
195
+ * Ex.: `11.222.333/0001-81` ou `12ABC34501DE35`
196
+ */
197
+ CNPJ._pattern = /^[0-9A-Z]{2}\.?[0-9A-Z]{3}\.?[0-9A-Z]{3}\/?[0-9A-Z]{4}-?\d{2}$/i;
159
198
  /**
160
199
  *
161
200
  * Converte o caractere para o seu equivalente na tabela ASCII e em seguida
package/dist/cjs/cpf.d.ts CHANGED
@@ -61,17 +61,12 @@ import { Base } from './base';
61
61
  export declare class CPF extends Base {
62
62
  protected _value: string;
63
63
  protected _mask: string;
64
- constructor(_value: string);
65
- protected normalize(): void;
66
64
  /**
67
- * validate()
68
- * Valida se um número é válido e
69
- * retorna uma exceção se não estiver
70
- *
71
- * @param {String|Number} value Número a ser validado
72
- * @returns {Boolean}
65
+ * Formato aceito: 11 dígitos, com ou sem os pontos e o hífen da máscara.
66
+ * Ex.: `123.456.789-09` ou `12345678909`
73
67
  */
74
- protected validate(): boolean;
68
+ private static readonly _pattern;
69
+ constructor(_value: string);
75
70
  /**
76
71
  * Oculta os 3 primeiros dígitos e os 2 dígitos verificadores (padrão Bacen / CGU),
77
72
  * mantendo os 6 dígitos centrais.
@@ -79,11 +74,26 @@ export declare class CPF extends Base {
79
74
  */
80
75
  redact(): string;
81
76
  /**
82
- * fake()
77
+ * isValid()
78
+ * Diz se um valor é válido, sem criar uma instância e sem lançar exceção.
79
+ * Faz os mesmos passos do construtor: formato, limpeza e dígito verificador.
80
+ *
81
+ * @example
82
+ * CPF.isValid('133.782.710-00') // -> true
83
+ * CPF.isValid(' 133.782.710-00') // -> false
84
+ * CPF.isValid('111.111.111-11') // -> false
85
+ */
86
+ static isValid(value: string): boolean;
87
+ /**
88
+ * generate()
83
89
  * Gera um número válido
84
90
  *
85
91
  * @returns {String}
86
92
  */
93
+ static generate(): CPF;
94
+ /**
95
+ * @deprecated Use generate(). Será removido em uma versão futura.
96
+ */
87
97
  static fake(): CPF;
88
98
  /**
89
99
  * checksum()
@@ -91,4 +101,22 @@ export declare class CPF extends Base {
91
101
  *
92
102
  */
93
103
  static checksum(value: string): string;
104
+ /**
105
+ * _matches()
106
+ * Confere se o valor segue o formato do CPF. Não aceita espaços nem barras.
107
+ * Usa a string original, por isso deve rodar antes do _normalize().
108
+ */
109
+ private static _matches;
110
+ /**
111
+ * _normalize()
112
+ * Remove os pontos e o hífen.
113
+ * Só deve receber um valor que já passou pelo _matches().
114
+ */
115
+ private static _normalize;
116
+ /**
117
+ * _check()
118
+ * Rejeita sequências repetidas e compara os dígitos verificadores.
119
+ * Recebe o CPF normalizado, com 11 dígitos.
120
+ */
121
+ private static _check;
94
122
  }
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,32 +87,6 @@ class CPF extends base_1.Base {
80
87
  //
81
88
  //
82
89
  //
83
- normalize() {
84
- this._value = this._value.replace(/([.-])/g, '');
85
- }
86
- /**
87
- * validate()
88
- * Valida se um número é válido e
89
- * retorna uma exceção se não estiver
90
- *
91
- * @param {String|Number} value Número a ser validado
92
- * @returns {Boolean}
93
- */
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);
102
- }
103
- //
104
- //
105
- //
106
- //
107
- //
108
- //
109
90
  /**
110
91
  * Oculta os 3 primeiros dígitos e os 2 dígitos verificadores (padrão Bacen / CGU),
111
92
  * mantendo os 6 dígitos centrais.
@@ -115,15 +96,34 @@ class CPF extends base_1.Base {
115
96
  return `***.${this._value.slice(3, 6)}.${this._value.slice(6, 9)}-**`;
116
97
  }
117
98
  /**
118
- * fake()
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.
102
+ *
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
107
+ */
108
+ static isValid(value) {
109
+ return CPF._matches(value) && CPF._check(CPF._normalize(value));
110
+ }
111
+ /**
112
+ * generate()
119
113
  * Gera um número válido
120
114
  *
121
115
  * @returns {String}
122
116
  */
123
- static fake() {
117
+ static generate() {
124
118
  const num = random_1.Random.number(9, true);
125
119
  return new CPF(`${num}${CPF.checksum(num)}`);
126
120
  }
121
+ /**
122
+ * @deprecated Use generate(). Será removido em uma versão futura.
123
+ */
124
+ static fake() {
125
+ return CPF.generate();
126
+ }
127
127
  /**
128
128
  * checksum()
129
129
  * Calcula o dígito verificador de um número SEM o dígito incluído
@@ -140,5 +140,41 @@ class CPF extends base_1.Base {
140
140
  const dv2 = (0, utils_1.sumToDV)(sum2);
141
141
  return `${dv1}${dv2}`;
142
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
+ }
143
174
  }
144
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}$/;
@@ -7,15 +7,47 @@ export declare class Email extends Base {
7
7
  constructor(_value: string);
8
8
  get local(): string;
9
9
  get domain(): string;
10
- protected normalize(): void;
11
- protected validate(): boolean;
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;
12
21
  /**
13
22
  * Oculta parte do usuário (parte local) mantendo o domínio visível.
14
23
  * Para local com até 2 caracteres exibe o 1º caractere + `***`;
15
24
  * acima disso exibe os 2 primeiros + `***` + último caractere.
16
- * Ex.: `kl***o@gmail.com` / `a***@b.co`
25
+ * Ex.: `fu***o@exemplo.com` / `a***@b.co`
17
26
  */
18
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
+ */
19
46
  static fake(): Email;
20
47
  }
48
+ /**
49
+ *
50
+ * Função base que verifica se um valor é e-mail
51
+ *
52
+ */
21
53
  export declare function isEmail(value: string): boolean;
package/dist/cjs/email.js CHANGED
@@ -1,11 +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
4
  exports.isEmail = isEmail;
8
- const ValidationBRError_1 = __importDefault(require("./_exceptions/ValidationBRError"));
5
+ const ValidationBRError_1 = require("./_exceptions/ValidationBRError");
9
6
  const random_1 = require("./_helpers/random");
10
7
  const base_1 = require("./base");
11
8
  class Email extends base_1.Base {
@@ -15,13 +12,11 @@ class Email extends base_1.Base {
15
12
  this._mask = null;
16
13
  this._local = '';
17
14
  this._domain = '';
18
- if (typeof _value !== 'string') {
19
- throw new ValidationBRError_1.default('Email inválido');
20
- }
21
- this.normalize();
22
- if (!this.validate()) {
23
- throw new ValidationBRError_1.default('Email inválido');
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();
24
18
  }
19
+ this._value = Email._normalize(this._value);
25
20
  const atIndex = this._value.indexOf('@');
26
21
  this._local = this._value.slice(0, atIndex);
27
22
  this._domain = this._value.slice(atIndex + 1);
@@ -32,17 +27,26 @@ class Email extends base_1.Base {
32
27
  get domain() {
33
28
  return this._domain;
34
29
  }
35
- normalize() {
36
- this._value = this._value.trim().toLowerCase();
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);
37
37
  }
38
- validate() {
39
- return isEmail(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();
40
44
  }
41
45
  /**
42
46
  * Oculta parte do usuário (parte local) mantendo o domínio visível.
43
47
  * Para local com até 2 caracteres exibe o 1º caractere + `***`;
44
48
  * acima disso exibe os 2 primeiros + `***` + último caractere.
45
- * Ex.: `kl***o@gmail.com` / `a***@b.co`
49
+ * Ex.: `fu***o@exemplo.com` / `a***@b.co`
46
50
  */
47
51
  redact() {
48
52
  if (this._local.length <= 2) {
@@ -53,31 +57,59 @@ class Email extends base_1.Base {
53
57
  //
54
58
  // STATIC
55
59
  //
56
- static fake() {
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() {
57
77
  const servers = ['gmail.com', 'hotmail.com'];
58
78
  return new Email(`${random_1.Random.alpha(10)}@${random_1.Random.fromArray(servers)}`);
59
79
  }
80
+ /**
81
+ * @deprecated Use generate(). Será removido em uma versão futura.
82
+ */
83
+ static fake() {
84
+ return Email.generate();
85
+ }
60
86
  }
61
87
  exports.Email = Email;
62
88
  const ATEXT_PART = /^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+$/;
63
89
  const DOMAIN_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
64
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
+ */
65
96
  function isEmail(value) {
66
97
  if (typeof value !== 'string')
67
98
  return false;
68
- const trimmed = value.trim();
69
- if (trimmed.length < 3 || trimmed.length > 254)
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)
70
102
  return false;
71
- for (let i = 0; i < trimmed.length; i++) {
72
- const code = trimmed.charCodeAt(i);
103
+ for (let i = 0; i < email.length; i++) {
104
+ const code = email.charCodeAt(i);
73
105
  if (code <= 32 || code === 127)
74
106
  return false;
75
107
  }
76
- const atIndex = trimmed.indexOf('@');
77
- if (atIndex <= 0 || atIndex !== trimmed.lastIndexOf('@'))
108
+ const atIndex = email.indexOf('@');
109
+ if (atIndex <= 0 || atIndex !== email.lastIndexOf('@'))
78
110
  return false;
79
- const local = trimmed.slice(0, atIndex);
80
- const domain = trimmed.slice(atIndex + 1);
111
+ const local = email.slice(0, atIndex);
112
+ const domain = email.slice(atIndex + 1);
81
113
  if (local.length < 1 || local.length > 64)
82
114
  return false;
83
115
  if (local.startsWith('.') || local.endsWith('.') || local.includes('..')) {
@@ -11,7 +11,9 @@ export declare function isNUP17(value: string): boolean;
11
11
  export declare function isPhone(value: string): boolean;
12
12
  export declare function isPIS(value: string): boolean;
13
13
  export declare function isPixKey(value: string): boolean;
14
+ /** @deprecated Use isPix(). Será removido em uma versão futura. */
14
15
  export declare function isPixCopyPaste(value: string): boolean;
16
+ export declare function isPix(value: string): boolean;
15
17
  export declare function isPostalTrackCode(value: string): boolean;
16
18
  export declare function isRenavam(value: string): boolean;
17
19
  export declare function isTituloEleitor(value: string): boolean;
@@ -21,5 +23,7 @@ export declare function isBoleto(value: string): boolean;
21
23
  export declare function isCAEPF(value: string): boolean;
22
24
  export declare function isCEP(value: string): boolean;
23
25
  export declare function isCertidao(value: string): boolean;
26
+ export declare function isCIB(value: string): boolean;
27
+ /** @deprecated Use isCIB(). Será removido em uma versão futura. */
24
28
  export declare function isCBISinter(value: string): boolean;
25
29
  export declare function isUF(value: string): boolean;
package/dist/cjs/index.js CHANGED
@@ -11,6 +11,7 @@ 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;
@@ -19,6 +20,7 @@ exports.isBoleto = isBoleto;
19
20
  exports.isCAEPF = isCAEPF;
20
21
  exports.isCEP = isCEP;
21
22
  exports.isCertidao = isCertidao;
23
+ exports.isCIB = isCIB;
22
24
  exports.isCBISinter = isCBISinter;
23
25
  exports.isUF = isUF;
24
26
  const cnh_1 = require("./cnh");
@@ -32,6 +34,7 @@ const phone_1 = require("./phone");
32
34
  const pix_key_1 = require("./pix-key");
33
35
  Object.defineProperty(exports, "PixKeys", { enumerable: true, get: function () { return pix_key_1.PixKeys; } });
34
36
  const pix_copy_paste_1 = require("./pix-copy-paste");
37
+ const pix_1 = require("./pix");
35
38
  const judicial_process_1 = require("./judicial-process");
36
39
  const postal_track_code_1 = require("./postal-track-code");
37
40
  const tituloEleitor_1 = require("./tituloEleitor");
@@ -44,7 +47,7 @@ const cep_1 = require("./cep");
44
47
  const certidao_1 = require("./certidao");
45
48
  Object.defineProperty(exports, "CertidaoTipoLivro", { enumerable: true, get: function () { return certidao_1.CertidaoTipoLivro; } });
46
49
  Object.defineProperty(exports, "CertidaoServico", { enumerable: true, get: function () { return certidao_1.CertidaoServico; } });
47
- const cbi_sinter_1 = require("./cbi_sinter");
50
+ const cib_1 = require("./cib");
48
51
  const uf_1 = require("./uf");
49
52
  function validate(fn) {
50
53
  try {
@@ -55,23 +58,27 @@ function validate(fn) {
55
58
  return false;
56
59
  }
57
60
  }
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)); }
61
+ function isCNH(value) { return cnh_1.CNH.isValid(value); }
62
+ function isCNPJ(value) { return cnpj_1.CNPJ.isValid(value); }
63
+ function isCPF(value) { return cpf_1.CPF.isValid(value); }
64
+ function isCarPlate(value) { return carplate_1.CarPlate.isValid(value); }
65
+ function isJudicialProcess(value) { return judicial_process_1.JudicialProcess.isValid(value); }
66
+ function isNUP17(value) { return nup17_1.NUP17.isValid(value); }
67
+ function isPhone(value) { return phone_1.Phone.isValid(value); }
68
+ function isPIS(value) { return pis_pasep_1.PIS.isValid(value); }
69
+ function isPixKey(value) { return pix_key_1.PixKey.isValid(value); }
70
+ /** @deprecated Use isPix(). Será removido em uma versão futura. */
67
71
  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 isUUID(value) { return validate(() => new uuid_1.UUID(value)); }
72
- function isBoleto(value) { return validate(() => new boleto_1.Boleto(value)); }
73
- function isCAEPF(value) { return validate(() => new caepf_1.CAEPF(value)); }
74
- function isCEP(value) { return validate(() => new cep_1.CEP(value)); }
75
- function isCertidao(value) { return validate(() => new certidao_1.Certidao(value)); }
76
- function isCBISinter(value) { return validate(() => new cbi_sinter_1.CBISinter(value)); }
77
- function isUF(value) { return validate(() => new uf_1.UF(value)); }
72
+ function isPix(value) { return pix_1.Pix.isValid(value); }
73
+ function isPostalTrackCode(value) { return postal_track_code_1.PostalTrackCode.isValid(value); }
74
+ function isRenavam(value) { return renavam_1.Renavam.isValid(value); }
75
+ function isTituloEleitor(value) { return tituloEleitor_1.TituloEleitor.isValid(value); }
76
+ function isUUID(value) { return uuid_1.UUID.isValid(value); }
77
+ function isBoleto(value) { return boleto_1.Boleto.isValid(value); }
78
+ function isCAEPF(value) { return caepf_1.CAEPF.isValid(value); }
79
+ function isCEP(value) { return cep_1.CEP.isValid(value); }
80
+ function isCertidao(value) { return certidao_1.Certidao.isValid(value); }
81
+ function isCIB(value) { return cib_1.CIB.isValid(value); }
82
+ /** @deprecated Use isCIB(). Será removido em uma versão futura. */
83
+ function isCBISinter(value) { return cib_1.CIB.isValid(value); }
84
+ function isUF(value) { return uf_1.UF.isValid(value); }