1.0.13 • Published 4 years ago

v-mask-directive-filter v1.0.13

Weekly downloads
26
License
MIT
Repository
github
Last release
4 years ago

V-MASK-DIRECTIVE-FILTER

Support to Vue 3 available here

A incredibly LIGHTER input mask directive and filter compatible with Vue 2 and Vuetify 2

npm version Min Min Gziped

Travis Build Known Vulnerabilities

Browsers support

IE / EdgeFirefoxChromeChrome AndroidSafariiOS SafariOpera
IE9>, Edge6>1>18>3.1>2>12>

Instalation

$ yarn add v-mask-directive-filter

or

$ npm install --save v-mask-directive-filter

Directive

// Import the directive inside your main.(js|ts)

import { VMaskDirective } from 'v-mask-directive-filter'

Vue.directive('mask', VMaskDirective)

or

// using a custom directive

import { getCustomMaskDirective } from 'v-slim-mask'

const VMASKCustomDirective = getCustomMaskDirective({
  '#': /[0-9]/,
  Z: /[a-z]|[A-Z]/,
})
Vue.directive('mask', VMASKCustomDirective)

Filter

// Import the filter inside your main.(js|ts)

import { VFilterDirective } from 'v-mask-directive-filter'

Vue.filter('mask', VFilterDirective)

Config

Tokens

TokenPatternDescription
N0-9numbers only
Sa-z | A-Zstring a-z only
A0-9 | a-z | A-Zalphanumeric only
C^ required char
X.*optional char

Modifiers

ModifierDefaultDescription
unmaskfalseunmask the return value to the model
parseintfalseparse to int the return value to the model
init-changefalseset a initial value to the model on start
hide-on-emptyfalsehide the mask if no value

Usage

Using native input element

// Inside your .vue component

<template>
  <input v-model="cpf" v-mask="'NNN.NNN.NNN-NN'" />
</template>

// Entry => 99999999999 | cpf => "999.999.999-99"

Using v-text-field of Vuetify

// Inside your .vue component

<template>
  <v-text-field v-mask.unmask="'(NN) NNNNN - NNNN'" v-model="phoneNumber" />
</template>

// Entry => 83999998888 | phoneNumber => "83999998888"

<template>
  <v-text-field v-mask="'(NN) NNNNN - NNNN'" v-model="phoneNumber" />
</template>

// Entry => 83999998888 | phoneNumber => "(83) 99999 - 8888"

Using vue 2.x filter

// Inside your .vue component
<span> {{ '83999998888' | mask('(NN) NNNNN - NNNN') }} </span>

// This will result => (83) 99999 - 8888

Using helper functions

<script>
  import { maskTransform, unmaskTransform } from 'v-mask-directive-filter'
  export default Vue.extends({
    computed: {
      phoneFormatted(val) {
        return maskTransform(val, '(NN) NNNNN - NNNN')
      }
    }
  })
</script>

Demo

vue 2.x + vuetify 2.x sample https://codesandbox.io/s/flamboyant-kilby-xv8hz

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago