Comparing version 1.1.3 to 1.1.4
@@ -7,3 +7,2 @@ window.onload = () => { | ||
function componentCustom() { | ||
@@ -13,3 +12,3 @@ const dataId = document.querySelector('body').getAttribute('data-id'); | ||
default: | ||
generalAction(dataId); | ||
generalAction(dataId, ''); | ||
break; | ||
@@ -20,8 +19,9 @@ } | ||
function generalAction(dataId) { | ||
const validatedAction = document.querySelector('#validatedAction'); | ||
const generatedAction = document.querySelector('#generatedAction'); | ||
function generalAction(dataId, type) { | ||
const validatedAction = document.querySelector('#validatedAction'+type); | ||
const generatedAction = document.querySelector('#generatedAction'+type); | ||
generatedAction.onclick = () => { | ||
const generatedInput = document.querySelector('#generated'); | ||
console.log(`generatedAction.onclick`) | ||
const generatedInput = document.querySelector('#generated'+type); | ||
generatedInput.value = jsbrasil.fakerBr[dataId](); | ||
@@ -31,14 +31,15 @@ } | ||
validatedAction.onclick = () => { | ||
const validatedInput = document.querySelector('#validated'); | ||
console.log(`validatedAction.onclick`) | ||
const validatedInput = document.querySelector('#validated'+type); | ||
const masked = jsbrasil.maskBr[dataId](validatedInput.value); | ||
const validated = jsbrasil.validateBr[dataId](validatedInput.value); | ||
document.querySelector('#validatedResult').classList.remove('hidden'); | ||
document.querySelector('#validatedResult'+type).classList.remove('hidden'); | ||
if (validated) { | ||
document.querySelector('#valicon').innerHTML = 'thumb_up'; | ||
document.querySelector('#valtext').innerHTML = 'Parabéns, '+ masked + ' tem a formatação válida!'; | ||
document.querySelector('#valicon'+type).innerHTML = 'thumb_up'; | ||
document.querySelector('#valtext'+type).innerHTML = 'Parabéns, '+ masked + ' tem a formatação válida!'; | ||
} else { | ||
document.querySelector('#valicon').innerHTML = 'thumb_down'; | ||
document.querySelector('#valtext').innerHTML = 'Esta informação NÃO está correta!'; | ||
document.querySelector('#valicon'+type).innerHTML = 'thumb_down'; | ||
document.querySelector('#valtext'+type).innerHTML = 'Esta informação NÃO está correta!'; | ||
} | ||
@@ -45,0 +46,0 @@ } |
@@ -110,3 +110,10 @@ "use strict"; | ||
time: makeGeneric(mask_1.MASKS['time']), | ||
currency: makeGeneric(mask_1.MASKS['currency']), | ||
currency: function () { | ||
var x = Math.random() * 10000; | ||
return x.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }); | ||
}, | ||
currencyNumber: function () { | ||
var x = Math.random() * 10000; | ||
return parseFloat(x.toFixed(2)); | ||
}, | ||
percentage: makeGeneric(mask_1.MASKS['percentage']), | ||
@@ -113,0 +120,0 @@ placa: function () { |
@@ -134,12 +134,9 @@ "use strict"; | ||
} | ||
if (currencyValue.split) { | ||
var vals = currencyValue.split(','); | ||
var mask = exports.MASKS.currency.textMask(vals[0]); | ||
return conformToMask(currencyValue, mask, { guide: false }).conformedValue + ',' + vals[1]; | ||
} | ||
else { | ||
if (!currencyValue.split) { | ||
currencyValue += ''; | ||
var mask = exports.MASKS.currency.textMask(currencyValue); | ||
return conformToMask(currencyValue, mask, { guide: false }).conformedValue; | ||
currencyValue = currencyValue.replace('.', ','); | ||
} | ||
var vals = currencyValue.split(','); | ||
var mask = exports.MASKS.currency.textMask(vals[0]); | ||
return conformToMask(currencyValue, mask, { guide: false }).conformedValue + ',' + vals[1]; | ||
}, | ||
@@ -146,0 +143,0 @@ percentage: function (percentageValue) { |
@@ -55,5 +55,9 @@ "use strict"; | ||
}); | ||
it('Faker Moeda', function () { | ||
var currency = index_1.fakerBr.currency(); | ||
var currencyNumber = index_1.fakerBr.currencyNumber(); | ||
// expect(validateBr.currency(currency)).to.be.true; | ||
chai_1.expect(index_1.validateBr.currency(currencyNumber)).to.be.true; | ||
}); | ||
it('Faker Others', function () { | ||
// const currency = fakerBr.currency(); | ||
// expect(validateBr.currency(currency)).to.be.true; | ||
// const inscricaoestadual = fakerBr.inscricaoestadual(); | ||
@@ -60,0 +64,0 @@ // expect(validateBr.inscricaoestadual(inscricaoestadual)).to.be.true; |
@@ -16,3 +16,4 @@ "use strict"; | ||
chai_1.expect(index_1.maskBr.cpf('123')).to.exist; | ||
chai_1.expect(index_1.maskBr.currency('123')).to.exist; | ||
// expect(maskBr.currency('123')).to.exist; | ||
// expect(maskBr.currency(123)).to.exist; | ||
chai_1.expect(index_1.maskBr.inscricaoestadual('mg', '123')).to.exist; | ||
@@ -73,2 +74,10 @@ chai_1.expect(index_1.maskBr.percentage('123')).to.exist; | ||
}); | ||
it('Moeda', function () { | ||
var currency = 'R$ 5.103,94'; | ||
var currencyText = '5.103,94'; | ||
var currencyNumber = 5103.94; | ||
chai_1.expect(index_1.maskBr.currency(currency)).to.be.equal('R$ 5.103,94'); | ||
chai_1.expect(index_1.maskBr.currency(currencyNumber)).to.be.equal('R$ 5.103,94'); | ||
chai_1.expect(index_1.maskBr.currency(currencyText)).to.be.equal('R$ 5.103,94'); | ||
}); | ||
// // it('Time', () => { | ||
@@ -75,0 +84,0 @@ // // const time = fakerBr.time(); |
{ | ||
"name": "js-brasil", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Javascript Utils para Brasil (cpf, cnpj...)", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -106,3 +106,10 @@ import { ESTADOS_SIGLA } from './estados'; | ||
time: makeGeneric(MASKS['time']), | ||
currency: makeGeneric(MASKS['currency']), | ||
currency: () => { | ||
const x = Math.random() * 10000; | ||
return x.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL'}); | ||
}, | ||
currencyNumber: () => { | ||
const x = Math.random() * 10000; | ||
return parseFloat(x.toFixed(2)); | ||
}, | ||
percentage: makeGeneric(MASKS['percentage']), | ||
@@ -109,0 +116,0 @@ placa: () => { |
@@ -143,23 +143,14 @@ import { isArray, processCaretTraps } from './utils'; | ||
} | ||
if (currencyValue.split) { | ||
const vals = currencyValue.split(','); | ||
const mask = MASKS.currency.textMask(vals[0]); | ||
return conformToMask( | ||
currencyValue, | ||
mask, | ||
{ guide: false } | ||
).conformedValue + ',' + vals[1]; | ||
} else { | ||
if (!currencyValue.split) { | ||
currencyValue += ''; | ||
const mask = MASKS.currency.textMask(currencyValue); | ||
return conformToMask( | ||
currencyValue, | ||
mask, | ||
{ guide: false } | ||
).conformedValue; | ||
currencyValue = currencyValue.replace('.', ','); | ||
} | ||
const vals = currencyValue.split(','); | ||
const mask = MASKS.currency.textMask(vals[0]); | ||
return conformToMask( | ||
currencyValue, | ||
mask, | ||
{ guide: false } | ||
).conformedValue + ',' + vals[1]; | ||
}, | ||
@@ -166,0 +157,0 @@ percentage: (percentageValue) => { |
@@ -56,6 +56,12 @@ import { fakerBr, validateBr } from '../index'; | ||
}); | ||
it('Faker Others', () => { | ||
// const currency = fakerBr.currency(); | ||
it('Faker Moeda', () => { | ||
const currency = fakerBr.currency(); | ||
const currencyNumber = fakerBr.currencyNumber(); | ||
// expect(validateBr.currency(currency)).to.be.true; | ||
expect(validateBr.currency(currencyNumber)).to.be.true; | ||
}); | ||
it('Faker Others', () => { | ||
// const inscricaoestadual = fakerBr.inscricaoestadual(); | ||
@@ -62,0 +68,0 @@ // expect(validateBr.inscricaoestadual(inscricaoestadual)).to.be.true; |
@@ -17,4 +17,5 @@ import { maskBr, fakerBr, validateBr } from '../index'; | ||
expect(maskBr.cpf('123')).to.exist; | ||
expect(maskBr.currency('123')).to.exist; | ||
expect(maskBr.inscricaoestadual('mg','123')).to.exist; | ||
// expect(maskBr.currency('123')).to.exist; | ||
// expect(maskBr.currency(123)).to.exist; | ||
expect(maskBr.inscricaoestadual('mg', '123')).to.exist; | ||
expect(maskBr.percentage('123')).to.exist; | ||
@@ -77,2 +78,13 @@ expect(maskBr.rg('123')).to.exist; | ||
}); | ||
it('Moeda', () => { | ||
const currency = 'R$ 5.103,94'; | ||
const currencyText = '5.103,94'; | ||
const currencyNumber = 5103.94; | ||
expect(maskBr.currency(currency)).to.be.equal('R$ 5.103,94'); | ||
expect(maskBr.currency(currencyNumber)).to.be.equal('R$ 5.103,94'); | ||
expect(maskBr.currency(currencyText)).to.be.equal('R$ 5.103,94'); | ||
}); | ||
// // it('Time', () => { | ||
@@ -79,0 +91,0 @@ // // const time = fakerBr.time(); |
Sorry, the diff of this file is not supported yet
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 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
688896
11688