npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cmath10/jmask

v0.2.4

Published

Pure JavaScript mask

Readme

JMask - JavaScript Mask component

This package provides a mask component - a reworked version of jQuery-Mask-Plugin, without jQuery (and any other dependency either).

Installation

yarn add @cmath10/jmask

or

npm i @cmath10/jmask

Usage

Basic example

import JMask from '@cmath10/jmask'

// ...

const el = document.querySelector('input#phone')
const mask = new JMask(el, '+7-000-000-00-00')

JMask constructor arguments:

  • el - Element - element which will be managed by the mask component;
  • mask - string - mask to apply;
  • options - object - optional argument, provides following options:
    • clearIfNotMatch - boolean - value from input element will be erased on focus loose, if it wasn't input fully according the specified mask, defaults to false;
    • reverse - boolean - if true, mask accounting starts with the last characters, which makes it convenient to enter, for example, financial values, defaults to false;
    • exclude - string[] - an array of keys that will be excluded from accounting, needed for non-character keys so that they can be used as usual; by default excluded:
      • alt (both, left & right);
      • backspace
      • ctrl (both, left & right);
      • home;
      • shift (both, left & right);
      • tab;
      • window (left);
      • arrows;
    • descriptors - object - custom mask character definitions.

Descriptors

By default, JMask uses descriptors:

  • 0 - for digits [0-9], required, if 0 present in a mask, will reject any characters until a digit is entered;
  • 9 - for digits [0-9], optional, if 9 present in a mask, digit could be skipped;
  • # - for digits [0-9], allows you to enter digits in unlimited quantities;
  • A - alphanumeric, [a-zA-Z0-9] - allows to enter one character from range [a-z] regardless of case or range [0-9];
  • S - alphabetical, [a-zA-Z] - same as A but without digits.

Any other character (if no translation supplied for) considered as static - when entering reaches it, caret just will be pushed forward to the next translatable. From the example above these are +, 7, -, so you are able to enter a phone number like +7-913-815-12-22 by entering only 9138151222

You could supply new translation by adding to the options an object like:

{
  '0': { pattern: /\d/ },
  '9': { pattern: /\d/, optional: true },
  '#': { pattern: /\d/, recursive: true },
  'A': { pattern: /[a-zA-Z0-9]/ },
  'S': { pattern: /[a-zA-Z]/ },
}

Here the key is a character to translate and value is a translation config. Config contains:

  • pattern - RegExp - pattern to restrict characters (allows entering only matched characters), required;
  • optional - bool - if set, this character will be allowed to skip, defaults to false;
  • recursive - bool - allows repeatable input, defaults to false;
  • fallback - string - replacement, if entered character doesn't match the pattern and fallback id defined, component will use its value in masked string, defaults to undefined;

Development

Build requirements:

  • NodeJS >= 18.x

Setup

yarn install

Tests

yarn test

Visual testing

yarn sandbox:serve