validation-br 2.0.0-next-2 → 2.0.0-next-4

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.
Files changed (114) hide show
  1. package/.vscode/settings.json +5 -0
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +14 -1
  4. package/todo.md +2 -1
  5. package/dist/test/_helpers/crc.spec.d.ts +0 -2
  6. package/dist/test/_helpers/crc.spec.d.ts.map +0 -1
  7. package/dist/test/_helpers/crc.spec.js +0 -11
  8. package/dist/test/_helpers/crc.spec.js.map +0 -1
  9. package/dist/test/carplate.spec.d.ts +0 -2
  10. package/dist/test/carplate.spec.d.ts.map +0 -1
  11. package/dist/test/carplate.spec.js +0 -81
  12. package/dist/test/carplate.spec.js.map +0 -1
  13. package/dist/test/cep.spec.d.ts +0 -2
  14. package/dist/test/cep.spec.d.ts.map +0 -1
  15. package/dist/test/cep.spec.js +0 -95
  16. package/dist/test/cep.spec.js.map +0 -1
  17. package/dist/test/cnh.spec.d.ts +0 -2
  18. package/dist/test/cnh.spec.d.ts.map +0 -1
  19. package/dist/test/cnh.spec.js +0 -55
  20. package/dist/test/cnh.spec.js.map +0 -1
  21. package/dist/test/cnpj.spec.d.ts +0 -2
  22. package/dist/test/cnpj.spec.d.ts.map +0 -1
  23. package/dist/test/cnpj.spec.js +0 -105
  24. package/dist/test/cnpj.spec.js.map +0 -1
  25. package/dist/test/cpf.spec.d.ts +0 -2
  26. package/dist/test/cpf.spec.d.ts.map +0 -1
  27. package/dist/test/cpf.spec.js +0 -66
  28. package/dist/test/cpf.spec.js.map +0 -1
  29. package/dist/test/index.test.d.ts +0 -2
  30. package/dist/test/index.test.d.ts.map +0 -1
  31. package/dist/test/index.test.js +0 -77
  32. package/dist/test/index.test.js.map +0 -1
  33. package/dist/test/judicial-process.spec.d.ts +0 -2
  34. package/dist/test/judicial-process.spec.d.ts.map +0 -1
  35. package/dist/test/judicial-process.spec.js +0 -101
  36. package/dist/test/judicial-process.spec.js.map +0 -1
  37. package/dist/test/nup17.spec.d.ts +0 -2
  38. package/dist/test/nup17.spec.d.ts.map +0 -1
  39. package/dist/test/nup17.spec.js +0 -70
  40. package/dist/test/nup17.spec.js.map +0 -1
  41. package/dist/test/phone.spec.d.ts +0 -2
  42. package/dist/test/phone.spec.d.ts.map +0 -1
  43. package/dist/test/phone.spec.js +0 -79
  44. package/dist/test/phone.spec.js.map +0 -1
  45. package/dist/test/pis-pasep.spec.d.ts +0 -2
  46. package/dist/test/pis-pasep.spec.d.ts.map +0 -1
  47. package/dist/test/pis-pasep.spec.js +0 -65
  48. package/dist/test/pis-pasep.spec.js.map +0 -1
  49. package/dist/test/pix-copy-paste.spec.d.ts +0 -2
  50. package/dist/test/pix-copy-paste.spec.d.ts.map +0 -1
  51. package/dist/test/pix-copy-paste.spec.js +0 -31
  52. package/dist/test/pix-copy-paste.spec.js.map +0 -1
  53. package/dist/test/pix-key.spec.d.ts +0 -2
  54. package/dist/test/pix-key.spec.d.ts.map +0 -1
  55. package/dist/test/pix-key.spec.js +0 -36
  56. package/dist/test/pix-key.spec.js.map +0 -1
  57. package/dist/test/postal-track-code.test.d.ts +0 -2
  58. package/dist/test/postal-track-code.test.d.ts.map +0 -1
  59. package/dist/test/postal-track-code.test.js +0 -75
  60. package/dist/test/postal-track-code.test.js.map +0 -1
  61. package/dist/test/renavam.spec.d.ts +0 -2
  62. package/dist/test/renavam.spec.d.ts.map +0 -1
  63. package/dist/test/renavam.spec.js +0 -63
  64. package/dist/test/renavam.spec.js.map +0 -1
  65. package/dist/test/tituloEleitor.spec.d.ts +0 -2
  66. package/dist/test/tituloEleitor.spec.d.ts.map +0 -1
  67. package/dist/test/tituloEleitor.spec.js +0 -68
  68. package/dist/test/tituloEleitor.spec.js.map +0 -1
  69. package/dist/test/utils-checkRepeatedSequence.test.d.ts +0 -2
  70. package/dist/test/utils-checkRepeatedSequence.test.d.ts.map +0 -1
  71. package/dist/test/utils-checkRepeatedSequence.test.js +0 -18
  72. package/dist/test/utils-checkRepeatedSequence.test.js.map +0 -1
  73. package/dist/test/utils-clearValue.test.d.ts +0 -2
  74. package/dist/test/utils-clearValue.test.d.ts.map +0 -1
  75. package/dist/test/utils-clearValue.test.js +0 -74
  76. package/dist/test/utils-clearValue.test.js.map +0 -1
  77. package/dist/test/utils-insertAtPosition.test.d.ts +0 -2
  78. package/dist/test/utils-insertAtPosition.test.d.ts.map +0 -1
  79. package/dist/test/utils-insertAtPosition.test.js +0 -16
  80. package/dist/test/utils-insertAtPosition.test.js.map +0 -1
  81. package/dist/test/utils-removeFromPosition.test.d.ts +0 -2
  82. package/dist/test/utils-removeFromPosition.test.d.ts.map +0 -1
  83. package/dist/test/utils-removeFromPosition.test.js +0 -16
  84. package/dist/test/utils-removeFromPosition.test.js.map +0 -1
  85. package/dist/test/utils-sumElementsByMultipliers.test.d.ts +0 -2
  86. package/dist/test/utils-sumElementsByMultipliers.test.d.ts.map +0 -1
  87. package/dist/test/utils-sumElementsByMultipliers.test.js +0 -23
  88. package/dist/test/utils-sumElementsByMultipliers.test.js.map +0 -1
  89. package/dist/test/utils-sumToDV.test.d.ts +0 -2
  90. package/dist/test/utils-sumToDV.test.d.ts.map +0 -1
  91. package/dist/test/utils-sumToDV.test.js +0 -17
  92. package/dist/test/utils-sumToDV.test.js.map +0 -1
  93. package/test/_helpers/crc.spec.ts +0 -13
  94. package/test/carplate.spec.ts +0 -85
  95. package/test/cep.spec.ts +0 -127
  96. package/test/cnh.spec.ts +0 -67
  97. package/test/cnpj.spec.ts +0 -127
  98. package/test/cpf.spec.ts +0 -76
  99. package/test/index.test.ts +0 -112
  100. package/test/judicial-process.spec.ts +0 -131
  101. package/test/nup17.spec.ts +0 -79
  102. package/test/phone.spec.ts +0 -87
  103. package/test/pis-pasep.spec.ts +0 -73
  104. package/test/pix-copy-paste.spec.ts +0 -37
  105. package/test/pix-key.spec.ts +0 -41
  106. package/test/postal-track-code.test.ts +0 -83
  107. package/test/renavam.spec.ts +0 -71
  108. package/test/tituloEleitor.spec.ts +0 -72
  109. package/test/utils-checkRepeatedSequence.test.ts +0 -17
  110. package/test/utils-clearValue.test.ts +0 -85
  111. package/test/utils-insertAtPosition.test.ts +0 -15
  112. package/test/utils-removeFromPosition.test.ts +0 -15
  113. package/test/utils-sumElementsByMultipliers.test.ts +0 -24
  114. package/test/utils-sumToDV.test.ts +0 -16
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../src/utils");
4
- describe('sumElementsByMultipliers()', () => {
5
- test('Tipo do retorno', () => {
6
- const sum = (0, utils_1.sumElementsByMultipliers)('1234', [9, 8, 7, 6]);
7
- expect(typeof sum).toBe('number');
8
- expect(sum).toBe(70);
9
- });
10
- test.each([
11
- { input: '1234', multipliers: [9, 8, 7, 6], expected: 70 },
12
- // cnpj
13
- { input: '112223330001', multipliers: [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], expected: 102 },
14
- // cpf
15
- { input: '280012389', multipliers: [10, 9, 8, 7, 6, 5, 4, 3, 2], expected: 162 },
16
- { input: '2800123893', multipliers: [11, 10, 9, 8, 7, 6, 5, 4, 3, 2], expected: 201 },
17
- // titulo
18
- ])('Valores retornados', (item) => {
19
- const sum = (0, utils_1.sumElementsByMultipliers)(item.input, item.multipliers);
20
- expect(sum).toBe(item.expected);
21
- });
22
- });
23
- //# sourceMappingURL=utils-sumElementsByMultipliers.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils-sumElementsByMultipliers.test.js","sourceRoot":"","sources":["../../test/utils-sumElementsByMultipliers.test.ts"],"names":[],"mappings":";;AAAA,wCAAuD;AAEvD,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC1C,IAAI,CAAC,iBAAiB,EAAE,GAAG,EAAE;QAC3B,MAAM,GAAG,GAAG,IAAA,gCAAwB,EAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAE1D,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACjC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,IAAI,CAAC;QACR,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;QAC1D,OAAO;QACP,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE;QAC3F,MAAM;QACN,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE;QAChF,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE;QACrF,SAAS;KACV,CAAC,CAAC,oBAAoB,EAAE,CAAC,IAAI,EAAE,EAAE;QAChC,MAAM,GAAG,GAAG,IAAA,gCAAwB,EAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;QAClE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAEjC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=utils-sumToDV.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils-sumToDV.test.d.ts","sourceRoot":"","sources":["../../test/utils-sumToDV.test.ts"],"names":[],"mappings":""}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../src/utils");
4
- describe('sumToDV()', () => {
5
- test('Os resultados devem ser os esperados', () => {
6
- const list = [
7
- { value: 102, expected: 8 },
8
- { value: 120, expected: 1 },
9
- { value: 162, expected: 3 },
10
- { value: 179, expected: 8 },
11
- ];
12
- list.forEach((item) => {
13
- expect((0, utils_1.sumToDV)(item.value)).toBe(item.expected);
14
- });
15
- });
16
- });
17
- //# sourceMappingURL=utils-sumToDV.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils-sumToDV.test.js","sourceRoot":"","sources":["../../test/utils-sumToDV.test.ts"],"names":[],"mappings":";;AAAA,wCAAsC;AAEtC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAChD,MAAM,IAAI,GAAG;YACX,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE;YAC3B,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE;YAC3B,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE;YAC3B,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE;SAC5B,CAAA;QAED,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACpB,MAAM,CAAC,IAAA,eAAO,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACjD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,13 +0,0 @@
1
- import { CRC } from '../../src/_helpers/crc';
2
-
3
- describe('CRC', () => {
4
- test('Converte string para o formato CRC16', () => {
5
- // console.log(CRC(12345678))
6
- expect(new CRC('12345678').calculate()).toBe('A12B');
7
- expect(
8
- new CRC(
9
- '00020101021226390014BR.GOV.BCB.PIX0117klawdyo@gmail.com52040000530398654041.005802BR5924Jose Claudio Medeiros de6006AssuRN61085965000062200516SINASEFE-18/20216304'
10
- ).calculate()
11
- ).toBe('EB13');
12
- });
13
- });
@@ -1,85 +0,0 @@
1
- import { CarPlate } from '../src/carplate';
2
- import { isCarPlate } from '../src/main';
3
-
4
- describe('CarPlate', () => {
5
- describe('construtor', () => {
6
- test.each([
7
- 'AAA0000',
8
- 'AAA-0000',
9
- 'AAA0F00',
10
- 'AAA-0F00',
11
- 'AbA0F00',
12
- 'abc-0h00',
13
- 'abc-0h00 ',
14
- ])('A placa %s deve ser válida', (input) => {
15
- expect(new CarPlate(input)).toBeDefined();
16
- });
17
-
18
- test.each([
19
- 'A2A0000',
20
- 'AAA-00A0',
21
- 'AAA0F0',
22
- 'AAA0F077',
23
- 'AAA0F-077',
24
- '',
25
- null,
26
- undefined,
27
- ])('A placa %s deve lançar erro', (input) => {
28
- expect(() => new CarPlate(input as any)).toThrow();
29
- });
30
- });
31
-
32
- describe('isCarPlate', () => {
33
- test.each([
34
- 'AAA0000',
35
- 'AAA-0000',
36
- 'AAA0F00',
37
- 'AAA-0F00',
38
- 'AbA0F00',
39
- 'abc-0h00',
40
- ])('A placa %s deve ser válida', (clarPlate) => {
41
- expect(isCarPlate(clarPlate)).toBeTruthy();
42
- });
43
-
44
- test.each([
45
- 'A2A0000',
46
- 'AAA-00A0',
47
- 'AAA0F0',
48
- 'AAA0F077',
49
- '',
50
- null,
51
- undefined,
52
- ])('A placa %s não deve ser válida', (clarPlate) => {
53
- expect(isCarPlate(clarPlate as any)).toBeFalsy();
54
- });
55
- });
56
-
57
- describe('checlsum', () => {
58
- test('Car plate não tem DV', () => {
59
- expect(() => CarPlate.checksum('MYN-7442'));
60
- });
61
- });
62
-
63
- describe('fake', () => {
64
- test.each([...Array(5)])('Gera fakes sem mascara', () => {
65
- expect(CarPlate.fake()).toBeDefined();
66
- });
67
- });
68
-
69
- describe('mask', () => {
70
- test.each([
71
- 'AAA0000',
72
- 'AAA0900',
73
- 'AAA0F00',
74
- 'AGA0F00',
75
- 'aba0F00',
76
- 'abc0h00',
77
- ])('A placa %s deve ser válida', (clarPlate) => {
78
- const masked = new CarPlate(clarPlate).mask();
79
- expect(masked).toBeDefined();
80
- expect(masked).toBe(masked.toLocaleUpperCase());
81
- expect(masked.length).toBe(8);
82
- expect(masked).toMatch(/^[A-Z]{3}-[0-9][A-Z0-9][0-9]{2}$/);
83
- });
84
- });
85
- });
package/test/cep.spec.ts DELETED
@@ -1,127 +0,0 @@
1
- import { CEP } from '../src/cep';
2
- import { UF } from '../src/uf';
3
-
4
- describe('CEP', () => {
5
- describe('constructor', () => {
6
- test.each(['59650000', '59650-000', '59.650-000'])(
7
- '%s deve estar definido',
8
- (input) => {
9
- expect(new CEP(input)).toBeDefined();
10
- }
11
- );
12
-
13
- test.each([
14
- '5965000A', // letras
15
- '596000', // caracteres de menos
16
- '596500000', // caracteres de mais
17
- '5965-0000', // hífen fora do lugar
18
- '59.650000', // tem ponto mas não tem traço
19
- ])('%s deve lançar erro', (input) => {
20
- expect(() => new CEP(input)).toThrow();
21
- });
22
- });
23
-
24
- describe('constructor com validação por estado', () => {
25
- test.each(['59650000', '59650-000', '59.650-000'])(
26
- '%s deve estar definido',
27
- (input) => {
28
- expect(new CEP(input, { uf: UF.RN })).toBeDefined();
29
- }
30
- );
31
-
32
- test.each(['59650000', '59650-000', '59.650-000'])(
33
- '%s deve lançar erro pois não é um CEP do Ceará',
34
- (input) => {
35
- expect(() => new CEP(input, { uf: UF.CE })).toThrow();
36
- }
37
- );
38
- });
39
-
40
- describe('toString', () => {
41
- test.each(['59650000', '59650-000'])(
42
- 'CEP %s deve ser exibido sem máscara',
43
- (value) => {
44
- expect(new CEP(value).toString()).toBe('59650000');
45
- expect(new CEP(value).value).toBe('59650000');
46
- }
47
- );
48
- });
49
-
50
- describe('fake', () => {
51
- test.each([...Array(5)])('Gera fake válido', () => {
52
- const cep = CEP.fake();
53
- expect(cep).toBeDefined();
54
- expect(cep.value).toHaveLength(8);
55
- });
56
- });
57
-
58
- describe('checksum', () => {
59
- test('deve lançar erro pois cep não tem dígito verificador', () => {
60
- expect(() => CEP.checksum('59650000')).toThrow();
61
- });
62
- });
63
-
64
- describe('mask', () => {
65
- test.each([
66
- { value: '95471143', expected: '95471-143' },
67
- { value: '16474534', expected: '16474-534' },
68
- { value: '44471146', expected: '44471-146' },
69
- ])('%s deve gerar máscara corretamente', (input) => {
70
- const cep = new CEP(input.value);
71
-
72
- expect(cep.mask()).toBe(input.expected);
73
- expect(cep.mask()).toHaveLength(9);
74
- expect(cep.mask()).toMatch(/^\d{5}-\d{3}$/);
75
- });
76
- });
77
-
78
- //
79
- //
80
- //
81
- // SPECIFIC
82
- //
83
- //
84
- //
85
-
86
- describe('getUFByCEP', () => {
87
- test.each(['59650000', '59650-000', '59.650-000'])(
88
- 'O CEP de Assú deve retornar RN',
89
- (item) => {
90
- const uf = CEP.getUFByCEP(item);
91
- expect(uf).toBeDefined();
92
- expect(uf).toBeInstanceOf(UF);
93
- expect(uf.value).toBe('RN');
94
- }
95
- );
96
-
97
- test.each(['01123456', '01123-456', '01.123-456'])(
98
- 'Verifica CEPs de São Paulo para testar o "0" inicial',
99
- (item) => {
100
- const uf = CEP.getUFByCEP(item);
101
- expect(uf).toBeDefined();
102
- expect(uf).toBeInstanceOf(UF);
103
- expect(uf.value).toBe('SP');
104
- }
105
- );
106
- });
107
-
108
- describe('getRandomByUF', () => {
109
- test('Deve gerar um CEP aleatório dentro da faixa do RN', () => {
110
- const cep = CEP.getRandomByUF(UF.RN);
111
- expect(cep).toBeDefined();
112
- expect(cep.value >= '59000000').toBeTruthy();
113
- expect(cep.value <= '59999999').toBeTruthy();
114
- });
115
- });
116
-
117
- describe('getRangesByUF', () => {
118
- test.each(['59650000', '59650-000', '59.650-000'])(
119
- 'Pega as faixas do RN',
120
- () => {
121
- const [ranges] = CEP.getRangesByUF(UF.RN);
122
- expect(ranges).toBeDefined();
123
- expect(ranges).toMatchObject(['59000000', '59999999']);
124
- }
125
- );
126
- });
127
- });
package/test/cnh.spec.ts DELETED
@@ -1,67 +0,0 @@
1
- import { CNH } from '../src/cnh';
2
- import * as _cnh from '../src/cnh';
3
-
4
- describe('CNH', () => {
5
- describe('constructor', () => {
6
- test.each(['14490435923', '97286888262', '621049358-60', '491872350-50'])(
7
- 'deve estar definido',
8
- (input) => {
9
- expect(new CNH(input)).toBeDefined();
10
- }
11
- );
12
-
13
- test.each([
14
- '50995131143',
15
- '58916794534',
16
- '50995471165',
17
- '69944271146',
18
- '46990906839',
19
- '629729276-37',
20
- ])('deve lançar erro', (input) => {
21
- expect(() => new CNH(input)).toThrow();
22
- });
23
- });
24
-
25
- describe('fake', () => {
26
- test.each([...Array(5)])('Gera fakes', () => {
27
- const cnh = CNH.fake();
28
- expect(cnh).toBeDefined();
29
- expect(cnh.value).toHaveLength(11);
30
- });
31
- });
32
-
33
- describe('checksum', () => {
34
- test.each([
35
- { num: '501954711', expected: '65' },
36
- { num: '583164745', expected: '75' },
37
- { num: '690444711', expected: '17' },
38
- ])('O DV gerado deve estar correto', (item) => {
39
- const calcDv = CNH.checksum(item.num);
40
-
41
- expect(calcDv).toBe(item.expected);
42
- expect(typeof calcDv).toBe('string');
43
- });
44
-
45
- test.each(['50195471', '5831641745', ''])(
46
- 'deve lançar erro de dv',
47
- (item) => {
48
- expect(() => CNH.checksum(item)).toThrow();
49
- }
50
- );
51
- });
52
-
53
- describe('mask', () => {
54
- test.each([
55
- { value: '14490435923', expected: '144904359-23' },
56
- { value: '97286888262', expected: '972868882-62' },
57
- { value: '621049358-60', expected: '621049358-60' },
58
- { value: '491872350-50', expected: '491872350-50' },
59
- ])('máscara deve ser gerada corretamente', (input) => {
60
- const cnh = new CNH(input.value);
61
-
62
- expect(cnh.mask()).toBe(input.expected);
63
- expect(cnh.mask()).toHaveLength(12);
64
- expect(cnh.mask()).toMatch(/^\d{9}-\d{2}$/)
65
- });
66
- });
67
- });
package/test/cnpj.spec.ts DELETED
@@ -1,127 +0,0 @@
1
- import { CNPJ } from '../src/cnpj';
2
- import * as _cnpj from '../src/cnpj';
3
-
4
- describe('CNPJ', () => {
5
- describe('constructor', () => {
6
- test.each([
7
- // Com máscara
8
- '11.222.333/0001-81',
9
- '73.797.980/0001-79',
10
- '06.946.762/0001-61',
11
- '96.051.576/0001-57',
12
- '55.585.709/0001-98',
13
- '99360938000180',
14
- '23693443000100',
15
- '32432147000147',
16
- '91951438000100',
17
- ])('deve estar definido', (input) => {
18
- const cnpj = new CNPJ(input);
19
- expect(cnpj).toBeDefined();
20
- expect(cnpj.value).toMatch(/^\d{14}$/);
21
- });
22
-
23
- test.each([
24
- // Com máscara
25
- '11.222.333/0001-82', // dv invlido
26
- '73.797.980/0001-72', // dv invlido
27
- '06.946.762/0001-62', // dv invlido
28
- '96.051.576/0001-52', // dv invlido
29
- '55.585.709/0001-92', // dv invlido
30
- '993609380001804', // numero a mais
31
- '2369344300010', // numero a menos
32
- '', // vazio
33
- undefined, // undefined
34
- null, // null
35
- ])('deve lançar um erro', (input) => {
36
- expect(() => new CNPJ(input as any)).toThrow();
37
- });
38
- });
39
-
40
- describe('checksum', () => {
41
- test.each([
42
- { num: '112223330001', expected: '81' },
43
- { num: '993609380001', expected: '80' },
44
- { num: '324321470001', expected: '47' },
45
- { num: '132496630001', expected: '96' },
46
- { num: '752827070001', expected: '37' },
47
- { num: '265066480001', expected: '28' },
48
- { num: '708032680001', expected: '47' },
49
- { num: '195255840001', expected: '47' },
50
- { num: '888634370001', expected: '08' },
51
- { num: '060757490001', expected: '84' },
52
- { num: '554120850001', expected: '07' },
53
- { num: '754097240001', expected: '92' },
54
- ])('dv() - Verificando se o DV gerado está correto', (item) => {
55
- const calcDv = CNPJ.checksum(item.num);
56
- expect(calcDv).toBe(item.expected);
57
- expect(typeof calcDv).toBe('string');
58
- });
59
-
60
- test.each(['11222333000', '1122233300011', ''])(
61
- 'deve lançar erro de dv',
62
- (item) => {
63
- expect(() => CNPJ.checksum(item)).toThrow();
64
- }
65
- );
66
- });
67
-
68
- describe('mask', () => {
69
- test.each([
70
- { value: '11222333000181', expected: '11.222.333/0001-81' },
71
- { value: '99360938000180', expected: '99.360.938/0001-80' },
72
- { value: '32432147000147', expected: '32.432.147/0001-47' },
73
- { value: '00432147000150', expected: '00.432.147/0001-50' },
74
- ])('máscara correta em %s', (item) => {
75
- const masked = new CNPJ(item.value).mask();
76
- expect(masked).toBe(item.expected);
77
- expect(masked).toHaveLength(18);
78
- });
79
- });
80
-
81
- describe('fake', () => {
82
- test.each([...Array(5)])('fakes devem estar definidos', () => {
83
- const cnpj = CNPJ.fake();
84
- expect(cnpj).toBeDefined();
85
- expect(cnpj).toBeInstanceOf(CNPJ);
86
- });
87
-
88
- test.each([...Array(5)])(
89
- 'fakes alfanuméricos devem estar definidos',
90
- () => {
91
- const cnpj = CNPJ.fake({ alphanumeric: true });
92
- expect(cnpj).toBeDefined();
93
- expect(cnpj).toBeInstanceOf(CNPJ);
94
- }
95
- );
96
- });
97
-
98
- describe('CNPJ alfanumérico', () => {
99
- test.each(['A3.170.7X3/0001-36', 'A31707X3000136'])(
100
- 'isValid() - checa se o cnpj alfanumérico %s é válido',
101
- (cnpj) => {
102
- expect(new CNPJ(cnpj)).toBeDefined()
103
- }
104
- );
105
-
106
- test.each([
107
- { num: 'A12223330001', expected: '50' },
108
- { num: 'B12223330001', expected: '03' },
109
- { num: 'C12223330001', expected: '67' },
110
- { num: 'D12223330001', expected: '10' },
111
- { num: 'E12223330001', expected: '74' },
112
- ])('Deve gerar um DV correto a partir de %s ', (item) => {
113
- const calcDv = CNPJ.checksum(item.num);
114
- expect(calcDv).toBe(item.expected);
115
- expect(typeof calcDv).toBe('string');
116
- });
117
-
118
-
119
- test.each(['A1222333000', 'B122233300011', ''])(
120
- '%s deve lançar erro de dv',
121
- (item) => {
122
- expect(() => CNPJ.checksum(item)).toThrow();
123
- }
124
- );
125
-
126
- });
127
- });
package/test/cpf.spec.ts DELETED
@@ -1,76 +0,0 @@
1
- import { CPF } from '../src/cpf';
2
-
3
- describe('CPF', () => {
4
- describe('constructor', () => {
5
- test.each([
6
- '133.782.710-00',
7
- '400.448.260-79',
8
- '08796742020',
9
- '74172316085',
10
- '15886489070',
11
- '90889477086',
12
- ])('deve estar definido', (input) => {
13
- expect(new CPF(input)).toBeDefined();
14
- });
15
-
16
- test.each([
17
- '287.967.420-20',
18
- '333.782.710-00',
19
- '200.448.260-79',
20
- '24172316085',
21
- '25886489070',
22
- '20889477086',
23
- '11111111111', // repetido
24
- '', // vazio
25
- '012345678900', // caracteres a mais
26
- '12345678', // caracteres a menos
27
- null,
28
- undefined,
29
- ])('deve lançar erro', (input) => {
30
- expect(() => new CPF(input as any)).toThrow();
31
- });
32
- });
33
-
34
- describe('mask', () => {
35
- test.each([
36
- { num: '74172316085', expected: '741.723.160-85' },
37
- { num: '15886489070', expected: '158.864.890-70' },
38
- { num: '90889477086', expected: '908.894.770-86' },
39
- { num: '00889477000', expected: '008.894.770-00' },
40
- ])('mask() - Testando se a máscara foi gerada corretamente', (item) => {
41
- const masked = new CPF(item.num).mask();
42
-
43
- expect(masked).toBe(item.expected);
44
- expect(masked).toHaveLength(14);
45
- });
46
- });
47
-
48
- describe('fake', () => {
49
- test.each([...Array(5)])('fake() - Gera fakes sem máscara', () => {
50
- const cpf = CPF.fake();
51
- expect(cpf).toBeDefined();
52
- });
53
- });
54
-
55
- describe('checksum', () => {
56
- test.each([
57
- { num: '741723160', expected: '85' },
58
- { num: '158864890', expected: '70' },
59
- { num: '908894770', expected: '86' },
60
- ])('dv() - Verificando se o DV gerado está correto', (item) => {
61
- const calcDv = CPF.checksum(item.num);
62
-
63
- expect(calcDv).toBe(item.expected);
64
- expect(typeof calcDv).toBe('string');
65
- });
66
-
67
-
68
- test.each(['74172316', '1588648900', ''])(
69
- '%s deve lançar erro de dv',
70
- (item) => {
71
- expect(() => CPF.checksum(item)).toThrow();
72
- }
73
- );
74
-
75
- });
76
- });
@@ -1,112 +0,0 @@
1
- import {
2
- isCarPlate,
3
- isCNH,
4
- isCNPJ,
5
- isCPF,
6
- isJudicialProcess,
7
- isNUP17,
8
- isPhone,
9
- isPIS,
10
- isPixCopyPaste,
11
- isPixKey,
12
- isPostalTrackCode,
13
- isRenavam,
14
- isTituloEleitor,
15
- } from '../src/main'
16
-
17
- describe('ValidateBR', () => {
18
- test('Deve importar isCNH', () => {
19
- expect(isCNH).toBeDefined()
20
-
21
- expect(isCNH('69044271146')).toBeTruthy()
22
- expect(isCNH('69044271146')).toBeTruthy()
23
- })
24
-
25
- test('Deve importar isCNPJ', () => {
26
- expect(isCNPJ).toBeDefined()
27
-
28
- expect(isCNPJ('32432147000147')).toBeTruthy()
29
- expect(isCNPJ('32432147000147')).toBeTruthy()
30
- })
31
-
32
- test('Deve importar isCPF', () => {
33
- expect(isCPF).toBeDefined()
34
-
35
- expect(isCPF('15886489070')).toBeTruthy()
36
- expect(isCPF('15886489070')).toBeTruthy()
37
- })
38
-
39
- test('Deve importar isJudicialProcess', () => {
40
- expect(isJudicialProcess).toBeDefined()
41
-
42
- expect(isJudicialProcess('08002732820164058400')).toBeTruthy()
43
- expect(isJudicialProcess('08002732820164058400')).toBeTruthy()
44
- })
45
-
46
- test('Deve importar isNUP17', () => {
47
- expect(isNUP17).toBeDefined()
48
-
49
- expect(isNUP17('23037001462202165')).toBeTruthy()
50
- expect(isNUP17('23037001462202165')).toBeTruthy()
51
- })
52
-
53
- test('Deve importar isPIS', () => {
54
- expect(isPIS).toBeDefined()
55
-
56
- expect(isPIS('23795126955')).toBeTruthy()
57
- expect(isPIS('23795126955')).toBeTruthy()
58
- })
59
-
60
- test('Deve importar isPostalTrackCode', () => {
61
- expect(isPostalTrackCode).toBeDefined()
62
-
63
- expect(isPostalTrackCode('PN718252423BR')).toBeTruthy()
64
- expect(isPostalTrackCode('PN718252423BR')).toBeTruthy()
65
- })
66
-
67
- test('Deve importar isRenavam', () => {
68
- expect(isRenavam).toBeDefined()
69
-
70
- expect(isRenavam('80499688374')).toBeTruthy()
71
- expect(isRenavam('80499688374')).toBeTruthy()
72
- })
73
-
74
- test('Deve importar isTituloEleitor', () => {
75
- expect(isTituloEleitor).toBeDefined()
76
-
77
- expect(isTituloEleitor('153036161686')).toBeTruthy()
78
- expect(isTituloEleitor('153036161686')).toBeTruthy()
79
- })
80
-
81
- test('Deve importar isCarPlate', () => {
82
- expect(isCarPlate).toBeDefined()
83
-
84
- expect(isCarPlate('AAA-1A34')).toBeTruthy()
85
- expect(isCarPlate('AAA-1A34')).toBeTruthy()
86
- })
87
-
88
- test('Deve importar isPhone', () => {
89
- expect(isPhone).toBeDefined()
90
-
91
- expect(isPhone('+5584987654321')).toBeTruthy()
92
- expect(isPhone('+558433311454')).toBeTruthy()
93
- })
94
- test('Deve importar isPixKey', () => {
95
- expect(isPixKey).toBeDefined()
96
-
97
- expect(isPixKey('klawdyo@gmail.com')).toBeTruthy()
98
- expect(isPixKey('+5584987654321')).toBeTruthy()
99
- expect(isPixKey('+558433311454')).toBeTruthy()
100
- expect(isPixKey('01234567-0123-4567-8900-000000000000')).toBeTruthy()
101
- expect(isPixKey('99360938000180')).toBeTruthy()
102
- expect(isPixKey('74172316085')).toBeTruthy()
103
- })
104
- test('Deve importar isPixCopyPaste', () => {
105
- expect(isPixCopyPaste).toBeDefined()
106
- const pixStone = `00020101021226820014br.gov.bcb.pix2560pix.stone.com.br/pix/v2/b411f5c8-e97f-4a18-af0e-fc66491748d7520400005303986540510.005802BR5925DIOGO DA SILVA SANTOS LTD6014RIO DE JANEIRO622905251e3afd7926983f8ffe086cdc16304FF60`;
107
- const pixManual = `00020126550014BR.GOV.BCB.PIX0123alexandrepato@gmail.com0206almoco5204000053039865406100.005802BR5914Alexandre Pato6009Ipanguacu61085950800062490511PIXJS76657250300017BR.GOV.BCB.BRCODE01051.0.0630455CF`;
108
-
109
- expect(isPixCopyPaste(pixStone)).toBeTruthy()
110
- expect(isPixCopyPaste(pixManual)).toBeTruthy()
111
- })
112
- })