New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

mother-mask

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mother-mask

Lightweight input mask library for browsers

latest
Source
npmnpm
Version
2.0.5
Version published
Weekly downloads
654
16250%
Maintainers
1
Weekly downloads
 
Created
Source

mother-mask

Lightweight input mask library for browsers. Zero runtime dependencies, TypeScript-first, ships ESM, CJS, and UMD.

Published as mother-mask on npm.

Live demo

Try it on StackBlitz →

Install

npm install mother-mask
# or
pnpm add mother-mask

Usage

bind(input, mask, options?)

Attach a mask to any input element — this is the main API.

  • Idempotent — calling bind() again on the same element does nothing (the element is marked with data-masked).
  • Returns a dispose function — call it to remove listeners and attributes so you can bind again later.
  • Sets sensible defaults when missing: autocomplete, autocorrect, autocapitalize, spellcheck, and maxlength from the mask.
import { bind } from 'mother-mask'

const input = document.getElementById('phone') as HTMLInputElement

// Fixed mask
const dispose = bind(input, '(99) 99999-9999')

// Dynamic mask — picks the pattern from an ordered list (shortest → longest)
bind(input, ['(99) 9999-9999', '(99) 99999-9999'])

// Callback after paste or keyboard-driven changes
bind(input, '999.999.999-99', (value) => {
  console.log(value) // e.g. "123.456.789-01"
})

// Or options object (same as callback for a single `onChange`)
bind(input, '999.999.999-99', { onChange: (value) => console.log(value) })

// Later: allow rebinding
dispose()

Pattern syntax

CharacterMatches
9Digit (09)
ZLetter (az, AZ)
AAlphanumeric (digit or letter)
Anything elseLiteral — inserted as the user fills slots

Array masks

Pass an ordered array shortest → longest for variable-length inputs. The active mask is chosen from the count of alphanumeric “data” characters in the current value, so it works for both progressively masked input and fast typing.

bind(input, ['(99) 9999-9999', '(99) 99999-9999'])
bind(input, ['999.999.999-99', 'AA.AAA.AAA/AAAA-99'])

UMD / CDN

<script src="https://unpkg.com/mother-mask/dist/mother-mask.umd.js"></script>
<script>
  const dispose = MotherMask.bind(document.getElementById('cpf'), '999.999.999-99')
</script>

The global name is MotherMask.

API reference

bind (primary)

Signaturebind(input, mask, options?)
Returns() => void — call to remove listeners and attributes so the input can be bound again
Third argument{ onChange?: (value: string) => void }, or a legacy (value) => void callback

Other exports

ExportDescription
buildMask(value, mask, caret?)Build a Mask instance (array mask is resolved to one string first).
getMaxLength(mask)Maximum string length for the mask (for array masks, the longest pattern).
applyMask(value, mask, inputCaret?)Low-level: apply a single mask string; returns { value, caret }.

Mask class

buildMask returns a Mask for advanced use. The instance applies the pattern and keeps a caret position aligned with the masked output (see TypeScript definitions in the package).

Types

type MaskPattern = string | string[]

interface MaskResult {
  readonly value: string
  readonly caret: number
}

interface BindOptions {
  onChange?: (value: string) => void
}

MaskPattern, MaskResult, and BindOptions are exported as types.

License

MIT — Danilo Celestino de Castro

Keywords

input

FAQs

Package last updated on 06 Apr 2026

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