@cicerotcv/masker
v1.2.2
Published
Simple masking utility functions
Downloads
68
Readme
@cicerotcv/masker
A lightweight TypeScript library for masking and formatting strings, numbers, and more.
Perfect for input validation, formatting, and data presentation in web applications.
✨ Features
- Simple API for masking strings and numbers
- TypeScript support
- Zero dependencies
- Customizable masks
- Fast and lightweight
🚀 Installation
pnpm add @cicerotcv/masker
# or
npm install @cicerotcv/masker
# or
yarn add @cicerotcv/masker📦 Usage
import { 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); // 11123451234🛠 API
Apply the given pattern to a string or number
Masker.apply('1234567890', '(##) ####-####'); // (12) 3456-7890Create a curried masker function
const fmtPhoneNumber = Masker.create('(##) ####-####');
fmtPhoneNumber('1234567890'); // (12) 3456-7890Remove all non-numeric characters from a string
Masker.onlyNumbers('(12) 3456-7890'); // 1234567890🧪 Testing
Run unit tests with Vitest:
pnpm test:run📄 License
This project is open source and available under the MIT License.
