UNPKG

vue-brazil-money

Version:

If you just want a Vue 3 library to format brazillian money and don't want to configure anything, this library is perfect to you. https://www.npmjs.com/package/vue-brazil-money

2 lines 3.07 kB
(function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t(require("vue")):"function"===typeof define&&define.amd?define([],t):"object"===typeof exports?exports["vueBrazilMoney"]=t(require("vue")):e["vueBrazilMoney"]=t(e["Vue"])})("undefined"!==typeof self?self:this,(function(e){return function(){"use strict";var t={82:function(e,t){t.Z=(e,t)=>{const n=e.__vccOpts||e;for(const[r,o]of t)n[r]=o;return n}},203:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}!function(){r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})}}(),function(){r.g=function(){if("object"===typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"===typeof window)return window}}()}(),function(){r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}}(),function(){r.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}}(),function(){r.p=""}();var o={};return function(){if(r.r(o),r.d(o,{default:function(){return m},install:function(){return a}}),"undefined"!==typeof window){var e=window.document.currentScript,t=e&&e.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);t&&(r.p=t[1])}var n=r(203);function i(e,t,r,o,i,l){return(0,n.withDirectives)(((0,n.openBlock)(),(0,n.createElementBlock)("input",(0,n.mergeProps)({"onUpdate:modelValue":t[0]||(t[0]=e=>i.money=e)},e.$attrs,{onkeypress:"return event.charCode >= 48 && event.charCode <= 57",onInput:t[1]||(t[1]=e=>l.formatMoney(e.target.value))}),null,16)),[[n.vModelDynamic,i.money]])}var l={name:"vue-brazil-money",data(){return{money:""}},props:{modelValue:[Number,String],decimalPlaces:{type:Number,default:2}},methods:{updateInput(e,t){this.$emit("update:modelValue",t),this.money=e},fillWithZeros(e){let t=e.split("").reverse().join("");while(t.length<this.decimalPlaces+1)t+="0";return t.split("").reverse().join("")},formatMoney(e){let t=String(e).replace(/[^0-9]/g,"");t.length<this.decimalPlaces+1?t=this.fillWithZeros(t):t.length>=this.decimalPlaces+2&&"0"===t.substring(0,1)&&(t=t.substring(1));let n=t.split("").reverse().join("").substring(0,this.decimalPlaces).split("").reverse().join(""),r=String(Number(t.substring(0,t.length-this.decimalPlaces))),o="",i=r.split("").reverse();for(let l=0;i.length>0&&l<i.length;l++)o+=i[l],(l+1)%3===0&&i.length-l>1&&(o+=".");o=o.split("").reverse("").join(""),o=""===o||0===Number(o.replace(".",""))?"0":o,this.updateInput("R$ "+o+(this.decimalPlaces>0?","+n:""),o.replaceAll(".","")+(this.decimalPlaces>0?"."+n:""))}}},u=r(82);const s=(0,u.Z)(l,[["render",i]]);var c=s;function a(e){a.installed||(a.installed=!0,e.component("vue-brazil-money",c))}const f={install:a};let d=null;"undefined"!==typeof window?d=window.Vue:"undefined"!==typeof r.g&&(d=r.g.Vue),d&&d.use(f);var p=c,m=p}(),o}()})); //# sourceMappingURL=vueBrazilMoney.umd.min.js.map