@canutin/svelte-currency-input 0.6.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.
@@ -32,7 +32,7 @@ const handleKeyDown = (event) => {
32
32
  };
33
33
  let inputTarget;
34
34
  const currencyDecimal = new Intl.NumberFormat(locale).format(1.1).charAt(1); // '.' or ','
35
- const isDecimalComma = currencyDecimal === ','; // Remove currency formatting from `formattedValue` so we can assign it to `value`
35
+ const isDecimalComma = currencyDecimal === ',';
36
36
  const currencySymbol = formatCurrency(0, 0)
37
37
  .replace('0', '') // e.g. '$0' > '$'
38
38
  .replace(/\u00A0/, ''); // e.g '0 €' > '€'
@@ -41,6 +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
+ // Pressing `.` when the decimal point is `,` gets replaced with `,`
45
+ if (isDecimalComma && event.key === '.')
46
+ formattedValue = formattedValue.replace(/\.([^.]*)$/, currencyDecimal + '$1'); // Only replace the last occurence
47
+ // Pressing `,` when the decimal point is `.` gets replaced with `.`
48
+ if (!isDecimalComma && event.key === ',')
49
+ formattedValue = formattedValue.replace(/\,([^,]*)$/, currencyDecimal + '$1'); // Only replace the last occurence
44
50
  // Don't format if `formattedValue` is ['$', '-$', "-"]
45
51
  const ignoreSymbols = [currencySymbol, `-${currencySymbol}`, '-'];
46
52
  const strippedUnformattedValue = formattedValue.replace(' ', '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canutin/svelte-currency-input",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "exports": {
5
5
  "./package.json": "./package.json",
6
6
  ".": "./index.js",