
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
@coffeeandfun/remove-pii
Advanced tools
A Node.js module to remove personally identifiable information (PII) from text.
Protect privacy by removing personally identifiable information (PII) from text!
@coffeeandfun/remove-pii is a powerful Node.js package designed to help with privacy by automatically detecting and removing personally identifiable information from text. Originally developed for Helperbird.com, this module has evolved into a comprehensive tool for protecting privacy in text processing.
Created by Robert James Gabriel at Coffee & Fun LLC - making the web more accessible and privacy-focused for everyone.
For Privacy Protection:
For Developers:
npm install @coffeeandfun/remove-pii
import { removePII } from '@coffeeandfun/remove-pii';
const text = "John's email is john@example.com and his phone number is 123-456-7890.";
const cleanedText = removePII(text);
console.log(cleanedText);
// Output: "John's email is [email removed] and his phone number is [phone removed]."
john@example.com123-456-7890, (555) 123-4567123-45-67891234 5678 9012 3456123 Main StreetAB1234567D123456789192.168.1.112345, 12345-67891234567890123456https://example.com01/15/1990removePII(text, options)Main function that removes PII and returns cleaned text.
const cleanedText = removePII("Email: john@example.com, Phone: 123-456-7890");
// Returns: "Email: [email removed], Phone: [phone removed]"
removePIIDetailed(text, options)Enhanced version with detailed information about what was removed.
const result = removePIIDetailed("Email: john@example.com");
console.log(result);
// {
// cleanedText: "Email: [email removed]",
// removedItems: [{ type: 'email', count: 1, items: ['john@example.com'] }],
// originalLength: 23,
// cleanedLength: 20,
// reductionPercentage: 13
// }
detectPII(text, options)Detects PII without removing it - useful for analysis.
const analysis = detectPII("Email: john@example.com, Phone: 123-456-7890");
console.log(analysis);
// {
// text: "Email: john@example.com, Phone: 123-456-7890",
// hasPII: true,
// totalMatches: 2,
// types: ['email', 'phone'],
// detectedItems: [...]
// }
analyzePII(text, options)Comprehensive analysis with statistics and risk assessment.
const analysis = analyzePII("Email: john@example.com, SSN: 123-45-6789");
console.log(analysis);
// {
// original: { text: "...", length: 45, wordCount: 6 },
// cleaned: { text: "...", length: 35, wordCount: 6 },
// pii: { detected: [...], totalCount: 2, types: ['email', 'ssn'] },
// risk: { level: 'medium', score: 13 }
// }
validatePIICompliance(text, options)Check if text is PII-compliant with recommendations.
const compliance = validatePIICompliance("Email: john@example.com");
console.log(compliance);
// {
// isCompliant: false,
// violations: [{ type: 'email', count: 1 }],
// riskLevel: 'low',
// recommendations: ['📧 Email detected - Consider using hashed emails']
// }
const options = {
email: { remove: true, replacement: "[EMAIL HIDDEN]" },
phone: { remove: false },
ssn: { remove: true, replacement: "[SSN REDACTED]" }
};
const cleaned = removePII(text, options);
const highPrivacy = {
email: { remove: true },
phone: { remove: true },
ssn: { remove: true },
creditCard: { remove: true },
address: { remove: true },
passport: { remove: true },
driversLicense: { remove: true },
ipAddress: { remove: true },
zipCode: { remove: true },
bankAccount: { remove: true },
url: { remove: true },
dateOfBirth: { remove: true }
};
const moderatePrivacy = {
ssn: { remove: true },
creditCard: { remove: true },
bankAccount: { remove: true },
email: { remove: false },
phone: { remove: false },
address: { remove: true }
};
const customReplacements = {
email: { replacement: "📧 [CONTACT INFO]" },
phone: { replacement: "📞 [PHONE NUMBER]" },
address: { replacement: "🏠 [LOCATION]" }
};
import { processBatch } from '@coffeeandfun/remove-pii';
const texts = [
"Email: john@example.com",
"Phone: 123-456-7890",
"Regular text"
];
const results = processBatch(texts);
console.log(results);
// Array of results with success/failure status
const compliance = validatePIICompliance(text);
console.log(`Risk Level: ${compliance.riskLevel}`);
console.log(`Risk Score: ${compliance.riskScore}`);
console.log(`Recommendations: ${compliance.recommendations.join(', ')}`);
import { getAvailableTypes } from '@coffeeandfun/remove-pii';
const types = getAvailableTypes();
types.forEach(type => {
console.log(`${type.type}: ${type.description}`);
});
import { removePII, validatePIICompliance } from '@coffeeandfun/remove-pii';
function cleanUserData(userData) {
const compliance = validatePIICompliance(userData);
if (!compliance.isCompliant) {
console.log(`⚠️ PII detected: ${compliance.violationCount} violations`);
return removePII(userData);
}
return userData;
}
import { removePIIDetailed } from '@coffeeandfun/remove-pii';
function sanitizeLogs(logEntry) {
const result = removePIIDetailed(logEntry);
if (result.removedItems.length > 0) {
console.log(`🔒 Sanitized log: removed ${result.removedItems.length} PII items`);
}
return result.cleanedText;
}
import { analyzePII } from '@coffeeandfun/remove-pii';
function sanitizeApiResponse(response) {
const analysis = analyzePII(JSON.stringify(response));
if (analysis.pii.totalCount > 0) {
console.log(`⚠️ API response contains PII: ${analysis.pii.types.join(', ')}`);
return JSON.parse(analysis.cleaned.text);
}
return response;
}
npm test
We've included comprehensive tests covering:
We welcome contributions!
git clone https://github.com/RobertJGabriel/remove-pii
cd remove-pii
npm install
npm test
MIT License - feel free to use in your projects!
Created with ❤️ by:
Originally developed for:
Need help protecting privacy in your applications?
Stay privacy-focused! 🔒
FAQs
A Node.js module to remove personally identifiable information (PII) from text.
The npm package @coffeeandfun/remove-pii receives a total of 318 weekly downloads. As such, @coffeeandfun/remove-pii popularity was classified as not popular.
We found that @coffeeandfun/remove-pii demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.