digital-mask
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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

Package Sidebar

Install

npm i digital-mask

Weekly Downloads

13

Version

1.2.0

License

MIT

Unpacked Size

7.79 kB

Total Files

11

Last publish

Collaborators

  • neki-development