Skip to content

cicerotcv/masker

Repository files navigation

@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.

Version npm version Monthly downloads License TypeScript React Vite pnpm license CI update and publish wakatime buy-me-a-bitcoffee

✨ 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-7890

Create a curried masker function

const fmtPhoneNumber = Masker.create('(##) ####-####');
fmtPhoneNumber('1234567890'); // (12) 3456-7890

Remove 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.

About

A lightweight utility library for applying input masks to format numbers and text with custom patterns

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •