1.0.3 • Published 2 years ago

vanilla-mask v1.0.3

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

Vanilla mask 1.0.3

It's a pure JavaScript mask input. Now you can use a simple and pure javascript lib to mask your input elements, without need to load jQuery.

Usage

Using npm run:

npm install vanilla-mask --save

To use with ES6:

import Mask from 'vanilla-mask'

var mask = new Mask();
mask.build('text','format');

Examples:

mask.build('1234567890','(##) ####-####'); // Formatted (12) 3456-7890
mask.build('12345678901','###.###.###-##'); // Formatted 123.456.789-01

// Formatted with placeholder
mask.build('12345','(##) ####-####', '_'); // Formatted (12) 345_-____
mask.build('123456','###.###.###-##', ' '); // Formatted 123.456.   -  

Working with regexp

For better performance, it is recommended to use regexp, which will give you more freedom and more speed in the construction of the mask.

const config = {
    cpf: [/\d/, /\d/, /\d/, '.', /\d/, /\d/, /\d/, '.', /\d/, /\d/, /\d/, '-', /\d/, /\d/],
     cnpj: [/\d/, /\d/, '.', /\d/, /\d/, /\d/, '.', /\d/, /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/],
     date: [/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/],
     datetime: [/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/, ' ', /\d/, /\d/, ':', /\d/, /\d/, ':', /\d/, /\d/],
    phone: ['(', /\d/, /\d/, ')', /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
    time: [/\d/, /\d/, ':', /\d/, /\d/, ':', /\d/, /\d/],
    zipcode: [/\d/, /\d/, /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/],
};

var mask = new Mask(config);

mask.exec('1234567890','phone'); // Formatted (12) 3456-7890
mask.exec('12345678901','cpf'); // Formatted 123.456.789-01
1.0.2

2 years ago

1.0.3

2 years ago

1.0.0-1

5 years ago

1.0.1

5 years ago

1.0.0

7 years ago

0.0.5-beta

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago