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 🙏

© 2026 – Pkg Stats / Ryan Hefner

unimask

v1.0.2

Published

A lightweight utility library for creating mask for input values

Readme

unimask npm build status Download

A lightweight TypeScript library for masking and formatting input values.

Features

  • Masking: Apply predefined or custom masks to input values.
  • Formatting: Format input values based on the applied mask.
  • Framework Agnostic: Can be used with any JavaScript framework or library.
  • Customizable: Define your own masks and formatting rules.
  • Lightweight: Small footprint with no external dependencies.
  • Tests: Comprehensive test coverage to ensure reliability. (90%+)

Installation

# npm
npm install unimask

# yarn
yarn add unimask

# pnpm
pnpm add unimask

Usage

Basic Masking

import { createMaskProcessor } from 'unimask';

const maskProcessor = createMaskProcessor('(###) ###-####');
const result = maskProcessor('12345678');

console.log(result.formatted); // Output: (123) 456-78
console.log(result.placeholder); // Output: (123) 456-78##

Array of Masks

const maskProcessor = createMaskProcessor(['+1 (###) ###-####', '###-###-####']);
const result1 = maskProcessor('1234567890');
const result2 = maskProcessor('1234567');

console.log(result1.formatted); // Output: 123-456-7890
console.log(result2.formatted); // Output: 123-4567

Dynamic Masks

It will automatically switch between masks based on the input value. Also order of masks does not matter, it will use from less to most complicated.

const maskProcessor = createMaskProcessor((value: string) => {
  return value.startsWith("+")
    ? "+1 (###) ###-####"
    : "###-###-####";
});

const result1 = maskProcessor('1234567890');
const result2 = maskProcessor('+12345678901');

console.log(result1.formatted); // Output: 123-456-7890
console.log(result2.formatted); // Output: +1 (234) 567-8901

Turn off trimming

It will return formatted string but will not trim the excess characters.

const maskProcessor = createMaskProcessor('(###) ###-####', { trim: false });

const result = maskProcessor('12345678');
const result2 = maskProcessor('12345678901234567890');

console.log(result.formatted); // Output: (123) 456-78
console.log(result2.formatted); // Output: (123) 456-78901234567890

API

createMaskProcessor(mask: MaskInput, options?: MaskProcessorOptions) Creates a mask processor function.

  • mask: A mask string, an array of masks, or a function that returns a mask string based on the input value.
  • options: An optional object with the following properties:
    • trim: A boolean indicating whether to trim excess characters from the input value. Defaults to true.

MaskInput

Type alias for the mask input:

type MaskInput = string | string[] | ((value: string, lastChar: string, cursorPos: number) => string);

MaskProcessorOptions

Type alias for the mask processor options:

type MaskProcessorOptions = {
  trim?: boolean;
};

MaskProcessorResult Type alias for the result of the mask processor function:

type MaskProcessorResult = {
  formatted: string; // The formatted value based on the mask (just filled characters)
  placeholder: string; // The placeholder value based on the mask (with filled and unfilled characters)
  cursorPosition: number; // The cursor position after formatting
};

Mask Tokens

The following tokens are supported in the mask:

  • #: Digit (0-9).
  • a: Alphabetic character in lowercase (a-z).
  • A: Alphabetic character in uppercase (A-Z).
  • S: Alphabetic character (a-zA-Z).
  • X: Alphanumeric character (0-9, a-z, A-Z).
  • *: Any character.
  • !: Escape character. The next character will be treated as a literal character and will not be masked.

Other characters in the mask are treated as literals and will be included in the formatted value.

Integrations

Vue directive

<template>
  <input v-model="value" v-unimask="'(###) ###-####'" />
</template>
<script setup lang="ts">
import { vUnimask } from "unimask/vue";
import { ref } from "vue";

const value = ref("");
</script>

Enjoy!

If you have any questions or suggestions, feel free to open an issue or pull request.

Roadmap

  • [x] Create a library
  • [x] Add tests
  • [x] Add documentation
  • [x] Vue directive
  • [ ] Vue composable
  • [ ] React hook
  • [ ] Angular directive
  • [ ] Svelte directive
  • [ ] Custom tokens and formatters

License

MIT

Copyright (c) 2025 by Dmytro Shevchenko