validation-br 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintcache +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/judicialProcess.d.ts +12 -0
- package/dist/judicialProcess.js +23 -4
- package/dist/judicialProcess.js.map +1 -1
- package/jest.config.js +2 -0
- package/package.json +1 -1
- package/readme.md +14 -205
package/.eslintcache
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"D:\\Desenvolvimento\\Javascript\\Validation-BR\\boilerplate-jest-eslint-ts\\.eslintrc.js":"1","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\cnh.ts":"2","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\cnpj.ts":"3","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\cpf.ts":"4","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\judicialProcess.ts":"5","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\pisPasep.ts":"6","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\postalCode.ts":"7","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\renavam.ts":"8","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\tituloEleitor.ts":"9","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\index.ts":"10","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\nup17.test.ts":"11","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\nup17.ts":"12","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\utils.ts":"13","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\judicialProcess.test.ts":"14","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\utils-randomLetter.test.ts":"15"},{"size":2512,"mtime":1641739367275,"results":"
|
|
1
|
+
[{"D:\\Desenvolvimento\\Javascript\\Validation-BR\\boilerplate-jest-eslint-ts\\.eslintrc.js":"1","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\cnh.ts":"2","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\cnpj.ts":"3","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\cpf.ts":"4","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\judicialProcess.ts":"5","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\pisPasep.ts":"6","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\postalCode.ts":"7","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\renavam.ts":"8","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\tituloEleitor.ts":"9","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\index.ts":"10","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\nup17.test.ts":"11","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\nup17.ts":"12","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\utils.ts":"13","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\judicialProcess.test.ts":"14","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\utils-randomLetter.test.ts":"15","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\jest.config.js":"16","D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\index.test.ts":"17"},{"size":2512,"mtime":1641739367275,"results":"18","hashOfConfig":"19"},{"size":3670,"mtime":1641857909477,"results":"20","hashOfConfig":"21"},{"size":3665,"mtime":1641857909477,"results":"22","hashOfConfig":"21"},{"size":3860,"mtime":1641857909479,"results":"23","hashOfConfig":"21"},{"size":6137,"mtime":1664635131177,"results":"24","hashOfConfig":"25"},{"size":3185,"mtime":1641857909611,"results":"26","hashOfConfig":"21"},{"size":3625,"mtime":1642529307638,"results":"27","hashOfConfig":"21"},{"size":3038,"mtime":1641857909470,"results":"28","hashOfConfig":"21"},{"size":3933,"mtime":1641857909467,"results":"29","hashOfConfig":"21"},{"size":1233,"mtime":1664635827132,"results":"30","hashOfConfig":"25"},{"size":3279,"mtime":1641854975529,"results":"31","hashOfConfig":"21"},{"size":4949,"mtime":1641857909475,"results":"32","hashOfConfig":"21"},{"size":5373,"mtime":1642529564093,"results":"33","hashOfConfig":"21"},{"size":4177,"mtime":1664635178621,"results":"34","hashOfConfig":"25"},{"size":316,"mtime":1642529055968,"results":"35","hashOfConfig":"21"},{"size":357,"mtime":1664633645786,"results":"36","hashOfConfig":"25"},{"size":1492,"mtime":1664635705606,"results":"37","hashOfConfig":"25"},{"filePath":"38","messages":"39","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1mhu42l",{"filePath":"40","messages":"41","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1oacsom",{"filePath":"42","messages":"43","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"44","messages":"45","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"46","messages":"47","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1mffhgm",{"filePath":"48","messages":"49","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"50","messages":"51","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"52","messages":"53","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"54","messages":"55","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"56","messages":"57","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"58","messages":"59","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"60","messages":"61","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"62","messages":"63","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"64","messages":"65","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"66","messages":"67","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"68","messages":"69","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"70","messages":"71","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"D:\\Desenvolvimento\\Javascript\\Validation-BR\\boilerplate-jest-eslint-ts\\.eslintrc.js",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\cnh.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\cnpj.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\cpf.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\judicialProcess.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\pisPasep.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\postalCode.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\renavam.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\tituloEleitor.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\index.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\nup17.test.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\nup17.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\utils.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\judicialProcess.test.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\utils-randomLetter.test.ts",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\jest.config.js",[],"D:\\Desenvolvimento\\Javascript\\Validation-BR\\Lib\\src\\index.test.ts",[]]
|
package/dist/index.d.ts
CHANGED
|
@@ -3,19 +3,19 @@ export declare const isCNPJ: (value: string | number) => boolean;
|
|
|
3
3
|
export declare const isCPF: (value: string | number) => boolean;
|
|
4
4
|
export declare const isJudicialProcess: (value: string) => boolean;
|
|
5
5
|
export declare const isPIS: (value: string) => boolean;
|
|
6
|
-
export declare const isPostalCode: (value: string
|
|
6
|
+
export declare const isPostalCode: (value: string) => boolean;
|
|
7
7
|
export declare const isRenavam: (value: string) => boolean;
|
|
8
8
|
export declare const isTituloEleitor: (value: string | number) => boolean;
|
|
9
|
-
export declare const isNUP17: (value: string
|
|
9
|
+
export declare const isNUP17: (value: string) => boolean;
|
|
10
10
|
declare const _default: {
|
|
11
11
|
isCNH: (value: string | number) => boolean;
|
|
12
12
|
isCNPJ: (value: string | number) => boolean;
|
|
13
13
|
isCPF: (value: string | number) => boolean;
|
|
14
14
|
isJudicialProcess: (value: string) => boolean;
|
|
15
15
|
isPIS: (value: string) => boolean;
|
|
16
|
-
isPostalCode: (value: string
|
|
16
|
+
isPostalCode: (value: string) => boolean;
|
|
17
17
|
isRenavam: (value: string) => boolean;
|
|
18
18
|
isTituloEleitor: (value: string | number) => boolean;
|
|
19
|
-
isNUP17: (value: string
|
|
19
|
+
isNUP17: (value: string) => boolean;
|
|
20
20
|
};
|
|
21
21
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -10,16 +10,15 @@ const pisPasep_1 = require("./pisPasep");
|
|
|
10
10
|
const postalCode_1 = require("./postalCode");
|
|
11
11
|
const renavam_1 = require("./renavam");
|
|
12
12
|
const tituloEleitor_1 = require("./tituloEleitor");
|
|
13
|
-
// export const isCNH = import('./cnh')
|
|
14
13
|
exports.isCNH = (value) => cnh_1.validate(value);
|
|
15
14
|
exports.isCNPJ = (value) => cnpj_1.validate(value);
|
|
16
15
|
exports.isCPF = (value) => cpf_1.validate(value);
|
|
17
16
|
exports.isJudicialProcess = (value) => judicialProcess_1.validate(value);
|
|
18
|
-
exports.isPIS = (value) =>
|
|
19
|
-
exports.isPostalCode = (value) =>
|
|
20
|
-
exports.isRenavam = (value) =>
|
|
21
|
-
exports.isTituloEleitor = (value) =>
|
|
22
|
-
exports.isNUP17 = (value) =>
|
|
17
|
+
exports.isPIS = (value) => pisPasep_1.validate(value);
|
|
18
|
+
exports.isPostalCode = (value) => postalCode_1.validate(value);
|
|
19
|
+
exports.isRenavam = (value) => renavam_1.validate(value);
|
|
20
|
+
exports.isTituloEleitor = (value) => tituloEleitor_1.validate(value);
|
|
21
|
+
exports.isNUP17 = (value) => nup17_1.validate(value);
|
|
23
22
|
exports.default = {
|
|
24
23
|
isCNH: exports.isCNH,
|
|
25
24
|
isCNPJ: exports.isCNPJ,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+BAAuC;AACvC,iCAAyC;AACzC,+BAAuC;AACvC,uDAA+D;AAC/D,mCAA2C;AAC3C,yCAAiD;AACjD,6CAAqD;AACrD,uCAA+C;AAC/C,mDAA2D;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+BAAuC;AACvC,iCAAyC;AACzC,+BAAuC;AACvC,uDAA+D;AAC/D,mCAA2C;AAC3C,yCAAiD;AACjD,6CAAqD;AACrD,uCAA+C;AAC/C,mDAA2D;AAE9C,QAAA,KAAK,GAAG,CAAC,KAAsB,EAAW,EAAE,CAAC,cAAG,CAAC,KAAK,CAAC,CAAA;AACvD,QAAA,MAAM,GAAG,CAAC,KAAsB,EAAW,EAAE,CAAC,eAAI,CAAC,KAAK,CAAC,CAAA;AACzD,QAAA,KAAK,GAAG,CAAC,KAAsB,EAAW,EAAE,CAAC,cAAG,CAAC,KAAK,CAAC,CAAA;AACvD,QAAA,iBAAiB,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,0BAAe,CAAC,KAAK,CAAC,CAAA;AACtE,QAAA,KAAK,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,mBAAQ,CAAC,KAAK,CAAC,CAAA;AACnD,QAAA,YAAY,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,qBAAU,CAAC,KAAK,CAAC,CAAA;AAC5D,QAAA,SAAS,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,kBAAO,CAAC,KAAK,CAAC,CAAA;AACtD,QAAA,eAAe,GAAG,CAAC,KAAsB,EAAW,EAAE,CAAC,wBAAa,CAAC,KAAK,CAAC,CAAA;AAC3E,QAAA,OAAO,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,gBAAK,CAAC,KAAK,CAAC,CAAA;AAE/D,kBAAe;IACb,KAAK,EAAL,aAAK;IACL,MAAM,EAAN,cAAM;IACN,KAAK,EAAL,aAAK;IACL,iBAAiB,EAAjB,yBAAiB;IACjB,KAAK,EAAL,aAAK;IACL,YAAY,EAAZ,oBAAY;IACZ,SAAS,EAAT,iBAAS;IACT,eAAe,EAAf,uBAAe;IACf,OAAO,EAAP,eAAO;CACR,CAAA"}
|
|
@@ -111,4 +111,16 @@ export declare const validateOrFail: (value: string) => boolean;
|
|
|
111
111
|
* @returns {Boolean}
|
|
112
112
|
*/
|
|
113
113
|
export declare const validate: (value: string) => boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Gera um número fake da sub corte de acordo com as regras:
|
|
116
|
+
* - Precisa ser uma string numérica de 2 dígitos.
|
|
117
|
+
* - Não pode ser '0'. CAso seja zero, mude para '01'.
|
|
118
|
+
*
|
|
119
|
+
* A função aceita um parâmetro para viabilizar os testes. Caso
|
|
120
|
+
* não seja definido, será gerado aleatoriamente.
|
|
121
|
+
*
|
|
122
|
+
* @param
|
|
123
|
+
*
|
|
124
|
+
*/
|
|
125
|
+
export declare function _getSubCourt(courte?: string | undefined): string;
|
|
114
126
|
export default validate;
|
package/dist/judicialProcess.js
CHANGED
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
* Fonte: https://juslaboris.tst.jus.br/bitstream/handle/20.500.12178/30318/2008_res0065_cnj_rep01.pdf?sequence=2
|
|
80
80
|
*/
|
|
81
81
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
82
|
-
exports.validate = exports.validateOrFail = exports.fake = exports.mask = exports.dv = void 0;
|
|
82
|
+
exports._getSubCourt = exports.validate = exports.validateOrFail = exports.fake = exports.mask = exports.dv = void 0;
|
|
83
83
|
const utils_1 = require("./utils");
|
|
84
84
|
/**
|
|
85
85
|
*
|
|
@@ -88,7 +88,6 @@ const utils_1 = require("./utils");
|
|
|
88
88
|
exports.dv = (value) => {
|
|
89
89
|
if (!value)
|
|
90
90
|
throw new Error('Número do processo é obrigatório');
|
|
91
|
-
// if (typeof value !== 'string') throw new Error('Número do processo precisa ser string')
|
|
92
91
|
const judicialProcess = utils_1.clearValue(value, 18);
|
|
93
92
|
const num = judicialProcess.substring(0, 7);
|
|
94
93
|
const yearAndCourt = judicialProcess.substring(7, 14);
|
|
@@ -111,8 +110,7 @@ exports.fake = (withMask = false) => {
|
|
|
111
110
|
const year = new Date().getFullYear() - +utils_1.fakeNumber(1);
|
|
112
111
|
let courte1 = utils_1.fakeNumber(1, true); // Não pode ser '0'
|
|
113
112
|
courte1 = courte1 === '0' ? '1' : courte1;
|
|
114
|
-
|
|
115
|
-
courte2 = courte2 === '0' ? '01' : courte2;
|
|
113
|
+
const courte2 = _getSubCourt();
|
|
116
114
|
const courte = `${courte1}${courte2}`;
|
|
117
115
|
const origin = utils_1.fakeNumber(4, true);
|
|
118
116
|
const judicialProcess = `${num}${year}${courte}${origin}`;
|
|
@@ -156,5 +154,26 @@ exports.validate = (value) => {
|
|
|
156
154
|
return false;
|
|
157
155
|
}
|
|
158
156
|
};
|
|
157
|
+
// ////////////////////////////////////////////
|
|
158
|
+
//
|
|
159
|
+
// Funções auxiliares
|
|
160
|
+
//
|
|
161
|
+
// ////////////////////////////////////////////
|
|
162
|
+
/**
|
|
163
|
+
* Gera um número fake da sub corte de acordo com as regras:
|
|
164
|
+
* - Precisa ser uma string numérica de 2 dígitos.
|
|
165
|
+
* - Não pode ser '0'. CAso seja zero, mude para '01'.
|
|
166
|
+
*
|
|
167
|
+
* A função aceita um parâmetro para viabilizar os testes. Caso
|
|
168
|
+
* não seja definido, será gerado aleatoriamente.
|
|
169
|
+
*
|
|
170
|
+
* @param
|
|
171
|
+
*
|
|
172
|
+
*/
|
|
173
|
+
function _getSubCourt(courte = undefined) {
|
|
174
|
+
courte = courte !== null && courte !== void 0 ? courte : utils_1.fakeNumber(2, true).toString();
|
|
175
|
+
return +courte === 0 ? '01' : courte;
|
|
176
|
+
}
|
|
177
|
+
exports._getSubCourt = _getSubCourt;
|
|
159
178
|
exports.default = exports.validate;
|
|
160
179
|
//# sourceMappingURL=judicialProcess.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"judicialProcess.js","sourceRoot":"","sources":["../src/judicialProcess.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;;;AAEH,mCAAiG;AAEjG;;;GAGG;AACU,QAAA,EAAE,GAAG,CAAC,KAAa,EAAU,EAAE;IAC1C,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"judicialProcess.js","sourceRoot":"","sources":["../src/judicialProcess.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;;;A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AAK,CAAA;KACb;AACH,CAAC,CAAA;AAED,+CAA+C;AAC/C,EAAE;AACF,qBAAqB;AACrB,EAAE;AACF,+CAA+C;AAE/C;;;;;;;;;;GAUG;AACH,SAAgB,YAAY,CAAC,SAA6B,SAAS;IACjE,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,kBAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAA;IACjD,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAA;AACtC,CAAC;AAHD,oCAGC;AAED,kBAAe,gBAAQ,CAAA"}
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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": "1.4.
|
|
4
|
+
"version": "1.4.1",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "./dist/types.d.ts",
|
|
7
7
|
"author": "Cláudio Medeiros <klawdyo@gmail.com>",
|
package/readme.md
CHANGED
|
@@ -72,7 +72,6 @@ cpf.validateOrFail('01234567890') // -> true
|
|
|
72
72
|
- [isCPF](#isCPF-value-) - Validação do CPF
|
|
73
73
|
- [isCNPJ](#isCNPJ-value-) - Validação do CNPJ
|
|
74
74
|
- [isNUP17](#isNUP17-value-) - Validação de Número Unificado de Protocolo do Governo Federal
|
|
75
|
-
- [isPostalCode](#isPostalCode-value-) - Validação de Objetos Registrados dos Correios
|
|
76
75
|
- [isJudicialProcess](#isJudicialProcess-value-) - Validação de Números de Processos Judiciais
|
|
77
76
|
- [isPIS](#isPIS-value-) - Validação de PIS, PASEP, NIS e NIT
|
|
78
77
|
- [isPostalCode](#isPostalCode-value-) - Validação de Objetos Registrados dos Correios
|
|
@@ -381,218 +380,28 @@ titulo.dv('5250288816') // -> '94'
|
|
|
381
380
|
|
|
382
381
|
# Usando com outras bibliotecas de validação
|
|
383
382
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
<details>
|
|
387
|
-
<summary>Mostrar exemplos do vuelidate</summary>
|
|
388
|
-
|
|
389
|
-
```js
|
|
390
|
-
// Importação
|
|
391
|
-
import { validation as isCPF } from 'validation-br/dist/cpf'
|
|
392
|
-
|
|
393
|
-
const fnCpf = helpers.withMessage('CPF inválido', isCPF)
|
|
394
|
-
|
|
395
|
-
// ou
|
|
396
|
-
|
|
397
|
-
const fnCpf = { $validator: isCPF, $message: 'CPF inválido' }
|
|
398
|
-
|
|
399
|
-
// Definição das regras do vuelidate
|
|
400
|
-
import { required, minLength } from '@vuelidate/validators'
|
|
401
|
-
|
|
402
|
-
const rules = {
|
|
403
|
-
cpf: { fnCpf },
|
|
404
|
-
}
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
**Saiba mais**
|
|
408
|
-
|
|
409
|
-
- [Vuelidate](https://vuelidate-next.netlify.app/)
|
|
410
|
-
|
|
411
|
-
</details>
|
|
412
|
-
|
|
413
|
-
## class-validator
|
|
414
|
-
|
|
415
|
-
<details>
|
|
416
|
-
<summary>Mostrar exemplos do class-validator</summary>
|
|
417
|
-
|
|
418
|
-
Adiciona os decorators ao class-validator.
|
|
419
|
-
|
|
420
|
-
Crie um arquivo iscpf.decorator.ts e adicione em seu diretório de validadores, exemplo:
|
|
421
|
-
`src/validators/iscpf.decorator.ts` ou em qualquer outro diretório a seu critério.
|
|
422
|
-
|
|
423
|
-
```js
|
|
424
|
-
// src/validators/iscpf.decorator.ts
|
|
425
|
-
import {
|
|
426
|
-
registerDecorator,
|
|
427
|
-
ValidationOptions,
|
|
428
|
-
ValidatorConstraint,
|
|
429
|
-
ValidatorConstraintInterface,
|
|
430
|
-
ValidationArguments,
|
|
431
|
-
} from 'class-validator'
|
|
432
|
-
|
|
433
|
-
// Importa o isCPF do validation-br
|
|
434
|
-
import { isCPF } from 'validation-br'
|
|
435
|
-
|
|
436
|
-
@ValidatorConstraint({ async: false })
|
|
437
|
-
export class IsCpfConstraint implements ValidatorConstraintInterface {
|
|
438
|
-
validate(cpf: any, args: ValidationArguments) {
|
|
439
|
-
return isCPF(cpf)
|
|
440
|
-
}
|
|
441
|
-
defaultMessage() {
|
|
442
|
-
return 'CPF inválido'
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// Registra o decorator
|
|
447
|
-
export function IsCpf(validationOptions?: ValidationOptions) {
|
|
448
|
-
return function (object: any, propertyName: string) {
|
|
449
|
-
registerDecorator({
|
|
450
|
-
target: object.constructor,
|
|
451
|
-
propertyName: propertyName,
|
|
452
|
-
options: validationOptions,
|
|
453
|
-
constraints: [],
|
|
454
|
-
validator: IsCpfConstraint,
|
|
455
|
-
})
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
Forma de uso no DTO
|
|
461
|
-
|
|
462
|
-
```ts
|
|
463
|
-
import { IsCpf } from '../../validators/iscpf.decorator'
|
|
464
|
-
|
|
465
|
-
export class CreateUserDto {
|
|
466
|
-
@IsString()
|
|
467
|
-
@IsNotEmpty()
|
|
468
|
-
@IsCpf()
|
|
469
|
-
cpf: string
|
|
470
|
-
}
|
|
471
|
-
```
|
|
472
|
-
|
|
473
|
-
**Saiba mais**
|
|
474
|
-
|
|
475
|
-
- [NestJS](https://nestjs.com)
|
|
476
|
-
- [class-validator](https://github.com/typestack/class-validator)
|
|
477
|
-
- [TypeORM](https://typeorm.io/)
|
|
478
|
-
</details>
|
|
479
|
-
|
|
480
|
-
## YUP
|
|
383
|
+
Validation-BR pode ser utilizado em conjunto com quaisquer bibliotecas de validação que permita estender seus métodos.
|
|
481
384
|
|
|
482
|
-
|
|
483
|
-
<summary>Mostrar exemplos do Yup</summary>
|
|
385
|
+
Abaixo seguem alguns exemplos. Sinta-se convidado a adicionar a sua biblioteca favorita em nosso wiki.
|
|
484
386
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
```js
|
|
490
|
-
// Importe o Yup
|
|
491
|
-
import * as yup from 'yup'
|
|
492
|
-
|
|
493
|
-
// Importe o validateOrFail do submódulo de CPF do validation-br
|
|
494
|
-
import { validateOrFail } from 'validation-br/dist/cpf'
|
|
495
|
-
|
|
496
|
-
// Crie seu método personalizado chamado cpf()
|
|
497
|
-
function cpf(message) {
|
|
498
|
-
return this.test('cpf', message, function (value) {
|
|
499
|
-
const { path, createError } = this
|
|
500
|
-
|
|
501
|
-
try {
|
|
502
|
-
const valid = validateOrFail(value)
|
|
503
|
-
return true
|
|
504
|
-
} catch (error) {
|
|
505
|
-
// Cria um erro se cair no catch
|
|
506
|
-
return createError({
|
|
507
|
-
path,
|
|
508
|
-
// Exibe a mensagem do catch
|
|
509
|
-
message: message ?? error.message,
|
|
510
|
-
})
|
|
511
|
-
}
|
|
512
|
-
})
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// Adiciona seu método cpf() ao grupo de strings do yup
|
|
516
|
-
yup.addMethod(yup.string, 'cpf', cpf)
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
### Como usar
|
|
520
|
-
|
|
521
|
-
cpf() já está disponível para uso dentro do Yup
|
|
522
|
-
|
|
523
|
-
```js
|
|
524
|
-
const validationSchema = yup.object().shape({
|
|
525
|
-
cpf: yup.string().required().cpf(),
|
|
526
|
-
})
|
|
527
|
-
```
|
|
528
|
-
|
|
529
|
-
**Saiba mais**
|
|
530
|
-
|
|
531
|
-
- [Yup](https://github.com/jquense/yup)
|
|
532
|
-
|
|
533
|
-
</details>
|
|
534
|
-
|
|
535
|
-
## Indicative
|
|
536
|
-
|
|
537
|
-
<details>
|
|
538
|
-
<summary>Mostrar exemplos do AdonisJS (Indicative)</summary>
|
|
539
|
-
|
|
540
|
-
[AdonisJS 4](https://legacy.adonisjs.com/docs/4.1/installation) usa [indicative](https://indicative-v5.adonisjs.com/) para realizar suas validações.
|
|
541
|
-
|
|
542
|
-
Crie um arquivo `validation_br.js` em seu diretório de validações customizadas, exemplo ´/app/Validators/extend/validation_br.js´.
|
|
543
|
-
|
|
544
|
-
```js
|
|
545
|
-
const { isCPF } = require('validation-br')
|
|
546
|
-
|
|
547
|
-
///app/Validators/extend/validation_br.js
|
|
548
|
-
const _cpf = async (payload, fieldName, message, arguments, get) => {
|
|
549
|
-
// Pega o valor do campo
|
|
550
|
-
const cpf = get(payload, fieldName)
|
|
551
|
-
// Pulando caso esteja vazio
|
|
552
|
-
if (!cpf) return
|
|
553
|
-
|
|
554
|
-
if (!isCPF(cpf)) {
|
|
555
|
-
throw message
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
const Validator = use('Validator')
|
|
560
|
-
Validator.extend('cpf', _cpf)
|
|
561
|
-
```
|
|
562
|
-
|
|
563
|
-
### Como usar
|
|
564
|
-
|
|
565
|
-
Agora é necessário importar o arquivo na página que avalia as suas regras de validação do seu endpoint.
|
|
566
|
-
|
|
567
|
-
```js
|
|
568
|
-
|
|
569
|
-
// Importa o arquivo com as validações customizadas
|
|
570
|
-
require('../extend/validation_br')
|
|
571
|
-
|
|
572
|
-
// Inclui a regra criada para o campo cpf
|
|
573
|
-
get rules() {
|
|
574
|
-
return {
|
|
575
|
-
cpf: [
|
|
576
|
-
rule('required'),
|
|
577
|
-
rule('cpf'),
|
|
578
|
-
]
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
**Saiba mais**
|
|
584
|
-
|
|
585
|
-
- [Adonis 4](https://legacy.adonisjs.com/docs/4.1/installation)
|
|
586
|
-
- [Indicative](https://indicative-v5.adonisjs.com/)
|
|
587
|
-
|
|
588
|
-
</details>
|
|
387
|
+
- [Vuelidate](https://github.com/klawdyo/validation-br/wiki/Vuelidate)
|
|
388
|
+
- [class-validator](https://github.com/klawdyo/validation-br/wiki/class-validator)
|
|
389
|
+
- [YUP](https://github.com/klawdyo/validation-br/wiki/YUP)
|
|
390
|
+
- [Indicative](https://github.com/klawdyo/validation-br/wiki/Indicative)
|
|
589
391
|
|
|
590
392
|
# Testes
|
|
591
393
|
|
|
592
|
-
|
|
394
|
+
Todos os testes passando com 100% de cobertura
|
|
395
|
+
|
|
396
|
+

|
|
593
397
|
|
|
594
398
|
# Changelog
|
|
595
399
|
|
|
400
|
+
- **01/10/2022**:
|
|
401
|
+
- 1.4.1
|
|
402
|
+
- Correção na importação principal dos módulos
|
|
403
|
+
- Refatoração do isJudicialProcess para permitir 100% de cobertura dos testes
|
|
404
|
+
- Inclusão de mais testes unitários para atingir 100% de cobertura
|
|
596
405
|
- **10/01/2022**:
|
|
597
406
|
- 1.1.0 - Adicionado NUP17 - Número Unificado de Protocolo de 17 dígitos do Governo Federal
|
|
598
407
|
- **09/01/2022**:
|