All Projects → beholdr → Maska

beholdr / Maska

Simple zero-dependency input mask for Vue.js and vanilla JS.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Maska

Jquery Mask Plugin
A jQuery Plugin to make masks on form fields and HTML elements.
Stars: ✭ 4,534 (+5234.12%)
Mutual labels:  mask
Nn mask
multichannel linear filters based on mask estimation neural networks for CHiME4
Stars: ✭ 26 (-69.41%)
Mutual labels:  mask
Brazilian Utils
Utils library for specific Brazilian businesses
Stars: ✭ 1,023 (+1103.53%)
Mutual labels:  mask
Albert pytorch
A Lite Bert For Self-Supervised Learning Language Representations
Stars: ✭ 539 (+534.12%)
Mutual labels:  mask
Nativescript Masked Text Field
#️⃣ A NativeScript Masked Text Field widget
Stars: ✭ 24 (-71.76%)
Mutual labels:  mask
Prompt Password
This repository has been archived, use the built-in password prompt in Enquirer instead.
Stars: ✭ 8 (-90.59%)
Mutual labels:  mask
Wedatasphere
WeDataSphere is a financial level one-stop open-source suitcase for big data platforms. Currently the source code of Scriptis and Linkis has already been released to the open-source community. WeDataSphere, Big Data Made Easy!
Stars: ✭ 372 (+337.65%)
Mutual labels:  mask
Animation Rigging Advanced Character Interaction
Advanced Animation Rigging: Character and Props interaction
Stars: ✭ 74 (-12.94%)
Mutual labels:  mask
React Native Text Input Mask
Text input mask for React Native, Android and iOS
Stars: ✭ 922 (+984.71%)
Mutual labels:  mask
Pymasker
generate masks from Landsat and MODIS land product QA band
Stars: ✭ 31 (-63.53%)
Mutual labels:  mask
Masked Edittext
Android library contain custom realisation of EditText component for masking and formatting input text
Stars: ✭ 592 (+596.47%)
Mutual labels:  mask
Ngx Mask
Angular Plugin to make masks on form fields and html elements.
Stars: ✭ 772 (+808.24%)
Mutual labels:  mask
Preloader.ophiuchus
Custom Label to apply animations on whole text or letters.
Stars: ✭ 880 (+935.29%)
Mutual labels:  mask
Maskara
A simple way to format text fields without getting affected by input filters
Stars: ✭ 515 (+505.88%)
Mutual labels:  mask
Svelte Input Mask
Input masking component for Svelte with simple API and rich customization
Stars: ✭ 56 (-34.12%)
Mutual labels:  mask
Edittext Mask
The custom masks for EditText. The solution for input phone numbers, SSN, and so on for Android
Stars: ✭ 413 (+385.88%)
Mutual labels:  mask
Php Bitmap
Bitmap representation with bitwise operations
Stars: ✭ 7 (-91.76%)
Mutual labels:  mask
Bufferutil
WebSocket buffer utils
Stars: ✭ 83 (-2.35%)
Mutual labels:  mask
Unity2019shaderdevelopment
Creating Shaders (via code and Shader Graph) in Unity 2019
Stars: ✭ 65 (-23.53%)
Mutual labels:  mask
Opencv Cheat Sheet
Opencv cheat sheet for C++
Stars: ✭ 30 (-64.71%)
Mutual labels:  mask

Maska

Simple zero-dependency input mask for Vue.js and vanilla JS. Demo and examples.

  • No dependencies
  • Small size (~2 Kb gziped)
  • Ability to define custom tokens
  • Supports repeat symbols and dynamic masks
  • Works on any input (custom or native)

Install

npm install maska

To load latest version from CDN you can use:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/maska.js"></script>

Usage with Vue 2.x

If you load Vue.js via <script> then just add v-maska directive to your input:

<input v-maska="'###'">

You can add custom tokens by passing in object instead of string to directive:

<input v-maska="{ mask: 'Z*', tokens: { 'Z': { pattern: /[а-яА-Я]/ }}}">

With bundlers you can add global directive:

import Maska from 'maska'
Vue.use(Maska)

or import maska directive for local usage in component:

<template>
    <form>
        <input v-maska="'###'">
    </form>
</template>

<script>
import { maska } from 'maska'

export default {
    directives: { maska }
}
</script>

With Vue you could use computed property as mask value. In this case mask will be reactive.

Usage with Vue 3.x

With Vue 3.x you need to explicitly add Maska plugin or directive to your app:

const app = Vue.createApp({...})
// use as plugin
app.use(Maska);
// or as directive
// app.directive('maska', Maska.maska);
app.mount('#app');

Usage with vanilla JS

Just load script maska.js and init it, passing element(s) or document.querySelector expression:

var mask = Maska.create('.masked');

Mask could be set as data-mask attribute on element:

<input data-mask='##/##/####'>

or can be set by mask option on initialization:

var mask = Maska.create('.masked', {
    mask: '##/##/####'
});

You can pass custom tokens while initialization:

var mask = Maska.create('.masked', {
    tokens: { 'Z': { pattern: /[а-яА-Я]/ }}
});

You can destroy mask like that:

var mask = Maska.create('.masked');
mask.destroy();

Mask syntax

Default tokens:

{
    '#': { pattern: /[0-9]/ },
    'X': { pattern: /[0-9a-zA-Z]/ },
    'S': { pattern: /[a-zA-Z]/ },
    'A': { pattern: /[a-zA-Z]/, uppercase: true },
    'a': { pattern: /[a-zA-Z]/, lowercase: true },
    '!': { escape: true },
    '*': { repeat: true }
}
  • Escape symbol escapes next token (mask !# will render #)
  • Repeat symbol allows repeating current token until it’s valid (e.g. mask #* for all digits or A* A* for CARDHOLDER NAME)

You can add your own tokens by passing them in maska directive or create method at initialization (see above). Important: pattern field should be JS regular expression (/[0-9]/) or string without delimiters ("[0-9]").

Transform function for tokens

While specifying custom tokens you can also add a symbol-transformation behavior such as uppercase, lowercase, or even define a transform function:

{
    'T': { pattern: /[0-9]/, transform: (char) => String(Number(char) % 2) } // '1234567890' -> '1010101010'
}

Getting raw (unmasked) value

To get raw value read data-mask-raw-value property of input. You can subscribe to @maska event to know when this value updates. Please see examples page.

Dynamic masks

To use several masks on single input, pass array instead of string as mask value.

You could use it with Vue directives:

<input v-maska="['+1 (###) ##-##-##', '+1 (###) ###-##-##']">

<input v-maska="{ mask: ['!#HHHHHH', '!#HHHHHH-HH'], tokens: { 'H': { pattern: /[0-9a-fA-F]/, uppercase: true }}}">

and with vanilla JS attribute, but make sure that mask value is proper JSON, so use double quotes inside array:

<input data-mask='["# cm", "#.# cm", "#.## cm"]'>

Known issues

When used on input of type number could have inconsistent behavior in different browsers. Use attribute inputmode if you just need a numeric keyboard for given input.

Source of Inspiration

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].