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

js-brasil

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-brasil - npm Package Compare versions

Comparing version 1.4.2 to 1.4.3

7

dist/src/validate.js

@@ -196,4 +196,7 @@ "use strict";

function validate_currency(currency) {
var regex = /^\d+(?:\.\d{0,2})$/;
return regex.test(currency.toString());
if (typeof currency === 'number') {
return true;
}
var regex = /^(R\$|R\$ )?((\d{1,3})(?:.[0-9]{3}){0,1}|(\d{1})(?:.[0-9]{3}){0,2}|(\d{1,7}))(\,\d{1,2})?$/g;
return regex.test(currency);
}

@@ -200,0 +203,0 @@ exports.validate_currency = validate_currency;

@@ -6,7 +6,16 @@ "use strict";

describe('Validate test', function () {
it('Celular', function () {
// expect(validateBr.celular('31 999876767')).to.be.true;
chai_1.expect(index_1.validateBr.celular('31 99876767')).to.be.false;
// expect(validateBr.celular('(90) 1057-1600')).to.be.true;
// expect(validateBr.celular('(90) 00057-1600')).to.be.false;
chai_1.expect(index_1.validateBr.celular('1234')).to.be.false;
});
it('CEP', function () {
chai_1.expect(index_1.validateBr.cep('30.380-123')).to.be.true;
chai_1.expect(index_1.validateBr.cep('1234')).to.be.false;
});
it('CNPJ', function () {
chai_1.expect(index_1.validateBr.cnpj('56.853.433/0001-44')).to.be.true;
chai_1.expect(index_1.validateBr.cnpj('1234')).to.be.false;
});

@@ -19,8 +28,16 @@ it('CPF', function () {

chai_1.expect(index_1.validateBr.cpf('00.000.000/0000-00')).to.be.false;
chai_1.expect(index_1.validateBr.cpf('1234')).to.be.false;
});
it('RG', function () {
// expect(validateBr.currency('R$ 1234')).to.be.true;
// // expect(validateBr.inscricaoestadual('1234')).to.be.true;
// expect(validateBr.percentage('10')).to.be.true;
chai_1.expect(index_1.validateBr.rg('mg 11124567')).to.be.true;
context('Currency', function () {
it('Pass when valid', function () {
// expect(validateBr.currency('R$ 1234')).to.be.true;
chai_1.expect(index_1.validateBr.currency('R$ 1234,10')).to.be.true;
chai_1.expect(index_1.validateBr.currency('R$ 1.234,10')).to.be.true;
chai_1.expect(index_1.validateBr.currency('1234,56')).to.be.true;
chai_1.expect(index_1.validateBr.currency('1.234,56')).to.be.true;
});
it('Error when not valid', function () {
chai_1.expect(index_1.validateBr.currency('$1234')).to.be.false;
chai_1.expect(index_1.validateBr.currency('1,234.00')).to.be.false;
});
});

@@ -32,7 +49,24 @@ it('Inscricao Estadual', function () {

chai_1.expect(index_1.validateBr.inscricaoestadual('111111111111', 'mg').message).to.be.equal('ie com todos dígitos iguais');
chai_1.expect(index_1.validateBr.inscricaoestadual('1234', 'mg')).to.be.false;
});
it('Percentage', function () {
it('Pass when valid', function () {
chai_1.expect(index_1.validateBr.percentage('10')).to.be.true;
});
it('Error when not valid', function () {
chai_1.expect(index_1.validateBr.percentage('1234')).to.be.false;
});
});
it('PLACA', function () {
chai_1.expect(index_1.validateBr.placa('ABC1234')).to.be.true;
chai_1.expect(index_1.validateBr.placa('SAW0002')).to.be.false;
chai_1.expect(index_1.validateBr.placa('1234')).to.be.false;
});
it('PROCESSO', function () {
chai_1.expect(index_1.validateBr.processo('0123456-15.2008.100.0000')).to.be.true;
});
it('RG', function () {
chai_1.expect(index_1.validateBr.rg('mg 11124567')).to.be.true;
chai_1.expect(index_1.validateBr.rg('1234')).to.be.false;
});
it('RENAVAM', function () {

@@ -46,31 +80,13 @@ chai_1.expect(index_1.validateBr.renavam('72176426415')).to.be.true;

chai_1.expect(index_1.validateBr.telefone('(90) 0057-1600')).to.be.false;
chai_1.expect(index_1.validateBr.telefone('1234')).to.be.false;
});
it('Celular', function () {
// expect(validateBr.celular('31 999876767')).to.be.true;
chai_1.expect(index_1.validateBr.celular('31 99876767')).to.be.false;
// expect(validateBr.celular('(90) 1057-1600')).to.be.true;
// expect(validateBr.celular('(90) 00057-1600')).to.be.false;
});
it('TITULO', function () {
chai_1.expect(index_1.validateBr.titulo('6490.8084.4421')).to.be.true;
chai_1.expect(index_1.validateBr.titulo('6490.8084.4422')).to.be.false;
chai_1.expect(index_1.validateBr.titulo('1234')).to.be.false;
});
it('PROCESSO', function () {
chai_1.expect(index_1.validateBr.processo('0123456-15.2008.100.0000')).to.be.true;
});
it('To check when is NOT valid', function () {
chai_1.expect(index_1.validateBr.cep('1234')).to.be.false;
chai_1.expect(index_1.validateBr.cnpj('1234')).to.be.false;
chai_1.expect(index_1.validateBr.cpf('1234')).to.be.false;
chai_1.expect(index_1.validateBr.currency('1234')).to.be.false;
chai_1.expect(index_1.validateBr.inscricaoestadual('1234', 'mg')).to.be.false;
chai_1.expect(index_1.validateBr.percentage('1234')).to.be.false;
chai_1.expect(index_1.validateBr.rg('1234')).to.be.false;
chai_1.expect(index_1.validateBr.placa('1234')).to.be.false;
chai_1.expect(index_1.validateBr.telefone('1234')).to.be.false;
chai_1.expect(index_1.validateBr.celular('1234')).to.be.false;
it('Time', function () {
chai_1.expect(index_1.validateBr.time('1234')).to.be.false;
chai_1.expect(index_1.validateBr.titulo('1234')).to.be.false;
});
});
//# sourceMappingURL=validate.js.map
{
"name": "js-brasil",
"version": "1.4.2",
"version": "1.4.3",
"description": "Javascript Utils para Brasil (cpf, cnpj...)",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -211,4 +211,7 @@ import { modulo11 } from "./utils";

export function validate_currency(currency: string | number) {
const regex = /^\d+(?:\.\d{0,2})$/;
return regex.test(currency.toString());
if(typeof currency === 'number'){
return true;
}
const regex = /^(R\$|R\$ )?((\d{1,3})(?:.[0-9]{3}){0,1}|(\d{1})(?:.[0-9]{3}){0,2}|(\d{1,7}))(\,\d{1,2})?$/g;
return regex.test(currency);
}

@@ -215,0 +218,0 @@

@@ -5,4 +5,14 @@ import { validateBr } from '../index';

describe('Validate test', () => {
it('Celular', () => {
// expect(validateBr.celular('31 999876767')).to.be.true;
expect(validateBr.celular('31 99876767')).to.be.false;
// expect(validateBr.celular('(90) 1057-1600')).to.be.true;
// expect(validateBr.celular('(90) 00057-1600')).to.be.false;
expect(validateBr.celular('1234')).to.be.false;
});
it('CEP', () => {
expect(validateBr.cep('30.380-123')).to.be.true;
expect(validateBr.cep('1234')).to.be.false;
});

@@ -12,2 +22,3 @@

expect(validateBr.cnpj('56.853.433/0001-44')).to.be.true;
expect(validateBr.cnpj('1234')).to.be.false;
});

@@ -21,12 +32,19 @@

expect(validateBr.cpf('00.000.000/0000-00')).to.be.false;
expect(validateBr.cpf('1234')).to.be.false;
});
it('RG', () => {
// expect(validateBr.currency('R$ 1234')).to.be.true;
// // expect(validateBr.inscricaoestadual('1234')).to.be.true;
// expect(validateBr.percentage('10')).to.be.true;
expect(validateBr.rg('mg 11124567')).to.be.true;
});
context('Currency', ()=>{
it('Pass when valid', () => {
// expect(validateBr.currency('R$ 1234')).to.be.true;
expect(validateBr.currency('R$ 1234,10')).to.be.true;
expect(validateBr.currency('R$ 1.234,10')).to.be.true;
expect(validateBr.currency('1234,56')).to.be.true;
expect(validateBr.currency('1.234,56')).to.be.true;
});
it('Error when not valid', () => {
expect(validateBr.currency('$1234')).to.be.false;
expect(validateBr.currency('1,234.00')).to.be.false;
});
})
it('Inscricao Estadual', () => {

@@ -37,9 +55,31 @@ expect(validateBr.inscricaoestadual('862.445.372/2351', 'mg')).to.be.true;

expect(validateBr.inscricaoestadual('111111111111', 'mg').message).to.be.equal('ie com todos dígitos iguais');
expect(validateBr.inscricaoestadual('1234', 'mg')).to.be.false;
});
it('Percentage', () => {
it('Pass when valid', () => {
expect(validateBr.percentage('10')).to.be.true;
});
it('Error when not valid', () => {
expect(validateBr.percentage('1234')).to.be.false;
});
});
it('PLACA', () => {
expect(validateBr.placa('ABC1234')).to.be.true;
expect(validateBr.placa('SAW0002')).to.be.false;
expect(validateBr.placa('1234')).to.be.false;
});
it('PROCESSO', () => {
expect(validateBr.processo('0123456-15.2008.100.0000')).to.be.true;
});
it('RG', () => {
expect(validateBr.rg('mg 11124567')).to.be.true;
expect(validateBr.rg('1234')).to.be.false;
});
it('RENAVAM', () => {

@@ -54,38 +94,14 @@ expect(validateBr.renavam('72176426415')).to.be.true;

expect(validateBr.telefone('(90) 0057-1600')).to.be.false;
expect(validateBr.telefone('1234')).to.be.false;
});
it('Celular', () => {
// expect(validateBr.celular('31 999876767')).to.be.true;
expect(validateBr.celular('31 99876767')).to.be.false;
// expect(validateBr.celular('(90) 1057-1600')).to.be.true;
// expect(validateBr.celular('(90) 00057-1600')).to.be.false;
});
it('TITULO', () => {
expect(validateBr.titulo('6490.8084.4421')).to.be.true;
expect(validateBr.titulo('6490.8084.4422')).to.be.false;
expect(validateBr.titulo('1234')).to.be.false;
});
it('PROCESSO', () => {
expect(validateBr.processo('0123456-15.2008.100.0000')).to.be.true;
});
it('To check when is NOT valid', () => {
expect(validateBr.cep('1234')).to.be.false;
expect(validateBr.cnpj('1234')).to.be.false;
expect(validateBr.cpf('1234')).to.be.false;
expect(validateBr.currency('1234')).to.be.false;
expect(validateBr.inscricaoestadual('1234', 'mg')).to.be.false;
expect(validateBr.percentage('1234')).to.be.false;
expect(validateBr.rg('1234')).to.be.false;
expect(validateBr.placa('1234')).to.be.false;
expect(validateBr.telefone('1234')).to.be.false;
expect(validateBr.celular('1234')).to.be.false;
it('Time', () => {
expect(validateBr.time('1234')).to.be.false;
expect(validateBr.titulo('1234')).to.be.false;
});
});

Sorry, the diff of this file is too big to display

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 too big to display

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