maskly
v1.0.6
Published
Mask sensitive data in strings, objects, and arrays easily. Useful for logger, debugging, security.
Maintainers
Readme
🕶️ maskly
Lightweight utility to mask sensitive data in strings, objects, and arrays — with dynamic field control and customization. Useful for logger, debugging, security.
🚀 Features
- 🔒 Mask any string, object, or array
- ⚙️ Works with dynamic field names
- 🧩 Supports nested objects
- 🎛️ Customizable options (
visibleStart,visibleEnd,maskChar) - 💪 Written in TypeScript, works in JavaScript
- ⚡ Zero dependencies
📦 Installation
npm install maskly
# or
yarn add maskly🧠 Usage
🔹 Basic Example
import { maskly } from "maskly";
const user = {
name: "Vinod Selvin",
email: "[email protected]",
phone: "9876543210",
password: "supersecret"
};
console.log(maskly(user));
/*
{
name: 'Vinod Selvin',
email: 'vi***********om',
phone: '98******10',
password: 'su**********et'
}
*/🔹 Mask Specific Fields
maskly(user, ["email", "name"]);
/*
{
name: 'Vi*******in',
email: 'vi***********om',
phone: '9876543210',
password: 'supersecret'
}
*/🔹 Customize Options
maskly(user, ["email"], { visibleStart: 3, visibleEnd: 1, maskChar: "#" });
/*
{
name: 'Vinod Selvin',
email: 'vin##########m',
phone: '9876543210',
password: 'supersecret'
}
*/🔹 Mask Strings or Arrays Directly
maskly("mysecretpassword");
// => "my************rd"
maskly(["[email protected]", "[email protected]"]);
// => ["he***********om", "te**********om"]⚙️ API
maskly(value, fields?, options?)
| Parameter | Type | Description |
|------------|------|-------------|
| value | string | object | array | Input value to mask |
| fields | string[] (optional) | List of fields to mask (for objects) |
| options | object (optional) | Customization options |
Options
| Key | Type | Default | Description |
|-----|------|----------|-------------|
| visibleStart | number | 2 | Number of characters visible at start |
| visibleEnd | number | 2 | Number of characters visible at end |
| maskChar | string | "*" | Character used for masking |
🧰 Example with TypeScript
import { maskly } from "maskly";
interface User {
name: string;
email: string;
password: string;
}
const user: User = {
name: "John Doe",
email: "[email protected]",
password: "mypassword123"
};
console.log(maskly(user, ["email", "password"]));🧪 Run Tests
npm test📄 License
MIT © 2025 Vinod Selvin
