privacy-brush
v1.1.1
Published
Automatically mask sensitive information in terminal outputs and logs. Keep your data safe when sharing.
Downloads
691
Maintainers
Readme
✨ Features
- 🎯 Smart Detection - Auto-detects 20+ sensitive information patterns
- 🔧 Highly Configurable - Custom masking rules and characters
- ⚡ High Performance - Stream processing for large files
- 🛡️ Privacy First - Local processing only, no data leaves your machine
- 📦 Multiple Formats - CLI, API, Stream, File processing
- 🌐 Multi-language - Supports English, Chinese, and other log formats
- 🎨 Customizable - Add your own sensitive patterns
🚀 Quick Start
Basic Usage
# Direct terminal output processing
flutter devices | pnpx privacy-brush
flutter doctor | pnpx privacy-brush
# Process files
privacy-brush -i input.log -o masked.log
# Real-time command output
echo 'Microsoft Windows [Version 10.0.12345.6785]' | privacy-brushIn Your Node.js Project
// Or ES Module
import { PrivacyBrush } from 'privacy-brush';
// Create instance
const brush = new PrivacyBrush();
// Process text
const sensitiveText = `Windows [Version 10.0.12345.1234]
Chrome 144.0.1234.12
User IP: 192.123.1.123`;
const safeText = brush.maskText(sensitiveText);
console.log(safeText);
// Output:
// Windows [Version 10.█.█████.████]
// Chrome 144.█.████.██
// User IP: 192.███.█.███📖 Examples
Example 1: Process Flutter Output
Original:
❯ flutter devices
Found 4 connected devices:
Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.12345.1234]
Chrome (web) • chrome • web-javascript • Google Chrome 144.0.1234.60After PrivacyBrush:
❯ flutter devices | privacy-brush
Found 4 connected devices:
Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.█.█████.████]
Chrome (web) • chrome • web-javascript • Google Chrome 144.█.████.██Example 2: Process Node.js Debug Logs
const masker = new PrivacyBrush({
maskChar: '*',
preserveFirstPart: false
});
const debugLog = `
DEBUG: User login from IP 192.168.1.100
DEBUG: Session ID: abc123def456
DEBUG: Browser: Chrome/144.0.1234.60
DEBUG: OS: Windows 10.0.12345
`;
console.log(masker.mask(debugLog));
// Output:
// DEBUG: User login from IP ***.***.*.***
// DEBUG: Session ID: ************
// DEBUG: Browser: Chrome/***.*.***.**
// DEBUG: OS: Windows **.*.*****⚙️ Configuration
CLI Options
# Basic usage
privacy-brush [options]
# Options
--char, -c <char> Mask character (default: █)
--preserve-first Keep first part of version numbers
--input, -i <file> File to read from
--output, -o <file> Output to file
--strict Strict mode (mask more info)
--config <file> Use config file
--list-patterns List all built-in patterns
--add-pattern <regex> Add custom regex pattern
--version Show version
--help Show helpRead from stdin by default.
JavaScript API Options
const masker = new PrivacyBrush({
// Basic config
maskChar: '█', // Mask character
preserveFirstPart: true, // Keep first part of versions
// Pattern config
patterns: {
ipAddress: true,
macAddress: true,
email: true,
phone: true,
creditCard: true,
jwtToken: true,
apiKey: true,
osVersion: true,
browserVersion: true,
appVersion: true,
deviceId: true,
serialNumber: true,
filePaths: false, // Don't mask file paths
localhost: false // Don't mask localhost
},
// Custom patterns
customPatterns: [
{
name: 'custom-id',
regex: /ID-\d{6}/g,
mask: 'ID-******'
}
]
});🔧 Built-in Patterns
PrivacyBrush includes 20+ pre-configured sensitive information patterns:
🔐 Personal Information
- Email addresses
[email protected]→***@example.com - Phone numbers
13800138000→138****8000 - ID numbers
110101199001011234→110101********1234
💻 Technical Information
- IP addresses
192.168.1.100→192.168.*.* - MAC addresses
00:1A:2B:3C:4D:5E→00:**:**:**:**:** - Port numbers
:8080→:**** - API keys
sk_live_1234567890→sk_live_********
🖥️ System & Browser
- Windows versions
10.0.12345.1234→10.███.███.███ - Chrome versions
144.0.1234.60→144.███.███.███ - Android versions
Android 16→Android ██
🏢 Business Data
- Credit cards
4111 1111 1111 1111→4111 **** **** 1111 - JWT tokens
eyJhbGciOiJIUzI1...→eyJ********... - Session IDs
session-abc123def456→session-************
🛠️ Advanced Usage
Stream Processing for Large Files
import { createReadStream, createWriteStream } from "node:fs"
import { pipeline } from "node:stream/promises"
import { PrivacyBrush } from "privacy-brush"
const brush = new PrivacyBrush()
const inputStream = createReadStream("./test/fixtures/huge.log")
const maskStream = await brush.createMaskStream()
const dist = `./test/fixtures/masked-huge-${Date.now()}.generated.log`
// biome-ignore format: one stream per line
await pipeline(
inputStream,
maskStream,
createWriteStream(dist)
)
console.log("✅ Large file processing completed!", dist)Git Hook Integration
#!/bin/bash
# .git/hooks/pre-commit
for file in $(git diff --cached --name-only | grep -E '\.(log|txt|json)$'); do
if privacy-brush --check "$file"; then
echo "❌ File $file contains unmasked sensitive information"
echo "Use: privacy-brush $file -o $file && git add $file"
exit 1
fi
done📁 Configuration File
Create privacy-brush.config.json:
{
"maskChar": "█",
"preserveFirstPart": true,
"patterns": {
"ipAddress": true,
"email": true,
"phone": true,
"osVersion": true,
"browserVersion": true
},
"customPatterns": [
{
"name": "project-api-key",
"regex": "PROJECT_API_KEY=\\w{32}",
"mask": "PROJECT_API_KEY=******************************"
}
]
}🤝 Contributing
We welcome contributions! See CONTRIBUTING.md for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
MIT License © 2024 PrivacyBrush Contributors
📞 Support
Terminal Output Masking Tool | Safely Share Logs by Hiding Sensitive Information
Development
# mask stdin with custom patterns
echo 'DEEPSEEK_API_KEY=sk-af75149812524eb08eb302bf9604c8e8' | node src/cli.mjs --pattern '/sk-[a-z0-9]{20,}/'
echo '/c/Users/legend80s/AppData/ /Users/test/code/' | node src/cli.mjs --pattern '/Users/[a-z]{2,}/i'
# /c/Users/█████████/AppData/ /Users/████/code/