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

mask-any-number

v2.3.3

Published

Apply flexible numeric masks to any string. Perfect for phone numbers, documents, and custom input formatting.

Readme

📜 mask-any-number

A lightweight, flexible number-masking library — supports multiple mask patterns and automatically picks the best fit based on the input length.

npm version npm downloads license types

🔧 Installation

npm install mask-any-number

or

yarn add mask-any-number

🌍 Country Phone Masks (built-in)

import { maskNumber, countries } from 'mask-any-number';

// Germany 🇩🇪
maskNumber('493012345678', countries.find(country => country.iso2 === 'DE').masks); 
// "30 1234 5678"

// Brazil 🇧🇷
maskNumber('5511998765432', countries.find(country => country.iso2 === 'BR').masks); 
// "11 99876 5432"

// US 🇺🇸
maskNumber('1234567890', countries.find(country => country.iso2 === 'US').masks); 
// "(123) 456-7890"

🎨 Custom Masks

import { maskNumber } from 'mask-any-number';

// Basic usage
maskNumber('1234567890', ['000-000-0000']); // "123-456-7890"

// Multiple masks, chooses first that fits
maskNumber('12345', ['000-000', '00000']); // "12345"
maskNumber('123456', ['000-000', '00000']); // "123-456"

### Phone Numbers
// US: (XXX) XXX-XXXX
maskNumber('1234567890', ['(000) 000-0000']); // "(123) 456-7890"

// Europe (DE): +49 XX XXXX XXXX
maskNumber('493012345678', ['+49 00 0000 0000']); // "+49 30 1234 5678"

// China: +86 10 1234 5678
maskNumber('861012345678', ['+86 00 0000 0000']); // "+86 10 1234 5678"

⚙️ API

| Parameter | Type | Description | |--------------------|------------|-----------------------------------------------------| | value | string | Input numeric string to mask | | masks | string[] | Array of mask patterns using 0 as digit placeholder |

Return: string — formatted number according to the first mask that fits.

🔁 Visual Summary

| Type | Input | Mask | Output | |-------------|-----------------|---------------------|----------------| | US Phone | 1234567890 | (000) 000-0000 | (123) 456-7890 | | EU Phone | 493012345678 | 00 0000 0000 | 30 1234 5678 | | CN Phone | 861012345678 | 00 0000 0000 | 10 1234 5678 |

🧪 Testing with Mock Data

const examples = [
    { value: '1234567890', masks: ['000-000-0000'] },
    { value: '31122025', masks: ['00/00/0000'] },
];

examples.forEach(({ value, masks }) => {
    console.log(maskNumber(value, masks));
});

💡 Tips

Use multiple masks to handle variable-length numbers.

Keep 0 as the digit placeholder; all other characters are treated as literals.

Ideal for phone numbers, dates, IDs, and other numeric inputs.

For local development:

Inside the library folder

npm run build

npm link

💡 Tips

Use multiple masks to handle variable-length numbers.

Keep 0 as the digit placeholder; all other characters are treated as literals.

Ideal for phone numbers, dates, IDs, and other numeric inputs.

For local development:

Inside the library folder

npm run build

npm link

npm link mask-any-number

⚠️ After the initial link, you only need to run npm run build when updating the library.

Gabriel GitHub

🧾 License

MIT © 2025