2
0
mirror of https://github.com/tenrok/maska.git synced 2026-05-15 11:59:38 +03:00

fix: correct check for NaN #228

This commit is contained in:
Alexander Shabunevich
2024-08-26 21:22:47 +03:00
parent f5ec443c76
commit 1a885ce41d
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ export const processNumber = (value: string, masked = true, opts: MaskOptions):
const decimal = parts.find((part) => part.type === 'decimal')?.value ?? '.'
const float = prepare(value, group, decimal)
if (float === '' || Number.isNaN(float)) return sign
if (Number.isNaN(parseFloat(float))) return sign
// allow zero at the end
const floatParts = float.split('.')
+8
View File
@@ -166,3 +166,11 @@ test('initial brazilian number', () => {
expect(mask.masked('1.23')).toBe('123')
expect(mask.masked('1,23')).toBe('1,23')
})
// https://github.com/beholdr/maska/issues/228
test('NaN check', () => {
const mask = new Mask({ number: { locale: 'uk', fraction: 2 } })
expect(mask.masked('.')).toBe('')
expect(mask.masked(',')).toBe('')
})