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 🙏

© 2024 – Pkg Stats / Ryan Hefner

make-mask

v1.0.3

Published

[![NPM](https://img.shields.io/npm/l/make-mask)](https://www.npmjs.com/package/make-mask) [![Coverage Status](https://coveralls.io/repos/github/holasoycael/make-mask/badge.svg?branch=main)](https://coveralls.io/github/holasoycael/make-mask?branch=main) [!

Downloads

110

Readme

Make Mask

NPM Coverage Status npm gzip size

make-mask is a lightweight javascript library of approximately 1kb for working with text masks. It was built to solve problems mainly in HTML inputs with javascript free from any other library. It was designed to solve inputs, but it is also valid when used to print texts in a simple and objective way. I guarantee a secure library covered with tests and open source!

It is very simple to use to create masks using the patterns below:

0 — Digits Only numbers

9 — Optional digits Indicates whether there will be a number or not

# — Recursive digits Use this pattern to create infinitely repeatable formulas

A — Letters and numbers Uppercase, lowercase letters and numbers

S — Letters Uppercase, lowercase letters

Installing

Using npm:

npm install make-mask

Using yarn:

yarn add make-mask

Using jsDelivr CDN:

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

Using unpkg CDN:

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

Usage

Default function arguments

It's very simple to use!

import mask from 'make-mask'

mask('12345678', '00000-000') // => 12345-678

Type information about the function

/**
 * Returns the transformed value
 * @param   {string} value    original value
 * @param   {string} mask     syntax pattern
 * @param   {object} options  options object
 * @return  {string}          mask result
*/
fn(value, mask[ , options])

Most common examples

Date

mask('27101', '00/00/0000')     // => 27/10/1
mask('271018', '00/00/0000')    // => 27/10/18
mask('2710182', '00/00/0000')   // => 27/10/182
mask('27101820', '00/00/0000')  // => 27/10/1820

Hour

mask('203', '00:00:00')     // => 20:3
mask('2039', '00:00:00')    // => 20:39
mask('20392', '00:00:00')   // => 20:39:2
mask('203922', '00:00:00')  // => 20:39:22

ZIP Code

mask('01310', '00000-000')    // => 01310
mask('013109', '00000-000')   // => 01310-9
mask('0131093', '00000-000')  // => 01310-93
mask('01310930', '00000-000') // => 01310-930

Money

const options = { reverse: true }
mask('6689', '#.##0,00', options)     // => 66,89
mask('66899', '#.##0,00', options)    // => 668,99
mask('668993', '#.##0,00', options)   // => 6.689,93
mask('6689932', '#.##0,00', options)  // => 66.899,32

Telephone with DDD

const m = '(00) 0000-0000'
mask('11994132', m)     // => (11) 9413-2
mask('119941325', m)    // => (11) 9413-25
mask('1199413256', m)   // => (11) 9413-256
mask('11994132568', m)  // => (11) 9413-2568

CPF

const options = { reverse: true }
const m = '000.000.000-00'
mask('6698', m, options)    // => 66-98
mask('66980', m, options)   // => 669-80
mask('669809', m, options)  // => 6.698-09
mask('6698090', m, options) // => 66.980-90

CNPJ

const options = { reverse: true }
const m = '00.000.000/0000-00'
mask('0000', m, options)    // => 00-00
mask('00001', m, options)   // => 000-01
mask('000016', m, options)  // => 0000-16
mask('0000168', m, options) // => 0/0001-68

IP Address

const m = '099.099.099.099'
mask('255255', m)       // => 255.255
mask('25525525', m)     // => 255.255.25
mask('2552552552', m)   // => 255.255.255.2
mask('255255255255', m) // => 255.255.255.255

We recommended for you

Maybe when working with price values directly in inputs, this library is not suitable for your needs. And we recommend exploring the make-currency library!

License

MIT