1.1.7 • Published 1 year ago

digital-mask v1.1.7

Weekly downloads
43
License
MIT
Repository
github
Last release
1 year ago

⚡ Digital mask

Npm package version Small size Testing Building

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

/**
 * Update input value to masked on `input` event
 */
bindInputMask(
  // Input
  input: HTMLInputElement,
  // Mask for format
  format: string,
  // Сhar from replace
  def: string = '_'
): Function
  • Example for string

const { applyStringMask } = require('digital-mask');

const result1 = applyStringMask('1234', '___-___');
console.log(result1); // Output: 123-4__

const result2 = applyStringMask('1234', '***-***', '*');
console.log(result2); // Output: 123-4**

const result3 = applyStringMask('chars1234and56', '___-___');
console.log(result3); // Output: 123-456
  • Example for input

const { bindInputMask } = require('digital-mask');

const input = document.getElementById('inputPhone');
const unbind = bindInputMask(input, '___-___');
// ...
unbind();
const { applyInputMask } = require('digital-mask');

const input = document.getElementById('inputPhone');
input.addEventListener('input', () => {
  applyInputMask(input, '___-___');
});
1.1.7

1 year ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.0.2

2 years ago

1.1.0

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago