Comparing version 1.0.9 to 1.1.0
@@ -18,4 +18,6 @@ "use strict"; | ||
telefone: validate_1.validate_telefone, | ||
celular: validate_1.validate_celular, | ||
time: validate_1.validate_time, | ||
titulo: validate_1.validate_titulo | ||
titulo: validate_1.validate_titulo, | ||
processo: validate_1.validate_processo | ||
}; | ||
@@ -22,0 +24,0 @@ exports.utilsBr = { |
@@ -23,4 +23,7 @@ "use strict"; | ||
} | ||
else if (c === /[1-9]/.toString()) { | ||
return (Math.floor(Math.random() * 9) + 1).toString(); | ||
else if (c.indexOf('/[') === 0) { // /[1-9]/ ou /[5-9]/ | ||
c = c.replace('/[', '').replace(']/', '').split('-'); | ||
var mult = c[1] - c[0]; | ||
var plus = parseInt(c[0]); | ||
return (Math.floor(Math.random() * mult) + plus).toString(); | ||
} | ||
@@ -87,2 +90,3 @@ else { | ||
placa: makeGeneric(utils_1.MASKS['placa']), | ||
processo: makeGeneric(utils_1.MASKS['processo']), | ||
titulo: function () { | ||
@@ -92,4 +96,9 @@ var titulo = makeGeneric(utils_1.MASKS['titulo'])(); | ||
return titulo.substr(0, titulo.length - 2) + dig1 + dig2; | ||
}, | ||
renavam: function () { | ||
var renavam = makeGeneric(utils_1.MASKS['renavam'])(); | ||
var dv = validate_1.create_renavam(renavam); | ||
return renavam.substr(0, renavam.length - 1) + dv; | ||
} | ||
}; | ||
//# sourceMappingURL=faker.js.map |
@@ -48,4 +48,5 @@ "use strict"; | ||
placa: makeGeneric('placa'), | ||
titulo: makeGeneric('titulo') | ||
titulo: makeGeneric('titulo'), | ||
processo: makeGeneric('processo') | ||
}; | ||
//# sourceMappingURL=mask.js.map |
@@ -83,2 +83,21 @@ "use strict"; | ||
textMask: [/\d/, /\d/, /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/] | ||
}, | ||
processo: { | ||
text: '0000000-00.0000.AAA.0000', | ||
textMask: [/\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/, '.', /[A-Za-z]/, /[A-Za-z]/, /[A-Za-z]/, '.', /\d/, /\d/, /\d/, /\d/] | ||
}, | ||
renavam: { | ||
textMaskFunction: function mask(userInput) { | ||
var numbers = userInput.match(/\d/g); | ||
var numberLength = 0; | ||
if (numbers) { | ||
numberLength = numbers.join('').length; | ||
} | ||
if (!userInput || numberLength < 9) { | ||
return [/\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/]; | ||
} | ||
else { | ||
return [/\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/]; | ||
} | ||
} | ||
} | ||
@@ -85,0 +104,0 @@ }; |
@@ -182,2 +182,14 @@ "use strict"; | ||
exports.validate_telefone = validate_telefone; | ||
function validate_celular(cel) { | ||
var celClean = cel.replace(/[^\d]+/g, ''); | ||
cel = cel.replace(/_/g, ''); | ||
if (!(celClean.length === 10 || celClean.length === 11)) { | ||
return false; | ||
} | ||
if (celClean[0] == 0 || celClean[2] < 5) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
exports.validate_celular = validate_celular; | ||
function validate_rg(rg) { | ||
@@ -293,2 +305,50 @@ var rgClean = rg.replace(/\./g, ''); | ||
exports.create_titulo = create_titulo; | ||
function validate_processo(processo) { | ||
var processoClean = processo.replace(/\./g, ''); | ||
processoClean = processoClean.replace(/\-/g, ''); | ||
var exp = /\d{7}\-\d{2}\.\d{4}\.\d{3}\.\d{4}/; | ||
var expClean = /\d{7}\d{4}\d{4}/; | ||
if (!exp.test(processoClean) && !expClean.test(processoClean)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
exports.validate_processo = validate_processo; | ||
function validate_renavam(renavam) { | ||
var renavamClean = renavam.replace(/\./g, ''); | ||
renavamClean = renavamClean.replace(/\-/g, ''); | ||
// const expClean = /\d{10}\d{4}\d{4}/; | ||
// if (!exp.test(renavamClean) && !expClean.test(renavamClean)) { | ||
// return false; | ||
// } | ||
var dv = create_renavam(renavam); | ||
var tam = renavam.length; | ||
var digitos = renavam.substr(tam - 1, 1); | ||
if (digitos.charCodeAt(0) - 48 === dv) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
exports.validate_renavam = validate_renavam; | ||
function create_renavam(renavam) { | ||
var dig1 = 0; | ||
var tam = renavam.length; | ||
renavam = renavam.substr(0, tam - 2); | ||
renavam = '000000000000' + renavam; | ||
renavam = renavam.substr(renavam.length - 11, renavam.length - 1); | ||
dig1 = (renavam.charCodeAt(0) - 48) * 3 + (renavam.charCodeAt(1) - 48) * 2 + (renavam.charCodeAt(2) - 48) * 9 + (renavam.charCodeAt(3) - 48) * 8 + | ||
(renavam.charCodeAt(4) - 48) * 7 + (renavam.charCodeAt(5) - 48) * 6 + (renavam.charCodeAt(6) - 48) * 5 + | ||
(renavam.charCodeAt(7) - 48) * 4 + (renavam.charCodeAt(8) - 48) * 3 + (renavam.charCodeAt(9) - 48) * 2; | ||
dig1 = dig1 * 10; | ||
var resto = (dig1 % 11); | ||
if (resto === 10) { | ||
return 0; | ||
} | ||
else { | ||
return resto; | ||
} | ||
} | ||
exports.create_renavam = create_renavam; | ||
//# sourceMappingURL=validate.js.map |
@@ -45,3 +45,4 @@ "use strict"; | ||
var celular = index_1.fakerBr.celular(); | ||
chai_1.expect(index_1.validateBr.telefone(celular)).to.be.true; | ||
console.log(celular); | ||
chai_1.expect(index_1.validateBr.celular(celular)).to.be.true; | ||
}); | ||
@@ -48,0 +49,0 @@ // it('Faker Time', () => { |
@@ -24,2 +24,3 @@ "use strict"; | ||
chai_1.expect(index_1.maskBr.titulo('123')).to.exist; | ||
chai_1.expect(index_1.maskBr.processo('123')).to.exist; | ||
}); | ||
@@ -38,2 +39,3 @@ it('Generic Testing with Faker , Mask and Validate', function () { | ||
testGeneric('titulo'); | ||
// testGeneric('processo'); | ||
}); | ||
@@ -68,2 +70,6 @@ it('CEP', function () { | ||
}); | ||
it('Processos', function () { | ||
var processo = '000001001520081000000'; | ||
// expect(maskBr.processo(processo)).to.be.equal('00000100-15.2008.100.0000'); | ||
}); | ||
// // it('Time', () => { | ||
@@ -70,0 +76,0 @@ // // const time = fakerBr.time(); |
@@ -31,2 +31,5 @@ "use strict"; | ||
}); | ||
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 () { | ||
@@ -33,0 +36,0 @@ chai_1.expect(index_1.validateBr.cep('1234')).to.be.false; |
@@ -6,3 +6,3 @@ import { | ||
valida_cep, validate_cnpj, validate_cpf, validate_telefone, | ||
validate_placa, validate_currency, validate_percentage, validate_rg, validate_time, validate_titulo | ||
validate_placa, validate_currency, validate_percentage, validate_rg, validate_time, validate_titulo, validate_processo, validate_celular | ||
} from './src/validate'; | ||
@@ -23,4 +23,6 @@ import { validar } from './src/inscricaoestadual'; | ||
telefone: validate_telefone, | ||
celular: validate_celular, | ||
time: validate_time, | ||
titulo: validate_titulo | ||
titulo: validate_titulo, | ||
processo: validate_processo | ||
}; | ||
@@ -27,0 +29,0 @@ |
{ | ||
"name": "js-brasil", | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"description": "Javascript Utils para Brasil (cpf, cnpj...)", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# js-brasil | ||
Javascript Utils para Brasil (cpf, cnpj...) | ||
Javascript Utils para Brasil (cpf, cnpj, inscrição estadual, ...) | ||
@@ -15,4 +15,6 @@ | ||
# Validate | ||
Módilos ValidateBR, MaskBR e FakerBR | ||
# ValidateBR | ||
Verifique se os dados dos seus usuários são válidos | ||
@@ -41,3 +43,3 @@ | ||
# Mask | ||
# MaskBR | ||
@@ -72,5 +74,5 @@ Formate seus dados com mascaras de tipos de dados brasileiros | ||
# Faker | ||
# FakerBR | ||
Gere dados de teste usando tipos de dados brasileiro, similar o fakejs | ||
Gerador de dados de teste usando tipos de dados brasileiro, similar o fakejs | ||
@@ -106,6 +108,8 @@ Javascript: | ||
* rg | ||
* placa | ||
* placa de carro | ||
* telefone | ||
* celular | ||
* time | ||
* titulo | ||
* titulo de eleitor | ||
* processo da justiça | ||
@@ -112,0 +116,0 @@ |
import { MASKS, ESTADOS_SIGLA } from './utils'; | ||
import { create_cpf, create_cnpj, CEPRange, create_titulo } from './validate'; | ||
import { create_cpf, create_cnpj, CEPRange, create_titulo, create_renavam } from './validate'; | ||
import { randexp } from 'randexp'; | ||
@@ -7,3 +7,3 @@ | ||
return () => { | ||
if(!val.textMask || !val.textMask.map){ | ||
if (!val.textMask || !val.textMask.map) { | ||
return ''; | ||
@@ -20,4 +20,7 @@ } | ||
return randomLetter(1).toString(); | ||
} else if (c === /[1-9]/.toString()) { | ||
return (Math.floor(Math.random() * 9) + 1).toString(); | ||
} else if (c.indexOf('/[') === 0) { // /[1-9]/ ou /[5-9]/ | ||
c = c.replace('/[', '').replace(']/', '').split('-') | ||
const mult = c[1] - c[0]; | ||
const plus = parseInt(c[0]); | ||
return (Math.floor(Math.random() * mult) + plus).toString(); | ||
} else { | ||
@@ -87,6 +90,12 @@ return c; | ||
placa: makeGeneric(MASKS['placa']), | ||
processo: makeGeneric(MASKS['processo']), | ||
titulo: () => { | ||
const titulo = makeGeneric(MASKS['titulo'])(); | ||
const {dig1, dig2} = create_titulo(titulo); | ||
const { dig1, dig2 } = create_titulo(titulo); | ||
return titulo.substr(0, titulo.length - 2) + dig1 + dig2; | ||
}, | ||
renavam: () => { | ||
const renavam = makeGeneric(MASKS['renavam'])(); | ||
const dv = create_renavam(renavam); | ||
return renavam.substr(0, renavam.length - 1) + dv; | ||
} | ||
@@ -93,0 +102,0 @@ }; |
@@ -67,3 +67,4 @@ import { MASKS, conformToMask } from './utils'; | ||
placa: makeGeneric('placa'), | ||
titulo: makeGeneric('titulo') | ||
titulo: makeGeneric('titulo'), | ||
processo: makeGeneric('processo') | ||
}; |
@@ -82,2 +82,20 @@ import { IEMASKS } from './inscricaoestadual'; | ||
textMask: [/\d/, /\d/, /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/] | ||
}, | ||
processo: { | ||
text: '0000000-00.0000.AAA.0000', | ||
textMask: [/\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, '.', /\d/, /\d/, /\d/, /\d/, '.', /[A-Za-z]/, /[A-Za-z]/, /[A-Za-z]/, '.', /\d/, /\d/, /\d/, /\d/] | ||
}, | ||
renavam: { | ||
textMaskFunction: function mask(userInput) { | ||
const numbers = userInput.match(/\d/g); | ||
let numberLength = 0; | ||
if (numbers) { | ||
numberLength = numbers.join('').length; | ||
} | ||
if (!userInput || numberLength < 9) { | ||
return [/\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/]; | ||
} else { | ||
return [/\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/]; | ||
} | ||
} | ||
} | ||
@@ -84,0 +102,0 @@ } |
@@ -186,6 +186,6 @@ | ||
tel = tel.replace(/_/g, ''); | ||
if(!(telClean.length === 10 || telClean.length === 11)){ | ||
if (!(telClean.length === 10 || telClean.length === 11)) { | ||
return false; | ||
} | ||
if(telClean[0]==0 || telClean[2]==0){ | ||
if (telClean[0] == 0 || telClean[2] == 0) { | ||
return false; | ||
@@ -202,2 +202,14 @@ } | ||
export function validate_celular(cel) { | ||
const celClean = cel.replace(/[^\d]+/g, ''); | ||
cel = cel.replace(/_/g, ''); | ||
if (!(celClean.length === 10 || celClean.length === 11)) { | ||
return false; | ||
} | ||
if (celClean[0] == 0 || celClean[2] < 5) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
export function validate_rg(rg) { | ||
@@ -254,3 +266,3 @@ let rgClean = rg.replace(/\./g, ''); | ||
function validaTituloVerificador(titulo) { | ||
const {dig1, dig2} =create_titulo(titulo); | ||
const { dig1, dig2 } = create_titulo(titulo); | ||
const tam = titulo.length; | ||
@@ -307,3 +319,50 @@ const digitos = titulo.substr(tam - 2, 2); | ||
} | ||
return {dig1, dig2}; | ||
return { dig1, dig2 }; | ||
} | ||
export function validate_processo(processo) { | ||
let processoClean = processo.replace(/\./g, ''); | ||
processoClean = processoClean.replace(/\-/g, ''); | ||
const exp = /\d{7}\-\d{2}\.\d{4}\.\d{3}\.\d{4}/; | ||
const expClean = /\d{7}\d{4}\d{4}/; | ||
if (!exp.test(processoClean) && !expClean.test(processoClean)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
export function validate_renavam(renavam) { | ||
let renavamClean = renavam.replace(/\./g, ''); | ||
renavamClean = renavamClean.replace(/\-/g, ''); | ||
// const expClean = /\d{10}\d{4}\d{4}/; | ||
// if (!exp.test(renavamClean) && !expClean.test(renavamClean)) { | ||
// return false; | ||
// } | ||
const dv = create_renavam(renavam); | ||
const tam = renavam.length; | ||
const digitos = renavam.substr(tam - 1, 1); | ||
if (digitos.charCodeAt(0) - 48 === dv) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
export function create_renavam(renavam) { | ||
let dig1 = 0; | ||
const tam = renavam.length; | ||
renavam = renavam.substr(0, tam - 2); | ||
renavam = '000000000000' + renavam; | ||
renavam = renavam.substr(renavam.length - 11, renavam.length - 1); | ||
dig1 = (renavam.charCodeAt(0) - 48) * 3 + (renavam.charCodeAt(1) - 48) * 2 + (renavam.charCodeAt(2) - 48) * 9 + (renavam.charCodeAt(3) - 48) * 8 + | ||
(renavam.charCodeAt(4) - 48) * 7 + (renavam.charCodeAt(5) - 48) * 6 + (renavam.charCodeAt(6) - 48) * 5 + | ||
(renavam.charCodeAt(7) - 48) * 4 + (renavam.charCodeAt(8) - 48) * 3 + (renavam.charCodeAt(9) - 48) * 2; | ||
dig1 = dig1 * 10; | ||
let resto = (dig1 % 11); | ||
if (resto === 10) { | ||
return 0; | ||
} else { | ||
return resto; | ||
} | ||
} |
@@ -46,3 +46,4 @@ import { fakerBr, validateBr } from '../index'; | ||
const celular = fakerBr.celular(); | ||
expect(validateBr.telefone(celular)).to.be.true; | ||
console.log(celular) | ||
expect(validateBr.celular(celular)).to.be.true; | ||
}); | ||
@@ -49,0 +50,0 @@ // it('Faker Time', () => { |
@@ -25,2 +25,3 @@ import { maskBr, fakerBr, validateBr } from '../index'; | ||
expect(maskBr.titulo('123')).to.exist; | ||
expect(maskBr.processo('123')).to.exist; | ||
}); | ||
@@ -40,2 +41,3 @@ | ||
testGeneric('titulo'); | ||
// testGeneric('processo'); | ||
}); | ||
@@ -72,2 +74,6 @@ | ||
}); | ||
it('Processos', () => { | ||
const processo = '000001001520081000000'; | ||
// expect(maskBr.processo(processo)).to.be.equal('00000100-15.2008.100.0000'); | ||
}); | ||
// // it('Time', () => { | ||
@@ -74,0 +80,0 @@ // // const time = fakerBr.time(); |
@@ -37,2 +37,8 @@ import { validateBr } from '../index'; | ||
it('PROCESSO', () => { | ||
expect(validateBr.processo('0123456-15.2008.100.0000')).to.be.true; | ||
}); | ||
it('To check when is NOT valid', () => { | ||
@@ -39,0 +45,0 @@ expect(validateBr.cep('1234')).to.be.false; |
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
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
Sorry, the diff of this file is too big to display
326195
7136
117