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

masky-js

v1.0.1

Published

A lightweight and flexible JavaScript library for input masking. Supports custom masks, prefixes, suffixes, and built-in CPF/CNPJ validation for forms.

Readme

Masky.js

Bundle Size

📦 Masky.js – A compact and high-performance JavaScript library for input masking. Weighing only 1.3 KB (gzip), it’s optimized for fast loading and ideal for any project requiring lightweight, flexible, and customizable input masks.


Features

  • Super Lightweight: Only 1.3 KB gzipped, minimizing your app’s bundle size.
  • Automatic Enhancements:
    • inputmode support: Dynamically adjusts for better mobile user experience.
    • minlength and maxlength: Automatically calculated based on the mask.
  • Built-in Validations: Native support for CPF and CNPJ validation.
  • Flexible Masks: Add custom masks with prefixes, suffixes, and dynamic formatting.
  • Ease of Use: Just add data-mask and optional attributes—Masky.js does the rest.
  • Vanilla JS: Works without any dependencies, making it adaptable to any environment.

Usage

Basic Example

Add data-mask to your input fields, and the library will handle the rest:

<input type="text" data-mask="(00) 00000-0000" />
<script src="dist/masky.min.js"></script>

Adding Prefixes and Suffixes

Add data-mask-prefix or data-mask-suffix to include additional characters:

<input type="text" data-mask="000-000" data-mask-prefix="+55 " data-mask-suffix=" ext" />

Validating CPF and CNPJ

Use data-mask-validation for built-in validation of CPF and CNPJ:

<input type="text" data-mask="000.000.000-00" data-mask-validation="cpf" />
<input type="text" data-mask="00.000.000/0000-00" data-mask-validation="cnpj" />

Available Tokens

Masky.js provides the following tokens for creating masks:

| Token | Description | Example Input | Example Mask | | |-------|-----------------------|---------------|--------------|---| | 0 | Numeric digits only | 123 | 000 → 123 | | | A | Alphanumeric | 1aB | AAA → 1AB | | | S | Alphabetic characters | abc | SSS → abc | |

Why Masky.js?

  • Automatic Enhancements: Input mode (inputmode) and field limits (minlength and maxlength) are calculated and applied automatically based on the mask.
  • Built for Performance: With only 1.3 KB gzipped, it’s one of the most efficient libraries available.
  • Flexibility: Perfect for any environment—websites, frameworks, or CMS integrations.
  • Ease of Integration: Add data-mask to your inputs, and Masky.js takes care of formatting, validation, and user experience.

Example

<input type="text" data-mask="(00) 00000-0000" />
<input type="text" data-mask="000-000" data-mask-prefix="+55 " data-mask-suffix=" ext" />
<input type="text" data-mask="AAA-SSS-000" />
<script src="dist/masky.min.js"></script>
  • No need to manually define inputmode or limits-—Masky.js handles them automatically.
  • Add as much customization as needed with data-mask-prefix and data-mask-suffix.

Installation

🌐 Via CDN

Use Masky.js directly from a reliable CDN:

jsDelivr

<script src="https://cdn.jsdelivr.net/npm/masky-js/dist/masky.min.js"></script>

UNPKG

<script src="https://unpkg.com/masky-js/dist/masky.min.js"></script>

📦 Via npm

Masky.js is available on npm. Install it using the following command:

npm install masky-js

After installation, include the file in your project:

import 'masky-js/dist/masky.min.js';

📂 Copy the File

For now, download or copy the file directly from the /dist directory of the repository:

  1. Go to the /dist folder in this repository.
  2. Download or copy the masky.min.js file.
  3. Include it in your project:
<script src="path/to/masky.min.js"></script>

Contributing

We welcome contributions! Fork the repository, create a branch, and open a pull request.

License

This project is licensed under the MIT License.