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.
- package/dist/cjs/_exceptions/ValidationBRError.d.ts +12 -0
- package/dist/cjs/_exceptions/ValidationBRError.js +30 -1
- package/dist/cjs/_helpers/pix-fields.d.ts +106 -0
- package/dist/cjs/_helpers/pix-fields.js +296 -0
- package/dist/cjs/_helpers/utils.d.ts +0 -1
- package/dist/cjs/_helpers/utils.js +0 -1
- package/dist/cjs/base.d.ts +14 -6
- package/dist/cjs/base.js +16 -0
- package/dist/cjs/boleto.d.ts +47 -7
- package/dist/cjs/boleto.js +67 -16
- package/dist/cjs/caepf.d.ts +41 -5
- package/dist/cjs/caepf.js +68 -21
- package/dist/cjs/carplate.d.ts +45 -7
- package/dist/cjs/carplate.js +68 -24
- package/dist/cjs/cep.d.ts +43 -11
- package/dist/cjs/cep.js +73 -28
- package/dist/cjs/certidao.d.ts +50 -2
- package/dist/cjs/certidao.js +76 -15
- package/dist/cjs/cib.d.ts +166 -0
- package/dist/cjs/cib.js +232 -0
- package/dist/cjs/cnh.d.ts +43 -6
- package/dist/cjs/cnh.js +71 -24
- package/dist/cjs/cnpj.d.ts +41 -5
- package/dist/cjs/cnpj.js +68 -21
- package/dist/cjs/cpf.d.ts +42 -8
- package/dist/cjs/cpf.js +69 -25
- package/dist/cjs/email.d.ts +47 -6
- package/dist/cjs/email.js +118 -20
- package/dist/cjs/index.d.ts +5 -2
- package/dist/cjs/index.js +27 -24
- package/dist/cjs/judicial-process.d.ts +42 -8
- package/dist/cjs/judicial-process.js +74 -26
- package/dist/cjs/nup17.d.ts +35 -9
- package/dist/cjs/nup17.js +62 -26
- package/dist/cjs/phone.d.ts +52 -14
- package/dist/cjs/phone.js +87 -35
- package/dist/cjs/pis-pasep.d.ts +41 -8
- package/dist/cjs/pis-pasep.js +68 -25
- package/dist/cjs/pix-copy-paste.d.ts +10 -0
- package/dist/cjs/pix-copy-paste.js +12 -0
- package/dist/cjs/pix-key.d.ts +63 -4
- package/dist/cjs/pix-key.js +103 -32
- package/dist/cjs/pix.d.ts +193 -0
- package/dist/cjs/pix.js +191 -0
- package/dist/cjs/postal-track-code.d.ts +42 -12
- package/dist/cjs/postal-track-code.js +68 -32
- package/dist/cjs/renavam.d.ts +38 -8
- package/dist/cjs/renavam.js +67 -28
- package/dist/cjs/standard-schema/create-schema.d.ts +5 -0
- package/dist/cjs/standard-schema/create-schema.js +87 -0
- package/dist/cjs/standard-schema/index.d.ts +48 -0
- package/dist/cjs/standard-schema/index.js +50 -0
- package/dist/cjs/standard-schema/types.d.ts +58 -0
- package/dist/cjs/standard-schema/types.js +2 -0
- package/dist/cjs/tituloEleitor.d.ts +43 -8
- package/dist/cjs/tituloEleitor.js +78 -27
- package/dist/cjs/uf.d.ts +35 -2
- package/dist/cjs/uf.js +61 -25
- package/dist/cjs/uuid.d.ts +42 -2
- package/dist/cjs/uuid.js +62 -14
- package/dist/esm/_exceptions/ValidationBRError.d.ts +12 -0
- package/dist/esm/_exceptions/ValidationBRError.js +26 -0
- package/dist/esm/_helpers/pix-fields.d.ts +106 -0
- package/dist/esm/_helpers/pix-fields.js +292 -0
- package/dist/esm/_helpers/utils.d.ts +0 -1
- package/dist/esm/_helpers/utils.js +0 -1
- package/dist/esm/base.d.ts +14 -6
- package/dist/esm/base.js +16 -0
- package/dist/esm/boleto.d.ts +47 -7
- package/dist/esm/boleto.js +67 -16
- package/dist/esm/caepf.d.ts +41 -5
- package/dist/esm/caepf.js +70 -23
- package/dist/esm/carplate.d.ts +45 -7
- package/dist/esm/carplate.js +68 -24
- package/dist/esm/cep.d.ts +43 -11
- package/dist/esm/cep.js +73 -28
- package/dist/esm/certidao.d.ts +50 -2
- package/dist/esm/certidao.js +76 -15
- package/dist/esm/cib.d.ts +166 -0
- package/dist/esm/cib.js +228 -0
- package/dist/esm/cnh.d.ts +43 -6
- package/dist/esm/cnh.js +73 -26
- package/dist/esm/cnpj.d.ts +41 -5
- package/dist/esm/cnpj.js +70 -23
- package/dist/esm/cpf.d.ts +42 -8
- package/dist/esm/cpf.js +71 -27
- package/dist/esm/email.d.ts +47 -6
- package/dist/esm/email.js +119 -19
- package/dist/esm/index.d.ts +5 -2
- package/dist/esm/index.js +25 -22
- package/dist/esm/judicial-process.d.ts +42 -8
- package/dist/esm/judicial-process.js +75 -27
- package/dist/esm/nup17.d.ts +35 -9
- package/dist/esm/nup17.js +64 -28
- package/dist/esm/phone.d.ts +52 -14
- package/dist/esm/phone.js +87 -35
- package/dist/esm/pis-pasep.d.ts +41 -8
- package/dist/esm/pis-pasep.js +70 -27
- package/dist/esm/pix-copy-paste.d.ts +10 -0
- package/dist/esm/pix-copy-paste.js +12 -0
- package/dist/esm/pix-key.d.ts +63 -4
- package/dist/esm/pix-key.js +103 -32
- package/dist/esm/pix.d.ts +193 -0
- package/dist/esm/pix.js +187 -0
- package/dist/esm/postal-track-code.d.ts +42 -12
- package/dist/esm/postal-track-code.js +69 -33
- package/dist/esm/renavam.d.ts +38 -8
- package/dist/esm/renavam.js +69 -30
- package/dist/esm/standard-schema/create-schema.d.ts +5 -0
- package/dist/esm/standard-schema/create-schema.js +50 -0
- package/dist/esm/standard-schema/index.d.ts +48 -0
- package/dist/esm/standard-schema/index.js +47 -0
- package/dist/esm/standard-schema/types.d.ts +58 -0
- package/dist/esm/standard-schema/types.js +1 -0
- package/dist/esm/tituloEleitor.d.ts +43 -8
- package/dist/esm/tituloEleitor.js +80 -29
- package/dist/esm/uf.d.ts +35 -2
- package/dist/esm/uf.js +62 -26
- package/dist/esm/uuid.d.ts +42 -2
- package/dist/esm/uuid.js +62 -11
- package/package.json +12 -3
- package/readme.md +158 -860
- package/dist/cjs/cbi_sinter.d.ts +0 -78
- package/dist/cjs/cbi_sinter.js +0 -123
- package/dist/esm/cbi_sinter.d.ts +0 -78
- package/dist/esm/cbi_sinter.js +0 -119
package/dist/esm/cpf.js
CHANGED
|
@@ -57,17 +57,24 @@
|
|
|
57
57
|
* @param {String} value Título eleitoral
|
|
58
58
|
* @returns {Boolean}
|
|
59
59
|
*/
|
|
60
|
-
import { EmptyValueException, InvalidChecksumException, InvalidFormatException } from './_exceptions/ValidationBRError.js';
|
|
60
|
+
import { EmptyValueException, InvalidChecksumException, InvalidFormatException, RepeatedSequenceException, } from './_exceptions/ValidationBRError.js';
|
|
61
61
|
import { Random } from './_helpers/random.js';
|
|
62
62
|
import { Base } from './base.js';
|
|
63
|
-
import { sumElementsByMultipliers, sumToDV,
|
|
63
|
+
import { sumElementsByMultipliers, sumToDV, checkRepeatedSequence, } from './_helpers/utils.js';
|
|
64
64
|
export class CPF extends Base {
|
|
65
65
|
constructor(_value) {
|
|
66
66
|
super(_value);
|
|
67
67
|
this._value = _value;
|
|
68
68
|
this._mask = '000.000.000-00';
|
|
69
|
-
|
|
70
|
-
if (!this.
|
|
69
|
+
// O formato é conferido antes de qualquer limpeza, com o valor exatamente como chegou
|
|
70
|
+
if (!CPF._matches(this._value)) {
|
|
71
|
+
throw new InvalidFormatException();
|
|
72
|
+
}
|
|
73
|
+
this._value = CPF._normalize(this._value);
|
|
74
|
+
if (checkRepeatedSequence(this._value)) {
|
|
75
|
+
throw new RepeatedSequenceException();
|
|
76
|
+
}
|
|
77
|
+
if (!CPF._check(this._value)) {
|
|
71
78
|
throw new InvalidChecksumException();
|
|
72
79
|
}
|
|
73
80
|
}
|
|
@@ -77,42 +84,43 @@ export class CPF extends Base {
|
|
|
77
84
|
//
|
|
78
85
|
//
|
|
79
86
|
//
|
|
80
|
-
|
|
81
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Oculta os 3 primeiros dígitos e os 2 dígitos verificadores (padrão Bacen / CGU),
|
|
89
|
+
* mantendo os 6 dígitos centrais.
|
|
90
|
+
* Ex.: `***.782.710-**`
|
|
91
|
+
*/
|
|
92
|
+
redact() {
|
|
93
|
+
return `***.${this._value.slice(3, 6)}.${this._value.slice(6, 9)}-**`;
|
|
82
94
|
}
|
|
83
95
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
96
|
+
* isValid()
|
|
97
|
+
* Diz se um valor é válido, sem criar uma instância e sem lançar exceção.
|
|
98
|
+
* Faz os mesmos passos do construtor: formato, limpeza e dígito verificador.
|
|
87
99
|
*
|
|
88
|
-
* @
|
|
89
|
-
*
|
|
100
|
+
* @example
|
|
101
|
+
* CPF.isValid('133.782.710-00') // -> true
|
|
102
|
+
* CPF.isValid(' 133.782.710-00') // -> false
|
|
103
|
+
* CPF.isValid('111.111.111-11') // -> false
|
|
90
104
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
rejectEmpty: true,
|
|
94
|
-
rejectIfLonger: true,
|
|
95
|
-
rejectIfShorter: true,
|
|
96
|
-
rejectEqualSequence: true,
|
|
97
|
-
});
|
|
98
|
-
return CPF.checksum(cpf.substring(0, 9)) === cpf.substring(9, 11);
|
|
105
|
+
static isValid(value) {
|
|
106
|
+
return CPF._matches(value) && CPF._check(CPF._normalize(value));
|
|
99
107
|
}
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
108
|
/**
|
|
107
|
-
*
|
|
109
|
+
* generate()
|
|
108
110
|
* Gera um número válido
|
|
109
111
|
*
|
|
110
112
|
* @returns {String}
|
|
111
113
|
*/
|
|
112
|
-
static
|
|
114
|
+
static generate() {
|
|
113
115
|
const num = Random.number(9, true);
|
|
114
116
|
return new CPF(`${num}${CPF.checksum(num)}`);
|
|
115
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* @deprecated Use generate(). Será removido em uma versão futura.
|
|
120
|
+
*/
|
|
121
|
+
static fake() {
|
|
122
|
+
return CPF.generate();
|
|
123
|
+
}
|
|
116
124
|
/**
|
|
117
125
|
* checksum()
|
|
118
126
|
* Calcula o dígito verificador de um número SEM o dígito incluído
|
|
@@ -129,4 +137,40 @@ export class CPF extends Base {
|
|
|
129
137
|
const dv2 = sumToDV(sum2);
|
|
130
138
|
return `${dv1}${dv2}`;
|
|
131
139
|
}
|
|
140
|
+
//
|
|
141
|
+
//
|
|
142
|
+
//
|
|
143
|
+
//
|
|
144
|
+
//
|
|
145
|
+
//
|
|
146
|
+
/**
|
|
147
|
+
* _matches()
|
|
148
|
+
* Confere se o valor segue o formato do CPF. Não aceita espaços nem barras.
|
|
149
|
+
* Usa a string original, por isso deve rodar antes do _normalize().
|
|
150
|
+
*/
|
|
151
|
+
static _matches(value) {
|
|
152
|
+
return typeof value === 'string' && CPF._pattern.test(value);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* _normalize()
|
|
156
|
+
* Remove os pontos e o hífen.
|
|
157
|
+
* Só deve receber um valor que já passou pelo _matches().
|
|
158
|
+
*/
|
|
159
|
+
static _normalize(value) {
|
|
160
|
+
return value.replace(/[.-]/g, '');
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* _check()
|
|
164
|
+
* Rejeita sequências repetidas e compara os dígitos verificadores.
|
|
165
|
+
* Recebe o CPF normalizado, com 11 dígitos.
|
|
166
|
+
*/
|
|
167
|
+
static _check(value) {
|
|
168
|
+
return (!checkRepeatedSequence(value) &&
|
|
169
|
+
CPF.checksum(value.substring(0, 9)) === value.substring(9, 11));
|
|
170
|
+
}
|
|
132
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Formato aceito: 11 dígitos, com ou sem os pontos e o hífen da máscara.
|
|
174
|
+
* Ex.: `123.456.789-09` ou `12345678909`
|
|
175
|
+
*/
|
|
176
|
+
CPF._pattern = /^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/;
|
package/dist/esm/email.d.ts
CHANGED
|
@@ -1,12 +1,53 @@
|
|
|
1
|
-
import { Base } from
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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/esm/email.js
CHANGED
|
@@ -1,36 +1,136 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Random } from
|
|
3
|
-
import { Base } from
|
|
1
|
+
import { InvalidFormatException } 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.
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
this._local = '';
|
|
10
|
+
this._domain = '';
|
|
11
|
+
// O formato é conferido antes de qualquer limpeza, com o valor exatamente como chegou
|
|
12
|
+
if (!Email._matches(this._value)) {
|
|
13
|
+
throw new InvalidFormatException();
|
|
12
14
|
}
|
|
15
|
+
this._value = Email._normalize(this._value);
|
|
16
|
+
const atIndex = this._value.indexOf('@');
|
|
17
|
+
this._local = this._value.slice(0, atIndex);
|
|
18
|
+
this._domain = this._value.slice(atIndex + 1);
|
|
13
19
|
}
|
|
14
|
-
get
|
|
15
|
-
return this.
|
|
20
|
+
get local() {
|
|
21
|
+
return this._local;
|
|
16
22
|
}
|
|
17
|
-
|
|
18
|
-
return this.
|
|
23
|
+
get domain() {
|
|
24
|
+
return this._domain;
|
|
19
25
|
}
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
/**
|
|
27
|
+
* _matches()
|
|
28
|
+
* Confere o e-mail com as regras da isEmail(). Não aceita espaços, nem nas pontas.
|
|
29
|
+
* Usa a string original, por isso deve rodar antes do _normalize().
|
|
30
|
+
*/
|
|
31
|
+
static _matches(value) {
|
|
32
|
+
return isEmail(value);
|
|
22
33
|
}
|
|
23
|
-
|
|
24
|
-
|
|
34
|
+
/**
|
|
35
|
+
* _normalize()
|
|
36
|
+
* Converte para minúsculas. Só deve receber um valor que já passou pelo _matches().
|
|
37
|
+
*/
|
|
38
|
+
static _normalize(value) {
|
|
39
|
+
return value.toLowerCase();
|
|
25
40
|
}
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Oculta parte do usuário (parte local) mantendo o domínio visível.
|
|
43
|
+
* Para local com até 2 caracteres exibe o 1º caractere + `***`;
|
|
44
|
+
* acima disso exibe os 2 primeiros + `***` + último caractere.
|
|
45
|
+
* Ex.: `fu***o@exemplo.com` / `a***@b.co`
|
|
46
|
+
*/
|
|
47
|
+
redact() {
|
|
48
|
+
if (this._local.length <= 2) {
|
|
49
|
+
return `${this._local[0]}***@${this._domain}`;
|
|
50
|
+
}
|
|
51
|
+
return `${this._local.slice(0, 2)}***${this._local.slice(-1)}@${this._domain}`;
|
|
28
52
|
}
|
|
29
|
-
//
|
|
53
|
+
//
|
|
30
54
|
// STATIC
|
|
31
|
-
//
|
|
32
|
-
|
|
55
|
+
//
|
|
56
|
+
/**
|
|
57
|
+
* isValid()
|
|
58
|
+
* Diz se um valor é um e-mail válido, sem criar uma instância e sem lançar exceção.
|
|
59
|
+
* É o mesmo que a função isEmail().
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* Email.isValid('fulano@exemplo.com') // -> true
|
|
63
|
+
* Email.isValid(' fulano@exemplo.com') // -> false
|
|
64
|
+
*/
|
|
65
|
+
static isValid(value) {
|
|
66
|
+
return Email._matches(value);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* generate()
|
|
70
|
+
* Gera um e-mail válido aleatório.
|
|
71
|
+
*/
|
|
72
|
+
static generate() {
|
|
33
73
|
const servers = ['gmail.com', 'hotmail.com'];
|
|
34
74
|
return new Email(`${Random.alpha(10)}@${Random.fromArray(servers)}`);
|
|
35
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* @deprecated Use generate(). Será removido em uma versão futura.
|
|
78
|
+
*/
|
|
79
|
+
static fake() {
|
|
80
|
+
return Email.generate();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const ATEXT_PART = /^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+$/;
|
|
84
|
+
const DOMAIN_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
|
|
85
|
+
const TLD = /^(?:[a-z]{2,}|xn--[a-z0-9]{2,59})$/i;
|
|
86
|
+
/**
|
|
87
|
+
*
|
|
88
|
+
* Função base que verifica se um valor é e-mail
|
|
89
|
+
*
|
|
90
|
+
*/
|
|
91
|
+
export function isEmail(value) {
|
|
92
|
+
if (typeof value !== 'string')
|
|
93
|
+
return false;
|
|
94
|
+
// Sem trim(): espaço antes ou depois do e-mail o torna inválido (o laço abaixo rejeita)
|
|
95
|
+
const email = value;
|
|
96
|
+
if (email.length < 3 || email.length > 254)
|
|
97
|
+
return false;
|
|
98
|
+
for (let i = 0; i < email.length; i++) {
|
|
99
|
+
const code = email.charCodeAt(i);
|
|
100
|
+
if (code <= 32 || code === 127)
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const atIndex = email.indexOf('@');
|
|
104
|
+
if (atIndex <= 0 || atIndex !== email.lastIndexOf('@'))
|
|
105
|
+
return false;
|
|
106
|
+
const local = email.slice(0, atIndex);
|
|
107
|
+
const domain = email.slice(atIndex + 1);
|
|
108
|
+
if (local.length < 1 || local.length > 64)
|
|
109
|
+
return false;
|
|
110
|
+
if (local.startsWith('.') || local.endsWith('.') || local.includes('..')) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
const localParts = local.split('.');
|
|
114
|
+
for (const part of localParts) {
|
|
115
|
+
if (!ATEXT_PART.test(part))
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (domain.length < 3 || domain.length > 253)
|
|
119
|
+
return false;
|
|
120
|
+
if (domain.startsWith('.') || domain.endsWith('.') || domain.includes('..')) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
const labels = domain.split('.');
|
|
124
|
+
if (labels.length < 2)
|
|
125
|
+
return false;
|
|
126
|
+
for (const label of labels) {
|
|
127
|
+
if (label.length < 1 || label.length > 63)
|
|
128
|
+
return false;
|
|
129
|
+
if (!DOMAIN_LABEL.test(label))
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const tld = labels[labels.length - 1];
|
|
133
|
+
if (!TLD.test(tld))
|
|
134
|
+
return false;
|
|
135
|
+
return true;
|
|
36
136
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
26
|
+
export declare function isCIB(value: string): boolean;
|
|
24
27
|
export declare function isUF(value: string): boolean;
|
package/dist/esm/index.js
CHANGED
|
@@ -8,16 +8,17 @@ import { CarPlate } from './carplate.js';
|
|
|
8
8
|
import { Phone } from './phone.js';
|
|
9
9
|
import { PixKey, PixKeys } from './pix-key.js';
|
|
10
10
|
import { PixCopyPaste } from './pix-copy-paste.js';
|
|
11
|
+
import { Pix } from './pix.js';
|
|
11
12
|
import { JudicialProcess } from './judicial-process.js';
|
|
12
13
|
import { PostalTrackCode } from './postal-track-code.js';
|
|
13
14
|
import { TituloEleitor } from './tituloEleitor.js';
|
|
14
15
|
import { UUID } from './uuid.js';
|
|
15
|
-
import {
|
|
16
|
+
import { isEmail } from './email.js';
|
|
16
17
|
import { Boleto } from './boleto.js';
|
|
17
18
|
import { CAEPF } from './caepf.js';
|
|
18
19
|
import { CEP } from './cep.js';
|
|
19
20
|
import { Certidao, CertidaoTipoLivro, CertidaoServico } from './certidao.js';
|
|
20
|
-
import {
|
|
21
|
+
import { CIB } from './cib.js';
|
|
21
22
|
import { UF } from './uf.js';
|
|
22
23
|
export { PixKeys, CertidaoTipoLivro, CertidaoServico };
|
|
23
24
|
function validate(fn) {
|
|
@@ -29,24 +30,26 @@ function validate(fn) {
|
|
|
29
30
|
return false;
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
export function isCNH(value) { return
|
|
33
|
-
export function isCNPJ(value) { return
|
|
34
|
-
export function isCPF(value) { return
|
|
35
|
-
export function isCarPlate(value) { return
|
|
36
|
-
export function isJudicialProcess(value) { return
|
|
37
|
-
export function isNUP17(value) { return
|
|
38
|
-
export function isPhone(value) { return
|
|
39
|
-
export function isPIS(value) { return
|
|
40
|
-
export function isPixKey(value) { return
|
|
33
|
+
export function isCNH(value) { return CNH.isValid(value); }
|
|
34
|
+
export function isCNPJ(value) { return CNPJ.isValid(value); }
|
|
35
|
+
export function isCPF(value) { return CPF.isValid(value); }
|
|
36
|
+
export function isCarPlate(value) { return CarPlate.isValid(value); }
|
|
37
|
+
export function isJudicialProcess(value) { return JudicialProcess.isValid(value); }
|
|
38
|
+
export function isNUP17(value) { return NUP17.isValid(value); }
|
|
39
|
+
export function isPhone(value) { return Phone.isValid(value); }
|
|
40
|
+
export function isPIS(value) { return PIS.isValid(value); }
|
|
41
|
+
export function isPixKey(value) { return PixKey.isValid(value); }
|
|
42
|
+
/** @deprecated Use isPix(). Será removido em uma versão futura. */
|
|
41
43
|
export function isPixCopyPaste(value) { return validate(() => new PixCopyPaste(value)); }
|
|
42
|
-
export function
|
|
43
|
-
export function
|
|
44
|
-
export function
|
|
45
|
-
export function
|
|
46
|
-
export
|
|
47
|
-
export function
|
|
48
|
-
export function
|
|
49
|
-
export function
|
|
50
|
-
export function
|
|
51
|
-
export function
|
|
52
|
-
export function
|
|
44
|
+
export function isPix(value) { return Pix.isValid(value); }
|
|
45
|
+
export function isPostalTrackCode(value) { return PostalTrackCode.isValid(value); }
|
|
46
|
+
export function isRenavam(value) { return Renavam.isValid(value); }
|
|
47
|
+
export function isTituloEleitor(value) { return TituloEleitor.isValid(value); }
|
|
48
|
+
export { isEmail };
|
|
49
|
+
export function isUUID(value) { return UUID.isValid(value); }
|
|
50
|
+
export function isBoleto(value) { return Boleto.isValid(value); }
|
|
51
|
+
export function isCAEPF(value) { return CAEPF.isValid(value); }
|
|
52
|
+
export function isCEP(value) { return CEP.isValid(value); }
|
|
53
|
+
export function isCertidao(value) { return Certidao.isValid(value); }
|
|
54
|
+
export function isCIB(value) { return CIB.isValid(value); }
|
|
55
|
+
export function isUF(value) { return 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
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
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
|
-
* @
|
|
105
|
-
*
|
|
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
|
-
|
|
118
|
+
static isValid(value: string): boolean;
|
|
108
119
|
/**
|
|
109
|
-
*
|
|
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;
|
|
@@ -80,14 +80,19 @@
|
|
|
80
80
|
import ValidationBRError, { EmptyValueException, InvalidChecksumException, InvalidFormatException, } from './_exceptions/ValidationBRError.js';
|
|
81
81
|
import { Random } from './_helpers/random.js';
|
|
82
82
|
import { Base } from './base.js';
|
|
83
|
-
import {
|
|
83
|
+
import { insertAtPosition, removeFromPosition, } from './_helpers/utils.js';
|
|
84
84
|
export class JudicialProcess extends Base {
|
|
85
85
|
constructor(_value) {
|
|
86
86
|
super(_value);
|
|
87
87
|
this._value = _value;
|
|
88
88
|
this._mask = '0000000-00.0000.0.00.0000';
|
|
89
|
-
|
|
90
|
-
if (!this.
|
|
89
|
+
// O formato é conferido antes de qualquer limpeza, com o valor exatamente como chegou
|
|
90
|
+
if (!JudicialProcess._matches(this._value)) {
|
|
91
|
+
throw new InvalidFormatException();
|
|
92
|
+
}
|
|
93
|
+
this._value = JudicialProcess._normalize(this._value);
|
|
94
|
+
// O _check() lança um erro próprio quando o órgão judiciário é 0
|
|
95
|
+
if (!JudicialProcess._check(this._value)) {
|
|
91
96
|
throw new InvalidChecksumException();
|
|
92
97
|
}
|
|
93
98
|
this.parse();
|
|
@@ -124,40 +129,39 @@ export class JudicialProcess extends Base {
|
|
|
124
129
|
//
|
|
125
130
|
//
|
|
126
131
|
//
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Oculta o número sequencial do processo e os dígitos verificadores,
|
|
134
|
+
* mantendo ano, segmento da justiça, tribunal e unidade de origem.
|
|
135
|
+
* Ex.: `*******-**.2016.4.05.8400`
|
|
136
|
+
*/
|
|
137
|
+
redact() {
|
|
138
|
+
return `*******-**.${this._value.slice(9, 13)}.${this._value.slice(13, 14)}.${this._value.slice(14, 16)}.${this._value.slice(16, 20)}`;
|
|
129
139
|
}
|
|
130
140
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
141
|
+
* isValid()
|
|
142
|
+
* Diz se um valor é válido, sem criar uma instância e sem lançar exceção.
|
|
143
|
+
* Faz os mesmos passos do construtor: formato, limpeza e dígito verificador.
|
|
134
144
|
*
|
|
135
|
-
* @
|
|
136
|
-
*
|
|
145
|
+
* @example
|
|
146
|
+
* JudicialProcess.isValid('6105283-83.2009.8.13.0024') // -> true
|
|
147
|
+
* JudicialProcess.isValid('6105283/83.2009.8.13.0024') // -> false
|
|
137
148
|
*/
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return (JudicialProcess.checksum(processWithoutDV) === judicialProcess.substring(7, 9));
|
|
149
|
+
static isValid(value) {
|
|
150
|
+
// O _check() lança erro quando o código do órgão judiciário é 0
|
|
151
|
+
try {
|
|
152
|
+
return JudicialProcess._matches(value) && JudicialProcess._check(JudicialProcess._normalize(value));
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
147
157
|
}
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
158
|
/**
|
|
155
|
-
*
|
|
159
|
+
* generate()
|
|
156
160
|
* Gera um número válido
|
|
157
161
|
*
|
|
158
162
|
* @returns {String}
|
|
159
163
|
*/
|
|
160
|
-
static
|
|
164
|
+
static generate(options = {}) {
|
|
161
165
|
const num = Random.number(7, true);
|
|
162
166
|
//
|
|
163
167
|
if (options.court)
|
|
@@ -179,6 +183,12 @@ export class JudicialProcess extends Base {
|
|
|
179
183
|
const finalNumber = insertAtPosition(judicialProcess, checksum, 7);
|
|
180
184
|
return new JudicialProcess(finalNumber);
|
|
181
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* @deprecated Use generate(). Será removido em uma versão futura.
|
|
188
|
+
*/
|
|
189
|
+
static fake(options = {}) {
|
|
190
|
+
return JudicialProcess.generate(options);
|
|
191
|
+
}
|
|
182
192
|
/**
|
|
183
193
|
* checksum()
|
|
184
194
|
* Calcula o dígito verificador de um número SEM o dígito incluído
|
|
@@ -250,4 +260,42 @@ export class JudicialProcess extends Base {
|
|
|
250
260
|
if (!value || value.length !== 4)
|
|
251
261
|
throw new ValidationBRError('Digite um ano com 4 caracteres.');
|
|
252
262
|
}
|
|
263
|
+
//
|
|
264
|
+
//
|
|
265
|
+
//
|
|
266
|
+
//
|
|
267
|
+
//
|
|
268
|
+
//
|
|
269
|
+
/**
|
|
270
|
+
* _matches()
|
|
271
|
+
* Confere se o valor segue o formato do processo judicial. Não aceita espaços nem barras.
|
|
272
|
+
* Usa a string original, por isso deve rodar antes do _normalize().
|
|
273
|
+
*/
|
|
274
|
+
static _matches(value) {
|
|
275
|
+
return typeof value === 'string' && JudicialProcess._pattern.test(value);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* _normalize()
|
|
279
|
+
* Remove o hífen e os pontos.
|
|
280
|
+
* Só deve receber um valor que já passou pelo _matches().
|
|
281
|
+
*/
|
|
282
|
+
static _normalize(value) {
|
|
283
|
+
return value.replace(/[.-]/g, '');
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* _check()
|
|
287
|
+
* Compara os dígitos verificadores (posições 8 e 9) com os calculados.
|
|
288
|
+
* Recebe o processo normalizado, com 20 dígitos.
|
|
289
|
+
* Lança erro se o código do órgão judiciário for 0.
|
|
290
|
+
*/
|
|
291
|
+
static _check(value) {
|
|
292
|
+
const withoutChecksum = removeFromPosition(value, 7, 9);
|
|
293
|
+
JudicialProcess.validateCourt(withoutChecksum.substring(11, 12));
|
|
294
|
+
return JudicialProcess.checksum(withoutChecksum) === value.substring(7, 9);
|
|
295
|
+
}
|
|
253
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Formato aceito: 20 dígitos, com ou sem o hífen e os pontos da máscara.
|
|
299
|
+
* Ex.: `0000001-80.2016.4.05.8400` ou `00000018020164058400`
|
|
300
|
+
*/
|
|
301
|
+
JudicialProcess._pattern = /^\d{7}-?\d{2}\.?\d{4}\.?\d\.?\d{2}\.?\d{4}$/;
|