From 1a885ce41db42e462c0c1888afe06aa1d8dc4557 Mon Sep 17 00:00:00 2001 From: Alexander Shabunevich Date: Mon, 26 Aug 2024 21:22:47 +0300 Subject: [PATCH] fix: correct check for NaN #228 --- src/number.ts | 2 +- test/number.test.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/number.ts b/src/number.ts index 0bc353e..edb37d8 100644 --- a/src/number.ts +++ b/src/number.ts @@ -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('.') diff --git a/test/number.test.ts b/test/number.test.ts index 46e772e..2057386 100644 --- a/test/number.test.ts +++ b/test/number.test.ts @@ -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('') +})