uNmAnNeR / imaskjs

vanilla javascript input mask

Home Page:https://imask.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Number mask pipe has a problem since 6.5.0

avin opened this issue · comments

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

@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);

@uNmAnNeR, thank you for the explanation!