A library that exposes functions to masks strings. To use it, it's pretty simple. First, you need to install it:
npm i mask-js
Then, you can import its functions and use at will:
import {maskJs, maskCurrency} from 'mask-js';
console.log(maskJs('(99) 99', '0123456') === '(01) 23'); // true
console.log(maskCurrency('12345') === 123.45); // true
The library also supports optional digits. For example:
import maskJs from 'mask-js';
console.log(maskJs('(99) 9999?9', '0123456') === '(01) 23456'); // true
console.log(maskJs('(99) 999-9?9', '012345') === '(01) 234-5'); // true
console.log(maskJs('(99) 99?9-9?9', '012345') === '(01) 23-45'); // true
console.log(maskJs('(99) 9999?9-9999', '0123456789') === '(01) 2345-6789'); // true
console.log(maskJs('(99) 9999?9-9999', '01234567890') === '(01) 23456-7890'); // true
This project is licensed under the MIT license. See the LICENSE file for more info.