# vue-imask

> Vue input mask

Latest version **7.6.1** (published 2024-05-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install vue-imask
pnpm add vue-imask
yarn add vue-imask
bun add vue-imask
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 7.6.1 |
| Published | 2024-05-21 |
| First published | 2017-11-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 142.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5177 |
| Author | Alexey Kryazhev |
| Maintainers | unmanner |
| Keywords | vue, imask, javascript, input, mask |

## Links

- npm: https://www.npmjs.com/package/vue-imask
- Repository: https://github.com/uNmAnNeR/imaskjs.git#master
- Homepage: https://github.com/uNmAnNeR/imaskjs/tree/master#readme
- Issues: https://github.com/uNmAnNeR/imaskjs/issues
- npm.io page: https://npm.io/package/vue-imask

## Dependencies (2)

- [imask](https://npm.io/package/imask.md) ^7.6.1
- [vue-demi](https://npm.io/package/vue-demi.md) ^0.14.7

## Recent versions

- 7.6.1 (latest) — 2024-05-21
- 7.5.1-alpha.0 (next) — 2024-03-20
- 7.6.0 — 2024-04-09
- 7.5.0 — 2024-02-28
- 7.4.0 — 2024-02-08
- 7.3.1-alpha.0 — 2024-01-31
- 7.3.0 — 2023-12-25
- 7.2.1 — 2023-12-18
- 7.2.0 — 2023-12-13
- 7.1.3 — 2023-07-18
- 7.1.2 — 2023-07-12
- 7.1.1 — 2023-07-11
- 7.1.0 — 2023-07-11
- 7.1.0-alpha.2 — 2023-07-11
- 7.1.0-alpha.1 — 2023-07-11
- … 75 more at https://npm.io/package/vue-imask/versions

## README

# Vue IMask Plugin
vue-imask

[![npm version](https://badge.fury.io/js/vue-imask.svg)](https://badge.fury.io/js/vue-imask)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

<a href="https://opencollective.com/imask/donate" target="_blank">
  <img src="https://opencollective.com/imask/donate/button.png?color=blue" width=300 />
</a>

## Install
`npm i vue-imask`

for Vue 2 also do:

`npm i -D @vue/composition-api`

If you are using NuxtJS with Vue 2 you also need to install:

`npm i -D @nuxtjs/composition-api`

And then add `@nuxtjs/composition-api/module` in the buildModules option in your `nuxt.config.js`.

## Mask Component Example (Vue 2)
```html
<template>
  <imask-input
    v-model="numberModel"
    :mask="Number"
    radix="."
    :unmask="true"
    <!-- depending on prop above first argument of 'accept' callback is
    `value` if `unmask=false`,
    `unmaskedValue` if `unmask=true`,
    `typedValue` if `unmask='typed'` -->
    @accept="onAccept"

    <!-- ...see more mask props in a guide -->

    <!-- other input props -->
    placeholder='Enter number here'
  />
</template>

<script>
  import { IMaskComponent } from 'vue-imask';

  export default {
    data () {
      return {
        numberModel: '',
        onAccept (value) {
          console.log(value);
        }
      }
    },
    components: {
      'imask-input': IMaskComponent
    }
  }
</script>
```


## Mask Component Example (Vue 3)
```html
<template>
  <imask-input
    <!-- possible to use 'v-model' = 'v-model:value' = 'v-model:masked' and 'v-model:unmasked' -->
    v-model:typed="numberModel"
    :mask="Number"
    radix="."
    @accept:masked="onAccept" <!-- accept value (same as '@accept:value' or just '@accept') -->
    @accept:unmasked="onAcceptUnmasked"
    <!--
      @accept:typed="onAccepttyped"
      @complete:typed="onCompleteTyped"
    -->

    <!-- ...see more mask props in a guide -->

    <!-- other input props -->
    placeholder='Enter number here'
  />
</template>

<script>
  import { IMaskComponent } from 'vue-imask';

  export default {
    data () {
      return {
        numberModel: '',
        onAccept (value) {
          console.log({ value });
        },
        onAcceptUnmasked (unmaskedValue) {
          console.log({ unmaskedValue });
        }
      }
    },
    components: {
      'imask-input': IMaskComponent
    }
  }
</script>
```

## Mask Directive Example
In some cases value bindings (`v-model`) might not work for directive, you can use `@accept` or `@complete` events to update the value.
```html
<template>
  <input
    :value="value"
    v-imask="mask"
    @accept="onAccept"
    @complete="onComplete">
</template>

<script>
  import { IMaskDirective } from 'vue-imask';

  export default {
    data () {
      return {
        value: '',
        mask: {
          mask: '{8}000000',
          lazy: false
        },
      },
    },
    methods: {
      onAccept (e) {
        const maskRef = e.detail;
        this.value = maskRef.value;
        console.log('accept', maskRef.value);
      },
      onComplete (e) {
        const maskRef = e.detail;
        console.log('complete', maskRef.unmaskedValue);
      },
    },
    directives: {
      imask: IMaskDirective
    }
  }
</script>
```
More options see in a [guide](https://imask.js.org/guide.html).

## Mask Composable (Vue 3)
```html
<template>
  <input ref="el">
</template>

<script>
  import { useIMask } from 'vue-imask';

  export default {
    setup (props) {
      const { el, masked } = useIMask({
        mask: Number,
        radix: '.',
      }, /* optional {
        emit,
        onAccept,
        onComplete,
        defaultValue,
        defaultUnmaskedValue,
        defaultTypedValue,
      } */);
  
      return { el };
    }
  }
</script>
```

---
_Source: https://npm.io/package/vue-imask · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
