Skip to content

Commit

Permalink
fix: correct checking of the number.unsigned flag
Browse files Browse the repository at this point in the history
Issue #251
  • Loading branch information
beholdr committed Nov 28, 2024
1 parent e3a601e commit 7aba7fd
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 @@ -11,7 +11,7 @@ const createFormatter = (min: number, max: number, opts: MaskOptions): Intl.Numb
})

export const processNumber = (value: string, masked = true, opts: MaskOptions): string => {
const sign = opts.number?.unsigned == null && value.startsWith('-') ? '-' : ''
const sign = opts.number?.unsigned !== true && value.startsWith('-') ? '-' : ''
const fraction = opts.number?.fraction ?? 0

let formatter = createFormatter(0, fraction, opts)
Expand Down
8 changes: 8 additions & 0 deletions test/number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ test('unsigned number', () => {
expect(mask.masked('--1')).toBe('1')
})

test('unsigned false number', () => {
const mask = new Mask({ number: { unsigned: false } })

expect(mask.masked('1')).toBe('1')
expect(mask.masked('-1')).toBe('-1')
expect(mask.masked('--1')).toBe('-1')
})

test('russian number', () => {
const mask = new Mask({ number: { locale: 'ru', fraction: 2 } })

Expand Down

0 comments on commit 7aba7fd

Please sign in to comment.