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

fix: correct checking of the number.unsigned flag

Issue #251
This commit is contained in:
Alexander Shabunevich
2024-11-28 16:08:11 +03:00
parent e3a601e131
commit 7aba7fd0c2
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -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)
+8
View File
@@ -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 } })