Vue Input Facade (Input Masking)

2.2.0 · active · verified Sun Apr 19

vue-input-facade is a lightweight and dependency-free library for adding input masking capabilities to Vue applications. It offers a versatile approach to formatting user input through directives, components, or a programmatic API. The library prioritizes minimal overhead and efficient performance by avoiding external dependencies. The current stable version, 2.2.0, is designed for Vue 2 projects. A significant upgrade to version 3.0.0 is currently in beta, introducing full compatibility with Vue 3 and modernizing the import system to ES Module-style named imports. Development for v3 is ongoing, alongside maintenance updates for v2, indicating an active, albeit deliberate, release cadence. Its primary distinction within the Vue ecosystem is its compact size and singular focus on robust input masking without bloat.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates registering and using the `v-facade` directive in a Vue 3 application to apply various input masks like phone numbers, credit card numbers, and currency formats to input fields.

import { createApp } from 'vue';
import App from './App.vue';
import { vFacade } from 'vue-input-facade';

const app = createApp(App);
app.directive('facade', vFacade);
app.mount('#app');

// App.vue
<template>
  <div>
    <h2>Input Masking Example</h2>
    <p>Phone Number (###) ###-####:</p>
    <input type="text" v-facade="'(###) ###-####'" v-model="phoneNumber" placeholder="(123) 456-7890" />
    <p>Value: {{ phoneNumber }}</p>

    <p>Credit Card Number #### #### #### ####:</p>
    <input type="text" v-facade="'#### #### #### ####'" v-model="creditCard" placeholder="0000 0000 0000 0000" />
    <p>Value: {{ creditCard }}</p>

    <p>Currency ($###,###.##):</p>
    <input type="text" v-facade="'$###,###.##'" v-model="currency" placeholder="$0.00" />
    <p>Value: {{ currency }}</p>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';

export default defineComponent({
  name: 'App',
  setup() {
    const phoneNumber = ref('');
    const creditCard = ref('');
    const currency = ref('');

    return {
      phoneNumber,
      creditCard,
      currency,
    };
  },
});
</script>

view raw JSON →