validation-br 1.6.0 → 1.6.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/dist/_exceptions/ValidationBRError.d.ts +7 -0
- package/dist/_exceptions/ValidationBRError.js +11 -0
- package/dist/_exceptions/ValidationBRError.js.map +1 -0
- package/dist/cnh.d.ts +98 -0
- package/dist/cnh.js +149 -0
- package/dist/cnh.js.map +1 -0
- package/dist/cnpj.d.ts +121 -0
- package/dist/cnpj.js +191 -0
- package/dist/cnpj.js.map +1 -0
- package/dist/cpf.d.ts +106 -0
- package/dist/cpf.js +157 -0
- package/dist/cpf.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/judicialProcess.d.ts +133 -0
- package/dist/judicialProcess.js +200 -0
- package/dist/judicialProcess.js.map +1 -0
- package/dist/nup17.d.ts +103 -0
- package/dist/nup17.js +159 -0
- package/dist/nup17.js.map +1 -0
- package/dist/package-lock.json +4372 -0
- package/dist/package.json +117 -0
- package/dist/pisPasep.d.ts +88 -0
- package/dist/pisPasep.js +136 -0
- package/dist/pisPasep.js.map +1 -0
- package/dist/postalCode.d.ts +92 -0
- package/dist/postalCode.js +144 -0
- package/dist/postalCode.js.map +1 -0
- package/dist/readme.md +492 -0
- package/dist/renavam.d.ts +82 -0
- package/dist/renavam.js +132 -0
- package/dist/renavam.js.map +1 -0
- package/dist/tituloEleitor.d.ts +100 -0
- package/dist/tituloEleitor.js +157 -0
- package/dist/tituloEleitor.js.map +1 -0
- package/dist/utils.d.ts +131 -0
- package/dist/utils.js +190 -0
- package/dist/utils.js.map +1 -0
- package/package.json +14 -3
- package/readme.md +1 -1
- package/.prettierignore +0 -1
- package/.prettierrc.js +0 -7
- package/dist/test/cnh.test.d.ts +0 -1
- package/dist/test/cnh.test.js +0 -116
- package/dist/test/cnh.test.js.map +0 -1
- package/dist/test/cnpj.test.d.ts +0 -1
- package/dist/test/cnpj.test.js +0 -181
- package/dist/test/cnpj.test.js.map +0 -1
- package/dist/test/cpf.test.d.ts +0 -1
- package/dist/test/cpf.test.js +0 -136
- package/dist/test/cpf.test.js.map +0 -1
- package/dist/test/index.test.d.ts +0 -1
- package/dist/test/index.test.js +0 -83
- package/dist/test/index.test.js.map +0 -1
- package/dist/test/judicialProcess.test.d.ts +0 -1
- package/dist/test/judicialProcess.test.js +0 -124
- package/dist/test/judicialProcess.test.js.map +0 -1
- package/dist/test/nup17.test.d.ts +0 -1
- package/dist/test/nup17.test.js +0 -133
- package/dist/test/nup17.test.js.map +0 -1
- package/dist/test/pisPasep.test.d.ts +0 -1
- package/dist/test/pisPasep.test.js +0 -135
- package/dist/test/pisPasep.test.js.map +0 -1
- package/dist/test/postalCode.test.d.ts +0 -1
- package/dist/test/postalCode.test.js +0 -123
- package/dist/test/postalCode.test.js.map +0 -1
- package/dist/test/renavam.test.d.ts +0 -1
- package/dist/test/renavam.test.js +0 -91
- package/dist/test/renavam.test.js.map +0 -1
- package/dist/test/tituloEleitor.test.d.ts +0 -1
- package/dist/test/tituloEleitor.test.js +0 -118
- package/dist/test/tituloEleitor.test.js.map +0 -1
- package/dist/test/utils-applyMask.test.d.ts +0 -1
- package/dist/test/utils-applyMask.test.js +0 -15
- package/dist/test/utils-applyMask.test.js.map +0 -1
- package/dist/test/utils-checkRepeatedSequence.test.d.ts +0 -1
- package/dist/test/utils-checkRepeatedSequence.test.js +0 -18
- package/dist/test/utils-checkRepeatedSequence.test.js.map +0 -1
- package/dist/test/utils-clearValue.test.d.ts +0 -1
- package/dist/test/utils-clearValue.test.js +0 -59
- package/dist/test/utils-clearValue.test.js.map +0 -1
- package/dist/test/utils-fakeNumber.test.d.ts +0 -1
- package/dist/test/utils-fakeNumber.test.js +0 -24
- package/dist/test/utils-fakeNumber.test.js.map +0 -1
- package/dist/test/utils-insertAtPosition.test.d.ts +0 -1
- package/dist/test/utils-insertAtPosition.test.js +0 -16
- package/dist/test/utils-insertAtPosition.test.js.map +0 -1
- package/dist/test/utils-randomLetter.test.d.ts +0 -1
- package/dist/test/utils-randomLetter.test.js +0 -11
- package/dist/test/utils-randomLetter.test.js.map +0 -1
- package/dist/test/utils-removeFromPosition.test.d.ts +0 -1
- package/dist/test/utils-removeFromPosition.test.js +0 -12
- package/dist/test/utils-removeFromPosition.test.js.map +0 -1
- package/dist/test/utils-sumElementsByMultipliers.test.d.ts +0 -1
- package/dist/test/utils-sumElementsByMultipliers.test.js +0 -23
- package/dist/test/utils-sumElementsByMultipliers.test.js.map +0 -1
- package/dist/test/utils-sumToDV.test.d.ts +0 -1
- package/dist/test/utils-sumToDV.test.js +0 -14
- package/dist/test/utils-sumToDV.test.js.map +0 -1
- package/eslint.config.js +0 -82
- package/jest.config.js +0 -11
- package/test/cnh.test.ts +0 -113
- package/test/cnpj.test.ts +0 -179
- package/test/cpf.test.ts +0 -124
- package/test/index.test.ts +0 -85
- package/test/judicialProcess.test.ts +0 -120
- package/test/nup17.test.ts +0 -127
- package/test/pisPasep.test.ts +0 -126
- package/test/postalCode.test.ts +0 -114
- package/test/renavam.test.ts +0 -77
- package/test/tituloEleitor.test.ts +0 -110
- package/test/utils-applyMask.test.ts +0 -13
- package/test/utils-checkRepeatedSequence.test.ts +0 -17
- package/test/utils-clearValue.test.ts +0 -69
- package/test/utils-fakeNumber.test.ts +0 -28
- package/test/utils-insertAtPosition.test.ts +0 -15
- package/test/utils-randomLetter.test.ts +0 -9
- package/test/utils-removeFromPosition.test.ts +0 -10
- package/test/utils-sumElementsByMultipliers.test.ts +0 -24
- package/test/utils-sumToDV.test.ts +0 -12
- package/tsconfig.json +0 -25
package/test/cnh.test.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import isCNH, { dv, fake, mask, normalize, validate, validateOrFail } from '../src/cnh';
|
|
2
|
-
import * as _cnh from '../src/cnh';
|
|
3
|
-
|
|
4
|
-
describe('CNH', () => {
|
|
5
|
-
test.each([
|
|
6
|
-
// como inteiro
|
|
7
|
-
50195131143,
|
|
8
|
-
58316794534,
|
|
9
|
-
50195471165,
|
|
10
|
-
// como string
|
|
11
|
-
'69044271146',
|
|
12
|
-
'46190906839',
|
|
13
|
-
// com máscara
|
|
14
|
-
'624729276-37',
|
|
15
|
-
])('isCNH() - Números válidos', (item) => {
|
|
16
|
-
|
|
17
|
-
expect(isCNH(item)).toBeTruthy();
|
|
18
|
-
expect(_cnh.validate(item)).toBeTruthy();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test.each([
|
|
24
|
-
// como inteiro
|
|
25
|
-
50195131143,
|
|
26
|
-
58316794534,
|
|
27
|
-
// como string
|
|
28
|
-
'69044271146',
|
|
29
|
-
'46190906839',
|
|
30
|
-
// com máscara
|
|
31
|
-
'624729276-37',
|
|
32
|
-
])('validate() - Números válidos', (item) => {
|
|
33
|
-
|
|
34
|
-
// t.true(isCNH(cnh), `CNH ${cnh} deve ser válida`)
|
|
35
|
-
expect(validate(item)).toBeTruthy();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test.each([
|
|
39
|
-
//
|
|
40
|
-
'50195471143',
|
|
41
|
-
'58316474534',
|
|
42
|
-
'69044471146',
|
|
43
|
-
'33333333333',
|
|
44
|
-
'88888888888'
|
|
45
|
-
])('validate() - Números inválidos', (item) => {
|
|
46
|
-
|
|
47
|
-
expect(validate(item)).toBeFalsy();
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test.each(['50195471143', '58316474534', '69044471146', '33333333333', '88888888888'])('validateOrFail() - Números inválidos', (item) => {
|
|
52
|
-
expect(() => validateOrFail(item)).toThrow();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('Parâmetro não informado', () => {
|
|
56
|
-
expect(isCNH('')).toBeFalsy();
|
|
57
|
-
expect(validate('')).toBeFalsy();
|
|
58
|
-
expect(() => validateOrFail('')).toThrow();
|
|
59
|
-
expect(() => dv('')).toThrow();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test.each([...Array(5)])('fake() - Gera fakes sem máscara', () => {
|
|
63
|
-
const cnh = fake();
|
|
64
|
-
expect(validate(cnh)).toBeTruthy();
|
|
65
|
-
expect(cnh).toHaveLength(11);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test.each([...Array(5)])('fake() - Gera fakes com máscara', () => {
|
|
69
|
-
const cnh = fake(true);
|
|
70
|
-
expect(validate(cnh)).toBeTruthy();
|
|
71
|
-
expect(cnh).toHaveLength(12);
|
|
72
|
-
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test.each([
|
|
76
|
-
{ value: '501954711', expected: '65' },
|
|
77
|
-
{ value: 583164745, expected: '75' },
|
|
78
|
-
{ value: 690444711, expected: '17' },
|
|
79
|
-
])('dv() - Verificando se o DV gerado está correto', (item) => {
|
|
80
|
-
|
|
81
|
-
const calcDv = dv(item.value);
|
|
82
|
-
|
|
83
|
-
expect(calcDv).toBe(item.expected);
|
|
84
|
-
expect(typeof calcDv).toBe('string');
|
|
85
|
-
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test.each([
|
|
89
|
-
{ value: 50195471143, expected: '501954711-43' },
|
|
90
|
-
{ value: 58316474534, expected: '583164745-34' },
|
|
91
|
-
{ value: 69044471146, expected: '690444711-46' },
|
|
92
|
-
])('mask() - Testando se a máscara foi gerada corretamente', (item) => {
|
|
93
|
-
const masked = mask(item.value);
|
|
94
|
-
|
|
95
|
-
expect(masked).toBe(item.expected);
|
|
96
|
-
expect(masked).toHaveLength(12);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test.each([
|
|
100
|
-
{ value: '501954711-43', expected: '50195471143' },
|
|
101
|
-
{ value: '583164745-34', expected: '58316474534' },
|
|
102
|
-
{ value: '690444711-46', expected: '69044471146' },
|
|
103
|
-
{ value: '50195471143', expected: '50195471143' },
|
|
104
|
-
{ value: '58316474534', expected: '58316474534' },
|
|
105
|
-
{ value: '69044471146', expected: '69044471146' },
|
|
106
|
-
])('normalize() - Testando se remove a máscara corretamente', (item) => {
|
|
107
|
-
|
|
108
|
-
const normalized = normalize(item.value);
|
|
109
|
-
|
|
110
|
-
expect(normalized).toBe(item.expected);
|
|
111
|
-
expect(normalized).toHaveLength(11);
|
|
112
|
-
});
|
|
113
|
-
});
|
package/test/cnpj.test.ts
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import isCNPJ, { dv, fake, mask, validate, validateOrFail, normalize } from '../src/cnpj';
|
|
2
|
-
import * as _cnpj from '../src/cnpj';
|
|
3
|
-
|
|
4
|
-
describe('CNPJ', () => {
|
|
5
|
-
test.each([
|
|
6
|
-
// Com máscara
|
|
7
|
-
'11.222.333/0001-81',
|
|
8
|
-
'73.797.980/0001-79',
|
|
9
|
-
'06.946.762/0001-61',
|
|
10
|
-
'96.051.576/0001-57',
|
|
11
|
-
'55.585.709/0001-98',
|
|
12
|
-
// inteiro
|
|
13
|
-
99360938000180,
|
|
14
|
-
23693443000100,
|
|
15
|
-
// string
|
|
16
|
-
'32432147000147',
|
|
17
|
-
'91951438000100',
|
|
18
|
-
])('isCNPJ() - Números válidos', (cnpj) => {
|
|
19
|
-
expect(isCNPJ(cnpj)).toBeTruthy();
|
|
20
|
-
expect(_cnpj.validate(cnpj)).toBeTruthy();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test.each([
|
|
24
|
-
// Com máscara
|
|
25
|
-
'11.222.333/0001-81',
|
|
26
|
-
'73.797.980/0001-79',
|
|
27
|
-
'06.946.762/0001-61',
|
|
28
|
-
'96.051.576/0001-57',
|
|
29
|
-
'55.585.709/0001-98',
|
|
30
|
-
// inteiro
|
|
31
|
-
99360938000180,
|
|
32
|
-
23693443000100,
|
|
33
|
-
// string
|
|
34
|
-
'32432147000147',
|
|
35
|
-
'91951438000100',
|
|
36
|
-
])('validate() - Números válidos', (cnpj) => {
|
|
37
|
-
|
|
38
|
-
expect(validate(cnpj)).toBeTruthy();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test.each([
|
|
42
|
-
'53.797.980/0001-79',
|
|
43
|
-
'36.946.762/0001-61',
|
|
44
|
-
'26.051.576/0001-57',
|
|
45
|
-
'85.585.709/0001-98',
|
|
46
|
-
'39360938000180',
|
|
47
|
-
'93693443000100',
|
|
48
|
-
'12432147000147',
|
|
49
|
-
'61951438000100',
|
|
50
|
-
'11111111111111',
|
|
51
|
-
])('validate() - Números inválidos', (cnpj) => {
|
|
52
|
-
expect(validate(cnpj)).toBeFalsy();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test.each([
|
|
56
|
-
'53.797.980/0001-79',
|
|
57
|
-
'36.946.762/0001-61',
|
|
58
|
-
'26.051.576/0001-57',
|
|
59
|
-
'85.585.709/0001-98',
|
|
60
|
-
'39360938000180',
|
|
61
|
-
'93693443000100',
|
|
62
|
-
'12432147000147',
|
|
63
|
-
'61951438000100',
|
|
64
|
-
'11111111111111',
|
|
65
|
-
])('validateOrFail() - Números inválidos', (cnpj) => {
|
|
66
|
-
expect(() => validateOrFail(cnpj)).toThrow();
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('Parâmetro não informado', () => {
|
|
72
|
-
expect(isCNPJ('')).toBeFalsy();
|
|
73
|
-
expect(validate('')).toBeFalsy();
|
|
74
|
-
expect(() => validateOrFail('')).toThrow();
|
|
75
|
-
expect(() => dv('')).toThrow();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test.each([...Array(5)])('fake() - Gera fakes sem máscara', () => {
|
|
79
|
-
const cnpj = fake();
|
|
80
|
-
expect(validate(cnpj)).toBeTruthy();
|
|
81
|
-
expect(cnpj).toHaveLength(14);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test.each([...Array(5)])('fake() - Gera fakes com máscara', () => {
|
|
85
|
-
const cnpj = fake(true);
|
|
86
|
-
expect(validate(cnpj)).toBeTruthy();
|
|
87
|
-
expect(cnpj).toHaveLength(18);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test.each([...Array(5)])('fake() - Gera fakes com máscara usando opções como objeto', () => {
|
|
91
|
-
const cnpj = fake({ withMask: true, alphanumeric: false });
|
|
92
|
-
expect(validate(cnpj)).toBeTruthy();
|
|
93
|
-
expect(cnpj).toHaveLength(18);
|
|
94
|
-
expect(cnpj).toMatch(/^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test.each([...Array(5)])('fake() - Gera fakes sem máscara usando opções como objeto', () => {
|
|
98
|
-
const cnpj = fake({ withMask: false, alphanumeric: false });
|
|
99
|
-
expect(cnpj).toMatch(/^\d{14}$/);
|
|
100
|
-
expect(validate(cnpj)).toBeTruthy();
|
|
101
|
-
expect(cnpj).toHaveLength(14);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test.each([...Array(5)])('fake() - Gera CNPJs alfanuméricos', () => {
|
|
105
|
-
const cnpj = fake({ withMask: false, alphanumeric: true });
|
|
106
|
-
expect(cnpj).toMatch(/^[0-9A-Z]{14}$/);
|
|
107
|
-
expect(validate(cnpj)).toBeTruthy();
|
|
108
|
-
expect(cnpj).toHaveLength(14);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test.each([
|
|
112
|
-
{ num: '112223330001', expected: '81' },
|
|
113
|
-
{ num: 993609380001, expected: '80' },
|
|
114
|
-
{ num: '324321470001', expected: '47' },
|
|
115
|
-
{ num: '132496630001', expected: '96' },
|
|
116
|
-
{ num: '752827070001', expected: '37' },
|
|
117
|
-
{ num: '265066480001', expected: '28' },
|
|
118
|
-
{ num: '708032680001', expected: '47' },
|
|
119
|
-
{ num: '195255840001', expected: '47' },
|
|
120
|
-
{ num: '888634370001', expected: '08' },
|
|
121
|
-
{ num: '060757490001', expected: '84' },
|
|
122
|
-
{ num: '554120850001', expected: '07' },
|
|
123
|
-
{ num: '754097240001', expected: '92' },
|
|
124
|
-
|
|
125
|
-
])('dv() - Verificando se o DV gerado está correto', (item) => {
|
|
126
|
-
const calcDv = dv(item.num);
|
|
127
|
-
expect(calcDv).toBe(item.expected);
|
|
128
|
-
expect(typeof calcDv).toBe('string');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test.each([
|
|
132
|
-
{ value: '11222333000181', expected: '11.222.333/0001-81' },
|
|
133
|
-
{ value: 99360938000180, expected: '99.360.938/0001-80' },
|
|
134
|
-
{ value: '32432147000147', expected: '32.432.147/0001-47' },
|
|
135
|
-
{ value: 432147000147, expected: '00.432.147/0001-47' },
|
|
136
|
-
])('mask() - Testando se a máscara foi gerada corretamente', (item) => {
|
|
137
|
-
const masked = mask(item.value);
|
|
138
|
-
expect(masked).toBe(item.expected);
|
|
139
|
-
expect(masked).toHaveLength(18);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test.each([
|
|
143
|
-
{ value: '11.222.333/0001-81', expected: '11222333000181' },
|
|
144
|
-
{ value: '73.797.980/0001-79', expected: '73797980000179' },
|
|
145
|
-
{ value: '06.946.762/0001-61', expected: '06946762000161' },
|
|
146
|
-
{ value: '96.051.576/0001-57', expected: '96051576000157' },
|
|
147
|
-
{ value: '55.585.709/0001-98', expected: '55585709000198' },
|
|
148
|
-
])('normalize() - Deve remover a máscara corretamente', (item) => {
|
|
149
|
-
const normalized = normalize(item.value);
|
|
150
|
-
expect(normalized).toBe(item.expected);
|
|
151
|
-
expect(normalized).toHaveLength(14);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe('CNPJ alfanumérico', () => {
|
|
157
|
-
|
|
158
|
-
test.each([
|
|
159
|
-
'A3.170.7X3/0001-36',
|
|
160
|
-
'A31707X3000136',
|
|
161
|
-
])('isValid() - checa se o cnpj alfanumérico %s é válido', (cnpj) => {
|
|
162
|
-
expect(validate(cnpj)).toBeTruthy();
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
test.each([
|
|
167
|
-
{ num: 'A1.222.333/0001', expected: '50' },
|
|
168
|
-
{ num: 'B1.222.333/0001', expected: '03' },
|
|
169
|
-
{ num: 'C1.222.333/0001', expected: '67' },
|
|
170
|
-
{ num: 'D12223330001', expected: '10' },
|
|
171
|
-
{ num: 'E12223330001', expected: '74' },
|
|
172
|
-
])('dv() - Verificando se o DV gerado de %s está correto', (item) => {
|
|
173
|
-
const calcDv = dv(item.num);
|
|
174
|
-
expect(calcDv).toBe(item.expected);
|
|
175
|
-
expect(typeof calcDv).toBe('string');
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
package/test/cpf.test.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import isCPF, { dv, fake, mask, validate, validateOrFail, normalize } from '../src/cpf';
|
|
2
|
-
import * as _cpf from '../src/cpf';
|
|
3
|
-
|
|
4
|
-
describe('CPF', () => {
|
|
5
|
-
test.each([
|
|
6
|
-
// masked
|
|
7
|
-
'133.782.710-00',
|
|
8
|
-
'400.448.260-79',
|
|
9
|
-
// integer
|
|
10
|
-
8796742020, // começa com zero
|
|
11
|
-
74172316085,
|
|
12
|
-
// string
|
|
13
|
-
'15886489070',
|
|
14
|
-
'90889477086',
|
|
15
|
-
])('isCPF() - Números válidos', (item) => {
|
|
16
|
-
|
|
17
|
-
expect(isCPF(item)).toBeTruthy();
|
|
18
|
-
expect(_cpf.validate(item)).toBeTruthy();
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test.each([
|
|
23
|
-
// masked
|
|
24
|
-
'133.782.710-00',
|
|
25
|
-
'400.448.260-79',
|
|
26
|
-
// integer
|
|
27
|
-
8796742020, // começa com zero
|
|
28
|
-
74172316085,
|
|
29
|
-
// string
|
|
30
|
-
'15886489070',
|
|
31
|
-
'90889477086',
|
|
32
|
-
])('validate() - Números válidos', (item) => {
|
|
33
|
-
expect(validate(item)).toBeTruthy();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test.each([
|
|
37
|
-
'287.967.420-20',
|
|
38
|
-
'333.782.710-00',
|
|
39
|
-
'200.448.260-79',
|
|
40
|
-
'24172316085',
|
|
41
|
-
'25886489070',
|
|
42
|
-
'20889477086',
|
|
43
|
-
'11111111111',
|
|
44
|
-
])('validate() - Números inválidos', (item) => {
|
|
45
|
-
expect(validate(item)).toBeFalsy();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test.each([
|
|
49
|
-
'287.967.420-20',
|
|
50
|
-
'333.782.710-00',
|
|
51
|
-
'200.448.260-79',
|
|
52
|
-
'24172316085',
|
|
53
|
-
'25886489070',
|
|
54
|
-
'20889477086',
|
|
55
|
-
'11111111111',
|
|
56
|
-
])('validateOrFail() - Números inválidos', (item) => {
|
|
57
|
-
expect(() => validateOrFail(item)).toThrow();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test.each([
|
|
61
|
-
'24172316085000000',
|
|
62
|
-
'25886489070999999',
|
|
63
|
-
'20889477086888888',
|
|
64
|
-
'11111111111777777',
|
|
65
|
-
])('validate() - Números válidos com caracteres adicionais', (item) => {
|
|
66
|
-
expect(validate(item)).toBeFalsy();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('Parâmetro não informado', () => {
|
|
70
|
-
expect(isCPF('')).toBeFalsy();
|
|
71
|
-
expect(validate('')).toBeFalsy();
|
|
72
|
-
expect(() => validateOrFail('')).toThrow();
|
|
73
|
-
expect(() => dv('')).toThrow();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test.each([...Array(5)])('fake() - Gera fakes sem máscara', () => {
|
|
77
|
-
const cpf = fake();
|
|
78
|
-
expect(validate(cpf)).toBeTruthy();
|
|
79
|
-
expect(cpf).toHaveLength(11);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test.each([...Array(5)])('fake() - Gera fakes com máscara', () => {
|
|
83
|
-
const cpf = fake(true);
|
|
84
|
-
expect(validate(cpf)).toBeTruthy();
|
|
85
|
-
expect(cpf).toHaveLength(14);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test.each([
|
|
89
|
-
{ num: '741723160', expected: '85' },
|
|
90
|
-
{ num: 158864890, expected: '70' },
|
|
91
|
-
{ num: '908894770', expected: '86' },
|
|
92
|
-
])('dv() - Verificando se o DV gerado está correto', (item) => {
|
|
93
|
-
const calcDv = dv(item.num);
|
|
94
|
-
expect(calcDv).toBe(item.expected);
|
|
95
|
-
expect(typeof calcDv).toBe('string');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test.each([
|
|
99
|
-
{ num: '74172316085', expected: '741.723.160-85' },
|
|
100
|
-
{ num: 15886489070, expected: '158.864.890-70' },
|
|
101
|
-
{ num: '90889477086', expected: '908.894.770-86' },
|
|
102
|
-
{ num: 889477086, expected: '008.894.770-86' },
|
|
103
|
-
])('mask() - Testando se a máscara foi gerada corretamente', (item) => {
|
|
104
|
-
const masked = mask(item.num);
|
|
105
|
-
expect(masked).toBe(item.expected);
|
|
106
|
-
expect(masked).toHaveLength(14);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test.each([
|
|
110
|
-
{ value: '741.723.160-85', expected: '74172316085' },
|
|
111
|
-
{ value: '158.864.890-70', expected: '15886489070' },
|
|
112
|
-
{ value: '908.894.770-86', expected: '90889477086' },
|
|
113
|
-
{ value: '008.894.770-86', expected: '00889477086' },
|
|
114
|
-
{ value: '74172316085', expected: '74172316085' },
|
|
115
|
-
{ value: '15886489070', expected: '15886489070' },
|
|
116
|
-
{ value: '90889477086', expected: '90889477086' },
|
|
117
|
-
{ value: '889477086', expected: '00889477086' },
|
|
118
|
-
])('normalize() - Testando se remove a máscara corretamente', (item) => {
|
|
119
|
-
const masked = normalize(item.value);
|
|
120
|
-
|
|
121
|
-
expect(masked).toBe(item.expected);
|
|
122
|
-
expect(masked).toHaveLength(11);
|
|
123
|
-
});
|
|
124
|
-
});
|
package/test/index.test.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import ValidateBR, {
|
|
2
|
-
isCNH,
|
|
3
|
-
isCNPJ,
|
|
4
|
-
isCPF,
|
|
5
|
-
isJudicialProcess,
|
|
6
|
-
isNUP17,
|
|
7
|
-
isPIS,
|
|
8
|
-
isPostalCode,
|
|
9
|
-
isRenavam,
|
|
10
|
-
isTituloEleitor,
|
|
11
|
-
} from '../src/index';
|
|
12
|
-
|
|
13
|
-
describe('ValidateBR', () => {
|
|
14
|
-
test('Deve importar isCNH', () => {
|
|
15
|
-
expect(ValidateBR.isCNH).toBeDefined();
|
|
16
|
-
expect(isCNH).toBeDefined();
|
|
17
|
-
|
|
18
|
-
expect(ValidateBR.isCNH('69044271146')).toBeTruthy();
|
|
19
|
-
expect(isCNH('69044271146')).toBeTruthy();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('Deve importar isCNPJ', () => {
|
|
23
|
-
expect(ValidateBR.isCNPJ).toBeDefined();
|
|
24
|
-
expect(isCNPJ).toBeDefined();
|
|
25
|
-
|
|
26
|
-
expect(ValidateBR.isCNPJ('32432147000147')).toBeTruthy();
|
|
27
|
-
expect(isCNPJ('32432147000147')).toBeTruthy();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('Deve importar isCPF', () => {
|
|
31
|
-
expect(ValidateBR.isCPF).toBeDefined();
|
|
32
|
-
expect(isCPF).toBeDefined();
|
|
33
|
-
|
|
34
|
-
expect(ValidateBR.isCPF('15886489070')).toBeTruthy();
|
|
35
|
-
expect(isCPF('15886489070')).toBeTruthy();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('Deve importar isJudicialProcess', () => {
|
|
39
|
-
expect(ValidateBR.isJudicialProcess).toBeDefined();
|
|
40
|
-
expect(isJudicialProcess).toBeDefined();
|
|
41
|
-
|
|
42
|
-
expect(ValidateBR.isJudicialProcess('08002732820164058400')).toBeTruthy();
|
|
43
|
-
expect(isJudicialProcess('08002732820164058400')).toBeTruthy();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('Deve importar isNUP17', () => {
|
|
47
|
-
expect(ValidateBR.isNUP17).toBeDefined();
|
|
48
|
-
expect(isNUP17).toBeDefined();
|
|
49
|
-
|
|
50
|
-
expect(ValidateBR.isNUP17('23037001462202165')).toBeTruthy();
|
|
51
|
-
expect(isNUP17('23037001462202165')).toBeTruthy();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('Deve importar isPIS', () => {
|
|
55
|
-
expect(ValidateBR.isPIS).toBeDefined();
|
|
56
|
-
expect(isPIS).toBeDefined();
|
|
57
|
-
|
|
58
|
-
expect(ValidateBR.isPIS('23795126955')).toBeTruthy();
|
|
59
|
-
expect(isPIS('23795126955')).toBeTruthy();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('Deve importar isPostalCode', () => {
|
|
63
|
-
expect(ValidateBR.isPostalCode).toBeDefined();
|
|
64
|
-
expect(isPostalCode).toBeDefined();
|
|
65
|
-
|
|
66
|
-
expect(ValidateBR.isPostalCode('PN718252423BR')).toBeTruthy();
|
|
67
|
-
expect(isPostalCode('PN718252423BR')).toBeTruthy();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('Deve importar isRenavam', () => {
|
|
71
|
-
expect(ValidateBR.isRenavam).toBeDefined();
|
|
72
|
-
expect(isRenavam).toBeDefined();
|
|
73
|
-
|
|
74
|
-
expect(ValidateBR.isRenavam('80499688374')).toBeTruthy();
|
|
75
|
-
expect(isRenavam('80499688374')).toBeTruthy();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('Deve importar isTituloEleitor', () => {
|
|
79
|
-
expect(ValidateBR.isTituloEleitor).toBeDefined();
|
|
80
|
-
expect(isTituloEleitor).toBeDefined();
|
|
81
|
-
|
|
82
|
-
expect(ValidateBR.isTituloEleitor('153036161686')).toBeTruthy();
|
|
83
|
-
expect(isTituloEleitor('153036161686')).toBeTruthy();
|
|
84
|
-
});
|
|
85
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import isJudicialProcess, {
|
|
2
|
-
dv,
|
|
3
|
-
fake,
|
|
4
|
-
mask,
|
|
5
|
-
validate,
|
|
6
|
-
validateOrFail,
|
|
7
|
-
_getSubCourt,
|
|
8
|
-
normalize,
|
|
9
|
-
} from '../src/judicialProcess';
|
|
10
|
-
|
|
11
|
-
import * as _judicialProcess from '../src/judicialProcess';
|
|
12
|
-
|
|
13
|
-
describe('JudicialProcess', () => {
|
|
14
|
-
test.each([
|
|
15
|
-
'20802520125150049',
|
|
16
|
-
'61052838320098130024',
|
|
17
|
-
'00110060720168200100',
|
|
18
|
-
'08002785520134058400',
|
|
19
|
-
'08002732820164058400',
|
|
20
|
-
])('isJudicialProcess() - Números válidos', (item) => {
|
|
21
|
-
expect(isJudicialProcess(item)).toBeTruthy();
|
|
22
|
-
expect(_judicialProcess.validate(item)).toBeTruthy();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test.each([
|
|
26
|
-
'20802520125150044',
|
|
27
|
-
'61052838320098130023',
|
|
28
|
-
'00110060720168200102',
|
|
29
|
-
'08002785520134058401',
|
|
30
|
-
'08002732820164058406',
|
|
31
|
-
'08002732820160058400', // Órgão judiciário igual a 0
|
|
32
|
-
])('Números inválidos', (judicialProcess) => {
|
|
33
|
-
expect(validate(judicialProcess)).toBeFalsy();
|
|
34
|
-
expect(() => validateOrFail(judicialProcess)).toThrow();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('Parâmetro não informado', () => {
|
|
38
|
-
expect(isJudicialProcess('')).toBeFalsy();
|
|
39
|
-
expect(validate('')).toBeFalsy();
|
|
40
|
-
expect(() => validateOrFail('')).toThrow();
|
|
41
|
-
expect(() => dv('')).toThrow();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test.each([...Array(5)])('fake() - Gera fakes sem máscara', () => {
|
|
45
|
-
const judicialProcess = fake();
|
|
46
|
-
expect(validate(judicialProcess)).toBeTruthy();
|
|
47
|
-
expect(judicialProcess).toHaveLength(20);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test.each([...Array(5)])('fake() - Gera fakes com máscara', () => {
|
|
51
|
-
const judicialProcess = fake(true);
|
|
52
|
-
expect(validate(judicialProcess)).toBeTruthy();
|
|
53
|
-
expect(judicialProcess).toHaveLength(25);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test.each([
|
|
57
|
-
{ num: '000208020125150049', expected: '25' },
|
|
58
|
-
{ num: '610528320098130024', expected: '83' },
|
|
59
|
-
{ num: '001100620168200100', expected: '07' },
|
|
60
|
-
{ num: '080027820134058400', expected: '55' },
|
|
61
|
-
{ num: '080027320164058400', expected: '28' },
|
|
62
|
-
])('dv() - Verificando se o DV gerado está correto', (item) => {
|
|
63
|
-
const calcDv = dv(item.num);
|
|
64
|
-
|
|
65
|
-
expect(calcDv).toBe(item.expected);
|
|
66
|
-
expect(typeof calcDv).toBe('string');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test.each([
|
|
70
|
-
{ num: '20802520125150049', expected: '0002080-25.2012.5.15.0049' },
|
|
71
|
-
{ num: '61052838320098130024', expected: '6105283-83.2009.8.13.0024' },
|
|
72
|
-
{ num: '00110060720168200100', expected: '0011006-07.2016.8.20.0100' },
|
|
73
|
-
{ num: '08002785520134058400', expected: '0800278-55.2013.4.05.8400' },
|
|
74
|
-
{ num: '08002732820164058400', expected: '0800273-28.2016.4.05.8400' },
|
|
75
|
-
])('mask() - Testando se a máscara foi gerada corretamente', (item) => {
|
|
76
|
-
const masked = mask(item.num);
|
|
77
|
-
|
|
78
|
-
expect(masked).toBe(item.expected);
|
|
79
|
-
expect(masked).toHaveLength(25);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test.each([
|
|
83
|
-
{ value: '0002080-25.2012.5.15.0049', expected: '00020802520125150049' },
|
|
84
|
-
{ value: '6105283-83.2009.8.13.0024', expected: '61052838320098130024' },
|
|
85
|
-
{ value: '0011006-07.2016.8.20.0100', expected: '00110060720168200100' },
|
|
86
|
-
{ value: '0800278-55.2013.4.05.8400', expected: '08002785520134058400' },
|
|
87
|
-
{ value: '0800273-28.2016.4.05.8400', expected: '08002732820164058400' },
|
|
88
|
-
// Already normalized values
|
|
89
|
-
{ value: '20802520125150049', expected: '00020802520125150049' },
|
|
90
|
-
{ value: '61052838320098130024', expected: '61052838320098130024' },
|
|
91
|
-
{ value: '110060720168200100', expected: '00110060720168200100' },
|
|
92
|
-
{ value: '8002785520134058400', expected: '08002785520134058400' },
|
|
93
|
-
{ value: '8002732820164058400', expected: '08002732820164058400' },
|
|
94
|
-
])('normalize() - Testando se remove a máscara corretamente', (item) => {
|
|
95
|
-
const masked = normalize(item.value);
|
|
96
|
-
expect(masked).toBe(item.expected);
|
|
97
|
-
expect(masked).toHaveLength(20);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('_getSubCourt() - Valor diferente de zero', () => {
|
|
101
|
-
expect(_getSubCourt('01')).toBe('01');
|
|
102
|
-
expect(_getSubCourt('02')).toBe('02');
|
|
103
|
-
expect(_getSubCourt('03')).toBe('03');
|
|
104
|
-
expect(_getSubCourt('04')).toBe('04');
|
|
105
|
-
expect(_getSubCourt('05')).toBe('05');
|
|
106
|
-
expect(_getSubCourt('06')).toBe('06');
|
|
107
|
-
expect(_getSubCourt('07')).toBe('07');
|
|
108
|
-
expect(_getSubCourt('08')).toBe('08');
|
|
109
|
-
expect(_getSubCourt('09')).toBe('09');
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test('_getSubCourt() - Valor igual a zero', () => {
|
|
113
|
-
expect(_getSubCourt('00')).toBe('01');
|
|
114
|
-
expect(_getSubCourt('0')).toBe('01');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('_getSubCourt() - Valor vazio', () => {
|
|
118
|
-
expect(_getSubCourt().length).toBe(2);
|
|
119
|
-
});
|
|
120
|
-
});
|