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

refactor!: change completed behavior for dynamic mask

This commit is contained in:
Alexander Shabunevich
2024-07-07 16:50:51 +03:00
parent c442153ce1
commit f47d4ca65d
3 changed files with 18 additions and 5 deletions
+13 -1
View File
@@ -81,7 +81,7 @@ const options = reactive({
</template>
```
## Changed eager mode
## Eager mode
With v2, when using eager mode, entered characters appeared after the static mask characters:
@@ -100,3 +100,15 @@ mask.masked('1') // -> 1
mask.masked('12') // -> 12
mask.masked('2') // -> 12
```
## Completed behavior for dynamic masks
In v2 a dynamic mask is considered completed when it matches the longest mask in the array.
For example, when you have enter `1-234`, but not `1-2`:
```html
<input v-maska data-maska="['#-#', '#-###']">
```
In v3 a dynamic mask is considered complete if it matches the first matched mask.
So `1-2` and `1-234` are considered complete, but `1-23` is not.
+1 -3
View File
@@ -78,11 +78,9 @@ export class Mask {
if (typeof this.opts.mask === 'string') {
return length >= this.opts.mask.length
} else if (typeof this.opts.mask === 'function') {
return length >= mask.length
}
return this.opts.mask.filter((m) => length >= m.length).length === this.opts.mask.length
return length >= mask.length
}
private findMask (value: string): string | null {
+4 -1
View File
@@ -770,7 +770,10 @@ test('dynamic mask', () => {
expect(mask.unmasked('a123456789012345')).toBe('12345678901234')
expect(mask.completed('12345678901')).toBe(false)
expect(mask.completed('1234567890')).toBe(false)
expect(mask.completed('12345678901')).toBe(true)
expect(mask.completed('123456789012')).toBe(false)
expect(mask.completed('1234567890123')).toBe(false)
expect(mask.completed('12345678901234')).toBe(true)
})