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

256 lines (210 loc) 9.45 kB
/******/ (function() { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ 89: /***/ (function(__unused_webpack_module, exports) { var __webpack_unused_export__; __webpack_unused_export__ = ({ value: true }); // runtime helper for setting properties on components // in a tree-shakable way exports.Z = (sfc, props) => { const target = sfc.__vccOpts || sfc; for (const [key, val] of props) { target[key] = val; } return target; }; /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/define property getters */ /******/ !function() { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = function(exports, definition) { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/global */ /******/ !function() { /******/ __webpack_require__.g = (function() { /******/ if (typeof globalThis === 'object') return globalThis; /******/ try { /******/ return this || new Function('return this')(); /******/ } catch (e) { /******/ if (typeof window === 'object') return window; /******/ } /******/ })(); /******/ }(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ !function() { /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } /******/ }(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ !function() { /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/publicPath */ /******/ !function() { /******/ __webpack_require__.p = ""; /******/ }(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. !function() { // ESM COMPAT FLAG __webpack_require__.r(__webpack_exports__); // EXPORTS __webpack_require__.d(__webpack_exports__, { "default": function() { return /* binding */ entry_lib; }, "install": function() { return /* reexport */ install; } }); ;// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js /* eslint-disable no-var */ // This file is imported into lib/wc client bundles. if (typeof window !== 'undefined') { var currentScript = window.document.currentScript if (false) { var getCurrentScript; } var src = currentScript && currentScript.src.match(/(.+\/)[^/]+\.js(\?.*)?$/) if (src) { __webpack_require__.p = src[1] // eslint-disable-line } } // Indicate to webpack that this file can be concatenated /* harmony default export */ var setPublicPath = (null); ;// CONCATENATED MODULE: external {"commonjs":"vue","commonjs2":"vue","root":"Vue"} var external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject = require("vue"); ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/vue-loader/dist/templateLoader.js??ruleSet[1].rules[3]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/components/money.vue?vue&type=template&id=2de8beaf function render(_ctx, _cache, $props, $setup, $data, $options) { return (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.withDirectives)(((0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.openBlock)(), (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementBlock)("input", (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.mergeProps)({ "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => $data.money = $event) }, _ctx.$attrs, { onkeypress: "return event.charCode >= 48 && event.charCode <= 57", onInput: _cache[1] || (_cache[1] = $event => $options.formatMoney($event.target.value)) }), null, 16)), [[external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.vModelDynamic, $data.money]]); } ;// CONCATENATED MODULE: ./src/components/money.vue?vue&type=template&id=2de8beaf ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/components/money.vue?vue&type=script&lang=js /* harmony default export */ var moneyvue_type_script_lang_js = ({ name: "vue-brazil-money", data() { return { money: "" }; }, props: { modelValue: [Number, String], decimalPlaces: { type: Number, default: 2 } }, methods: { updateInput(maskedValue, floatValue) { this.$emit("update:modelValue", floatValue); this.money = maskedValue; }, fillWithZeros(strValue) { let filledStr = strValue.split("").reverse().join(""); while (filledStr.length < this.decimalPlaces + 1) { filledStr += "0"; } return filledStr.split("").reverse().join(""); }, formatMoney(value) { let strValue = String(value).replace(/[^0-9]/g, ""); if (strValue.length < this.decimalPlaces + 1) { strValue = this.fillWithZeros(strValue); } else if (strValue.length >= this.decimalPlaces + 2) { if (strValue.substring(0, 1) === "0") strValue = strValue.substring(1); } let afterDecimalPoint = strValue.split("").reverse().join("").substring(0, this.decimalPlaces).split("").reverse().join(""); let beforeDecimalPoint = String(Number(strValue.substring(0, strValue.length - this.decimalPlaces))); let beforeDecimalPointWithDot = ""; let beforeDecimalPointArray = beforeDecimalPoint.split("").reverse(); for (let i = 0; beforeDecimalPointArray.length > 0 && i < beforeDecimalPointArray.length; i++) { beforeDecimalPointWithDot += beforeDecimalPointArray[i]; if ((i + 1) % 3 === 0 && beforeDecimalPointArray.length - i > 1) { beforeDecimalPointWithDot += "."; } } beforeDecimalPointWithDot = beforeDecimalPointWithDot.split("").reverse("").join(""); beforeDecimalPointWithDot = beforeDecimalPointWithDot === "" || Number(beforeDecimalPointWithDot.replace(".", "")) === 0 ? "0" : beforeDecimalPointWithDot; this.updateInput("R$ " + (beforeDecimalPointWithDot + (this.decimalPlaces > 0 ? "," + afterDecimalPoint : "")), beforeDecimalPointWithDot.replaceAll(".", "") + (this.decimalPlaces > 0 ? "." + afterDecimalPoint : "")); } } }); ;// CONCATENATED MODULE: ./src/components/money.vue?vue&type=script&lang=js // EXTERNAL MODULE: ./node_modules/vue-loader/dist/exportHelper.js var exportHelper = __webpack_require__(89); ;// CONCATENATED MODULE: ./src/components/money.vue ; const __exports__ = /*#__PURE__*/(0,exportHelper/* default */.Z)(moneyvue_type_script_lang_js, [['render',render]]) /* harmony default export */ var money = (__exports__); ;// CONCATENATED MODULE: ./src/index.js // Declare install function executed by Vue.use() function install(Vue) { if (install.installed) return; install.installed = true; Vue.component('vue-brazil-money', money); } // Create module definition for Vue.use() const src_plugin = { install }; // Auto-install when vue is found (eg. in browser via <script> tag) let GlobalVue = null; if (typeof window !== 'undefined') { GlobalVue = window.Vue; } else if (typeof __webpack_require__.g !== 'undefined') { GlobalVue = __webpack_require__.g.Vue; } if (GlobalVue) { GlobalVue.use(src_plugin); } // To allow use as module (npm/webpack/etc.) export component /* harmony default export */ var src_0 = (money); ;// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/entry-lib.js /* harmony default export */ var entry_lib = (src_0); }(); module.exports = __webpack_exports__; /******/ })() ; //# sourceMappingURL=vueBrazilMoney.common.js.map