mirror of
https://github.com/tenrok/maska.git
synced 2026-06-08 17:22:27 +03:00
feat: allow float input
This commit is contained in:
+7
-7
@@ -53,12 +53,12 @@ export class Mask {
|
||||
this.opts = opts
|
||||
}
|
||||
|
||||
masked (value: string): string {
|
||||
return this.process(value, this.findMask(value))
|
||||
masked (value: string | number): string {
|
||||
return this.process(String(value), this.findMask(String(value)))
|
||||
}
|
||||
|
||||
unmasked (value: string): string {
|
||||
return this.process(value, this.findMask(value), false)
|
||||
unmasked (value: string | number): string {
|
||||
return this.process(String(value), this.findMask(String(value)), false)
|
||||
}
|
||||
|
||||
isEager (): boolean {
|
||||
@@ -69,12 +69,12 @@ export class Mask {
|
||||
return this.opts.reversed === true
|
||||
}
|
||||
|
||||
completed (value: string): boolean {
|
||||
const mask = this.findMask(value)
|
||||
completed (value: string | number): boolean {
|
||||
const mask = this.findMask(String(value))
|
||||
|
||||
if (this.opts.mask == null || mask == null) return false
|
||||
|
||||
const length = this.process(value, mask).length
|
||||
const length = this.process(String(value), mask).length
|
||||
|
||||
if (typeof this.opts.mask === 'string') {
|
||||
return length >= this.opts.mask.length
|
||||
|
||||
@@ -182,3 +182,10 @@ test('NaN check', () => {
|
||||
expect(mask.masked('.')).toBe('')
|
||||
expect(mask.masked(',')).toBe('')
|
||||
})
|
||||
|
||||
test('float input', () => {
|
||||
const mask = new Mask({ number: { locale: 'uk', fraction: 2 } })
|
||||
|
||||
expect(mask.masked(1234.56)).toBe('1 234,56')
|
||||
expect(mask.unmasked(1234.56)).toBe('1234.56')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user