vue-currency-input
Advanced tools
Comparing version 2.0.0 to 2.0.1
/** | ||
* Vue Currency Input 2.0.0 | ||
* Vue Currency Input 2.0.1 | ||
* (c) 2018-2021 Matthias Stiller | ||
@@ -37,2 +37,14 @@ * @license MIT | ||
class CurrencyFormat { | ||
locale; | ||
currency; | ||
currencyDisplay; | ||
digits; | ||
decimalSymbol; | ||
groupingSymbol; | ||
minusSymbol; | ||
minimumFractionDigits; | ||
maximumFractionDigits; | ||
prefix; | ||
negativePrefix; | ||
suffix; | ||
constructor(options) { | ||
@@ -147,2 +159,3 @@ const { currency, currencyDisplay, locale, precision } = options; | ||
class AbstractInputMask { | ||
currencyFormat; | ||
constructor(currencyFormat) { | ||
@@ -228,2 +241,12 @@ this.currencyFormat = currencyFormat; | ||
class CurrencyInput { | ||
el; | ||
options; | ||
numberValue; | ||
currencyFormat; | ||
decimalSymbolInsertedAt; | ||
numberMask; | ||
formattedValue; | ||
focus; | ||
minValue; | ||
maxValue; | ||
constructor(el, options) { | ||
@@ -362,38 +385,37 @@ this.el = el; | ||
this.el.addEventListener('input', (e) => { | ||
if (!e.isTrusted) { | ||
return; | ||
} | ||
const { value, selectionStart } = this.el; | ||
const inputEvent = e; | ||
if (selectionStart && inputEvent.data && DECIMAL_SEPARATORS.includes(inputEvent.data)) { | ||
this.decimalSymbolInsertedAt = selectionStart - 1; | ||
} | ||
this.format(value); | ||
if (this.focus && selectionStart != null) { | ||
const getCaretPositionAfterFormat = () => { | ||
const { prefix, suffix, decimalSymbol, maximumFractionDigits, groupingSymbol } = this.currencyFormat; | ||
let caretPositionFromLeft = value.length - selectionStart; | ||
const newValueLength = this.formattedValue.length; | ||
if (this.formattedValue.substr(selectionStart, 1) === groupingSymbol && | ||
count(this.formattedValue, groupingSymbol) === count(value, groupingSymbol) + 1) { | ||
return newValueLength - caretPositionFromLeft - 1; | ||
} | ||
if (decimalSymbol) { | ||
const decimalSymbolPosition = value.indexOf(decimalSymbol) + 1; | ||
if (Math.abs(newValueLength - value.length) > 1 && selectionStart <= decimalSymbolPosition) { | ||
return this.formattedValue.indexOf(decimalSymbol) + 1; | ||
if (!e.detail) { | ||
const { value, selectionStart } = this.el; | ||
const inputEvent = e; | ||
if (selectionStart && inputEvent.data && DECIMAL_SEPARATORS.includes(inputEvent.data)) { | ||
this.decimalSymbolInsertedAt = selectionStart - 1; | ||
} | ||
this.format(value); | ||
if (this.focus && selectionStart != null) { | ||
const getCaretPositionAfterFormat = () => { | ||
const { prefix, suffix, decimalSymbol, maximumFractionDigits, groupingSymbol } = this.currencyFormat; | ||
let caretPositionFromLeft = value.length - selectionStart; | ||
const newValueLength = this.formattedValue.length; | ||
if (this.formattedValue.substr(selectionStart, 1) === groupingSymbol && | ||
count(this.formattedValue, groupingSymbol) === count(value, groupingSymbol) + 1) { | ||
return newValueLength - caretPositionFromLeft - 1; | ||
} | ||
else { | ||
if (!this.options.autoDecimalDigits && selectionStart > decimalSymbolPosition) { | ||
if (this.currencyFormat.onlyDigits(value.substr(decimalSymbolPosition)).length - 1 === maximumFractionDigits) { | ||
caretPositionFromLeft -= 1; | ||
if (decimalSymbol) { | ||
const decimalSymbolPosition = value.indexOf(decimalSymbol) + 1; | ||
if (Math.abs(newValueLength - value.length) > 1 && selectionStart <= decimalSymbolPosition) { | ||
return this.formattedValue.indexOf(decimalSymbol) + 1; | ||
} | ||
else { | ||
if (!this.options.autoDecimalDigits && selectionStart > decimalSymbolPosition) { | ||
if (this.currencyFormat.onlyDigits(value.substr(decimalSymbolPosition)).length - 1 === maximumFractionDigits) { | ||
caretPositionFromLeft -= 1; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return this.options.hideCurrencySymbolOnFocus | ||
? newValueLength - caretPositionFromLeft | ||
: Math.max(newValueLength - Math.max(caretPositionFromLeft, suffix.length), prefix.length); | ||
}; | ||
this.setCaretPosition(getCaretPositionAfterFormat()); | ||
return this.options.hideCurrencySymbolOnFocus | ||
? newValueLength - caretPositionFromLeft | ||
: Math.max(newValueLength - Math.max(caretPositionFromLeft, suffix.length), prefix.length); | ||
}; | ||
this.setCaretPosition(getCaretPositionAfterFormat()); | ||
} | ||
} | ||
@@ -438,6 +460,5 @@ }, { capture: true }); | ||
this.el.addEventListener('change', (e) => { | ||
if (!e.isTrusted) { | ||
return; | ||
if (!e.detail) { | ||
this.dispatchEvent('change'); | ||
} | ||
this.dispatchEvent('change'); | ||
}, { capture: true }); | ||
@@ -514,2 +535,2 @@ } | ||
exports.default = useCurrencyInput; | ||
exports['default'] = useCurrencyInput; |
@@ -41,3 +41,2 @@ import { Ref } from 'vue-demi'; | ||
export default _default; | ||
export { CurrencyDisplay, CurrencyInputOptions, CurrencyInputValue, NumberRange, UseCurrencyInput }; | ||
export { CurrencyDisplay, CurrencyInputOptions, CurrencyInputValue, NumberRange, UseCurrencyInput, _default as default }; |
/** | ||
* Vue Currency Input 2.0.0 | ||
* Vue Currency Input 2.0.1 | ||
* (c) 2018-2021 Matthias Stiller | ||
@@ -33,2 +33,14 @@ * @license MIT | ||
class CurrencyFormat { | ||
locale; | ||
currency; | ||
currencyDisplay; | ||
digits; | ||
decimalSymbol; | ||
groupingSymbol; | ||
minusSymbol; | ||
minimumFractionDigits; | ||
maximumFractionDigits; | ||
prefix; | ||
negativePrefix; | ||
suffix; | ||
constructor(options) { | ||
@@ -143,2 +155,3 @@ const { currency, currencyDisplay, locale, precision } = options; | ||
class AbstractInputMask { | ||
currencyFormat; | ||
constructor(currencyFormat) { | ||
@@ -224,2 +237,12 @@ this.currencyFormat = currencyFormat; | ||
class CurrencyInput { | ||
el; | ||
options; | ||
numberValue; | ||
currencyFormat; | ||
decimalSymbolInsertedAt; | ||
numberMask; | ||
formattedValue; | ||
focus; | ||
minValue; | ||
maxValue; | ||
constructor(el, options) { | ||
@@ -358,38 +381,37 @@ this.el = el; | ||
this.el.addEventListener('input', (e) => { | ||
if (!e.isTrusted) { | ||
return; | ||
} | ||
const { value, selectionStart } = this.el; | ||
const inputEvent = e; | ||
if (selectionStart && inputEvent.data && DECIMAL_SEPARATORS.includes(inputEvent.data)) { | ||
this.decimalSymbolInsertedAt = selectionStart - 1; | ||
} | ||
this.format(value); | ||
if (this.focus && selectionStart != null) { | ||
const getCaretPositionAfterFormat = () => { | ||
const { prefix, suffix, decimalSymbol, maximumFractionDigits, groupingSymbol } = this.currencyFormat; | ||
let caretPositionFromLeft = value.length - selectionStart; | ||
const newValueLength = this.formattedValue.length; | ||
if (this.formattedValue.substr(selectionStart, 1) === groupingSymbol && | ||
count(this.formattedValue, groupingSymbol) === count(value, groupingSymbol) + 1) { | ||
return newValueLength - caretPositionFromLeft - 1; | ||
} | ||
if (decimalSymbol) { | ||
const decimalSymbolPosition = value.indexOf(decimalSymbol) + 1; | ||
if (Math.abs(newValueLength - value.length) > 1 && selectionStart <= decimalSymbolPosition) { | ||
return this.formattedValue.indexOf(decimalSymbol) + 1; | ||
if (!e.detail) { | ||
const { value, selectionStart } = this.el; | ||
const inputEvent = e; | ||
if (selectionStart && inputEvent.data && DECIMAL_SEPARATORS.includes(inputEvent.data)) { | ||
this.decimalSymbolInsertedAt = selectionStart - 1; | ||
} | ||
this.format(value); | ||
if (this.focus && selectionStart != null) { | ||
const getCaretPositionAfterFormat = () => { | ||
const { prefix, suffix, decimalSymbol, maximumFractionDigits, groupingSymbol } = this.currencyFormat; | ||
let caretPositionFromLeft = value.length - selectionStart; | ||
const newValueLength = this.formattedValue.length; | ||
if (this.formattedValue.substr(selectionStart, 1) === groupingSymbol && | ||
count(this.formattedValue, groupingSymbol) === count(value, groupingSymbol) + 1) { | ||
return newValueLength - caretPositionFromLeft - 1; | ||
} | ||
else { | ||
if (!this.options.autoDecimalDigits && selectionStart > decimalSymbolPosition) { | ||
if (this.currencyFormat.onlyDigits(value.substr(decimalSymbolPosition)).length - 1 === maximumFractionDigits) { | ||
caretPositionFromLeft -= 1; | ||
if (decimalSymbol) { | ||
const decimalSymbolPosition = value.indexOf(decimalSymbol) + 1; | ||
if (Math.abs(newValueLength - value.length) > 1 && selectionStart <= decimalSymbolPosition) { | ||
return this.formattedValue.indexOf(decimalSymbol) + 1; | ||
} | ||
else { | ||
if (!this.options.autoDecimalDigits && selectionStart > decimalSymbolPosition) { | ||
if (this.currencyFormat.onlyDigits(value.substr(decimalSymbolPosition)).length - 1 === maximumFractionDigits) { | ||
caretPositionFromLeft -= 1; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return this.options.hideCurrencySymbolOnFocus | ||
? newValueLength - caretPositionFromLeft | ||
: Math.max(newValueLength - Math.max(caretPositionFromLeft, suffix.length), prefix.length); | ||
}; | ||
this.setCaretPosition(getCaretPositionAfterFormat()); | ||
return this.options.hideCurrencySymbolOnFocus | ||
? newValueLength - caretPositionFromLeft | ||
: Math.max(newValueLength - Math.max(caretPositionFromLeft, suffix.length), prefix.length); | ||
}; | ||
this.setCaretPosition(getCaretPositionAfterFormat()); | ||
} | ||
} | ||
@@ -434,6 +456,5 @@ }, { capture: true }); | ||
this.el.addEventListener('change', (e) => { | ||
if (!e.isTrusted) { | ||
return; | ||
if (!e.detail) { | ||
this.dispatchEvent('change'); | ||
} | ||
this.dispatchEvent('change'); | ||
}, { capture: true }); | ||
@@ -510,3 +531,2 @@ } | ||
export default useCurrencyInput; | ||
export { CurrencyDisplay }; | ||
export { CurrencyDisplay, useCurrencyInput as default }; |
/** | ||
* Vue Currency Input 2.0.0 | ||
* Vue Currency Input 2.0.1 | ||
* (c) 2018-2021 Matthias Stiller | ||
@@ -34,2 +34,14 @@ * @license MIT | ||
class CurrencyFormat { | ||
locale; | ||
currency; | ||
currencyDisplay; | ||
digits; | ||
decimalSymbol; | ||
groupingSymbol; | ||
minusSymbol; | ||
minimumFractionDigits; | ||
maximumFractionDigits; | ||
prefix; | ||
negativePrefix; | ||
suffix; | ||
constructor(options) { | ||
@@ -144,2 +156,3 @@ const { currency, currencyDisplay, locale, precision } = options; | ||
class AbstractInputMask { | ||
currencyFormat; | ||
constructor(currencyFormat) { | ||
@@ -225,2 +238,12 @@ this.currencyFormat = currencyFormat; | ||
class CurrencyInput { | ||
el; | ||
options; | ||
numberValue; | ||
currencyFormat; | ||
decimalSymbolInsertedAt; | ||
numberMask; | ||
formattedValue; | ||
focus; | ||
minValue; | ||
maxValue; | ||
constructor(el, options) { | ||
@@ -359,38 +382,37 @@ this.el = el; | ||
this.el.addEventListener('input', (e) => { | ||
if (!e.isTrusted) { | ||
return; | ||
} | ||
const { value, selectionStart } = this.el; | ||
const inputEvent = e; | ||
if (selectionStart && inputEvent.data && DECIMAL_SEPARATORS.includes(inputEvent.data)) { | ||
this.decimalSymbolInsertedAt = selectionStart - 1; | ||
} | ||
this.format(value); | ||
if (this.focus && selectionStart != null) { | ||
const getCaretPositionAfterFormat = () => { | ||
const { prefix, suffix, decimalSymbol, maximumFractionDigits, groupingSymbol } = this.currencyFormat; | ||
let caretPositionFromLeft = value.length - selectionStart; | ||
const newValueLength = this.formattedValue.length; | ||
if (this.formattedValue.substr(selectionStart, 1) === groupingSymbol && | ||
count(this.formattedValue, groupingSymbol) === count(value, groupingSymbol) + 1) { | ||
return newValueLength - caretPositionFromLeft - 1; | ||
} | ||
if (decimalSymbol) { | ||
const decimalSymbolPosition = value.indexOf(decimalSymbol) + 1; | ||
if (Math.abs(newValueLength - value.length) > 1 && selectionStart <= decimalSymbolPosition) { | ||
return this.formattedValue.indexOf(decimalSymbol) + 1; | ||
if (!e.detail) { | ||
const { value, selectionStart } = this.el; | ||
const inputEvent = e; | ||
if (selectionStart && inputEvent.data && DECIMAL_SEPARATORS.includes(inputEvent.data)) { | ||
this.decimalSymbolInsertedAt = selectionStart - 1; | ||
} | ||
this.format(value); | ||
if (this.focus && selectionStart != null) { | ||
const getCaretPositionAfterFormat = () => { | ||
const { prefix, suffix, decimalSymbol, maximumFractionDigits, groupingSymbol } = this.currencyFormat; | ||
let caretPositionFromLeft = value.length - selectionStart; | ||
const newValueLength = this.formattedValue.length; | ||
if (this.formattedValue.substr(selectionStart, 1) === groupingSymbol && | ||
count(this.formattedValue, groupingSymbol) === count(value, groupingSymbol) + 1) { | ||
return newValueLength - caretPositionFromLeft - 1; | ||
} | ||
else { | ||
if (!this.options.autoDecimalDigits && selectionStart > decimalSymbolPosition) { | ||
if (this.currencyFormat.onlyDigits(value.substr(decimalSymbolPosition)).length - 1 === maximumFractionDigits) { | ||
caretPositionFromLeft -= 1; | ||
if (decimalSymbol) { | ||
const decimalSymbolPosition = value.indexOf(decimalSymbol) + 1; | ||
if (Math.abs(newValueLength - value.length) > 1 && selectionStart <= decimalSymbolPosition) { | ||
return this.formattedValue.indexOf(decimalSymbol) + 1; | ||
} | ||
else { | ||
if (!this.options.autoDecimalDigits && selectionStart > decimalSymbolPosition) { | ||
if (this.currencyFormat.onlyDigits(value.substr(decimalSymbolPosition)).length - 1 === maximumFractionDigits) { | ||
caretPositionFromLeft -= 1; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return this.options.hideCurrencySymbolOnFocus | ||
? newValueLength - caretPositionFromLeft | ||
: Math.max(newValueLength - Math.max(caretPositionFromLeft, suffix.length), prefix.length); | ||
}; | ||
this.setCaretPosition(getCaretPositionAfterFormat()); | ||
return this.options.hideCurrencySymbolOnFocus | ||
? newValueLength - caretPositionFromLeft | ||
: Math.max(newValueLength - Math.max(caretPositionFromLeft, suffix.length), prefix.length); | ||
}; | ||
this.setCaretPosition(getCaretPositionAfterFormat()); | ||
} | ||
} | ||
@@ -435,6 +457,5 @@ }, { capture: true }); | ||
this.el.addEventListener('change', (e) => { | ||
if (!e.isTrusted) { | ||
return; | ||
if (!e.detail) { | ||
this.dispatchEvent('change'); | ||
} | ||
this.dispatchEvent('change'); | ||
}, { capture: true }); | ||
@@ -511,3 +532,3 @@ } | ||
exports.default = useCurrencyInput; | ||
exports['default'] = useCurrencyInput; | ||
@@ -514,0 +535,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
{ | ||
"name": "vue-currency-input", | ||
"description": "Easy input of currency formatted numbers for Vue.js.", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"license": "MIT", | ||
@@ -47,3 +47,3 @@ "unpkg": "./dist/index.iife.js", | ||
"peerDependencies": { | ||
"@vue/composition-api": "^1.0.0-rc.1", | ||
"@vue/composition-api": "^1.0.0", | ||
"vue": "^2.6 || ^3.0.0" | ||
@@ -57,6 +57,7 @@ }, | ||
"devDependencies": { | ||
"@testing-library/dom": "^8.1.0", | ||
"@types/jest": "^26.0.23", | ||
"@typescript-eslint/eslint-plugin": "^4.14.2", | ||
"@typescript-eslint/parser": "^4.14.2", | ||
"@vue/composition-api": "^1.0.0-rc.8", | ||
"@vue/composition-api": "^1.0.5", | ||
"@vue/eslint-config-prettier": "^6.0.0", | ||
@@ -83,4 +84,4 @@ "@vue/eslint-config-typescript": "^7.0.0", | ||
"vite-plugin-windicss": "^0.15.10", | ||
"vitepress": "^0.13.2", | ||
"vue": "^3.0.11", | ||
"vitepress": "^0.15.6", | ||
"vue": "^3.1.5", | ||
"windicss": "^2.5.14" | ||
@@ -87,0 +88,0 @@ }, |
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
78049
1601
0
29