validation-br 1.6.0-a → 1.6.0-b
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/.prettierignore +1 -0
- package/.prettierrc.js +7 -0
- package/eslint.config.js +82 -0
- package/jest.config.js +11 -0
- package/package.json +1 -4
- package/test/cnh.test.ts +113 -0
- package/test/cnpj.test.ts +179 -0
- package/test/cpf.test.ts +124 -0
- package/test/index.test.ts +85 -0
- package/test/judicialProcess.test.ts +120 -0
- package/test/nup17.test.ts +127 -0
- package/test/pisPasep.test.ts +126 -0
- package/test/postalCode.test.ts +114 -0
- package/test/renavam.test.ts +77 -0
- package/test/tituloEleitor.test.ts +110 -0
- package/test/utils-applyMask.test.ts +13 -0
- package/test/utils-checkRepeatedSequence.test.ts +17 -0
- package/test/utils-clearValue.test.ts +69 -0
- package/test/utils-fakeNumber.test.ts +28 -0
- package/test/utils-insertAtPosition.test.ts +15 -0
- package/test/utils-randomLetter.test.ts +9 -0
- package/test/utils-removeFromPosition.test.ts +10 -0
- package/test/utils-sumElementsByMultipliers.test.ts +24 -0
- package/test/utils-sumToDV.test.ts +12 -0
- package/tsconfig.json +25 -0
- package/dist/src/_exceptions/ValidationBRError.d.ts +0 -7
- package/dist/src/_exceptions/ValidationBRError.js +0 -11
- package/dist/src/_exceptions/ValidationBRError.js.map +0 -1
- package/dist/src/cnh.d.ts +0 -98
- package/dist/src/cnh.js +0 -149
- package/dist/src/cnh.js.map +0 -1
- package/dist/src/cnpj.d.ts +0 -121
- package/dist/src/cnpj.js +0 -191
- package/dist/src/cnpj.js.map +0 -1
- package/dist/src/cpf.d.ts +0 -106
- package/dist/src/cpf.js +0 -157
- package/dist/src/cpf.js.map +0 -1
- package/dist/src/index.d.ts +0 -21
- package/dist/src/index.js +0 -42
- package/dist/src/index.js.map +0 -1
- package/dist/src/judicialProcess.d.ts +0 -133
- package/dist/src/judicialProcess.js +0 -200
- package/dist/src/judicialProcess.js.map +0 -1
- package/dist/src/nup17.d.ts +0 -103
- package/dist/src/nup17.js +0 -159
- package/dist/src/nup17.js.map +0 -1
- package/dist/src/pisPasep.d.ts +0 -88
- package/dist/src/pisPasep.js +0 -136
- package/dist/src/pisPasep.js.map +0 -1
- package/dist/src/postalCode.d.ts +0 -92
- package/dist/src/postalCode.js +0 -144
- package/dist/src/postalCode.js.map +0 -1
- package/dist/src/renavam.d.ts +0 -82
- package/dist/src/renavam.js +0 -132
- package/dist/src/renavam.js.map +0 -1
- package/dist/src/tituloEleitor.d.ts +0 -100
- package/dist/src/tituloEleitor.js +0 -157
- package/dist/src/tituloEleitor.js.map +0 -1
- package/dist/src/utils.d.ts +0 -131
- package/dist/src/utils.js +0 -190
- package/dist/src/utils.js.map +0 -1
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dist/
|
package/.prettierrc.js
ADDED
package/eslint.config.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
// root: true,
|
|
3
|
+
// extends: ['airbnb-base', 'prettier'],
|
|
4
|
+
// parserOptions: {
|
|
5
|
+
// ecmaVersion: 2018,
|
|
6
|
+
// sourceType: 'module',
|
|
7
|
+
// },
|
|
8
|
+
// env: {
|
|
9
|
+
// node: true,
|
|
10
|
+
// jest: true,
|
|
11
|
+
// },
|
|
12
|
+
settings: {
|
|
13
|
+
'import/resolver': {
|
|
14
|
+
node: {
|
|
15
|
+
extensions: ['.js', '.ts'],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
rules: {
|
|
20
|
+
// '@typescript-eslint/no-unused-vars': ['error', { varsIgnorePattern: '^_', args: 'none' }],
|
|
21
|
+
'array-callback-return': 'off',
|
|
22
|
+
'arrow-body-style': 'off',
|
|
23
|
+
curly: ['error', 'multi-line', 'consistent'],
|
|
24
|
+
'class-methods-use-this': 'off',
|
|
25
|
+
'consistent-return': 'warn',
|
|
26
|
+
'default-case': 'off',
|
|
27
|
+
// 'import/extensions': ['error', 'never'],
|
|
28
|
+
// 'import/first': 'warn',
|
|
29
|
+
// 'import/no-named-as-default': 'warn',
|
|
30
|
+
// 'import/no-named-as-default-member': 'warn',
|
|
31
|
+
// 'import/no-unresolved': 'warn',
|
|
32
|
+
// 'import/prefer-default-export': 'off',
|
|
33
|
+
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
|
|
34
|
+
'max-classes-per-file': 'off',
|
|
35
|
+
'max-len': ['error', 120, 2, { ignoreUrls: true, ignoreTemplateLiterals: true }],
|
|
36
|
+
'newline-per-chained-call': 'warn',
|
|
37
|
+
'no-await-in-loop': 'off',
|
|
38
|
+
'no-confusing-arrow': 'off',
|
|
39
|
+
'no-console': 'off',
|
|
40
|
+
'no-continue': 'off',
|
|
41
|
+
'no-else-return': ['error', { allowElseIf: true }],
|
|
42
|
+
'no-loop-func': 'off',
|
|
43
|
+
'no-mixed-operators': 'off',
|
|
44
|
+
'no-nested-ternary': 'off',
|
|
45
|
+
// 'no-only-tests/no-only-tests': 'error',
|
|
46
|
+
'no-param-reassign': 'off',
|
|
47
|
+
'no-plusplus': 'off',
|
|
48
|
+
'no-prototype-builtins': 'off',
|
|
49
|
+
'no-restricted-syntax': 'off',
|
|
50
|
+
'no-return-assign': 'warn',
|
|
51
|
+
'no-sequences': 'warn',
|
|
52
|
+
'no-shadow': 'off',
|
|
53
|
+
'no-underscore-dangle': 'off',
|
|
54
|
+
'no-unexpected-multiline': 'off',
|
|
55
|
+
'no-unused-vars': 'off',
|
|
56
|
+
'no-use-before-define': ['warn', { functions: false, classes: false }],
|
|
57
|
+
'prefer-destructuring': 'off',
|
|
58
|
+
semi: ['error', 'always'],
|
|
59
|
+
'sort-imports': 'off',
|
|
60
|
+
'no-unused-expressions': 'off',
|
|
61
|
+
quotes: ['error', 'single', { avoidEscape: true }],
|
|
62
|
+
// '@typescript-eslint/ban-types': 'error',
|
|
63
|
+
},
|
|
64
|
+
// overrides: [
|
|
65
|
+
// {
|
|
66
|
+
// files: ['*.ts'],
|
|
67
|
+
// rules: {
|
|
68
|
+
// 'no-dupe-class-members': 'off',
|
|
69
|
+
// 'no-undef': 'off',
|
|
70
|
+
// '@typescript-eslint/explicit-function-return-type': 'error',
|
|
71
|
+
// },
|
|
72
|
+
// },
|
|
73
|
+
// {
|
|
74
|
+
// files: ['*.d.ts'],
|
|
75
|
+
// rules: {
|
|
76
|
+
// 'no-useless-constructor': 'off', // crashes on constructor declaration in .d.ts files
|
|
77
|
+
// },
|
|
78
|
+
// },
|
|
79
|
+
// ],
|
|
80
|
+
// plugins: ['no-only-tests', '@typescript-eslint'],
|
|
81
|
+
ignores: ['dist/*', '/node_modules/**'],
|
|
82
|
+
};
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
moduleFileExtensions: ['ts', 'js'],
|
|
3
|
+
transform: {
|
|
4
|
+
'^.+\\.(ts|tsx)$': ['ts-jest', { /* ts-jest config goes here in Jest */ }],
|
|
5
|
+
},
|
|
6
|
+
testRegex: '(/test/.*\\.(test|spec))\\.(jsx?|tsx?)$',
|
|
7
|
+
testEnvironment: 'node',
|
|
8
|
+
coverageDirectory: './coverage/',
|
|
9
|
+
collectCoverage: true,
|
|
10
|
+
coverageProvider: 'v8',
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
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.6.0-
|
|
4
|
+
"version": "1.6.0-b",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist"
|
|
9
|
-
],
|
|
10
7
|
"author": "Cláudio Medeiros <klawdyo@gmail.com>",
|
|
11
8
|
"license": "MIT",
|
|
12
9
|
"scripts": {
|
package/test/cnh.test.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
});
|