digital-mask
v1.2.0
Published
Easy digital mask for string and inputs
Downloads
31
Maintainers
Readme
⚡ Digital mask
Easy digital mask for string and inputs
.
Install
npm i digital-mask
Usage
/**
* Return masked value from source string
*/
applyStringMask(
// Unformatted string
source: string,
// Mask for format
format: string,
// Сhar from replace
def: string = '_'
): string
/**
* Update input value to masked
*/
applyInputMask(
// Input
input: HTMLInputElement,
// Mask for format
format: string,
// Сhar from replace
def: string = '_'
): void
Example for string
import { applyStringMask } from 'digital-mask';
applyStringMask('1234', '___-___');
// => 123-4__
applyStringMask('1234', '***-***', '*');
// => 123-4**
applyStringMask('chars1234and56', '___-___');
// => 123-456
Example for input
import { applyInputMask } from 'digital-mask';
const input = document.getElementById('inputPhone');
input.addEventListener('input', (event) => {
applyInputMask(event.target, '___-___');
});