@canutin/svelte-currency-input 0.6.0 → 0.7.0

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,11 @@ 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
+ // Always convert _the opposite_ decimal key press to the `currencyDecimal` point
45
+ if (isDecimalComma && event.key === '.')
46
+ formattedValue = formattedValue.replace('.', currencyDecimal);
47
+ if (!isDecimalComma && event.key === ',')
48
+ formattedValue = formattedValue.replace(',', currencyDecimal);
44
49
  // Don't format if `formattedValue` is ['$', '-$', "-"]
45
50
  const ignoreSymbols = [currencySymbol, `-${currencySymbol}`, '-'];
46
51
  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.0",
4
4
  "exports": {
5
5
  "./package.json": "./package.json",
6
6
  ".": "./index.js",