vue-currency-input
Advanced tools
Comparing version 1.10.0 to 1.10.1
/** | ||
* Vue Currency Input 1.10.0 | ||
* Vue Currency Input 1.10.1 | ||
* (c) 2019 Matthias Stiller | ||
@@ -274,5 +274,2 @@ * @license MIT | ||
var optionsChanged = function (oldOptions, newOptions) { | ||
return Object.keys(defaultOptions).some(function (key) { return oldOptions[key] !== newOptions[key]; }) | ||
}; | ||
var init = function (el, optionsFromBinding, defaultOptions) { | ||
@@ -330,3 +327,3 @@ var inputElement = el.tagName.toLowerCase() === 'input' ? el : el.querySelector('input'); | ||
}; | ||
function updateInputValue (el, value, distractionFree) { | ||
var updateInputValue = function (el, value, distractionFree) { | ||
if ( distractionFree === void 0 ) distractionFree = false; | ||
@@ -351,4 +348,5 @@ if (value != null) { | ||
: fractionDigits.length | ||
}).format(conformedValue); | ||
el.value = "" + (conformedValue < 0 ? formatConfig.negativePrefix : formatConfig.prefix) + formattedValue + (formatConfig.suffix); | ||
}).format(Math.abs(conformedValue)); | ||
var isNegativeZero = conformedValue === 0 && (1 / conformedValue < 0); | ||
el.value = "" + (isNegativeZero || conformedValue < 0 ? formatConfig.negativePrefix : formatConfig.prefix) + formattedValue + (formatConfig.suffix); | ||
} else { | ||
@@ -361,3 +359,3 @@ el.value = conformedValue; | ||
el.$ci.previousConformedValue = el.value; | ||
} | ||
}; | ||
var format = function (el, value) { | ||
@@ -370,3 +368,3 @@ if ( value === void 0 ) value = el.value; | ||
}; | ||
function addEventListener (el) { | ||
var addEventListener = function (el) { | ||
el.addEventListener('input', function () { | ||
@@ -415,3 +413,3 @@ if (el.$ci.focus) { | ||
}); | ||
} | ||
}; | ||
var directive = { | ||
@@ -433,3 +431,3 @@ bind: function bind (el, ref, ref$1) { | ||
var context = ref$1.context; | ||
if (!!value && optionsChanged(oldValue, value)) { | ||
if (!!value && Object.keys(defaultOptions).some(function (key) { return oldValue[key] !== value[key]; })) { | ||
var inputElement = init(el, value, context.$CI_DEFAULT_OPTIONS || defaultOptions); | ||
@@ -436,0 +434,0 @@ applyFixedFractionFormat(inputElement, inputElement.$ci.numberValue); |
/** | ||
* Vue Currency Input 1.10.0 | ||
* Vue Currency Input 1.10.1 | ||
* (c) 2019 Matthias Stiller | ||
@@ -280,5 +280,2 @@ * @license MIT | ||
var optionsChanged = function (oldOptions, newOptions) { | ||
return Object.keys(defaultOptions).some(function (key) { return oldOptions[key] !== newOptions[key]; }) | ||
}; | ||
var init = function (el, optionsFromBinding, defaultOptions) { | ||
@@ -336,3 +333,3 @@ var inputElement = el.tagName.toLowerCase() === 'input' ? el : el.querySelector('input'); | ||
}; | ||
function updateInputValue (el, value, distractionFree) { | ||
var updateInputValue = function (el, value, distractionFree) { | ||
if ( distractionFree === void 0 ) distractionFree = false; | ||
@@ -357,4 +354,5 @@ if (value != null) { | ||
: fractionDigits.length | ||
}).format(conformedValue); | ||
el.value = "" + (conformedValue < 0 ? formatConfig.negativePrefix : formatConfig.prefix) + formattedValue + (formatConfig.suffix); | ||
}).format(Math.abs(conformedValue)); | ||
var isNegativeZero = conformedValue === 0 && (1 / conformedValue < 0); | ||
el.value = "" + (isNegativeZero || conformedValue < 0 ? formatConfig.negativePrefix : formatConfig.prefix) + formattedValue + (formatConfig.suffix); | ||
} else { | ||
@@ -367,3 +365,3 @@ el.value = conformedValue; | ||
el.$ci.previousConformedValue = el.value; | ||
} | ||
}; | ||
var format = function (el, value) { | ||
@@ -376,3 +374,3 @@ if ( value === void 0 ) value = el.value; | ||
}; | ||
function addEventListener (el) { | ||
var addEventListener = function (el) { | ||
el.addEventListener('input', function () { | ||
@@ -421,3 +419,3 @@ if (el.$ci.focus) { | ||
}); | ||
} | ||
}; | ||
var directive = { | ||
@@ -439,3 +437,3 @@ bind: function bind (el, ref, ref$1) { | ||
var context = ref$1.context; | ||
if (!!value && optionsChanged(oldValue, value)) { | ||
if (!!value && Object.keys(defaultOptions).some(function (key) { return oldValue[key] !== value[key]; })) { | ||
var inputElement = init(el, value, context.$CI_DEFAULT_OPTIONS || defaultOptions); | ||
@@ -442,0 +440,0 @@ applyFixedFractionFormat(inputElement, inputElement.$ci.numberValue); |
{ | ||
"name": "vue-currency-input", | ||
"description": "Easy input of currency formatted numbers for Vue.js.", | ||
"version": "1.10.0", | ||
"version": "1.10.1", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "unpkg": "dist/vue-currency-input.umd.js", |
@@ -7,6 +7,6 @@ import createCurrencyFormat from './utils/createCurrencyFormat' | ||
* @param {String} formattedValue The currency formatted string to be parsed, for example `$1,234.50`. | ||
* @param {String} locale A [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code (for example `USD` or `EUR`). | ||
* @param {String | Object} currency A [BCP 47](https://tools.ietf.org/html/bcp47) language tag (for example `en` or `de-DE`), an object `{prefix, suffix}` or `null`. | ||
* @param {String} locale A [BCP 47](https://tools.ietf.org/html/bcp47) language tag (for example `en` or `de-DE`). | ||
* @param {String | Object} currency A [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code (for example `USD` or `EUR`), an object `{prefix, suffix}` or `null`. | ||
* @returns {number | null} The parsed number or `null` if the formatted string does not match. | ||
*/ | ||
export const parseCurrency = (formattedValue, locale, currency) => parse(formattedValue, createCurrencyFormat({ locale, currency })) |
@@ -9,6 +9,2 @@ import Vue from 'vue' | ||
const optionsChanged = (oldOptions, newOptions) => { | ||
return Object.keys(defaultOptions).some((key) => oldOptions[key] !== newOptions[key]) | ||
} | ||
const init = (el, optionsFromBinding, defaultOptions) => { | ||
@@ -63,3 +59,3 @@ const inputElement = el.tagName.toLowerCase() === 'input' ? el : el.querySelector('input') | ||
function updateInputValue (el, value, distractionFree = false) { | ||
const updateInputValue = (el, value, distractionFree = false) => { | ||
if (value != null) { | ||
@@ -76,4 +72,5 @@ const { options, decimalFormat, currencyFormat, focus, previousConformedValue } = el.$ci | ||
: fractionDigits.length | ||
}).format(conformedValue) | ||
el.value = `${conformedValue < 0 ? formatConfig.negativePrefix : formatConfig.prefix}${formattedValue}${formatConfig.suffix}` | ||
}).format(Math.abs(conformedValue)) | ||
const isNegativeZero = conformedValue === 0 && (1 / conformedValue < 0) | ||
el.value = `${isNegativeZero || conformedValue < 0 ? formatConfig.negativePrefix : formatConfig.prefix}${formattedValue}${formatConfig.suffix}` | ||
} else { | ||
@@ -95,3 +92,3 @@ el.value = conformedValue | ||
function addEventListener (el) { | ||
const addEventListener = (el) => { | ||
el.addEventListener('input', () => { | ||
@@ -144,7 +141,6 @@ if (el.$ci.focus) { | ||
}) | ||
addEventListener(inputElement) | ||
}, | ||
componentUpdated (el, { value, oldValue }, { context }) { | ||
if (!!value && optionsChanged(oldValue, value)) { | ||
if (!!value && Object.keys(defaultOptions).some((key) => oldValue[key] !== value[key])) { | ||
const inputElement = init(el, value, context.$CI_DEFAULT_OPTIONS || defaultOptions) | ||
@@ -151,0 +147,0 @@ applyFixedFractionFormat(inputElement, inputElement.$ci.numberValue) |
64450
1560