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:
+1
-1
@@ -20,7 +20,7 @@ export const processNumber = (value: string, masked = true, opts: MaskOptions):
|
|||||||
const decimal = parts.find((part) => part.type === 'decimal')?.value ?? '.'
|
const decimal = parts.find((part) => part.type === 'decimal')?.value ?? '.'
|
||||||
const float = prepare(value, group, decimal)
|
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
|
// allow zero at the end
|
||||||
const floatParts = float.split('.')
|
const floatParts = float.split('.')
|
||||||
|
|||||||
@@ -166,3 +166,11 @@ test('initial brazilian number', () => {
|
|||||||
expect(mask.masked('1.23')).toBe('123')
|
expect(mask.masked('1.23')).toBe('123')
|
||||||
expect(mask.masked('1,23')).toBe('1,23')
|
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('')
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user