Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

validation-br

Package Overview
Dependencies
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validation-br - npm Package Compare versions

Comparing version 2.0.0-next-1 to 2.0.0-next-2

dist/test/cep.spec.d.ts

112

dist/test/carplate.spec.js

@@ -54,89 +54,29 @@ "use strict";

});
// describe('validate', () => {
// test.each([
// 'AAA0000',
// 'AAA-0000',
// 'AAA0F00',
// 'AAA-0F00',
// 'AbA0F00',
// 'abc-0h00',
// ])('A placa %s deve ser válida', (clarPlate) => {
// expect(validate(clarPlate)).toBeTruthy()
// });
// test.each([
// 'A2A0000',
// 'AAA-00A0',
// 'AAA0F0',
// 'AAA0F077',
// '',
// null,
// undefined,
// ])('A placa %s não deve ser válida', (clarPlate) => {
// // @ts-ignore
// expect(validate(clarPlate)).toBeFalsy()
// })
// })
// describe('validateOrFail', () => {
// test.each([
// 'AAA0000',
// 'AAA-0000',
// 'AAA0F00',
// 'AAA-0F00',
// 'AbA0F00',
// 'abc-0h00',
// ])('A placa %s deve ser válida', (clarPlate) => {
// expect(validateOrFail(clarPlate)).toBeTruthy()
// });
// test.each([
// 'A2A0000',
// 'AAA-00A0',
// 'AAA0F0',
// 'AAA0F077',
// '',
// null,
// undefined,
// ])('A placa %s não deve ser válida', (clarPlate) => {
// // @ts-ignore
// expect(()=>validateOrFail(clarPlate)).toThrow()
// })
// })
// describe('DV', () => {
// test('Car plate não tem DV', () => {
// expect(dv('AAA0000')).toBeNull()
// expect(checksum('AAA0000')).toBeNull()
// })
// })
// describe('fake', () => {
// test('Gera fakes sem mascara', () => {
// for (let i = 0; i <= 20; i++) {
// const carPlate = fake()
// expect(validate(carPlate)).toBeTruthy()
// expect(carPlate.length).toBe(7)
// }
// })
// test('Gera fakes com mascara', () => {
// for (let i = 0; i <= 20; i++) {
// const carPlate = fake(true)
// expect(validate(carPlate)).toBeTruthy()
// expect(carPlate.length).toBe(8)
// }
// })
// })
// describe('mask', () => {
// test.each([
// 'AAA0000',
// 'AAA0900',
// 'AAA0F00',
// 'AGA0F00',
// 'aba0F00',
// 'abc0h00',
// ])('A placa %s deve ser válida', (clarPlate) => {
// const masked = mask(clarPlate)
// expect(masked).toBeDefined()
// expect(masked).toBe(masked.toLocaleUpperCase())
// expect(masked.length).toBe(8)
// expect(masked).toMatch(/^[A-Z]{3}-[0-9][A-Z0-9][0-9]{2}$/)
// })
// })
describe('checlsum', () => {
test('Car plate não tem DV', () => {
expect(() => carplate_1.CarPlate.checksum('MYN-7442'));
});
});
describe('fake', () => {
test.each([...Array(5)])('Gera fakes sem mascara', () => {
expect(carplate_1.CarPlate.fake()).toBeDefined();
});
});
describe('mask', () => {
test.each([
'AAA0000',
'AAA0900',
'AAA0F00',
'AGA0F00',
'aba0F00',
'abc0h00',
])('A placa %s deve ser válida', (clarPlate) => {
const masked = new carplate_1.CarPlate(clarPlate).mask();
expect(masked).toBeDefined();
expect(masked).toBe(masked.toLocaleUpperCase());
expect(masked.length).toBe(8);
expect(masked).toMatch(/^[A-Z]{3}-[0-9][A-Z0-9][0-9]{2}$/);
});
});
});
//# sourceMappingURL=carplate.spec.js.map

@@ -6,21 +6,14 @@ "use strict";

describe('constructor', () => {
test.each([
'50195131143',
'58316794534',
'50195471165',
'69044271146',
'46190906839',
'624729276-37',
])('deve estar definido', (input) => {
test.each(['14490435923', '97286888262', '621049358-60', '491872350-50'])('deve estar definido', (input) => {
expect(new cnh_1.CNH(input)).toBeDefined();
});
test.each([
'50195131143',
'58316794534',
'50195471165',
'69044271146',
'46190906839',
'624729276-37',
'50995131143',
'58916794534',
'50995471165',
'69944271146',
'46990906839',
'629729276-37',
])('deve lançar erro', (input) => {
expect(new cnh_1.CNH(input)).toBeDefined();
expect(() => new cnh_1.CNH(input)).toThrow();
});

@@ -51,5 +44,6 @@ });

test.each([
{ value: '50195471143', expected: '501954711-43' },
{ value: '58316474534', expected: '583164745-34' },
{ value: '69044471146', expected: '690444711-46' },
{ value: '14490435923', expected: '144904359-23' },
{ value: '97286888262', expected: '972868882-62' },
{ value: '621049358-60', expected: '621049358-60' },
{ value: '491872350-50', expected: '491872350-50' },
])('máscara deve ser gerada corretamente', (input) => {

@@ -59,2 +53,3 @@ const cnh = new cnh_1.CNH(input.value);

expect(cnh.mask()).toHaveLength(12);
expect(cnh.mask()).toMatch(/^\d{9}-\d{2}$/);
});

@@ -61,0 +56,0 @@ });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const phone_1 = require("../src/phone");
const cellPhones = ['+5584999580685', '+55 84 9 9958 0685', '+55 (84) 9 9958-0685', '+55 (84) 99958-0685', '84 99958-0685'];
const phones = ['+558433311454', '84 3331-1454', '84 3331 1454', '(84) 3331 1454', '84-3331-1454'];
const cellPhones = [
'+5584999580685',
'+55 84 9 9958 0685',
'+55 (84) 9 9958-0685',
'+55 (84) 99958-0685',
'84 99958-0685',
];
const phones = [
'+558433311454',
'84 3331-1454',
'84 3331 1454',
'(84) 3331 1454',
'84-3331-1454',
];
describe('Phone', () => {

@@ -30,3 +42,3 @@ describe('constructor', () => {

});
test.each([...Array(5)])('Cria um fake com DDD 11', () => {
test.each([...Array(50)])('Cria um fake com DDD 11', () => {
const fake = phone_1.Phone.fake({ ddd: '11' });

@@ -33,0 +45,0 @@ expect(fake).toBeDefined();

{
"name": "validation-br",
"description": "Brazilian personal documents validation - cpf, cnpj, titulo, pis/pasep, cnh, renavam, processos judiciais, protocolo federal, código de rastreamento dos correios",
"version": "2.0.0-next-1",
"version": "2.0.0-next-2",
"main": "dist/index.js",

@@ -6,0 +6,0 @@ "types": "./dist/index.d.ts",

@@ -1,2 +0,2 @@

import { CarPlate } from '../src/carplate'
import { CarPlate } from '../src/carplate';
import { isCarPlate } from '../src/main';

@@ -6,3 +6,2 @@

describe('construtor', () => {
test.each([

@@ -17,3 +16,3 @@ 'AAA0000',

])('A placa %s deve ser válida', (input) => {
expect(new CarPlate(input)).toBeDefined()
expect(new CarPlate(input)).toBeDefined();
});

@@ -31,8 +30,7 @@

])('A placa %s deve lançar erro', (input) => {
expect(() => new CarPlate(input as any)).toThrow()
})
})
expect(() => new CarPlate(input as any)).toThrow();
});
});
describe('isCarPlate', () => {
test.each([

@@ -46,3 +44,3 @@ 'AAA0000',

])('A placa %s deve ser válida', (clarPlate) => {
expect(isCarPlate(clarPlate)).toBeTruthy()
expect(isCarPlate(clarPlate)).toBeTruthy();
});

@@ -59,108 +57,34 @@

])('A placa %s não deve ser válida', (clarPlate) => {
expect(isCarPlate(clarPlate as any)).toBeFalsy()
})
})
expect(isCarPlate(clarPlate as any)).toBeFalsy();
});
});
// describe('validate', () => {
describe('checlsum', () => {
test('Car plate não tem DV', () => {
expect(() => CarPlate.checksum('MYN-7442'));
});
});
// test.each([
// 'AAA0000',
// 'AAA-0000',
// 'AAA0F00',
// 'AAA-0F00',
// 'AbA0F00',
// 'abc-0h00',
// ])('A placa %s deve ser válida', (clarPlate) => {
// expect(validate(clarPlate)).toBeTruthy()
// });
describe('fake', () => {
test.each([...Array(5)])('Gera fakes sem mascara', () => {
expect(CarPlate.fake()).toBeDefined();
});
});
// test.each([
// 'A2A0000',
// 'AAA-00A0',
// 'AAA0F0',
// 'AAA0F077',
// '',
// null,
// undefined,
// ])('A placa %s não deve ser válida', (clarPlate) => {
// // @ts-ignore
// expect(validate(clarPlate)).toBeFalsy()
// })
// })
// describe('validateOrFail', () => {
// test.each([
// 'AAA0000',
// 'AAA-0000',
// 'AAA0F00',
// 'AAA-0F00',
// 'AbA0F00',
// 'abc-0h00',
// ])('A placa %s deve ser válida', (clarPlate) => {
// expect(validateOrFail(clarPlate)).toBeTruthy()
// });
// test.each([
// 'A2A0000',
// 'AAA-00A0',
// 'AAA0F0',
// 'AAA0F077',
// '',
// null,
// undefined,
// ])('A placa %s não deve ser válida', (clarPlate) => {
// // @ts-ignore
// expect(()=>validateOrFail(clarPlate)).toThrow()
// })
// })
// describe('DV', () => {
// test('Car plate não tem DV', () => {
// expect(dv('AAA0000')).toBeNull()
// expect(checksum('AAA0000')).toBeNull()
// })
// })
// describe('fake', () => {
// test('Gera fakes sem mascara', () => {
// for (let i = 0; i <= 20; i++) {
// const carPlate = fake()
// expect(validate(carPlate)).toBeTruthy()
// expect(carPlate.length).toBe(7)
// }
// })
// test('Gera fakes com mascara', () => {
// for (let i = 0; i <= 20; i++) {
// const carPlate = fake(true)
// expect(validate(carPlate)).toBeTruthy()
// expect(carPlate.length).toBe(8)
// }
// })
// })
// describe('mask', () => {
// test.each([
// 'AAA0000',
// 'AAA0900',
// 'AAA0F00',
// 'AGA0F00',
// 'aba0F00',
// 'abc0h00',
// ])('A placa %s deve ser válida', (clarPlate) => {
// const masked = mask(clarPlate)
// expect(masked).toBeDefined()
// expect(masked).toBe(masked.toLocaleUpperCase())
// expect(masked.length).toBe(8)
// expect(masked).toMatch(/^[A-Z]{3}-[0-9][A-Z0-9][0-9]{2}$/)
// })
// })
})
describe('mask', () => {
test.each([
'AAA0000',
'AAA0900',
'AAA0F00',
'AGA0F00',
'aba0F00',
'abc0h00',
])('A placa %s deve ser válida', (clarPlate) => {
const masked = new CarPlate(clarPlate).mask();
expect(masked).toBeDefined();
expect(masked).toBe(masked.toLocaleUpperCase());
expect(masked.length).toBe(8);
expect(masked).toMatch(/^[A-Z]{3}-[0-9][A-Z0-9][0-9]{2}$/);
});
});
});

@@ -6,22 +6,18 @@ import { CNH } from '../src/cnh';

describe('constructor', () => {
test.each([
'50195131143',
'58316794534',
'50195471165',
'69044271146',
'46190906839',
'624729276-37',
])('deve estar definido', (input) => {
expect(new CNH(input)).toBeDefined();
});
test.each(['14490435923', '97286888262', '621049358-60', '491872350-50'])(
'deve estar definido',
(input) => {
expect(new CNH(input)).toBeDefined();
}
);
test.each([
'50195131143',
'58316794534',
'50195471165',
'69044271146',
'46190906839',
'624729276-37',
'50995131143',
'58916794534',
'50995471165',
'69944271146',
'46990906839',
'629729276-37',
])('deve lançar erro', (input) => {
expect(new CNH(input)).toBeDefined();
expect(() => new CNH(input)).toThrow();
});

@@ -50,3 +46,2 @@ });

test.each(['50195471', '5831641745', ''])(

@@ -58,3 +53,2 @@ 'deve lançar erro de dv',

);
});

@@ -64,5 +58,6 @@

test.each([
{ value: '50195471143', expected: '501954711-43' },
{ value: '58316474534', expected: '583164745-34' },
{ value: '69044471146', expected: '690444711-46' },
{ value: '14490435923', expected: '144904359-23' },
{ value: '97286888262', expected: '972868882-62' },
{ value: '621049358-60', expected: '621049358-60' },
{ value: '491872350-50', expected: '491872350-50' },
])('máscara deve ser gerada corretamente', (input) => {

@@ -73,4 +68,5 @@ const cnh = new CNH(input.value);

expect(cnh.mask()).toHaveLength(12);
expect(cnh.mask()).toMatch(/^\d{9}-\d{2}$/)
});
});
});
import { Phone } from '../src/phone';
const cellPhones = ['+5584999580685', '+55 84 9 9958 0685', '+55 (84) 9 9958-0685', '+55 (84) 99958-0685', '84 99958-0685'];
const phones = ['+558433311454', '84 3331-1454', '84 3331 1454', '(84) 3331 1454', '84-3331-1454'];
const cellPhones = [
'+5584999580685',
'+55 84 9 9958 0685',
'+55 (84) 9 9958-0685',
'+55 (84) 99958-0685',
'84 99958-0685',
];
const phones = [
'+558433311454',
'84 3331-1454',
'84 3331 1454',
'(84) 3331 1454',
'84-3331-1454',
];

@@ -33,3 +45,3 @@ describe('Phone', () => {

test.each([...Array(5)])('Cria um fake com DDD 11', () => {
test.each([...Array(50)])('Cria um fake com DDD 11', () => {
const fake = Phone.fake({ ddd: '11' });

@@ -43,11 +55,11 @@ expect(fake).toBeDefined();

expect(fake).toBeDefined();
expect(fake.isMobile).toBeTruthy()
expect(fake.phone.length).toBe(9)
expect(fake.isMobile).toBeTruthy();
expect(fake.phone.length).toBe(9);
});
test.each([...Array(5)])('Cria um fake com isLandline=true', () => {
const fake = Phone.fake({ isLandline: true });
const fake = Phone.fake({ isLandline: true });
expect(fake).toBeDefined();
expect(fake.isMobile).toBeFalsy()
expect(fake.phone.length).toBe(8)
expect(fake.isMobile).toBeFalsy();
expect(fake.phone.length).toBe(8);
});

@@ -54,0 +66,0 @@ });

@@ -8,12 +8,26 @@ - [x] isCarPlate

- [ ] Conta bancária
- ~~[ ] Conta bancária~~
- [ ] isPixKey - verifica se é um dos tipos de chaves
- [x] isPixKey - verifica se é um dos tipos de chaves
- [x] isPixCopyPaste - verifica se é um dos tipos de chaves
- [ ] isCEP
- [x] isCEP
- https://github.com/ogilvieira/validator-brasil/blob/main/src/isCEP.ts
- @klawdyo/qrdapio
- [x] isUF
- @klawdyo/qrdapio
- isBoleto
- Construtor pode receber linha digitável
- Pra receber o código de barras, use o static fromBarcode()
- mask() pode devolver a linha digitável ou o código de barras. Por padrão, a linha digitável
- toString() devolve a linha digitável
- toBarcode() devolve a linha digitável
- parse() é chamado no início e já separa as partes
- [ ] isCAEPF
- https://www.gov.br/receitafederal/pt-br/assuntos/orientacao-tributaria/cadastros/caepf/legislacao
- https://github.com/VitorLuizC/brazilian-values/blob/master/src/validators/isCAEPF.ts

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc