@canutin/svelte-currency-input 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CurrencyInput.svelte +4 -3
- package/package.json +1 -1
package/CurrencyInput.svelte
CHANGED
|
@@ -41,11 +41,12 @@ const setUnformattedValue = (event) => {
|
|
|
41
41
|
// Don't format if the user is typing a `currencyDecimal` point
|
|
42
42
|
if (event.key === currencyDecimal)
|
|
43
43
|
return;
|
|
44
|
-
//
|
|
44
|
+
// Pressing `.` when the decimal point is `,` gets replaced with `,`
|
|
45
45
|
if (isDecimalComma && event.key === '.')
|
|
46
|
-
formattedValue = formattedValue.replace('
|
|
46
|
+
formattedValue = formattedValue.replace(/\.([^.]*)$/, currencyDecimal + '$1'); // Only replace the last occurence
|
|
47
|
+
// Pressing `,` when the decimal point is `.` gets replaced with `.`
|
|
47
48
|
if (!isDecimalComma && event.key === ',')
|
|
48
|
-
formattedValue = formattedValue.replace('
|
|
49
|
+
formattedValue = formattedValue.replace(/\,([^,]*)$/, currencyDecimal + '$1'); // Only replace the last occurence
|
|
49
50
|
// Don't format if `formattedValue` is ['$', '-$', "-"]
|
|
50
51
|
const ignoreSymbols = [currencySymbol, `-${currencySymbol}`, '-'];
|
|
51
52
|
const strippedUnformattedValue = formattedValue.replace(' ', '');
|