Socket
Book a DemoInstallSign in
Socket

@signalapp/minimask

Package Overview
Dependencies
Maintainers
9
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@signalapp/minimask

Simple HTML input masking

1.0.1
latest
Source
npmnpm
Version published
Maintainers
9
Created
Source

@signalapp/minimask

A tiny & modern library for masking inputs.

Install

npm install --save @signalapp/minimask

Usage

Setup an <input>:

<input
	id="creditCardNumber"
	type="text"
	inputmode="numeric"
	autocomplete="cc-number"
	placeholder="1234 1234 1234 1234"
	size="20"
/>

Create a formatter:

export function creditCardNumberFormatter(input) {
	let tokens = []
	let digits = 0

	for (let [index, char] of input.split("").entries()) {
		// skip non-digits
		if (!/\d/.test(char)) {
			continue
		}

		// push digits
		tokens.push({ char, index, mask: false })
		digits++

		// insert spaces when needed
		if (digits === 4 || digits === 8 || digits === 12) {
			tokens.push({ char: " ", index, mask: true })
		}

		// ignore any additional chars
		if (digits >= 16) {
			break
		}
	}

	return tokens
}

Attach the formatter to the input:

import { minimask } from "minimask"
import { creditCardNumberFormatter } from "./formatters"

let input = document.querySelector("#creditCardNumber")

minimask(input, formatter)

License

Copyright 2025 Signal Messenger, LLC

Licensed under the AGPLv3

Keywords

input

FAQs

Package last updated on 17 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.