Skip to content

Commit

Permalink
fix: correct check for NaN #228
Browse files Browse the repository at this point in the history
  • Loading branch information
beholdr committed Aug 26, 2024
1 parent f5ec443 commit 1a885ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('.')
Expand Down
8 changes: 8 additions & 0 deletions test/number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
})

0 comments on commit 1a885ce

Please sign in to comment.