All files / src/features text-mask.js

87.5% Statements 7/8
75% Branches 9/12
100% Functions 1/1
87.5% Lines 7/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23              12x 12x 12x 12x 12x 12x 12x                  
import IMask from 'imask'
 
export default {
  hooks: {
    model: [
      {
        handler(value, { context }) {
          const hasMask = 'vfe-mask' in context.attributes || 'vfeMask' in context.attributes
          Eif (context.classification === 'text' && hasMask) {
            const options = context.attributes['vfe-mask'] || context.attributes.vfeMask
            const maskOptions = typeof options === 'object' && options.mask ? options : { mask: options }
            const masked = IMask.createMask(maskOptions)
            const resolved = masked.resolve(value)
            return resolved
          } else {
            return value
          }
        },
      },
    ],
  },
}