A lightweight TypeScript library for masking and formatting strings, numbers, and more.
Perfect for input validation, formatting, and data presentation in web applications.
- Simple API for masking strings and numbers
- TypeScript support
- Zero dependencies
- Customizable masks
- Fast and lightweight
pnpm add @cicerotcv/masker
# or
npm install @cicerotcv/masker
# or
yarn add @cicerotcv/maskerimport { Masker } from '@cicerotcv/masker';
const phone = Masker.apply('1234567890', '## ####-####');
console.log(phone); // 12 3456-7890
const fmtCellphoneNumber = Masker.create('## ##### ####');
console.log(fmtCellphoneNumber('(11) 12345-1234')); // 11 12345 1234
const sanitized = Masker.onlyNumbers('(11) 12345-1234');
console.log(sanitized); // 11123451234Masker.apply('1234567890', '(##) ####-####'); // (12) 3456-7890const fmtPhoneNumber = Masker.create('(##) ####-####');
fmtPhoneNumber('1234567890'); // (12) 3456-7890Masker.onlyNumbers('(12) 3456-7890'); // 1234567890Run unit tests with Vitest:
pnpm test:runThis project is open source and available under the MIT License.