uNmAnNeR / imaskjs

vanilla javascript input mask
https://imask.js.org
MIT License
4.96k stars 258 forks source link

Number mask pipe has a problem since 6.5.0 #1026

Closed avin closed 7 months ago

avin commented 7 months ago

Hello! I don't know if this is an error, but it used to work differently before. If you specify the radix as "," and value with dot like "12.34" the value is converted incorrectly. The problem appeared in 6.5.0 (everything was fine in 6.4.3)

import IMask from 'imask';

const props = {
  mask: Number,
  scale: 2,
  thousandsSeparator: '',
  padFractionalZeros: false,
  normalizeZeros: true,
  radix: ',', // <<<--- Error here! If you specify the radix as ".", there will be no problems.
  mapToRadix: ['.', ','],
};

const pipe = IMask.createPipe(props);

const pre = '12.34';
console.log(`${pre} ->> ${pipe(pre)}`); // Output: "12.34 ->> 1234" but is was "12.34 ->> 12,34" before

Online playground https://stackblitz.com/edit/vitejs-vite-k5wm3i?file=main.js

uNmAnNeR commented 7 months ago

@avin 12.34 is unmasked value so you should specify it for pipe:

const pipe = IMask.createPipe(props, IMask.PIPE_TYPE.UNMASKED, IMask.PIPE_TYPE.MASKED);
avin commented 7 months ago

@uNmAnNeR, thank you for the explanation!