validation-br 2.0.0-next-8 → 2.0.0-next-10
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 → cjs/_helpers}/crc.js +0 -1
- package/dist/{_helpers → cjs/_helpers}/crockford.js +2 -2
- package/dist/{_helpers → cjs/_helpers}/mask.js +0 -1
- package/dist/{_helpers → cjs/_helpers}/random.js +1 -1
- package/dist/{base.js → cjs/base.js} +0 -1
- package/dist/{carplate.js → cjs/carplate.js} +1 -2
- package/dist/{cbi_sinter.js → cjs/cbi_sinter.js} +1 -1
- package/dist/{cep.js → cjs/cep.js} +70 -71
- package/dist/cjs/certidao.d.ts +111 -0
- package/dist/cjs/certidao.js +174 -0
- package/dist/{cnh.js → cjs/cnh.js} +1 -1
- package/dist/{cnpj.js → cjs/cnpj.js} +3 -3
- package/dist/{cpf.js → cjs/cpf.js} +1 -2
- package/dist/{email.js → cjs/email.js} +1 -2
- package/dist/{judicial-process.js → cjs/judicial-process.js} +1 -8
- package/dist/{nup17.js → cjs/nup17.js} +1 -2
- package/dist/cjs/package.json +3 -0
- package/dist/{phone.js → cjs/phone.js} +23 -23
- package/dist/{pis-pasep.js → cjs/pis-pasep.js} +1 -2
- package/dist/{pix-copy-paste.js → cjs/pix-copy-paste.js} +3 -3
- package/dist/{pix-key.js → cjs/pix-key.js} +5 -7
- package/dist/{postal-track-code.js → cjs/postal-track-code.js} +1 -1
- package/dist/{renavam.js → cjs/renavam.js} +1 -2
- package/dist/{tituloEleitor.js → cjs/tituloEleitor.js} +1 -2
- package/dist/{uf.js → cjs/uf.js} +33 -35
- package/dist/{uuid.js → cjs/uuid.js} +8 -6
- package/dist/esm/_exceptions/ValidationBRError.d.ts +24 -0
- package/dist/esm/_exceptions/ValidationBRError.js +40 -0
- package/dist/esm/_helpers/crc.d.ts +7 -0
- package/dist/esm/_helpers/crc.js +43 -0
- package/dist/esm/_helpers/crockford.d.ts +31 -0
- package/dist/esm/_helpers/crockford.js +58 -0
- package/dist/esm/_helpers/mask.d.ts +18 -0
- package/dist/esm/_helpers/mask.js +33 -0
- package/dist/esm/_helpers/random.d.ts +27 -0
- package/dist/esm/_helpers/random.js +50 -0
- package/dist/esm/_helpers/utils.d.ts +94 -0
- package/dist/esm/_helpers/utils.js +119 -0
- package/dist/esm/base.d.ts +33 -0
- package/dist/esm/base.js +45 -0
- package/dist/esm/carplate.d.ts +31 -0
- package/dist/esm/carplate.js +65 -0
- package/dist/esm/cbi_sinter.d.ts +78 -0
- package/dist/esm/cbi_sinter.js +119 -0
- package/dist/esm/cep.d.ts +61 -0
- package/dist/esm/cep.js +183 -0
- package/dist/esm/certidao.d.ts +111 -0
- package/dist/esm/certidao.js +170 -0
- package/dist/esm/cnh.d.ts +80 -0
- package/dist/esm/cnh.js +124 -0
- package/dist/esm/cnpj.d.ts +107 -0
- package/dist/esm/cnpj.js +170 -0
- package/dist/esm/cpf.d.ts +88 -0
- package/dist/esm/cpf.js +132 -0
- package/dist/esm/email.d.ts +12 -0
- package/dist/esm/email.js +36 -0
- package/dist/esm/index.d.ts +15 -0
- package/dist/esm/index.js +39 -0
- package/dist/esm/judicial-process.d.ts +150 -0
- package/dist/esm/judicial-process.js +253 -0
- package/dist/esm/nup17.d.ts +98 -0
- package/dist/esm/nup17.js +150 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/phone.d.ts +103 -0
- package/dist/esm/phone.js +165 -0
- package/dist/esm/pis-pasep.d.ts +70 -0
- package/dist/esm/pis-pasep.js +111 -0
- package/dist/esm/pix-copy-paste.d.ts +26 -0
- package/dist/esm/pix-copy-paste.js +78 -0
- package/dist/esm/pix-key.d.ts +29 -0
- package/dist/esm/pix-key.js +83 -0
- package/dist/esm/postal-track-code.d.ts +76 -0
- package/dist/esm/postal-track-code.js +125 -0
- package/dist/esm/renavam.d.ts +31 -0
- package/dist/esm/renavam.js +108 -0
- package/dist/esm/tituloEleitor.d.ts +82 -0
- package/dist/esm/tituloEleitor.js +129 -0
- package/dist/esm/uf.d.ts +89 -0
- package/dist/esm/uf.js +223 -0
- package/dist/esm/uuid.d.ts +9 -0
- package/dist/esm/uuid.js +29 -0
- package/package.json +138 -129
- package/readme.md +412 -160
- package/dist/certidao.d.ts +0 -83
- package/dist/certidao.js +0 -130
- /package/dist/{_exceptions → cjs/_exceptions}/ValidationBRError.d.ts +0 -0
- /package/dist/{_exceptions → cjs/_exceptions}/ValidationBRError.js +0 -0
- /package/dist/{_helpers → cjs/_helpers}/crc.d.ts +0 -0
- /package/dist/{_helpers → cjs/_helpers}/crockford.d.ts +0 -0
- /package/dist/{_helpers → cjs/_helpers}/mask.d.ts +0 -0
- /package/dist/{_helpers → cjs/_helpers}/random.d.ts +0 -0
- /package/dist/{_helpers → cjs/_helpers}/utils.d.ts +0 -0
- /package/dist/{_helpers → cjs/_helpers}/utils.js +0 -0
- /package/dist/{base.d.ts → cjs/base.d.ts} +0 -0
- /package/dist/{carplate.d.ts → cjs/carplate.d.ts} +0 -0
- /package/dist/{cbi_sinter.d.ts → cjs/cbi_sinter.d.ts} +0 -0
- /package/dist/{cep.d.ts → cjs/cep.d.ts} +0 -0
- /package/dist/{cnh.d.ts → cjs/cnh.d.ts} +0 -0
- /package/dist/{cnpj.d.ts → cjs/cnpj.d.ts} +0 -0
- /package/dist/{cpf.d.ts → cjs/cpf.d.ts} +0 -0
- /package/dist/{email.d.ts → cjs/email.d.ts} +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{judicial-process.d.ts → cjs/judicial-process.d.ts} +0 -0
- /package/dist/{nup17.d.ts → cjs/nup17.d.ts} +0 -0
- /package/dist/{phone.d.ts → cjs/phone.d.ts} +0 -0
- /package/dist/{pis-pasep.d.ts → cjs/pis-pasep.d.ts} +0 -0
- /package/dist/{pix-copy-paste.d.ts → cjs/pix-copy-paste.d.ts} +0 -0
- /package/dist/{pix-key.d.ts → cjs/pix-key.d.ts} +0 -0
- /package/dist/{postal-track-code.d.ts → cjs/postal-track-code.d.ts} +0 -0
- /package/dist/{renavam.d.ts → cjs/renavam.d.ts} +0 -0
- /package/dist/{tituloEleitor.d.ts → cjs/tituloEleitor.d.ts} +0 -0
- /package/dist/{uf.d.ts → cjs/uf.d.ts} +0 -0
- /package/dist/{uuid.d.ts → cjs/uuid.d.ts} +0 -0
|
@@ -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');
|
|
@@ -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();
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|
|
@@ -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 → cjs/uf.js}
RENAMED
|
@@ -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');
|
|
@@ -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
|
}
|
|
@@ -22,13 +21,16 @@ class UUID extends base_1.Base {
|
|
|
22
21
|
this._value = this._value.replace(/[^0-9a-z]+/gi, '').toLocaleLowerCase();
|
|
23
22
|
}
|
|
24
23
|
validate() {
|
|
25
|
-
|
|
24
|
+
// O quarto grupo (variante, RFC 4122) deve iniciar com 8, 9, a ou b.
|
|
25
|
+
// Os demais caracteres devem ser hexadecimais (0-9, a-f).
|
|
26
|
+
return /^[0-9a-f]{8}-?[0-9a-f]{4}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$/i.test(this._value);
|
|
26
27
|
}
|
|
27
|
-
//
|
|
28
|
+
//
|
|
28
29
|
// STATIC
|
|
29
|
-
//
|
|
30
|
+
//
|
|
30
31
|
static fake() {
|
|
31
|
-
|
|
32
|
+
const variant = random_1.Random.fromArray(['8', '9', 'a', 'b']);
|
|
33
|
+
return new UUID(`${random_1.Random.number(8, true)}-${random_1.Random.number(4, true)}-4${random_1.Random.number(3, true)}-${variant}${random_1.Random.alpha(3, false, true)}-${random_1.Random.number(12, true)}`);
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
exports.UUID = UUID;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default class ValidationBRError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class InvalidChecksumException extends ValidationBRError {
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
export declare class InvalidFormatException extends ValidationBRError {
|
|
8
|
+
constructor();
|
|
9
|
+
}
|
|
10
|
+
export declare class EmptyValueException extends ValidationBRError {
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
export declare class TooLongException extends ValidationBRError {
|
|
14
|
+
constructor();
|
|
15
|
+
}
|
|
16
|
+
export declare class TooShortException extends ValidationBRError {
|
|
17
|
+
constructor();
|
|
18
|
+
}
|
|
19
|
+
export declare class RepeatedSequenceException extends ValidationBRError {
|
|
20
|
+
constructor();
|
|
21
|
+
}
|
|
22
|
+
export declare class NoChecksumException extends ValidationBRError {
|
|
23
|
+
constructor();
|
|
24
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export default class ValidationBRError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export class InvalidChecksumException extends ValidationBRError {
|
|
7
|
+
constructor() {
|
|
8
|
+
super('Dígito verificador inválido');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class InvalidFormatException extends ValidationBRError {
|
|
12
|
+
constructor() {
|
|
13
|
+
super('Formato inválido');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class EmptyValueException extends ValidationBRError {
|
|
17
|
+
constructor() {
|
|
18
|
+
super('Valor não preenchido');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class TooLongException extends ValidationBRError {
|
|
22
|
+
constructor() {
|
|
23
|
+
super('Número de caracteres excedido');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class TooShortException extends ValidationBRError {
|
|
27
|
+
constructor() {
|
|
28
|
+
super('Número de caracteres muito curto');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class RepeatedSequenceException extends ValidationBRError {
|
|
32
|
+
constructor() {
|
|
33
|
+
super('Sequência de números repetidos não permitida');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export class NoChecksumException extends ValidationBRError {
|
|
37
|
+
constructor() {
|
|
38
|
+
super('Este objeto não possui dígito verificador');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export class CRC {
|
|
2
|
+
constructor(_value) {
|
|
3
|
+
this._value = _value;
|
|
4
|
+
}
|
|
5
|
+
get value() {
|
|
6
|
+
return this._value;
|
|
7
|
+
}
|
|
8
|
+
// https://github.com/NascentSecureTech/pix-qrcode-utils/blob/01a072f458d63dea2376e631284085405fd8b027/packages/data-schemas/src/data-utils.ts#L9
|
|
9
|
+
static numToHex(n, digits = 4) {
|
|
10
|
+
const hex = n.toString(16).toUpperCase();
|
|
11
|
+
return ('0'.repeat(digits) + hex).slice(-digits);
|
|
12
|
+
}
|
|
13
|
+
calculate(invert = false) {
|
|
14
|
+
const bytes = new TextEncoder().encode(this._value);
|
|
15
|
+
const crcTable = [
|
|
16
|
+
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273,
|
|
17
|
+
0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7,
|
|
18
|
+
0x44a4, 0x5485, 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 0xb75b,
|
|
19
|
+
0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 0xc9cc, 0xd9ed, 0xe98e, 0xf9af,
|
|
20
|
+
0x8948, 0x9969, 0xa90a, 0xb92b, 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b,
|
|
21
|
+
0xab1a, 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 0x6eb6,
|
|
22
|
+
0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c,
|
|
23
|
+
0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
|
|
24
|
+
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 0x34e2, 0x24c3, 0x14a0,
|
|
25
|
+
0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676,
|
|
26
|
+
0x4615, 0x5634, 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, 0xcb7d,
|
|
27
|
+
0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d,
|
|
28
|
+
0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9,
|
|
29
|
+
0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
|
|
30
|
+
];
|
|
31
|
+
let crc = 0xffff;
|
|
32
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
33
|
+
const c = bytes[i];
|
|
34
|
+
const j = (c ^ (crc >> 8)) & 0xff;
|
|
35
|
+
crc = crcTable[j] ^ (crc << 8);
|
|
36
|
+
}
|
|
37
|
+
const answer = (crc ^ 0) & 0xffff;
|
|
38
|
+
const hex = CRC.numToHex(answer, 4);
|
|
39
|
+
if (invert)
|
|
40
|
+
return hex.slice(2) + hex.slice(0, 2);
|
|
41
|
+
return hex;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare class Crockford {
|
|
2
|
+
private static readonly ALPHABET;
|
|
3
|
+
/**
|
|
4
|
+
* Normaliza a string conforme as regras do SINTER/CIB:
|
|
5
|
+
* 1. Remove pontuação e espaços
|
|
6
|
+
* 2. Converte para Maiúsculas
|
|
7
|
+
* 3. Substitui 'I' e 'L' por '1'
|
|
8
|
+
* 4. Substitui 'O' por '0'
|
|
9
|
+
* 5. Lança erro para o caractere proibido 'U'
|
|
10
|
+
*/
|
|
11
|
+
static normalize(value: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Converte um caractere alfanumérico para seu valor decimal (0-31)
|
|
14
|
+
*/
|
|
15
|
+
static charToInt(char: string): number;
|
|
16
|
+
/**
|
|
17
|
+
* Converte um valor numérico (0-31) para o caractere correspondente
|
|
18
|
+
*/
|
|
19
|
+
static intToChar(value: number): string;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* Retorna o alfabeto utilizado
|
|
23
|
+
*/
|
|
24
|
+
static getAlphabet(): string;
|
|
25
|
+
static getAlphabet(options: {
|
|
26
|
+
returnArray: false;
|
|
27
|
+
}): string;
|
|
28
|
+
static getAlphabet(options: {
|
|
29
|
+
returnArray: true;
|
|
30
|
+
}): string[];
|
|
31
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export class Crockford {
|
|
2
|
+
/**
|
|
3
|
+
* Normaliza a string conforme as regras do SINTER/CIB:
|
|
4
|
+
* 1. Remove pontuação e espaços
|
|
5
|
+
* 2. Converte para Maiúsculas
|
|
6
|
+
* 3. Substitui 'I' e 'L' por '1'
|
|
7
|
+
* 4. Substitui 'O' por '0'
|
|
8
|
+
* 5. Lança erro para o caractere proibido 'U'
|
|
9
|
+
*/
|
|
10
|
+
static normalize(value) {
|
|
11
|
+
if (!value)
|
|
12
|
+
return "";
|
|
13
|
+
let normalized = value
|
|
14
|
+
.toUpperCase()
|
|
15
|
+
.replace(/[-.\s]/g, ""); // Remove hífens, pontos e espaços
|
|
16
|
+
// Substituições de ambiguidade visual
|
|
17
|
+
normalized = normalized.replace(/[IL]/g, "1");
|
|
18
|
+
normalized = normalized.replace(/O/g, "0");
|
|
19
|
+
// Validação do caractere proibido
|
|
20
|
+
if (normalized.includes("U")) {
|
|
21
|
+
throw new Error("O caractere 'U' é proibido no padrão CIB/SINTER para evitar palavras obscenas.");
|
|
22
|
+
}
|
|
23
|
+
return normalized;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Converte um caractere alfanumérico para seu valor decimal (0-31)
|
|
27
|
+
*/
|
|
28
|
+
static charToInt(char) {
|
|
29
|
+
// Normaliza apenas o caractere para garantir que substituições (como 'i' -> '1') ocorram
|
|
30
|
+
const cleanChar = this.normalize(char);
|
|
31
|
+
if (cleanChar.length !== 1) {
|
|
32
|
+
throw new Error("Deve ser fornecido apenas um caractere.");
|
|
33
|
+
}
|
|
34
|
+
const index = this.ALPHABET.indexOf(cleanChar);
|
|
35
|
+
if (index === -1) {
|
|
36
|
+
throw new Error(`Caractere '${char}' não pertence ao alfabeto Crockford Base32.`);
|
|
37
|
+
}
|
|
38
|
+
return index;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Converte um valor numérico (0-31) para o caractere correspondente
|
|
42
|
+
*/
|
|
43
|
+
static intToChar(value) {
|
|
44
|
+
if (value < 0 || value > 31) {
|
|
45
|
+
throw new Error("O valor deve estar entre 0 e 31 para conversão em Base32.");
|
|
46
|
+
}
|
|
47
|
+
return this.ALPHABET[value];
|
|
48
|
+
}
|
|
49
|
+
static getAlphabet(options) {
|
|
50
|
+
const { returnArray = false } = options || {};
|
|
51
|
+
if (returnArray) {
|
|
52
|
+
return this.ALPHABET.split('');
|
|
53
|
+
}
|
|
54
|
+
return this.ALPHABET;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Alfabeto Base 32 de Douglas Crockford (32 caracteres)
|
|
58
|
+
Crockford.ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class Mask {
|
|
2
|
+
private _value;
|
|
3
|
+
constructor(_value: string);
|
|
4
|
+
/**
|
|
5
|
+
* applyMask()
|
|
6
|
+
* Aplica uma máscara a uma string
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* applyMask('59650000', '00.000-000') // -> 59.650-000
|
|
10
|
+
* applyMask('99877665544', '(00) 0 0000-0000') // -> (99) 8 7766-5544
|
|
11
|
+
*
|
|
12
|
+
* @param {String|Number} value Valor original
|
|
13
|
+
* @param {String} mask
|
|
14
|
+
* @returns {String}
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
apply(mask: string): string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { clearValue, insertAtPosition } from './utils.js';
|
|
2
|
+
export class Mask {
|
|
3
|
+
constructor(_value) {
|
|
4
|
+
this._value = _value;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* applyMask()
|
|
8
|
+
* Aplica uma máscara a uma string
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* applyMask('59650000', '00.000-000') // -> 59.650-000
|
|
12
|
+
* applyMask('99877665544', '(00) 0 0000-0000') // -> (99) 8 7766-5544
|
|
13
|
+
*
|
|
14
|
+
* @param {String|Number} value Valor original
|
|
15
|
+
* @param {String} mask
|
|
16
|
+
* @returns {String}
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
apply(mask) {
|
|
20
|
+
const maskLen = clearValue(mask).length;
|
|
21
|
+
let masked = clearValue(this._value, maskLen, {
|
|
22
|
+
fillZerosAtLeft: true,
|
|
23
|
+
trimAtRight: true,
|
|
24
|
+
});
|
|
25
|
+
const specialChars = ['/', '-', '.', '(', ')', ' '];
|
|
26
|
+
for (let position = 0; position < mask.length; position += 1) {
|
|
27
|
+
const current = mask[position];
|
|
28
|
+
if (specialChars.includes(current))
|
|
29
|
+
masked = insertAtPosition(masked, current, position);
|
|
30
|
+
}
|
|
31
|
+
return masked;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare class Random {
|
|
2
|
+
/**
|
|
3
|
+
* Devolve um inteiro aleatório entre um mínimo e um máximo.
|
|
4
|
+
*/
|
|
5
|
+
static between(min: number, max: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* Devolve um texto aleatório
|
|
8
|
+
*/
|
|
9
|
+
static alpha(length?: number, isUppercase?: boolean, isHex?: boolean): string;
|
|
10
|
+
/**
|
|
11
|
+
* Seleciona um item de um array aleatoramente
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const array = [1, 2, 3, 4, 5];
|
|
15
|
+
*
|
|
16
|
+
* const singleItem = Random.fromArray(array); // Pode retornar 1, 2, 3, 4 ou 5
|
|
17
|
+
* const multipleItems = Random.fromArray(array, 3); // Pode retornar [1, 2, 3], [4, 5, 1], etc.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
static fromArray<T>(array: T[], length: number): T[];
|
|
22
|
+
static fromArray<T>(array: T[], length?: 1): T;
|
|
23
|
+
/**
|
|
24
|
+
* Cria um número aleatório com a quantidade definida de caracteres
|
|
25
|
+
*/
|
|
26
|
+
static number(length: number, forceLength?: boolean, isAlpha?: boolean): string;
|
|
27
|
+
}
|