@coders-tm/vue-number-format
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -6,9 +6,3 @@ /** | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var vue = require('vue'); | ||
var options = { | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var options = { | ||
prefix: '', | ||
@@ -19,122 +13,149 @@ suffix: '', | ||
precision: 2, | ||
null_value: 0 | ||
}; | ||
null_value: 0, | ||
};function NumberFormat(input, opt) { | ||
var this$1$1 = this; | ||
if ( opt === void 0 ) opt = options; | ||
function NumberFormat (input, opt = options) { | ||
this.options = opt; | ||
this.input = input || this.options.null_value; | ||
this.numbers = function () { | ||
if (typeof this.input === 'number') { | ||
return this.input.toFixed(this.options.precision) | ||
var number = this$1$1.input; | ||
if (typeof this$1$1.input === 'number') { | ||
number = this$1$1.input.toFixed(this$1$1.options.precision); | ||
} else { | ||
return this.numberOnly() | ||
number = this$1$1.numberOnly(); | ||
} | ||
return number | ||
}; | ||
this.numberOnly = function (clean = false) { | ||
const regExp = new RegExp(`[^0-9\\${this.options.decimal}]+`, 'gi'); | ||
const numbers = this.input.toString().replace(regExp, ''); | ||
this.numberOnly = function (clean) { | ||
if ( clean === void 0 ) clean = false; | ||
var regExp = new RegExp(("[^0-9\\" + (this$1$1.options.decimal) + "]+"), 'gi'); | ||
var numbers = this$1$1.input.toString().replace(regExp, ''); | ||
if (clean) { | ||
const parts = numbers.split(this.options.decimal); | ||
return parts.length > 1 && parts[1] ? parts.join(this.options.decimal) : parts[0] | ||
var parts = numbers.split(this$1$1.options.decimal); | ||
return parts.length > 1 && parts[1] ? parts.join(this$1$1.options.decimal) : parts[0] | ||
} | ||
return numbers | ||
}; | ||
this.negative = (this.input.toString().indexOf('-') >= 0 && this.numbers() > 0) ? '-' : ''; | ||
this.parts = function () { | ||
var parts = this.numbers().toString().split(this.options.decimal); | ||
parts[0] = this.negative + (parseInt(parts[0]) ? parseInt(parts[0]) : 0); | ||
var parts = this$1$1.numbers().toString().split(this$1$1.options.decimal); | ||
parts[0] = this$1$1.negative + (Number(parts[0]) ? Number(parts[0]) : 0); | ||
if (parts.length > 1) { | ||
parts[1] = parts[1].slice(0, this.options.precision); | ||
parts[1] = parts[1].slice(0, this$1$1.options.precision); | ||
} | ||
return parts | ||
}; | ||
this.addSeparator = function (clean) { | ||
var parts = this.parts(); | ||
parts[0] = parts[0].toString().replace(/(\d)(?=(?:\d{3})+\b)/gm, `$1${this.options.separator}`); | ||
var parts = this$1$1.parts(); | ||
parts[0] = parts[0].toString().replace(/(\d)(?=(?:\d{3})+\b)/gm, ("$1" + (this$1$1.options.separator))); | ||
if (clean) { | ||
return parts[1] && parts[1].length > 0 ? parts.join(this.options.decimal) : parts[0] | ||
return parts[1] && parts[1].length > 0 ? parts.join(this$1$1.options.decimal) : parts[0] | ||
} | ||
return parts.join(this.options.decimal) | ||
return parts.join(this$1$1.options.decimal) | ||
}; | ||
this.format = function (clean = false) { | ||
return this.options.prefix + this.addSeparator(clean) + this.options.suffix | ||
this.format = function (clean) { | ||
if ( clean === void 0 ) clean = false; | ||
return this$1$1.options.prefix + this$1$1.addSeparator(clean) + this$1$1.options.suffix; | ||
}; | ||
this.unformat = function (clean = true) { | ||
return this.negative + this.numberOnly(clean) | ||
this.unformat = function (clean) { | ||
if ( clean === void 0 ) clean = true; | ||
return this$1$1.negative + this$1$1.numberOnly(clean); | ||
}; | ||
} | ||
function setCursor (el, position) { | ||
const setSelectionRange = function () { el.setSelectionRange(position, position); }; | ||
function setCursor(el, position) { | ||
var setSelectionRange = function () { el.setSelectionRange(position, position); }; | ||
if (el === document.activeElement) { | ||
setSelectionRange(); | ||
setTimeout(setSelectionRange, 1); | ||
setTimeout(setSelectionRange, 1); // Android Fix | ||
} | ||
} | ||
}function VNumber (el, binding) { | ||
var value = binding.value; | ||
if (!value) { return false } | ||
var config = Object.assign(options, value); | ||
// console.log('src/components/directive:config', config) | ||
function assign (defaults, extras) { | ||
defaults = defaults || {}; | ||
extras = extras || {}; | ||
return Object.keys(defaults).concat(Object.keys(extras)).reduce( function (acc, val) { | ||
acc[val] = extras[val] === undefined ? defaults[val] : extras[val]; | ||
return acc | ||
}, {}) | ||
} | ||
// v-number used on a component that's not a input element | ||
if (el.localName !== 'input') { | ||
var input = el.getElementsByTagName('input'); | ||
if (input.length < 1) { | ||
throw new Error(("v-number requires 1 input element, found " + (input.length))) | ||
} else { | ||
el = input[0]; | ||
} | ||
} | ||
function VNumber (el, binding) { | ||
const { value } = binding; | ||
if (!value) return false | ||
const config = assign(options, value); | ||
if (el.localName !== 'input') { | ||
const input = el.getElementsByTagName('input'); | ||
if (input.length < 1) { | ||
throw new Error("v-number requires 1 input element, found " + input.length) | ||
} else { | ||
el = input[0]; | ||
} | ||
} | ||
el.setAttribute('type', 'text'); | ||
el.oninput = function () { | ||
var positionFromEnd = el.value.length - el.selectionEnd; | ||
el.value = new NumberFormat(el.value, config).format(); | ||
positionFromEnd = Math.max(positionFromEnd, config.suffix.length); | ||
positionFromEnd = el.value.length - positionFromEnd; | ||
positionFromEnd = Math.max(positionFromEnd, config.prefix.length + 1); | ||
setCursor(el, positionFromEnd); | ||
}; | ||
el.onblur = function () { | ||
el.value = new NumberFormat(el.value, config).format(true); | ||
el.dispatchEvent(new Event('input')); | ||
el.dispatchEvent(new Event('change')); | ||
}; | ||
el.onfocus = function () { | ||
setCursor(el, el.value.length - config.suffix.length); | ||
}; | ||
el.onkeydown = function (evt) { | ||
if (evt.key === config.decimal && evt.target.value.includes(config.decimal)) { | ||
evt.preventDefault(); | ||
} | ||
if ( | ||
[46, 8, 9, 27, 13].indexOf(evt.keyCode) >= 0 || | ||
(evt.keyCode === 65 && (evt.ctrlKey || evt.metaKey)) || | ||
(evt.keyCode === 67 && (evt.ctrlKey || evt.metaKey)) || | ||
(evt.keyCode === 86 && (evt.ctrlKey || evt.metaKey)) || | ||
(evt.keyCode === 82 && (evt.ctrlKey || evt.metaKey)) || | ||
(evt.keyCode === 88 && (evt.ctrlKey || evt.metaKey)) || | ||
(evt.keyCode >= 35 && evt.keyCode <= 39) || | ||
(evt.keyCode >= 48 && evt.keyCode <= 57) || | ||
evt.keyCode === 109 || | ||
evt.key === config.decimal | ||
) { | ||
return | ||
} else { | ||
evt.preventDefault(); | ||
} | ||
}; | ||
el.oninput(); | ||
// change the input type to {text} because we can't use it to any other input types | ||
el.setAttribute('type', 'text'); | ||
el.oninput = function () { | ||
// console.log('oninput()') | ||
var positionFromEnd = el.value.length - el.selectionEnd; | ||
el.value = new NumberFormat(el.value, config).format(); | ||
positionFromEnd = Math.max(positionFromEnd, config.suffix.length); | ||
positionFromEnd = el.value.length - positionFromEnd; | ||
positionFromEnd = Math.max(positionFromEnd, config.prefix.length + 1); | ||
setCursor(el, positionFromEnd); | ||
}; | ||
el.onblur = function () { | ||
// clean up after end the input | ||
el.value = new NumberFormat(el.value, config).format(true); | ||
el.dispatchEvent(new Event('input')); | ||
el.dispatchEvent(new Event('change')); | ||
} | ||
}; | ||
el.onfocus = function () { | ||
// console.log('onfocus()') | ||
setCursor(el, el.value.length - config.suffix.length); | ||
}; | ||
el.onkeydown = function (evt) { | ||
// Check deciaml | ||
if (evt.key === config.decimal && evt.target.value.includes(config.decimal)) { | ||
evt.preventDefault(); | ||
} | ||
// Allow these keys only | ||
if ( | ||
// backspace, delete, tab, escape, enter | ||
[46, 8, 9, 27, 13].indexOf(evt.keyCode) >= 0 | ||
// Ctrl/cmd+A | ||
|| (evt.keyCode === 65 && (evt.ctrlKey || evt.metaKey)) | ||
// Ctrl/cmd+C | ||
|| (evt.keyCode === 67 && (evt.ctrlKey || evt.metaKey)) | ||
// Ctrl/cmd+V | ||
|| (evt.keyCode === 86 && (evt.ctrlKey || evt.metaKey)) | ||
// Ctrl/cmd+R | ||
|| (evt.keyCode === 82 && (evt.ctrlKey || evt.metaKey)) | ||
// Ctrl/cmd+X | ||
|| (evt.keyCode === 88 && (evt.ctrlKey || evt.metaKey)) | ||
// home, end, left, right | ||
|| (evt.keyCode >= 35 && evt.keyCode <= 39) | ||
|| (evt.keyCode >= 48 && evt.keyCode <= 57) | ||
|| evt.keyCode === 109 | ||
|| evt.key === config.decimal | ||
) { | ||
return true | ||
} | ||
evt.preventDefault(); | ||
}; | ||
// force format after initialization | ||
el.oninput(); | ||
el.dispatchEvent(new Event('input')); | ||
el.dispatchEvent(new Event('change')); | ||
}// | ||
var script = { | ||
name: 'Number', | ||
props: { | ||
@@ -144,37 +165,39 @@ value: { | ||
type: [Number, String], | ||
default: 0 | ||
default: 0, | ||
}, | ||
null_value: { | ||
type: [Number, String], | ||
default: () => options.null_value | ||
default: function () { return options.null_value; }, | ||
}, | ||
masked: { | ||
type: Boolean, | ||
default: false | ||
default: false, | ||
}, | ||
precision: { | ||
type: Number, | ||
default: () => options.precision | ||
default: function () { return options.precision; }, | ||
}, | ||
decimal: { | ||
type: String, | ||
default: () => options.decimal | ||
default: function () { return options.decimal; }, | ||
}, | ||
separator: { | ||
type: String, | ||
default: () => options.separator | ||
default: function () { return options.separator; }, | ||
}, | ||
prefix: { | ||
type: String, | ||
default: () => options.prefix | ||
default: function () { return options.prefix; }, | ||
}, | ||
suffix: { | ||
type: String, | ||
default: () => options.suffix | ||
} | ||
default: function () { return options.suffix; }, | ||
}, | ||
}, | ||
directives: { | ||
number: VNumber | ||
number: VNumber, | ||
}, | ||
data () { | ||
data: function data() { | ||
return { | ||
@@ -184,54 +207,137 @@ formattedValue: '', | ||
}, | ||
watch: { | ||
value: { | ||
immediate: true, | ||
handler (newValue) { | ||
const formatted = new NumberFormat(newValue, this.$props).format(); | ||
handler: function handler(newValue) { | ||
var formatted = new NumberFormat(newValue, this.$props).format(); | ||
if (formatted !== this.formattedValue) { | ||
this.formattedValue = formatted; | ||
} | ||
} | ||
} | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
change (evt) { | ||
const number = new NumberFormat(evt.target.value, this.$props); | ||
change: function change(evt) { | ||
var number = new NumberFormat(evt.target.value, this.$props); | ||
this.$emit('input', this.masked ? number.format(true) : number.unformat(true)); | ||
}, | ||
}, | ||
};function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) { | ||
if (typeof shadowMode !== 'boolean') { | ||
createInjectorSSR = createInjector; | ||
createInjector = shadowMode; | ||
shadowMode = false; | ||
} | ||
} | ||
}; | ||
// Vue.extend constructor export interop. | ||
var options = typeof script === 'function' ? script.options : script; | ||
// render functions | ||
if (template && template.render) { | ||
options.render = template.render; | ||
options.staticRenderFns = template.staticRenderFns; | ||
options._compiled = true; | ||
// functional template | ||
if (isFunctionalTemplate) { | ||
options.functional = true; | ||
} | ||
} | ||
// scopedId | ||
if (scopeId) { | ||
options._scopeId = scopeId; | ||
} | ||
var hook; | ||
if (moduleIdentifier) { | ||
// server build | ||
hook = function (context) { | ||
// 2.3 injection | ||
context = | ||
context || // cached call | ||
(this.$vnode && this.$vnode.ssrContext) || // stateful | ||
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext); // functional | ||
// 2.2 with runInNewContext: true | ||
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') { | ||
context = __VUE_SSR_CONTEXT__; | ||
} | ||
// inject component styles | ||
if (style) { | ||
style.call(this, createInjectorSSR(context)); | ||
} | ||
// register component module identifier for async chunk inference | ||
if (context && context._registeredComponents) { | ||
context._registeredComponents.add(moduleIdentifier); | ||
} | ||
}; | ||
// used by ssr in case component is cached and beforeCreate | ||
// never gets called | ||
options._ssrRegister = hook; | ||
} | ||
else if (style) { | ||
hook = shadowMode | ||
? function (context) { | ||
style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot)); | ||
} | ||
: function (context) { | ||
style.call(this, createInjector(context)); | ||
}; | ||
} | ||
if (hook) { | ||
if (options.functional) { | ||
// register for functional component in vue file | ||
var originalRender = options.render; | ||
options.render = function renderWithStyleInjection(h, context) { | ||
hook.call(context); | ||
return originalRender(h, context); | ||
}; | ||
} | ||
else { | ||
// inject component registration as beforeCreate hook | ||
var existing = options.beforeCreate; | ||
options.beforeCreate = existing ? [].concat(existing, hook) : [hook]; | ||
} | ||
} | ||
return script; | ||
}/* script */ | ||
var __vue_script__ = script; | ||
const _hoisted_1 = ["value"]; | ||
function render(_ctx, _cache, $props, $setup, $data, $options) { | ||
const _directive_number = vue.resolveDirective("number"); | ||
return vue.withDirectives((vue.openBlock(), vue.createElementBlock("input", { | ||
type: "text", | ||
autocomplete: "off", | ||
value: $data.formattedValue, | ||
onChange: _cache[0] || (_cache[0] = (...args) => ($options.change && $options.change(...args))), | ||
class: "v-number" | ||
}, null, 40 , _hoisted_1)), [ | ||
[_directive_number, {precision: $props.precision, decimal: $props.decimal, separator: $props.separator, prefix: $props.prefix, suffix: $props.suffix}] | ||
]) | ||
} | ||
/* template */ | ||
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('input',{directives:[{name:"number",rawName:"v-number",value:({precision: _vm.precision, decimal: _vm.decimal, separator: _vm.separator, prefix: _vm.prefix, suffix: _vm.suffix}),expression:"{precision, decimal, separator, prefix, suffix}"}],staticClass:"v-number",attrs:{"type":"text","autocomplete":"off"},domProps:{"value":_vm.formattedValue},on:{"change":_vm.change}},[])}; | ||
var __vue_staticRenderFns__ = []; | ||
script.render = render; | ||
script.__file = "src/component.vue"; | ||
/* style */ | ||
var __vue_inject_styles__ = undefined; | ||
/* scoped */ | ||
var __vue_scope_id__ = undefined; | ||
/* module identifier */ | ||
var __vue_module_identifier__ = "data-v-acb6fabe"; | ||
/* functional template */ | ||
var __vue_is_functional_template__ = false; | ||
/* style inject */ | ||
/* style inject SSR */ | ||
/* style inject shadow dom */ | ||
function install (Vue, globalOptions) { | ||
var __vue_component__ = /*#__PURE__*/normalizeComponent( | ||
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ }, | ||
__vue_inject_styles__, | ||
__vue_script__, | ||
__vue_scope_id__, | ||
__vue_is_functional_template__, | ||
__vue_module_identifier__, | ||
false, | ||
undefined, | ||
undefined, | ||
undefined | ||
);function install(Vue, globalOptions) { | ||
if (globalOptions) { | ||
Object.keys(globalOptions).map(function(key){ | ||
Object.keys(globalOptions).map(function (key) { | ||
options[key] = globalOptions[key]; | ||
return options | ||
}); | ||
} | ||
Vue.directive('number', VNumber); | ||
Vue.component('number', script); | ||
} | ||
if (typeof window !== 'undefined' && window.Vue) { | ||
window.Vue.use(install); | ||
} | ||
exports.Number = script; | ||
exports.VNumber = VNumber; | ||
exports['default'] = install; | ||
exports.options = options; | ||
Vue.component('number', __vue_component__); | ||
}exports.Number=__vue_component__;exports.VNumber=VNumber;exports['default']=install;exports.options=options;//# sourceMappingURL=index.cjs.js.map |
@@ -6,222 +6,3 @@ /** | ||
*/ | ||
import { resolveDirective, withDirectives, openBlock, createElementBlock } from 'vue'; | ||
var options = { | ||
prefix: '', | ||
suffix: '', | ||
separator: ',', | ||
decimal: '.', | ||
precision: 2, | ||
null_value: 0 | ||
}; | ||
function NumberFormat (input, opt = options) { | ||
this.options = opt; | ||
this.input = input || this.options.null_value; | ||
this.numbers = function () { | ||
if (typeof this.input === 'number') { | ||
return this.input.toFixed(this.options.precision) | ||
} else { | ||
return this.numberOnly() | ||
} | ||
}; | ||
this.numberOnly = function (clean = false) { | ||
const regExp = new RegExp(`[^0-9\\${this.options.decimal}]+`, 'gi'); | ||
const numbers = this.input.toString().replace(regExp, ''); | ||
if (clean) { | ||
const parts = numbers.split(this.options.decimal); | ||
return parts.length > 1 && parts[1] ? parts.join(this.options.decimal) : parts[0] | ||
} | ||
return numbers | ||
}; | ||
this.negative = (this.input.toString().indexOf('-') >= 0 && this.numbers() > 0) ? '-' : ''; | ||
this.parts = function () { | ||
var parts = this.numbers().toString().split(this.options.decimal); | ||
parts[0] = this.negative + (parseInt(parts[0]) ? parseInt(parts[0]) : 0); | ||
if (parts.length > 1) { | ||
parts[1] = parts[1].slice(0, this.options.precision); | ||
} | ||
return parts | ||
}; | ||
this.addSeparator = function (clean) { | ||
var parts = this.parts(); | ||
parts[0] = parts[0].toString().replace(/(\d)(?=(?:\d{3})+\b)/gm, `$1${this.options.separator}`); | ||
if (clean) { | ||
return parts[1] && parts[1].length > 0 ? parts.join(this.options.decimal) : parts[0] | ||
} | ||
return parts.join(this.options.decimal) | ||
}; | ||
this.format = function (clean = false) { | ||
return this.options.prefix + this.addSeparator(clean) + this.options.suffix | ||
}; | ||
this.unformat = function (clean = true) { | ||
return this.negative + this.numberOnly(clean) | ||
}; | ||
} | ||
function setCursor (el, position) { | ||
const setSelectionRange = function () { el.setSelectionRange(position, position); }; | ||
if (el === document.activeElement) { | ||
setSelectionRange(); | ||
setTimeout(setSelectionRange, 1); | ||
} | ||
} | ||
function assign (defaults, extras) { | ||
defaults = defaults || {}; | ||
extras = extras || {}; | ||
return Object.keys(defaults).concat(Object.keys(extras)).reduce( function (acc, val) { | ||
acc[val] = extras[val] === undefined ? defaults[val] : extras[val]; | ||
return acc | ||
}, {}) | ||
} | ||
function VNumber (el, binding) { | ||
const { value } = binding; | ||
if (!value) return false | ||
const config = assign(options, value); | ||
if (el.localName !== 'input') { | ||
const input = el.getElementsByTagName('input'); | ||
if (input.length < 1) { | ||
throw new Error("v-number requires 1 input element, found " + input.length) | ||
} else { | ||
el = input[0]; | ||
} | ||
} | ||
el.setAttribute('type', 'text'); | ||
el.oninput = function () { | ||
var positionFromEnd = el.value.length - el.selectionEnd; | ||
el.value = new NumberFormat(el.value, config).format(); | ||
positionFromEnd = Math.max(positionFromEnd, config.suffix.length); | ||
positionFromEnd = el.value.length - positionFromEnd; | ||
positionFromEnd = Math.max(positionFromEnd, config.prefix.length + 1); | ||
setCursor(el, positionFromEnd); | ||
}; | ||
el.onblur = function () { | ||
el.value = new NumberFormat(el.value, config).format(true); | ||
el.dispatchEvent(new Event('input')); | ||
el.dispatchEvent(new Event('change')); | ||
}; | ||
el.onfocus = function () { | ||
setCursor(el, el.value.length - config.suffix.length); | ||
}; | ||
el.onkeydown = function (evt) { | ||
if (evt.key === config.decimal && evt.target.value.includes(config.decimal)) { | ||
evt.preventDefault(); | ||
} | ||
if ( | ||
[46, 8, 9, 27, 13].indexOf(evt.keyCode) >= 0 || | ||
(evt.keyCode === 65 && (evt.ctrlKey || evt.metaKey)) || | ||
(evt.keyCode === 67 && (evt.ctrlKey || evt.metaKey)) || | ||
(evt.keyCode === 86 && (evt.ctrlKey || evt.metaKey)) || | ||
(evt.keyCode === 82 && (evt.ctrlKey || evt.metaKey)) || | ||
(evt.keyCode === 88 && (evt.ctrlKey || evt.metaKey)) || | ||
(evt.keyCode >= 35 && evt.keyCode <= 39) || | ||
(evt.keyCode >= 48 && evt.keyCode <= 57) || | ||
evt.keyCode === 109 || | ||
evt.key === config.decimal | ||
) { | ||
return | ||
} else { | ||
evt.preventDefault(); | ||
} | ||
}; | ||
el.oninput(); | ||
el.dispatchEvent(new Event('input')); | ||
el.dispatchEvent(new Event('change')); | ||
} | ||
var script = { | ||
name: 'Number', | ||
props: { | ||
value: { | ||
required: true, | ||
type: [Number, String], | ||
default: 0 | ||
}, | ||
null_value: { | ||
type: [Number, String], | ||
default: () => options.null_value | ||
}, | ||
masked: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
precision: { | ||
type: Number, | ||
default: () => options.precision | ||
}, | ||
decimal: { | ||
type: String, | ||
default: () => options.decimal | ||
}, | ||
separator: { | ||
type: String, | ||
default: () => options.separator | ||
}, | ||
prefix: { | ||
type: String, | ||
default: () => options.prefix | ||
}, | ||
suffix: { | ||
type: String, | ||
default: () => options.suffix | ||
} | ||
}, | ||
directives: { | ||
number: VNumber | ||
}, | ||
data () { | ||
return { | ||
formattedValue: '', | ||
} | ||
}, | ||
watch: { | ||
value: { | ||
immediate: true, | ||
handler (newValue) { | ||
const formatted = new NumberFormat(newValue, this.$props).format(); | ||
if (formatted !== this.formattedValue) { | ||
this.formattedValue = formatted; | ||
} | ||
} | ||
} | ||
}, | ||
methods: { | ||
change (evt) { | ||
const number = new NumberFormat(evt.target.value, this.$props); | ||
this.$emit('input', this.masked ? number.format(true) : number.unformat(true)); | ||
} | ||
} | ||
}; | ||
const _hoisted_1 = ["value"]; | ||
function render(_ctx, _cache, $props, $setup, $data, $options) { | ||
const _directive_number = resolveDirective("number"); | ||
return withDirectives((openBlock(), createElementBlock("input", { | ||
type: "text", | ||
autocomplete: "off", | ||
value: $data.formattedValue, | ||
onChange: _cache[0] || (_cache[0] = (...args) => ($options.change && $options.change(...args))), | ||
class: "v-number" | ||
}, null, 40 , _hoisted_1)), [ | ||
[_directive_number, {precision: $props.precision, decimal: $props.decimal, separator: $props.separator, prefix: $props.prefix, suffix: $props.suffix}] | ||
]) | ||
} | ||
script.render = render; | ||
script.__file = "src/component.vue"; | ||
function install (Vue, globalOptions) { | ||
if (globalOptions) { | ||
Object.keys(globalOptions).map(function(key){ | ||
options[key] = globalOptions[key]; | ||
}); | ||
} | ||
Vue.directive('number', VNumber); | ||
Vue.component('number', script); | ||
} | ||
if (typeof window !== 'undefined' && window.Vue) { | ||
window.Vue.use(install); | ||
} | ||
export { script as Number, VNumber, install as default, options }; | ||
var e={prefix:"",suffix:"",separator:",",decimal:".",precision:2,null_value:0};function t(t,n){var i=this;void 0===n&&(n=e),this.options=n,this.input=t||this.options.null_value,this.numbers=function(){i.input;return"number"==typeof i.input?i.input.toFixed(i.options.precision):i.numberOnly()},this.numberOnly=function(e){void 0===e&&(e=!1);var t=new RegExp("[^0-9\\"+i.options.decimal+"]+","gi"),n=i.input.toString().replace(t,"");if(e){var r=n.split(i.options.decimal);return r.length>1&&r[1]?r.join(i.options.decimal):r[0]}return n},this.negative=this.input.toString().indexOf("-")>=0&&this.numbers()>0?"-":"",this.parts=function(){var e=i.numbers().toString().split(i.options.decimal);return e[0]=i.negative+(Number(e[0])?Number(e[0]):0),e.length>1&&(e[1]=e[1].slice(0,i.options.precision)),e},this.addSeparator=function(e){var t=i.parts();return t[0]=t[0].toString().replace(/(\d)(?=(?:\d{3})+\b)/gm,"$1"+i.options.separator),e?t[1]&&t[1].length>0?t.join(i.options.decimal):t[0]:t.join(i.options.decimal)},this.format=function(e){return void 0===e&&(e=!1),i.options.prefix+i.addSeparator(e)+i.options.suffix},this.unformat=function(e){return void 0===e&&(e=!0),i.negative+i.numberOnly(e)}}function n(e,t){var n=function(){e.setSelectionRange(t,t)};e===document.activeElement&&(n(),setTimeout(n,1))}function i(i,r){var o=r.value;if(!o)return!1;var a=Object.assign(e,o);if("input"!==i.localName){var u=i.getElementsByTagName("input");if(u.length<1)throw new Error("v-number requires 1 input element, found "+u.length);i=u[0]}i.setAttribute("type","text"),i.oninput=function(){var e=i.value.length-i.selectionEnd;i.value=new t(i.value,a).format(),e=Math.max(e,a.suffix.length),e=i.value.length-e,e=Math.max(e,a.prefix.length+1),n(i,e)},i.onblur=function(){i.value=new t(i.value,a).format(!0),i.dispatchEvent(new Event("input")),i.dispatchEvent(new Event("change"))},i.onfocus=function(){n(i,i.value.length-a.suffix.length)},i.onkeydown=function(e){if(e.key===a.decimal&&e.target.value.includes(a.decimal)&&e.preventDefault(),[46,8,9,27,13].indexOf(e.keyCode)>=0||65===e.keyCode&&(e.ctrlKey||e.metaKey)||67===e.keyCode&&(e.ctrlKey||e.metaKey)||86===e.keyCode&&(e.ctrlKey||e.metaKey)||82===e.keyCode&&(e.ctrlKey||e.metaKey)||88===e.keyCode&&(e.ctrlKey||e.metaKey)||e.keyCode>=35&&e.keyCode<=39||e.keyCode>=48&&e.keyCode<=57||109===e.keyCode||e.key===a.decimal)return!0;e.preventDefault()},i.oninput(),i.dispatchEvent(new Event("input")),i.dispatchEvent(new Event("change"))}function r(e,t,n,i,r,o,a,u,s,l){"boolean"!=typeof a&&(s=u,u=a,a=!1);var c,f="function"==typeof n?n.options:n;if(e&&e.render&&(f.render=e.render,f.staticRenderFns=e.staticRenderFns,f._compiled=!0,r&&(f.functional=!0)),i&&(f._scopeId=i),o?(c=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,s(e)),e&&e._registeredComponents&&e._registeredComponents.add(o)},f._ssrRegister=c):t&&(c=a?function(e){t.call(this,l(e,this.$root.$options.shadowRoot))}:function(e){t.call(this,u(e))}),c)if(f.functional){var p=f.render;f.render=function(e,t){return c.call(t),p(e,t)}}else{var d=f.beforeCreate;f.beforeCreate=d?[].concat(d,c):[c]}return n}var o=r({render:function(){var e=this.$createElement;return(this._self._c||e)("input",{directives:[{name:"number",rawName:"v-number",value:{precision:this.precision,decimal:this.decimal,separator:this.separator,prefix:this.prefix,suffix:this.suffix},expression:"{precision, decimal, separator, prefix, suffix}"}],staticClass:"v-number",attrs:{type:"text",autocomplete:"off"},domProps:{value:this.formattedValue},on:{change:this.change}})},staticRenderFns:[]},void 0,{props:{value:{required:!0,type:[Number,String],default:0},null_value:{type:[Number,String],default:function(){return e.null_value}},masked:{type:Boolean,default:!1},precision:{type:Number,default:function(){return e.precision}},decimal:{type:String,default:function(){return e.decimal}},separator:{type:String,default:function(){return e.separator}},prefix:{type:String,default:function(){return e.prefix}},suffix:{type:String,default:function(){return e.suffix}}},directives:{number:i},data:function(){return{formattedValue:""}},watch:{value:{immediate:!0,handler:function(e){var n=new t(e,this.$props).format();n!==this.formattedValue&&(this.formattedValue=n)}}},methods:{change:function(e){var n=new t(e.target.value,this.$props);this.$emit("input",this.masked?n.format(!0):n.unformat(!0))}}},void 0,!1,void 0,!1,void 0,void 0,void 0);function a(t,n){n&&Object.keys(n).map((function(t){return e[t]=n[t],e})),t.directive("number",i),t.component("number",o)}export{o as Number,i as VNumber,a as default,e as options}; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@coders-tm/vue-number-format", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"private": false, | ||
"description": "Easy formatted numbers, currency and percentage with input/directive mask for Vue.js", | ||
"author": "Dipak Sarkar <hello@dipaksarkar.in> (https://dipaksarkar.in/)", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js", | ||
"unpkg": "dist/index.min.js", | ||
"style": "dist/styles.css", | ||
"licence": "MIT", | ||
"files": [ | ||
"dist/*", | ||
"src/**/*.vue" | ||
], | ||
"scripts": { | ||
"build": "rollup --c rollup.config.js", | ||
"lint": "eslint", | ||
"docs:build": "vuepress build docs", | ||
"docs:dev": "vuepress dev docs", | ||
"test": "jest", | ||
"test": "jest tests/*", | ||
"lint": "eslint 'src/**/*.{js,vue}'", | ||
"push": "clear && git config core.ignorecase false && branch=\"$(git symbolic-ref -q HEAD)\" || \"dev\" && branch=${branch##refs/heads/} && branch=${branch:-HEAD} && echo Pushing to Branch \"$branch\" && echo Please type your commit message && read msg && clear && git add . && git commit -m \"$msg\" && git push origin \"$branch\"" | ||
}, | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js", | ||
"files": [ | ||
"dist/*" | ||
], | ||
"devDependencies": { | ||
"@babel/core": "^7.15.5", | ||
"@babel/preset-env": "^7.15.6", | ||
"@coders-tm/vue-number-format": "^1.0.3", | ||
"@vue/babel-preset-app": "^4.5.13", | ||
"@vue/cli-plugin-unit-jest": "~4.5.0", | ||
"@vue/cli-service": "^4.5.13", | ||
"@vue/compiler-sfc": "^3.2.11", | ||
"@vue/eslint-config-prettier": "^6.0.0", | ||
"@vue/test-utils": "^1.0.3", | ||
"@babel/core": "^7.9.0", | ||
"@babel/preset-env": "^7.9.5", | ||
"@shopify/jest-dom-mocks": "^2.8.11", | ||
"@vue/cli-plugin-unit-jest": "^4.5.13", | ||
"@vue/test-utils": "^1.0.0-beta.33", | ||
"@vuedoc/md": "^1.6.0", | ||
"@vuepress/plugin-back-to-top": "^1.8.2", | ||
"@vuepress/plugin-medium-zoom": "^1.8.2", | ||
"@vuepress/plugin-register-components": "^1.8.2", | ||
"@vuepress/plugin-register-components": "^1.4.1", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-jest": "^27.1.1", | ||
"babel-preset-vue-app": "^2.0.0", | ||
"eslint": "^7.32.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-vue": "^7.17.0", | ||
"jest": "^26.6.3", | ||
"jest-environment-jsdom-fifteen": "^1.0.2", | ||
"prettier": "^2.4.0", | ||
"babel-jest": "^25.3.0", | ||
"babel-preset-env": "^1.7.0", | ||
"babel-preset-vue": "^2.0.2", | ||
"eslint": "^6.8.0", | ||
"eslint-config-airbnb-base": "^14.1.0", | ||
"eslint-plugin-import": "^2.20.2", | ||
"eslint-plugin-vue": "^6.2.2", | ||
"jest": "^25.3.0", | ||
"node-fetch": "^2.6.0", | ||
"npm-run-all": "^4.1.5", | ||
"quasar": "^1.11.3", | ||
"rollup": "^2.56.3", | ||
"rollup": "^2.6.1", | ||
"rollup-plugin-buble": "^0.19.8", | ||
"rollup-plugin-cleanup": "^3.2.1", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-css-only": "^3.1.0", | ||
"rollup-plugin-css-only": "^2.0.0", | ||
"rollup-plugin-filesize": "^9.1.1", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-vue": "^6.0.0", | ||
"rollup-plugin-replace": "^2.2.0", | ||
"rollup-plugin-terser": "^5.3.0", | ||
"rollup-plugin-vue": "^5.1.6", | ||
"vue": "^2.6.11", | ||
"vue-jest": "^3.0.7", | ||
"vuepress": "^1.8.2" | ||
"vue-jest": "^3.0.5", | ||
"vue-template-compiler": "^2.6.11", | ||
"vuepress": "^1.4.1", | ||
"vuepress-plugin-demo-code": "^0.5.0" | ||
}, | ||
@@ -80,3 +85,2 @@ "bugs": { | ||
}, | ||
"style": "dist/styles.css", | ||
"publishConfig": { | ||
@@ -83,0 +87,0 @@ "@coders-tm:registry": "https://npm.pkg.github.com" |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
77205
9
35
358
1