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

@ionited/mask

v0.7.0

Published

Create your masks easily

Readme

Mask

Create your masks easily

Mask comes with three basic implementations MaskDefault, MaskNumber and MaskDate, but you can use MaskCore to do your own masks implementation easily.

Quick start

Choose your favorite option below:

Install with NPM

npm i @ionited/mask

Get from UNPKG

https://unpkg.com/@ionited/mask@latest/dist/mask.js


Usage

To basic usage you can simply call:

Mask(document.querySelector('#input1'), { mask: '(99) 9999-9999' }); // To use MaskDefault
Mask(document.querySelector('#input2'), { number: true }); // To use MaskNumber
Mask(document.querySelector('#input3'), { date: 'DD/MM/YYYY' }); // To use MaskDate

MaskDefault

A mask that receives a regex or a string with numbers, letters or other symbols

Mask(el: HTMLElement, { mask: RegExp | string | MaskDefaultOptions });

interface MaskDefaultOptions {
  allowEmpty?: boolean;
  mask: RegExp | string;
}

| Symbol | Pattern | Description |:--------:|------------------|------------- | 9 | /^[0-9]$/ | Only numbers | A | /^[A-Za-zÀ-ÿ]$/| Only letters

Any other symbol is fixed.

MaskNumber

A mask for monetary and decimal values

Mask(el: HTMLElement, { number: true | MaskNumberOptions });

interface MaskNumberOptions {
  allowEmpty: boolean;
  allowNegative: boolean;
  decimal: number;
  decimalPoint: string;
  end: boolean;
  prefix: string;
  suffix: string;
  thousandPoint: string;
}

MaskDate

A mask for date and time values

Mask(el: HTMLElement, { date: string | MaskDateOptions });

interface MaskDateOptions {
  format: string;
  placeholders: { [key: string]: string };
}

| Format | Pattern | Description |:---------:|---------|------------- | YYYY | 0000-∞ | Year | MM | 01-12 | Month | DD | 01-31 | Day | hh | 00-23 | Hour | mm | 00-59 | Minutes | ss | 00-59 | Seconds

Any other symbol is fixed.

MaskCore

You can create your own mask logic easily, you only need register a mask and use:

Mask.register(name: string, mask: any): void;

The recommended way to do a new mask is writing a class that extends MaskOptions

interface MaskOptions {
  instance: MaskCore;
  init?(data: MaskData): void;
  input?(data: MaskData): void;
  format(data: MaskData): void;
  focus?(data: MaskData): void;
  blur?(data: MaskData): void;
  mouseover?(data: MaskData): void;
  mouseout?(data: MaskData): void;
}

interface MaskData {
  cursorPosition: number;
  delete: boolean;
  focus: boolean;
  input: string;
  output: string;
  outputRaw: any;
}

MyMask example (only accept numbers):

import { MaskData, MaskCore, MaskOptions } from '@ionited/mask/core';

export class MyMask implements MaskOptions {
  instance: MaskCore;

  constructor(el: HTMLInputElement) {
    this.instance = new MaskCore(el, this);
  }

  init(data: MaskData) {
    this.format(data);
  }

  format(data: MaskData) {
    data.output = data.input.replace(/[^0-9]/g, ''); 
  }
}

Register and use:

Mask.register('myMask', MyMask); // Register

Mask(document.querySelector('#myMask'), { myMask: true }); // Enjoy your own mask!

License

Copyright (c) 2021 Ion. Licensed under MIT License.

https://ionited.io