Skip to content

neki-dev/digital-mask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

âš¡ Digital mask

Version Size Test Build

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, '___-___');
});