2
0
mirror of https://github.com/tenrok/maska.git synced 2026-06-11 18:02:27 +03:00

Fixed bug with dynamic mask boundaries

This commit is contained in:
Alexander Shabunevich
2021-02-23 13:59:32 +03:00
parent 99013bd69d
commit b6266789e5
10 changed files with 41 additions and 22 deletions
+10 -1
View File
@@ -121,6 +121,15 @@ test('Dynamic CPF/CNPJ', () => {
expect(mask('12345678901234', '["###.###.###-##", "##.###.###/####-##"]', tokens)).toBe('12.345.678/9012-34')
})
test('Dynamic boundaries', () => {
expect(mask('12', '["!###", "!###-##", "!###-##-##"]', tokens)).toBe('#12')
expect(mask('1234', '["!###", "!###-##", "!###-##-##"]', tokens)).toBe('#12-34')
expect(mask('1234567', '["!###", "!###-##", "!###-##-##"]', tokens)).toBe('#12-34-56')
expect(mask('123', '["###", "###-##", "###.##.##"]', tokens)).toBe('123')
expect(mask('12345', '["###", "###-##", "###.##.##"]', tokens)).toBe('123-45')
expect(mask('12345678', '["###", "###-##", "###.##.##"]', tokens)).toBe('123.45.67')
})
test('Custom transform: odd number -> 1, even number -> 0', () => {
// isOdd
const transform = (numberLike) => String(Number(numberLike) % 2)
@@ -191,4 +200,4 @@ test('Custom transform with `uppercase` and `lowercase` enabled: abkTYX -> АВ
}
}
})).toBe('авктух')
})
})