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/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
|
-
|
|
73
|
-
if (!this.
|
|
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
|
-
|
|
84
|
-
|
|
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
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
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
|
-
* @
|
|
92
|
-
*
|
|
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
|
-
|
|
95
|
-
|
|
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
|
-
*
|
|
112
|
+
* generate()
|
|
111
113
|
* Gera um número válido
|
|
112
114
|
*
|
|
113
115
|
* @returns {String}
|
|
114
116
|
*/
|
|
115
|
-
static
|
|
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}$/;
|
package/dist/cjs/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/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
|
-
|
|
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.
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
21
|
-
return this.
|
|
24
|
+
get local() {
|
|
25
|
+
return this._local;
|
|
22
26
|
}
|
|
23
|
-
|
|
24
|
-
return this.
|
|
27
|
+
get domain() {
|
|
28
|
+
return this._domain;
|
|
25
29
|
}
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
30
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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
|
+
}
|
package/dist/cjs/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/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.
|
|
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
|
|
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
|
|
59
|
-
function isCNPJ(value) { return
|
|
60
|
-
function isCPF(value) { return
|
|
61
|
-
function isCarPlate(value) { return
|
|
62
|
-
function isJudicialProcess(value) { return
|
|
63
|
-
function isNUP17(value) { return
|
|
64
|
-
function isPhone(value) { return
|
|
65
|
-
function isPIS(value) { return
|
|
66
|
-
function isPixKey(value) { return
|
|
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
|
|
69
|
-
function
|
|
70
|
-
function
|
|
71
|
-
function
|
|
72
|
-
function isUUID(value) { return
|
|
73
|
-
function isBoleto(value) { return
|
|
74
|
-
function isCAEPF(value) { return
|
|
75
|
-
function isCEP(value) { return
|
|
76
|
-
function isCertidao(value) { return
|
|
77
|
-
function
|
|
78
|
-
function isUF(value) { return
|
|
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
|
-
*
|
|
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;
|