validation-br 2.0.0-next-7 → 2.0.0-next-9
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/_helpers/crc.js +0 -1
- package/dist/_helpers/crockford.js +2 -2
- package/dist/_helpers/mask.js +0 -1
- package/dist/_helpers/random.js +1 -1
- package/dist/base.js +0 -1
- package/dist/carplate.js +1 -2
- package/dist/cbi_sinter.js +1 -1
- package/dist/cep.js +70 -71
- package/dist/certidao.js +1 -2
- package/dist/cnh.js +1 -1
- package/dist/cnpj.js +3 -3
- package/dist/cpf.js +1 -2
- package/dist/email.js +1 -2
- package/dist/judicial-process.js +1 -8
- package/dist/nup17.js +1 -2
- package/dist/phone.js +23 -23
- package/dist/pis-pasep.js +1 -2
- package/dist/pix-copy-paste.js +3 -3
- package/dist/pix-key.js +11 -13
- package/dist/postal-track-code.js +1 -1
- package/dist/renavam.js +1 -2
- package/dist/tituloEleitor.js +1 -2
- package/dist/uf.js +33 -35
- package/dist/uuid.js +1 -2
- package/package.json +4 -1
- /package/dist/{main.d.ts → index.d.ts} +0 -0
- /package/dist/{main.js → index.js} +0 -0
package/dist/_helpers/crc.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Crockford = void 0;
|
|
4
4
|
class Crockford {
|
|
5
|
-
// Alfabeto Base 32 de Douglas Crockford (32 caracteres)
|
|
6
|
-
static ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
7
5
|
/**
|
|
8
6
|
* Normaliza a string conforme as regras do SINTER/CIB:
|
|
9
7
|
* 1. Remove pontuação e espaços
|
|
@@ -60,3 +58,5 @@ class Crockford {
|
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
60
|
exports.Crockford = Crockford;
|
|
61
|
+
// Alfabeto Base 32 de Douglas Crockford (32 caracteres)
|
|
62
|
+
Crockford.ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
package/dist/_helpers/mask.js
CHANGED
package/dist/_helpers/random.js
CHANGED
|
@@ -23,7 +23,7 @@ class Random {
|
|
|
23
23
|
return result;
|
|
24
24
|
}
|
|
25
25
|
static fromArray(array, length = 1) {
|
|
26
|
-
const _get = () => array
|
|
26
|
+
const _get = () => array[Random.between(0, array.length - 1)];
|
|
27
27
|
if (length === 1)
|
|
28
28
|
return _get();
|
|
29
29
|
const result = [];
|
package/dist/base.js
CHANGED
package/dist/carplate.js
CHANGED
|
@@ -11,11 +11,10 @@ const base_1 = require("./base");
|
|
|
11
11
|
const ValidationBRError_1 = require("./_exceptions/ValidationBRError");
|
|
12
12
|
const random_1 = require("./_helpers/random");
|
|
13
13
|
class CarPlate extends base_1.Base {
|
|
14
|
-
_value;
|
|
15
|
-
_mask = '000-0000';
|
|
16
14
|
constructor(_value) {
|
|
17
15
|
super(_value);
|
|
18
16
|
this._value = _value;
|
|
17
|
+
this._mask = '000-0000';
|
|
19
18
|
this.normalize();
|
|
20
19
|
if (!this.validate())
|
|
21
20
|
throw new ValidationBRError_1.InvalidFormatException();
|
package/dist/cbi_sinter.js
CHANGED
|
@@ -59,9 +59,9 @@ const random_1 = require("./_helpers/random");
|
|
|
59
59
|
const base_1 = require("./base");
|
|
60
60
|
const utils_1 = require("./_helpers/utils");
|
|
61
61
|
class CBISinter extends base_1.Base {
|
|
62
|
-
_mask = "0000000-0"; // Máscara apenas informativa
|
|
63
62
|
constructor(value) {
|
|
64
63
|
super(value);
|
|
64
|
+
this._mask = "0000000-0"; // Máscara apenas informativa
|
|
65
65
|
this.normalize();
|
|
66
66
|
if (!this.validate()) {
|
|
67
67
|
throw new ValidationBRError_1.InvalidChecksumException();
|
package/dist/cep.js
CHANGED
|
@@ -39,79 +39,10 @@ const random_1 = require("./_helpers/random");
|
|
|
39
39
|
const base_1 = require("./base");
|
|
40
40
|
const uf_1 = require("./uf");
|
|
41
41
|
class CEP extends base_1.Base {
|
|
42
|
-
_value;
|
|
43
|
-
_mask = '00000-000';
|
|
44
|
-
static _ranges = {
|
|
45
|
-
// São Paulo(SP) 01000-000 a 19999-999
|
|
46
|
-
[uf_1.UF.SP.value]: [['01000000', '19999999']],
|
|
47
|
-
// Rio de Janeiro(RJ) 20000-000 a 28999-999
|
|
48
|
-
[uf_1.UF.RJ.value]: [['20000000', '28999999']],
|
|
49
|
-
// Espírito Santo(ES) 29000-000 a 29999-999
|
|
50
|
-
[uf_1.UF.ES.value]: [['29000000', '29999999']],
|
|
51
|
-
// Minas Gerais(MG) 30000-000 a 39999-999
|
|
52
|
-
[uf_1.UF.MG.value]: [['30000000', '39999999']],
|
|
53
|
-
// Paraná(PR) 80000-000 a 87999-999
|
|
54
|
-
[uf_1.UF.PR.value]: [['80000000', '87999999']],
|
|
55
|
-
// Santa Catarina(SC) 88000-000 a 89999-999
|
|
56
|
-
[uf_1.UF.SC.value]: [['88000000', '89999999']],
|
|
57
|
-
// Rio Grande do Sul(RS) 90000-000 a 99999-999
|
|
58
|
-
[uf_1.UF.RS.value]: [['90000000', '99999999']],
|
|
59
|
-
// Bahia(BA) 40000-000 a 48999-999
|
|
60
|
-
[uf_1.UF.BA.value]: [['40000000', '48999999']],
|
|
61
|
-
// Sergipe(SE) 49000-000 a 49999-999
|
|
62
|
-
[uf_1.UF.SE.value]: [['49000000', '49999999']],
|
|
63
|
-
// Pernambuco(PE) 50000-000 a 56999-999
|
|
64
|
-
[uf_1.UF.PE.value]: [['50000000', '56999999']],
|
|
65
|
-
// Alagoas(AL) 57000-000 a 57999-999
|
|
66
|
-
[uf_1.UF.AL.value]: [['57000000', '57999999']],
|
|
67
|
-
// Paraíba(PB) 58000-000 a 58999-999
|
|
68
|
-
[uf_1.UF.PB.value]: [['58000000', '58999999']],
|
|
69
|
-
// Rio Grande do Norte(RN) 59000-000 a 59999-999
|
|
70
|
-
[uf_1.UF.RN.value]: [['59000000', '59999999']],
|
|
71
|
-
// Ceará(CE) 60000-000 a 63999-999
|
|
72
|
-
[uf_1.UF.CE.value]: [['60000000', '63999999']],
|
|
73
|
-
// Piauí(PI) 64000-000 a 64999-999
|
|
74
|
-
[uf_1.UF.PI.value]: [['64000000', '64999999']],
|
|
75
|
-
// Maranhão(MA) 65000-000 a 65999-999
|
|
76
|
-
[uf_1.UF.MA.value]: [['65000000', '65999999']],
|
|
77
|
-
// Pará(PA) 66000-000 a 68899-999
|
|
78
|
-
[uf_1.UF.PA.value]: [['66000000', '68899999']],
|
|
79
|
-
// Amapá(AP) 68900-000 a 68999-999
|
|
80
|
-
[uf_1.UF.AP.value]: [['68900000', '68999999']],
|
|
81
|
-
// Amazonas(AM) 1 69000-000 a 69299-999
|
|
82
|
-
// Amazonas(AM) 2 69400-000 a 69899-999
|
|
83
|
-
[uf_1.UF.AM.value]: [
|
|
84
|
-
['69000000', '69299999'],
|
|
85
|
-
['69400000', '69899999'],
|
|
86
|
-
],
|
|
87
|
-
// Roraima(RR) 69300-000 a 69399-999
|
|
88
|
-
[uf_1.UF.RR.value]: [['69300000', '69399999']],
|
|
89
|
-
// Acre(AC) 69900-000 a 69999-999
|
|
90
|
-
[uf_1.UF.AC.value]: [['69900000', '69999999']],
|
|
91
|
-
// Rondônia(RO) 76800-000 a 76999-999
|
|
92
|
-
[uf_1.UF.RO.value]: [['76800000', '76999999']],
|
|
93
|
-
// Tocantins(TO) 77000-000 a 77999-999
|
|
94
|
-
[uf_1.UF.TO.value]: [['77000000', '77999999']],
|
|
95
|
-
// Distrito Federal(DF) 1 70000-000 a 72799-999
|
|
96
|
-
// Distrito Federal(DF) 2 73000-000 a 73699-999
|
|
97
|
-
[uf_1.UF.DF.value]: [
|
|
98
|
-
['70000000', '72799999'],
|
|
99
|
-
['73000000', '73699999'],
|
|
100
|
-
],
|
|
101
|
-
// Goiás(GO) 1 72800-000 a 72999-999
|
|
102
|
-
// Goiás(GO) 2 73700-000 a 76799-999
|
|
103
|
-
[uf_1.UF.GO.value]: [
|
|
104
|
-
['72800000', '72999999'],
|
|
105
|
-
['73700000', '76799999'],
|
|
106
|
-
],
|
|
107
|
-
// Mato Grosso(MT) 78000-000 a 78899-999
|
|
108
|
-
[uf_1.UF.MT.value]: [['78000000', '78899999']],
|
|
109
|
-
// Mato Grosso do Sul(MS) 79000-000 a 79999-999
|
|
110
|
-
[uf_1.UF.MS.value]: [['79000000', '79999999']],
|
|
111
|
-
};
|
|
112
42
|
constructor(_value, options) {
|
|
113
43
|
super(_value);
|
|
114
44
|
this._value = _value;
|
|
45
|
+
this._mask = '00000-000';
|
|
115
46
|
if (!this.validate(options)) {
|
|
116
47
|
throw new ValidationBRError_1.InvalidFormatException();
|
|
117
48
|
}
|
|
@@ -146,7 +77,7 @@ class CEP extends base_1.Base {
|
|
|
146
77
|
if (!isValidFormat)
|
|
147
78
|
return false;
|
|
148
79
|
// Valida se tiver estado
|
|
149
|
-
if (options
|
|
80
|
+
if (options === null || options === void 0 ? void 0 : options.uf) {
|
|
150
81
|
return CEP.getUFByCEP(this._value).short === options.uf.short;
|
|
151
82
|
}
|
|
152
83
|
return true;
|
|
@@ -214,6 +145,74 @@ class CEP extends base_1.Base {
|
|
|
214
145
|
}
|
|
215
146
|
}
|
|
216
147
|
exports.CEP = CEP;
|
|
148
|
+
CEP._ranges = {
|
|
149
|
+
// São Paulo(SP) 01000-000 a 19999-999
|
|
150
|
+
[uf_1.UF.SP.value]: [['01000000', '19999999']],
|
|
151
|
+
// Rio de Janeiro(RJ) 20000-000 a 28999-999
|
|
152
|
+
[uf_1.UF.RJ.value]: [['20000000', '28999999']],
|
|
153
|
+
// Espírito Santo(ES) 29000-000 a 29999-999
|
|
154
|
+
[uf_1.UF.ES.value]: [['29000000', '29999999']],
|
|
155
|
+
// Minas Gerais(MG) 30000-000 a 39999-999
|
|
156
|
+
[uf_1.UF.MG.value]: [['30000000', '39999999']],
|
|
157
|
+
// Paraná(PR) 80000-000 a 87999-999
|
|
158
|
+
[uf_1.UF.PR.value]: [['80000000', '87999999']],
|
|
159
|
+
// Santa Catarina(SC) 88000-000 a 89999-999
|
|
160
|
+
[uf_1.UF.SC.value]: [['88000000', '89999999']],
|
|
161
|
+
// Rio Grande do Sul(RS) 90000-000 a 99999-999
|
|
162
|
+
[uf_1.UF.RS.value]: [['90000000', '99999999']],
|
|
163
|
+
// Bahia(BA) 40000-000 a 48999-999
|
|
164
|
+
[uf_1.UF.BA.value]: [['40000000', '48999999']],
|
|
165
|
+
// Sergipe(SE) 49000-000 a 49999-999
|
|
166
|
+
[uf_1.UF.SE.value]: [['49000000', '49999999']],
|
|
167
|
+
// Pernambuco(PE) 50000-000 a 56999-999
|
|
168
|
+
[uf_1.UF.PE.value]: [['50000000', '56999999']],
|
|
169
|
+
// Alagoas(AL) 57000-000 a 57999-999
|
|
170
|
+
[uf_1.UF.AL.value]: [['57000000', '57999999']],
|
|
171
|
+
// Paraíba(PB) 58000-000 a 58999-999
|
|
172
|
+
[uf_1.UF.PB.value]: [['58000000', '58999999']],
|
|
173
|
+
// Rio Grande do Norte(RN) 59000-000 a 59999-999
|
|
174
|
+
[uf_1.UF.RN.value]: [['59000000', '59999999']],
|
|
175
|
+
// Ceará(CE) 60000-000 a 63999-999
|
|
176
|
+
[uf_1.UF.CE.value]: [['60000000', '63999999']],
|
|
177
|
+
// Piauí(PI) 64000-000 a 64999-999
|
|
178
|
+
[uf_1.UF.PI.value]: [['64000000', '64999999']],
|
|
179
|
+
// Maranhão(MA) 65000-000 a 65999-999
|
|
180
|
+
[uf_1.UF.MA.value]: [['65000000', '65999999']],
|
|
181
|
+
// Pará(PA) 66000-000 a 68899-999
|
|
182
|
+
[uf_1.UF.PA.value]: [['66000000', '68899999']],
|
|
183
|
+
// Amapá(AP) 68900-000 a 68999-999
|
|
184
|
+
[uf_1.UF.AP.value]: [['68900000', '68999999']],
|
|
185
|
+
// Amazonas(AM) 1 69000-000 a 69299-999
|
|
186
|
+
// Amazonas(AM) 2 69400-000 a 69899-999
|
|
187
|
+
[uf_1.UF.AM.value]: [
|
|
188
|
+
['69000000', '69299999'],
|
|
189
|
+
['69400000', '69899999'],
|
|
190
|
+
],
|
|
191
|
+
// Roraima(RR) 69300-000 a 69399-999
|
|
192
|
+
[uf_1.UF.RR.value]: [['69300000', '69399999']],
|
|
193
|
+
// Acre(AC) 69900-000 a 69999-999
|
|
194
|
+
[uf_1.UF.AC.value]: [['69900000', '69999999']],
|
|
195
|
+
// Rondônia(RO) 76800-000 a 76999-999
|
|
196
|
+
[uf_1.UF.RO.value]: [['76800000', '76999999']],
|
|
197
|
+
// Tocantins(TO) 77000-000 a 77999-999
|
|
198
|
+
[uf_1.UF.TO.value]: [['77000000', '77999999']],
|
|
199
|
+
// Distrito Federal(DF) 1 70000-000 a 72799-999
|
|
200
|
+
// Distrito Federal(DF) 2 73000-000 a 73699-999
|
|
201
|
+
[uf_1.UF.DF.value]: [
|
|
202
|
+
['70000000', '72799999'],
|
|
203
|
+
['73000000', '73699999'],
|
|
204
|
+
],
|
|
205
|
+
// Goiás(GO) 1 72800-000 a 72999-999
|
|
206
|
+
// Goiás(GO) 2 73700-000 a 76799-999
|
|
207
|
+
[uf_1.UF.GO.value]: [
|
|
208
|
+
['72800000', '72999999'],
|
|
209
|
+
['73700000', '76799999'],
|
|
210
|
+
],
|
|
211
|
+
// Mato Grosso(MT) 78000-000 a 78899-999
|
|
212
|
+
[uf_1.UF.MT.value]: [['78000000', '78899999']],
|
|
213
|
+
// Mato Grosso do Sul(MS) 79000-000 a 79999-999
|
|
214
|
+
[uf_1.UF.MS.value]: [['79000000', '79999999']],
|
|
215
|
+
};
|
|
217
216
|
class NotFoundCEPException extends ValidationBRError_1.default {
|
|
218
217
|
constructor() {
|
|
219
218
|
super('CEP não encontrado');
|
package/dist/certidao.js
CHANGED
|
@@ -61,11 +61,10 @@ var CertidaoServico;
|
|
|
61
61
|
CertidaoServico["RegistroDistribuicao"] = "57";
|
|
62
62
|
})(CertidaoServico || (exports.CertidaoServico = CertidaoServico = {}));
|
|
63
63
|
class Certidao extends base_1.Base {
|
|
64
|
-
_value;
|
|
65
|
-
_mask = '000000 00 00 0000 0 00000 000 0000000 00';
|
|
66
64
|
constructor(_value) {
|
|
67
65
|
super(_value);
|
|
68
66
|
this._value = _value;
|
|
67
|
+
this._mask = '000000 00 00 0000 0 00000 000 0000000 00';
|
|
69
68
|
this.normalize();
|
|
70
69
|
if (!this.validate()) {
|
|
71
70
|
throw new ValidationBRError_1.InvalidChecksumException();
|
package/dist/cnh.js
CHANGED
|
@@ -61,9 +61,9 @@ const random_1 = require("./_helpers/random");
|
|
|
61
61
|
const base_1 = require("./base");
|
|
62
62
|
const utils_1 = require("./_helpers/utils");
|
|
63
63
|
class CNH extends base_1.Base {
|
|
64
|
-
_mask = '000000000-00';
|
|
65
64
|
constructor(value) {
|
|
66
65
|
super(value);
|
|
66
|
+
this._mask = '000000000-00';
|
|
67
67
|
this.normalize();
|
|
68
68
|
if (!this.validate()) {
|
|
69
69
|
throw new ValidationBRError_1.InvalidChecksumException();
|
package/dist/cnpj.js
CHANGED
|
@@ -84,11 +84,10 @@ const random_1 = require("./_helpers/random");
|
|
|
84
84
|
const base_1 = require("./base");
|
|
85
85
|
const utils_1 = require("./_helpers/utils");
|
|
86
86
|
class CNPJ extends base_1.Base {
|
|
87
|
-
_value;
|
|
88
|
-
_mask = '00.000.000/0000-00';
|
|
89
87
|
constructor(_value) {
|
|
90
88
|
super(_value);
|
|
91
89
|
this._value = _value;
|
|
90
|
+
this._mask = '00.000.000/0000-00';
|
|
92
91
|
this.normalize();
|
|
93
92
|
if (!this.validate()) {
|
|
94
93
|
throw new ValidationBRError_1.InvalidChecksumException();
|
|
@@ -142,7 +141,8 @@ class CNPJ extends base_1.Base {
|
|
|
142
141
|
*
|
|
143
142
|
*/
|
|
144
143
|
static fake(options = {}) {
|
|
145
|
-
|
|
144
|
+
var _a;
|
|
145
|
+
const num = random_1.Random.number(8, true, (_a = options === null || options === void 0 ? void 0 : options.alphanumeric) !== null && _a !== void 0 ? _a : false);
|
|
146
146
|
const fullNumber = `${num}0001`;
|
|
147
147
|
return new CNPJ(`${fullNumber}${CNPJ.checksum(fullNumber)}`);
|
|
148
148
|
}
|
package/dist/cpf.js
CHANGED
|
@@ -65,11 +65,10 @@ const random_1 = require("./_helpers/random");
|
|
|
65
65
|
const base_1 = require("./base");
|
|
66
66
|
const utils_1 = require("./_helpers/utils");
|
|
67
67
|
class CPF extends base_1.Base {
|
|
68
|
-
_value;
|
|
69
|
-
_mask = '000.000.000-00';
|
|
70
68
|
constructor(_value) {
|
|
71
69
|
super(_value);
|
|
72
70
|
this._value = _value;
|
|
71
|
+
this._mask = '000.000.000-00';
|
|
73
72
|
this.normalize();
|
|
74
73
|
if (!this.validate()) {
|
|
75
74
|
throw new ValidationBRError_1.InvalidChecksumException();
|
package/dist/email.js
CHANGED
|
@@ -8,11 +8,10 @@ const ValidationBRError_1 = __importDefault(require("./_exceptions/ValidationBRE
|
|
|
8
8
|
const random_1 = require("./_helpers/random");
|
|
9
9
|
const base_1 = require("./base");
|
|
10
10
|
class Email extends base_1.Base {
|
|
11
|
-
_value;
|
|
12
|
-
_mask = null;
|
|
13
11
|
constructor(_value) {
|
|
14
12
|
super(_value);
|
|
15
13
|
this._value = _value;
|
|
14
|
+
this._mask = null;
|
|
16
15
|
this.normalize();
|
|
17
16
|
if (!this.validate()) {
|
|
18
17
|
throw new ValidationBRError_1.default('Email inválido');
|
package/dist/judicial-process.js
CHANGED
|
@@ -118,17 +118,10 @@ const random_1 = require("./_helpers/random");
|
|
|
118
118
|
const base_1 = require("./base");
|
|
119
119
|
const utils_1 = require("./_helpers/utils");
|
|
120
120
|
class JudicialProcess extends base_1.Base {
|
|
121
|
-
_value;
|
|
122
|
-
_court;
|
|
123
|
-
_subCourt;
|
|
124
|
-
_origin;
|
|
125
|
-
_year;
|
|
126
|
-
_processNumber;
|
|
127
|
-
_checksum;
|
|
128
|
-
_mask = '0000000-00.0000.0.00.0000';
|
|
129
121
|
constructor(_value) {
|
|
130
122
|
super(_value);
|
|
131
123
|
this._value = _value;
|
|
124
|
+
this._mask = '0000000-00.0000.0.00.0000';
|
|
132
125
|
this.normalize();
|
|
133
126
|
if (!this.validate()) {
|
|
134
127
|
throw new ValidationBRError_1.InvalidChecksumException();
|
package/dist/nup17.js
CHANGED
|
@@ -67,11 +67,10 @@ const random_1 = require("./_helpers/random");
|
|
|
67
67
|
const base_1 = require("./base");
|
|
68
68
|
const utils_1 = require("./_helpers/utils");
|
|
69
69
|
class NUP17 extends base_1.Base {
|
|
70
|
-
_value;
|
|
71
|
-
_mask = '00000.000000/0000-00';
|
|
72
70
|
constructor(_value) {
|
|
73
71
|
super(_value);
|
|
74
72
|
this._value = _value;
|
|
73
|
+
this._mask = '00000.000000/0000-00';
|
|
75
74
|
this.normalize();
|
|
76
75
|
if (!this.validate()) {
|
|
77
76
|
throw new ValidationBRError_1.InvalidChecksumException();
|
package/dist/phone.js
CHANGED
|
@@ -76,26 +76,15 @@ const ValidationBRError_1 = __importStar(require("./_exceptions/ValidationBRErro
|
|
|
76
76
|
const random_1 = require("./_helpers/random");
|
|
77
77
|
const base_1 = require("./base");
|
|
78
78
|
class Phone extends base_1.Base {
|
|
79
|
-
_value;
|
|
80
|
-
_mask = null;
|
|
81
|
-
_regex = /^(?<ddi>\+55)?(?<ddd>\d{2})(?<phone>9\d{8}|[34]\d{7})$/;
|
|
82
|
-
// private _parts = { ddd: '', phone: '', isMobile: false };
|
|
83
|
-
static _ddds = [
|
|
84
|
-
'11', '12', '13', '14', '15', '16', '17', '18', '19', '21',
|
|
85
|
-
'22', '24', '27', '28', '31', '32', '33', '34', '35', '37',
|
|
86
|
-
'38', '41', '42', '43', '44', '45', '46', '47', '48', '49',
|
|
87
|
-
'51', '53', '54', '55', '61', '62', '63', '64', '65', '66',
|
|
88
|
-
'67', '68', '69', '71', '73', '74', '75', '77', '79', '81',
|
|
89
|
-
'82', '83', '84', '85', '86', '87', '88', '89', '91', '92',
|
|
90
|
-
'93', '94', '95', '96', '97', '98', '99',
|
|
91
|
-
];
|
|
92
|
-
_ddd = '';
|
|
93
|
-
_phone = '';
|
|
94
|
-
_ddi = '';
|
|
95
|
-
_isMobile = false;
|
|
96
79
|
constructor(_value) {
|
|
97
80
|
super(_value);
|
|
98
81
|
this._value = _value;
|
|
82
|
+
this._mask = null;
|
|
83
|
+
this._regex = /^(?<ddi>\+55)?(?<ddd>\d{2})(?<phone>9\d{8}|[34]\d{7})$/;
|
|
84
|
+
this._ddd = '';
|
|
85
|
+
this._phone = '';
|
|
86
|
+
this._ddi = '';
|
|
87
|
+
this._isMobile = false;
|
|
99
88
|
this.normalize();
|
|
100
89
|
this.parse();
|
|
101
90
|
if (!this.validate()) {
|
|
@@ -132,7 +121,7 @@ class Phone extends base_1.Base {
|
|
|
132
121
|
*/
|
|
133
122
|
parse() {
|
|
134
123
|
const match = this._regex.exec(this._value);
|
|
135
|
-
if (match
|
|
124
|
+
if (match === null || match === void 0 ? void 0 : match.groups) {
|
|
136
125
|
this._ddi = match.groups.ddi || '+55';
|
|
137
126
|
this._ddd = match.groups.ddd;
|
|
138
127
|
this._phone = match.groups.phone;
|
|
@@ -156,7 +145,7 @@ class Phone extends base_1.Base {
|
|
|
156
145
|
*
|
|
157
146
|
*/
|
|
158
147
|
mask(config) {
|
|
159
|
-
return `${config
|
|
148
|
+
return `${(config === null || config === void 0 ? void 0 : config.withCountry) ? '+55 ' : ''}${this._ddd} ${this._phone}`;
|
|
160
149
|
}
|
|
161
150
|
/**
|
|
162
151
|
* Devolve o checksum
|
|
@@ -171,20 +160,21 @@ class Phone extends base_1.Base {
|
|
|
171
160
|
*
|
|
172
161
|
*/
|
|
173
162
|
static fake(config) {
|
|
163
|
+
var _a;
|
|
174
164
|
// Se definir um DDD pro fake, ele precisa existir
|
|
175
|
-
const inputInvalidDDD = config
|
|
165
|
+
const inputInvalidDDD = (config === null || config === void 0 ? void 0 : config.ddd) && !Phone._ddds.includes(config === null || config === void 0 ? void 0 : config.ddd);
|
|
176
166
|
if (inputInvalidDDD)
|
|
177
167
|
throw new DDDNotFoundException();
|
|
178
168
|
// Se o DDD não estiver preenchido, escolha um da lista
|
|
179
|
-
const ddd = config
|
|
169
|
+
const ddd = (_a = config === null || config === void 0 ? void 0 : config.ddd) !== null && _a !== void 0 ? _a : random_1.Random.fromArray(Phone._ddds);
|
|
180
170
|
// Prefixos
|
|
181
171
|
const mobilePrefixes = ['99', '98', '97'];
|
|
182
172
|
const landLinePrefixes = ['3', '4'];
|
|
183
173
|
// Se não informar se quer mobile ou fixo, gere o tipo
|
|
184
174
|
let firstPart;
|
|
185
|
-
if (config
|
|
175
|
+
if (config === null || config === void 0 ? void 0 : config.isMobile)
|
|
186
176
|
firstPart = random_1.Random.fromArray(mobilePrefixes);
|
|
187
|
-
else if (config
|
|
177
|
+
else if (config === null || config === void 0 ? void 0 : config.isLandline)
|
|
188
178
|
firstPart = random_1.Random.fromArray(landLinePrefixes);
|
|
189
179
|
else
|
|
190
180
|
firstPart = random_1.Random.fromArray([...mobilePrefixes, ...landLinePrefixes]);
|
|
@@ -195,6 +185,16 @@ class Phone extends base_1.Base {
|
|
|
195
185
|
}
|
|
196
186
|
}
|
|
197
187
|
exports.Phone = Phone;
|
|
188
|
+
// private _parts = { ddd: '', phone: '', isMobile: false };
|
|
189
|
+
Phone._ddds = [
|
|
190
|
+
'11', '12', '13', '14', '15', '16', '17', '18', '19', '21',
|
|
191
|
+
'22', '24', '27', '28', '31', '32', '33', '34', '35', '37',
|
|
192
|
+
'38', '41', '42', '43', '44', '45', '46', '47', '48', '49',
|
|
193
|
+
'51', '53', '54', '55', '61', '62', '63', '64', '65', '66',
|
|
194
|
+
'67', '68', '69', '71', '73', '74', '75', '77', '79', '81',
|
|
195
|
+
'82', '83', '84', '85', '86', '87', '88', '89', '91', '92',
|
|
196
|
+
'93', '94', '95', '96', '97', '98', '99',
|
|
197
|
+
];
|
|
198
198
|
class DDDNotFoundException extends ValidationBRError_1.default {
|
|
199
199
|
constructor() {
|
|
200
200
|
super('DDD não encontrado');
|
package/dist/pis-pasep.js
CHANGED
|
@@ -47,11 +47,10 @@ const utils_1 = require("./_helpers/utils");
|
|
|
47
47
|
const base_1 = require("./base");
|
|
48
48
|
const random_1 = require("./_helpers/random");
|
|
49
49
|
class PIS extends base_1.Base {
|
|
50
|
-
_value;
|
|
51
|
-
_mask = '000.00000.00-0';
|
|
52
50
|
constructor(_value) {
|
|
53
51
|
super(_value);
|
|
54
52
|
this._value = _value;
|
|
53
|
+
this._mask = '000.00000.00-0';
|
|
55
54
|
this.normalize();
|
|
56
55
|
if (!this.validate()) {
|
|
57
56
|
throw new ValidationBRError_1.InvalidChecksumException();
|
package/dist/pix-copy-paste.js
CHANGED
|
@@ -5,11 +5,10 @@ const ValidationBRError_1 = require("./_exceptions/ValidationBRError");
|
|
|
5
5
|
const crc_1 = require("./_helpers/crc");
|
|
6
6
|
const base_1 = require("./base");
|
|
7
7
|
class PixCopyPaste extends base_1.Base {
|
|
8
|
-
_value;
|
|
9
|
-
_mask = null;
|
|
10
8
|
constructor(_value) {
|
|
11
9
|
super(_value);
|
|
12
10
|
this._value = _value;
|
|
11
|
+
this._mask = null;
|
|
13
12
|
this.normalize();
|
|
14
13
|
this.validate();
|
|
15
14
|
}
|
|
@@ -30,7 +29,8 @@ class PixCopyPaste extends base_1.Base {
|
|
|
30
29
|
const parse = PixPart.parse(this._value);
|
|
31
30
|
if (!parse || !Array.isArray(parse))
|
|
32
31
|
throw new ValidationBRError_1.InvalidFormatException();
|
|
33
|
-
|
|
32
|
+
const last = parse[parse.length - 1];
|
|
33
|
+
if (last.code !== '63' || last.size !== 4)
|
|
34
34
|
throw new ValidationBRError_1.InvalidFormatException();
|
|
35
35
|
return true;
|
|
36
36
|
}
|
package/dist/pix-key.js
CHANGED
|
@@ -7,7 +7,7 @@ const base_1 = require("./base");
|
|
|
7
7
|
const cnpj_1 = require("./cnpj");
|
|
8
8
|
const cpf_1 = require("./cpf");
|
|
9
9
|
const email_1 = require("./email");
|
|
10
|
-
const
|
|
10
|
+
const _1 = require(".");
|
|
11
11
|
const phone_1 = require("./phone");
|
|
12
12
|
const uuid_1 = require("./uuid");
|
|
13
13
|
var PixKeys;
|
|
@@ -24,12 +24,10 @@ var PixKeys;
|
|
|
24
24
|
*
|
|
25
25
|
*/
|
|
26
26
|
class PixKey extends base_1.Base {
|
|
27
|
-
_value;
|
|
28
|
-
_mask = null;
|
|
29
|
-
_type;
|
|
30
27
|
constructor(_value) {
|
|
31
28
|
super(_value);
|
|
32
29
|
this._value = _value;
|
|
30
|
+
this._mask = null;
|
|
33
31
|
this.normalize();
|
|
34
32
|
if (!this.validate()) {
|
|
35
33
|
throw new ValidationBRError_1.InvalidFormatException();
|
|
@@ -52,13 +50,13 @@ class PixKey extends base_1.Base {
|
|
|
52
50
|
PixKeys.cnpj, PixKeys.cpf, PixKeys.email, PixKeys.evp, PixKeys.phone,
|
|
53
51
|
]);
|
|
54
52
|
}
|
|
55
|
-
if (options
|
|
53
|
+
if ((options === null || options === void 0 ? void 0 : options.type) == PixKeys.cnpj)
|
|
56
54
|
return new PixKey(cnpj_1.CNPJ.fake().toString());
|
|
57
|
-
if (options
|
|
55
|
+
if ((options === null || options === void 0 ? void 0 : options.type) == PixKeys.cpf)
|
|
58
56
|
return new PixKey(cpf_1.CPF.fake().toString());
|
|
59
|
-
if (options
|
|
57
|
+
if ((options === null || options === void 0 ? void 0 : options.type) == PixKeys.phone)
|
|
60
58
|
return new PixKey(phone_1.Phone.fake().toString());
|
|
61
|
-
if (options
|
|
59
|
+
if ((options === null || options === void 0 ? void 0 : options.type) == PixKeys.email)
|
|
62
60
|
return new PixKey(email_1.Email.fake().toString());
|
|
63
61
|
return new PixKey(uuid_1.UUID.fake().toString());
|
|
64
62
|
}
|
|
@@ -69,11 +67,11 @@ class PixKey extends base_1.Base {
|
|
|
69
67
|
//
|
|
70
68
|
validate() {
|
|
71
69
|
return [
|
|
72
|
-
{ type: PixKeys.cpf, fn:
|
|
73
|
-
{ type: PixKeys.cnpj, fn:
|
|
74
|
-
{ type: PixKeys.evp, fn:
|
|
75
|
-
{ type: PixKeys.email, fn:
|
|
76
|
-
{ type: PixKeys.phone, fn:
|
|
70
|
+
{ type: PixKeys.cpf, fn: _1.isCPF },
|
|
71
|
+
{ type: PixKeys.cnpj, fn: _1.isCNPJ },
|
|
72
|
+
{ type: PixKeys.evp, fn: _1.isUUID },
|
|
73
|
+
{ type: PixKeys.email, fn: _1.isEmail },
|
|
74
|
+
{ type: PixKeys.phone, fn: _1.isPhone },
|
|
77
75
|
].some(({ type, fn }) => {
|
|
78
76
|
if (fn(this._value)) {
|
|
79
77
|
this._type = type;
|
|
@@ -49,9 +49,9 @@ const utils_1 = require("./_helpers/utils");
|
|
|
49
49
|
const base_1 = require("./base");
|
|
50
50
|
const random_1 = require("./_helpers/random");
|
|
51
51
|
class PostalTrackCode extends base_1.Base {
|
|
52
|
-
_mask = null;
|
|
53
52
|
constructor(value) {
|
|
54
53
|
super(value);
|
|
54
|
+
this._mask = null;
|
|
55
55
|
this.normalize();
|
|
56
56
|
this.validate();
|
|
57
57
|
}
|
package/dist/renavam.js
CHANGED
|
@@ -41,11 +41,10 @@ const utils_1 = require("./_helpers/utils");
|
|
|
41
41
|
const base_1 = require("./base");
|
|
42
42
|
const random_1 = require("./_helpers/random");
|
|
43
43
|
class Renavam extends base_1.Base {
|
|
44
|
-
_value;
|
|
45
|
-
_mask = '0000000000-0';
|
|
46
44
|
constructor(_value) {
|
|
47
45
|
super(_value);
|
|
48
46
|
this._value = _value;
|
|
47
|
+
this._mask = '0000000000-0';
|
|
49
48
|
this.normalize();
|
|
50
49
|
this.validate();
|
|
51
50
|
}
|
package/dist/tituloEleitor.js
CHANGED
|
@@ -92,11 +92,10 @@ const utils_1 = require("./_helpers/utils");
|
|
|
92
92
|
const base_1 = require("./base");
|
|
93
93
|
const random_1 = require("./_helpers/random");
|
|
94
94
|
class TituloEleitor extends base_1.Base {
|
|
95
|
-
_value;
|
|
96
|
-
_mask = '0000.0000.0000';
|
|
97
95
|
constructor(_value) {
|
|
98
96
|
super(_value);
|
|
99
97
|
this._value = _value;
|
|
98
|
+
this._mask = '0000.0000.0000';
|
|
100
99
|
this.normalize();
|
|
101
100
|
this.validate();
|
|
102
101
|
}
|
package/dist/uf.js
CHANGED
|
@@ -38,46 +38,12 @@ const ValidationBRError_1 = __importStar(require("./_exceptions/ValidationBRErro
|
|
|
38
38
|
const random_1 = require("./_helpers/random");
|
|
39
39
|
const base_1 = require("./base");
|
|
40
40
|
class UF extends base_1.Base {
|
|
41
|
-
_mask = null;
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
*/
|
|
45
|
-
static _values = [
|
|
46
|
-
{ name: 'Acre', short: 'AC' },
|
|
47
|
-
{ name: 'Alagoas', short: 'AL' },
|
|
48
|
-
{ name: 'Amapá', short: 'AP' },
|
|
49
|
-
{ name: 'Amazonas', short: 'AM' },
|
|
50
|
-
{ name: 'Bahia', short: 'BA' },
|
|
51
|
-
{ name: 'Ceará', short: 'CE' },
|
|
52
|
-
{ name: 'Distrito Federal', short: 'DF' },
|
|
53
|
-
{ name: 'Espírito Santo', short: 'ES' },
|
|
54
|
-
{ name: 'Goiás', short: 'GO' },
|
|
55
|
-
{ name: 'Maranhão', short: 'MA' },
|
|
56
|
-
{ name: 'Mato Grosso', short: 'MT' },
|
|
57
|
-
{ name: 'Mato Grosso do Sul', short: 'MS' },
|
|
58
|
-
{ name: 'Minas Gerais', short: 'MG' },
|
|
59
|
-
{ name: 'Pará', short: 'PA' },
|
|
60
|
-
{ name: 'Paraíba', short: 'PB' },
|
|
61
|
-
{ name: 'Paraná', short: 'PR' },
|
|
62
|
-
{ name: 'Pernambuco', short: 'PE' },
|
|
63
|
-
{ name: 'Piauí', short: 'PI' },
|
|
64
|
-
{ name: 'Rio de Janeiro', short: 'RJ' },
|
|
65
|
-
{ name: 'Rio Grande do Norte', short: 'RN' },
|
|
66
|
-
{ name: 'Rio Grande do Sul', short: 'RS' },
|
|
67
|
-
{ name: 'Rondônia', short: 'RO' },
|
|
68
|
-
{ name: 'Roraima', short: 'RR' },
|
|
69
|
-
{ name: 'Santa Catarina', short: 'SC' },
|
|
70
|
-
{ name: 'São Paulo', short: 'SP' },
|
|
71
|
-
{ name: 'Sergipe', short: 'SE' },
|
|
72
|
-
{ name: 'Tocantins', short: 'TO' },
|
|
73
|
-
];
|
|
74
|
-
_value;
|
|
75
|
-
_ufItem;
|
|
76
41
|
constructor(data) {
|
|
77
42
|
if (!data)
|
|
78
43
|
throw new ValidationBRError_1.EmptyValueException();
|
|
79
44
|
const isString = typeof data === 'string';
|
|
80
45
|
super(isString ? data : data.short);
|
|
46
|
+
this._mask = null;
|
|
81
47
|
if (isString) {
|
|
82
48
|
this._value = data;
|
|
83
49
|
this.normalize();
|
|
@@ -255,6 +221,38 @@ class UF extends base_1.Base {
|
|
|
255
221
|
}
|
|
256
222
|
}
|
|
257
223
|
exports.UF = UF;
|
|
224
|
+
/**
|
|
225
|
+
*
|
|
226
|
+
*/
|
|
227
|
+
UF._values = [
|
|
228
|
+
{ name: 'Acre', short: 'AC' },
|
|
229
|
+
{ name: 'Alagoas', short: 'AL' },
|
|
230
|
+
{ name: 'Amapá', short: 'AP' },
|
|
231
|
+
{ name: 'Amazonas', short: 'AM' },
|
|
232
|
+
{ name: 'Bahia', short: 'BA' },
|
|
233
|
+
{ name: 'Ceará', short: 'CE' },
|
|
234
|
+
{ name: 'Distrito Federal', short: 'DF' },
|
|
235
|
+
{ name: 'Espírito Santo', short: 'ES' },
|
|
236
|
+
{ name: 'Goiás', short: 'GO' },
|
|
237
|
+
{ name: 'Maranhão', short: 'MA' },
|
|
238
|
+
{ name: 'Mato Grosso', short: 'MT' },
|
|
239
|
+
{ name: 'Mato Grosso do Sul', short: 'MS' },
|
|
240
|
+
{ name: 'Minas Gerais', short: 'MG' },
|
|
241
|
+
{ name: 'Pará', short: 'PA' },
|
|
242
|
+
{ name: 'Paraíba', short: 'PB' },
|
|
243
|
+
{ name: 'Paraná', short: 'PR' },
|
|
244
|
+
{ name: 'Pernambuco', short: 'PE' },
|
|
245
|
+
{ name: 'Piauí', short: 'PI' },
|
|
246
|
+
{ name: 'Rio de Janeiro', short: 'RJ' },
|
|
247
|
+
{ name: 'Rio Grande do Norte', short: 'RN' },
|
|
248
|
+
{ name: 'Rio Grande do Sul', short: 'RS' },
|
|
249
|
+
{ name: 'Rondônia', short: 'RO' },
|
|
250
|
+
{ name: 'Roraima', short: 'RR' },
|
|
251
|
+
{ name: 'Santa Catarina', short: 'SC' },
|
|
252
|
+
{ name: 'São Paulo', short: 'SP' },
|
|
253
|
+
{ name: 'Sergipe', short: 'SE' },
|
|
254
|
+
{ name: 'Tocantins', short: 'TO' },
|
|
255
|
+
];
|
|
258
256
|
class NotFoundUFException extends ValidationBRError_1.default {
|
|
259
257
|
constructor() {
|
|
260
258
|
super('UF não localizada');
|
package/dist/uuid.js
CHANGED
|
@@ -8,11 +8,10 @@ const ValidationBRError_1 = __importDefault(require("./_exceptions/ValidationBRE
|
|
|
8
8
|
const random_1 = require("./_helpers/random");
|
|
9
9
|
const base_1 = require("./base");
|
|
10
10
|
class UUID extends base_1.Base {
|
|
11
|
-
_value;
|
|
12
|
-
_mask = '00000000-0000-0000-0000-000000000000';
|
|
13
11
|
constructor(_value) {
|
|
14
12
|
super(_value);
|
|
15
13
|
this._value = _value;
|
|
14
|
+
this._mask = '00000000-0000-0000-0000-000000000000';
|
|
16
15
|
if (!this.validate()) {
|
|
17
16
|
throw new ValidationBRError_1.default('UUID inválido');
|
|
18
17
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "validation-br",
|
|
3
3
|
"description": "Brazilian personal documents validation - cpf, cnpj, titulo, pis/pasep, cnh, renavam, processos judiciais, protocolo federal, código de rastreamento dos correios",
|
|
4
|
-
"version": "2.0.0-next-
|
|
4
|
+
"version": "2.0.0-next-9",
|
|
5
5
|
"author": "Cláudio Medeiros <klawdyo@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
8
|
+
"type": "commonjs",
|
|
8
9
|
"main": "dist/index.js",
|
|
9
10
|
"types": "dist/index.d.ts",
|
|
10
11
|
"files": [
|
|
@@ -13,10 +14,12 @@
|
|
|
13
14
|
"exports": {
|
|
14
15
|
".": {
|
|
15
16
|
"types": "./dist/index.d.ts",
|
|
17
|
+
"require": "./dist/index.js",
|
|
16
18
|
"default": "./dist/index.js"
|
|
17
19
|
},
|
|
18
20
|
"./*": {
|
|
19
21
|
"types": "./dist/*.d.ts",
|
|
22
|
+
"require": "./dist/*.js",
|
|
20
23
|
"default": "./dist/*.js"
|
|
21
24
|
}
|
|
22
25
|
},
|
|
File without changes
|
|
File without changes
|