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

@energma/input-mask-react

v1.0.6

Published

A React component for input mask with dynamic formatting. No dependencies.

Readme

🛠️ @energma/input-mask-react

input-mask-react is a React component for creating input fields with customizable input masks. It allows you to format user input according to a specified mask, handling dynamic cursor positions and formatting on-the-fly. This component supports various types of input masks such as numbers, letters, and both formats.

Compatibility

  • React 19+
  • NEXT 15+

Table of Contents

Features

  • Customizable Mask: You can define a mask format using a symbol (e.g., _) that will be replaced with user input.
  • Dynamic Cursor Management: The cursor position updates automatically as the user types, ensuring that the mask format is followed properly.
  • Type-based Input Sanitization: The input is sanitized based on the selected type (numbers, letters, or mixed).
  • React Integration: It is built specifically for use with React, and works seamlessly with TypeScript.

Installation

To install the @energma/input-mask-react package, run the following command in your project:

npm install @energma/input-mask-react
pnpm add @energma/input-mask-react
yarn add @energma/input-mask-react

Summary

This repository contains code for input-react-mask (https://github.com/Energma/input-mask-react)

Schema Types:

  • numbers type accept [0-9]

  • letters type accept [a-zA-Z]

  • mixed type accept [a-zA-Z0-9]

  • schema symbol can be of any character

Schema interface:

interface Schema {
  mask: string;
  symbol: string;
  type: "numbers" | "letters" | "mixed";
}

Usage

Masked Input Example in React (TypeScript)

This example demonstrates how to use @energma/input-mask-react in a React application with TypeScript.

import { MaskedInput, Schema } from "@energma/input-mask-react";
import { useState } from "react";

function MyComponent() {
  const [creditCardExpiration, setCreditCardExpiration] = useState<string>("");

  const schema: Schema = {
    mask: "__/__",
    symbol: "_",
    type: "numbers",
  };

  return (
    <MaskedInput
      schema={schema}
      value={creditCardExpiration}
      onChange={(e) => setCreditCardExpiration(e.target.value)}
      placeholder={schema.mask}
    />
  );
}

Masked Input Example in Next.js

In Next.js use "use client" directive to ensure that component is treated as a client component. This example demonstrates how to use @energma/input-mask-react in a Next.js client component.

"use client";

import { useState } from "react";
import { MaskedInput, Schema } from "@energma/input-mask-react";

export default function MyComponent() {
  const [creditCardExpiration, setCreditCardExpiration] = useState<string>("");

  const schema: Schema = {
    mask: "__/__",
    symbol: "_",
    type: "numbers",
  };

  return (
    <MaskedInput
      schema={schema}
      value={creditCardExpiration}
      onChange={(e) => setCreditCardExpiration(e.target.value)}
      placeholder={schema.mask}
    />
  );
}

You can also add object where properties can be className, id, label, etc like any other input element.

placeholder can be anything you like but good practice is to have mask there.

Props

| Prop | Type         | Description | | ----------------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ...InputProps | | Inherit all props of Input. | | schema | schema         | Object defines the masking rules for user input. - mask (string) – Defines the input pattern using a placeholder symbol. If it is a RegExp, it will validate the input. - symbol (string) – Represents the character that will be replaced by user input. - type (string) – Specifies the type of input allowed. REQUIRED | | value | number         | The value for controlled input. REQUIRED | | onChange | function         | Callback that is called when the input's text changes. REQUIRED | | onFocus | function         | Triggered when the user clicks away and then focuses again. It will position the cursor at the next valid input. |

Examples

Credit Card Expiration Date

<MaskedInput
  schema={{ mask: "__/__", symbol: "_", type: "numbers" }}
  value={creditCardExpiration}
  onChange={(e) => setCreditCardExpiration(e.target.value)}
  placeholder="__/__"
/>

Zip Code

<MaskedInput
  schema={{ mask: "_____", symbol: "_", type: "numbers" }}
  value={zipCode}
  onChange={(e) => setZipCode(e.target.value)}
  placeholder="_____"
/>

Canadian Zip Code

<MaskedInput
  schema={{ mask: "XXX XXX", symbol: "X", type: "mixed" }}
  value={canadianZipCode}
  onChange={(e) => setCanadianZipCode(e.target.value)}
  placeholder="XXX XXX"
/>

Telephone Number

<MaskedInput
  schema={{ mask: "(XXX)XXX-XXXX", symbol: "X", type: "numbers" }}
  value={telephone}
  onChange={(e) => setTelephone(e.target.value)}
  placeholder="(XXX)XXX-XXXX"
/>

Credit Card Number

<MaskedInput
  schema={{ mask: "0000 0000 0000 0000", symbol: "0", type: "numbers" }}
  value={creditCardNumber}
  onChange={(e) => setCreditCardNumber(e.target.value)}
  placeholder="0000 0000 0000 0000"
/>

Country Code

<MaskedInput
  schema={{ mask: "XXX", symbol: "X", type: "letters" }}
  value={countryCode}
  onChange={(e) => setCountryCode(e.target.value)}
  placeholder="XXX"
/>

These examples demonstrate the flexibility of the MaskedInput component and how it can be integrated into a React application to handle various input formats.

License

@energma/input-mask-react is released under the MIT license. See LICENSE for details.