mirror of
https://github.com/tenrok/maska.git
synced 2026-06-20 20:00:34 +03:00
Initial commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import Maska from './maska'
|
||||
import { isString } from './utils'
|
||||
|
||||
function getOpts (mask) {
|
||||
const opts = {}
|
||||
|
||||
if (isString(mask)) {
|
||||
opts.mask = mask
|
||||
} else if (mask.mask) {
|
||||
opts.mask = mask.mask
|
||||
opts.tokens = mask.tokens ? mask.tokens : {}
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
function needUpdate (mask) {
|
||||
if (isString(mask.value) && isString(mask.oldValue) && mask.value === mask.oldValue) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (mask.value && mask.oldValue && mask.value.mask === mask.oldValue.mask) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
export default function directive (el, mask) {
|
||||
if (!mask.value) return
|
||||
|
||||
if (mask.value && needUpdate(mask)) {
|
||||
return new Maska(el, getOpts(mask.value))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user