@tadashi/mask is a single-file, dependency-free ESM library for input masking in the browser — phone numbers, CPF/CNPJ, currency, credit cards. ~1KB min+gzip, native TypeScript types (JSDoc-generated), and a pure `Mask.core()` function that works without the DOM too.
Hey Product Hunt
I built @tadashi/mask because every time I needed a masked input, I ended up installing a library that pulled in a parser, a runtime, and a handful of transitive dependencies — just to reformat a string as someone types.
Masking is really a small problem: take the pattern (`999.999.999-99`, `(99) 9-9999-9999`), walk it against the input, reinsert literals. So the library stays that small too — single file, zero dependencies, ~1KB min+gzip.
A few things I focused on:
- `Mask.core(value, mask)` — a pure function, works without a DOM (Node.js included)
- Native TypeScript support — types generated straight from JSDoc, no separate `@types` package to install or fall out of sync
- Handles the real edge cases: switching CPF → CNPJ mid-typing, applying on blur vs. every keystroke, reading the pattern from a `data-mask` attribute
Live demo: https://codepen.io/lagden/pen/Xz...
Source: https://github.com/lagden/mask
npm: https://www.npmjs.com/package/@t...
Would love feedback — especially if you've hit friction with existing masking libraries and what would make this one better for you.