{"_id":"@coffeeandfun/remove-pii","_rev":"4-7b6515e227c9e903377c1819b8639998","name":"@coffeeandfun/remove-pii","dist-tags":{"latest":"3.0.1"},"versions":{"1.0.0":{"name":"@coffeeandfun/remove-pii","version":"1.0.0","keywords":["PII","privacy","text-processing","data-protection"],"author":{"name":"Coffee & Fun LLC"},"license":"ISC","_id":"@coffeeandfun/remove-pii@1.0.0","maintainers":[{"name":"robertjgabriel","email":"robert_gabriel@outlook.com"}],"homepage":"https://github.com/coffee-and-fun/remove-pii#readme","bugs":{"url":"https://github.com/coffee-and-fun/remove-pii/issues"},"dist":{"shasum":"db7c19280e4a87e4a92b797d7240b765debb234e","tarball":"https://registry.npmjs.org/@coffeeandfun/remove-pii/-/remove-pii-1.0.0.tgz","fileCount":8,"integrity":"sha512-2berODJtCZOsPIDJSuggXi3wRkMjFZkHLpLCPpUJKK11u6oTCg5dwZYltS6U9AsUB5NKbhT+E/+mNDIDjNEbXw==","signatures":[{"sig":"MEUCIQDXdSJXn+Z8HwFohJnTf2T1MSlhDlfmVA3gNgHEfeq9eAIgX3vrBN816uMEDAPiJxB263l0KL14WUs270D9BR4ZeqQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10895},"main":"index.js","type":"module","gitHead":"03ded469d04bc2dcf234b2154df8ac52a7fac257","scripts":{"test":"jest"},"_npmUser":{"name":"robertjgabriel","email":"robert_gabriel@outlook.com"},"repository":{"url":"git+https://github.com/coffee-and-fun/remove-pii.git","type":"git"},"_npmVersion":"9.7.1","description":"A Node.js module to remove personally identifiable information (PII) from text.","directories":{},"_nodeVersion":"18.16.1","_hasShrinkwrap":false,"devDependencies":{"jest":"^27.0.0"},"_npmOperationalInternal":{"tmp":"tmp/remove-pii_1.0.0_1700709352936_0.6710724189320327","host":"s3://npm-registry-packages"}},"1.0.5":{"name":"@coffeeandfun/remove-pii","version":"1.0.5","keywords":["PII","privacy","text-processing","data-protection"],"author":{"name":"Coffee & Fun LLC"},"license":"ISC","_id":"@coffeeandfun/remove-pii@1.0.5","maintainers":[{"name":"robertjgabriel","email":"robert_gabriel@outlook.com"}],"homepage":"https://github.com/coffee-and-fun/remove-pii#readme","bugs":{"url":"https://github.com/coffee-and-fun/remove-pii/issues"},"dist":{"shasum":"79f6404bdbb3ec50b3ceac750e54167e5cd79d38","tarball":"https://registry.npmjs.org/@coffeeandfun/remove-pii/-/remove-pii-1.0.5.tgz","fileCount":8,"integrity":"sha512-oaP9PLihXTnqfKsvEPqB1c1gMlMr7Cq2RhrGiJL2+1t//oJnslfTivVbxEv7Fmlykn0+nEtAXof2iGqEUmN8vw==","signatures":[{"sig":"MEUCIBRH2K7jwXyFoU30gEGY9oRMvMyV3aNr8bUpDlsCaJE0AiEAr97/0vqggnYouLRo8815oLmOWXnqC7qjfdfo79jNy8w=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10895},"main":"index.js","type":"module","gitHead":"0141cdf561d4d75434b191d3f39dd84373d7e45c","scripts":{"test":"jest"},"_npmUser":{"name":"robertjgabriel","email":"robert_gabriel@outlook.com"},"repository":{"url":"git+https://github.com/coffee-and-fun/remove-pii.git","type":"git"},"_npmVersion":"8.19.4","description":"A Node.js module to remove personally identifiable information (PII) from text.","directories":{},"_nodeVersion":"16.20.2","_hasShrinkwrap":false,"devDependencies":{"jest":"^27.0.0"},"_npmOperationalInternal":{"tmp":"tmp/remove-pii_1.0.5_1700709458233_0.2517998949906519","host":"s3://npm-registry-packages"}},"2.0.0":{"name":"@coffeeandfun/remove-pii","version":"2.0.0","keywords":["PII","privacy","text-processing","data-protection"],"author":{"name":"Coffee & Fun LLC"},"license":"ISC","_id":"@coffeeandfun/remove-pii@2.0.0","maintainers":[{"name":"robertjgabriel","email":"robert_gabriel@outlook.com"}],"homepage":"https://github.com/coffee-and-fun/remove-pii#readme","bugs":{"url":"https://github.com/coffee-and-fun/remove-pii/issues"},"dist":{"shasum":"539a3cb12dd30c909e33808f78cfc47804d36b20","tarball":"https://registry.npmjs.org/@coffeeandfun/remove-pii/-/remove-pii-2.0.0.tgz","fileCount":8,"integrity":"sha512-1CWFlq0MH2k9nX9d+Lz+T0GGmUH5VzyrGLlo70PnJ1gTvkTt/jNCFAJsymiHqk49tAwzhbUcmwsjhkjpk9nXzw==","signatures":[{"sig":"MEYCIQCsFRLOgjXUB5qyEc0rgje0Q6TAzqvun3iaPIh5QaP6AAIhAOBEzmcnqcKrRLtlJFuvzjjuUPMS8w7orf5hCCaQhYcc","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":39325},"main":"index.js","type":"module","gitHead":"3836d42de0e2113dcb501b982ae7a4dd1c72c8aa","scripts":{"test":"NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest","format":"npx prettier . --write"},"_npmUser":{"name":"robertjgabriel","email":"robert_gabriel@outlook.com"},"repository":{"url":"git+https://github.com/coffee-and-fun/remove-pii.git","type":"git"},"_npmVersion":"10.9.0","description":"A Node.js module to remove personally identifiable information (PII) from text.","directories":{},"_nodeVersion":"22.11.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^27.0.0"},"_npmOperationalInternal":{"tmp":"tmp/remove-pii_2.0.0_1752655143348_0.38827518699751606","host":"s3://npm-registry-packages-npm-production"}},"3.0.1":{"name":"@coffeeandfun/remove-pii","version":"3.0.1","description":"A Node.js module to remove personally identifiable information (PII) from text.","type":"module","main":"index.js","types":"index.d.ts","exports":{".":{"types":"./index.d.ts","import":"./index.js","default":"./index.js"},"./package.json":"./package.json"},"engines":{"node":">=16"},"scripts":{"format":"npx prettier . --write","test":"NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest","prepublishOnly":"npm test"},"repository":{"type":"git","url":"git+https://github.com/coffee-and-fun/remove-pii.git"},"bugs":{"url":"https://github.com/coffee-and-fun/remove-pii/issues"},"homepage":"https://github.com/coffee-and-fun/remove-pii#readme","keywords":["PII","privacy","text-processing","data-protection"],"author":{"name":"Coffee & Fun LLC"},"license":"MIT","devDependencies":{"jest":"^29.7.0"},"gitHead":"1aef97a2a27b492aa2dee41bdb8547e7e86df111","_id":"@coffeeandfun/remove-pii@3.0.1","_nodeVersion":"20.20.2","_npmVersion":"11.12.1","dist":{"integrity":"sha512-LPsHgzU8Ydg42gudEsJM2mj2YST3MroR7GcWf9iMYgIuz5UvJdVaT/OV9hZnEN5Ot0V+ey/ULETRptPK/X9D+w==","shasum":"2f2e0d24ccac592730e22b4ff93a4251df7e688e","tarball":"https://registry.npmjs.org/@coffeeandfun/remove-pii/-/remove-pii-3.0.1.tgz","fileCount":16,"unpackedSize":33383,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@coffeeandfun%2fremove-pii@3.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIFnpvJA4K4iZt2bCuMIBM1XTCgKkUZ9+7V07RpVuqyH/AiEAsPfdQEaerayu+Tmvi4JtCEcG869NGE6+SPV35Ji+V3I="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:86220906-c6ed-4ab6-901f-fd2ba6b1ea8a"}},"directories":{},"maintainers":[{"name":"robertjgabriel","email":"robert_gabriel@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/remove-pii_3.0.1_1776658337982_0.8360479764406763"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-23T03:15:52.844Z","modified":"2026-04-20T04:12:18.469Z","1.0.0":"2023-11-23T03:15:53.120Z","1.0.5":"2023-11-23T03:17:38.393Z","2.0.0":"2025-07-16T08:39:03.533Z","3.0.1":"2026-04-20T04:12:18.119Z"},"bugs":{"url":"https://github.com/coffee-and-fun/remove-pii/issues"},"author":{"name":"Coffee & Fun LLC"},"license":"MIT","homepage":"https://github.com/coffee-and-fun/remove-pii#readme","keywords":["PII","privacy","text-processing","data-protection"],"repository":{"type":"git","url":"git+https://github.com/coffee-and-fun/remove-pii.git"},"description":"A Node.js module to remove personally identifiable information (PII) from text.","maintainers":[{"name":"robertjgabriel","email":"robert_gabriel@outlook.com"}],"readme":"# 🔒 @coffeeandfun/remove-pii\n\n**Protect privacy by removing personally identifiable information (PII) from text!**\n\nA Node.js library that automatically detects and removes sensitive information from any string — emails, phone numbers, SSNs, credit cards, addresses, and more. Originally built for [Helperbird](https://helperbird.com) and now used anywhere privacy matters.\n\nCreated with ❤️ by **Robert James Gabriel** at **Coffee & Fun LLC**.\n\n---\n\n## 🎯 Why use this?\n\n**For privacy protection**\n- ✅ Automatically removes sensitive information\n- ✅ Prevents accidental data leaks in logs, analytics, and LLM prompts\n- ✅ Helps with GDPR, HIPAA, and general privacy compliance\n- ✅ Fully customizable per use case\n\n**For developers**\n- ✅ Easy integration — one import, one function call\n- ✅ Zero runtime dependencies\n- ✅ Pure ESM with TypeScript declarations\n- ✅ Detailed analysis and reporting when you need it\n\n---\n\n## 📦 Installation\n\n```bash\nnpm install @coffeeandfun/remove-pii\n```\n\nRequires **Node.js 16 or newer**. The package is pure ESM and ships with TypeScript types out of the box.\n\n---\n\n## 🏃‍♂️ Quick start\n\n```js\nimport { removePII } from '@coffeeandfun/remove-pii';\n\nconst text = \"John's email is john@example.com and his phone is 123-456-7890.\";\nconst cleaned = removePII(text);\n\nconsole.log(cleaned);\n// \"John's email is [email removed] and his phone is [phone removed].\"\n```\n\nThat's it. Three lines.\n\n---\n\n## 🛡️ PII types detected out of the box\n\n| | Type | Example |\n| :-: | --- | --- |\n| 📧 | Email addresses     | `john@example.com`        |\n| 📞 | Phone numbers       | `123-456-7890`, `(555) 123-4567` |\n| 🆔 | Social Security     | `123-45-6789`             |\n| 💳 | Credit cards        | `1234 5678 9012 3456`     |\n| 🏠 | Street addresses    | `123 Main Street`         |\n| 📋 | Passport numbers    | `AB1234567`               |\n| 🚗 | Driver's licenses   | `D123456789`              |\n| 🌐 | IP addresses        | `192.168.1.1`             |\n| 📮 | ZIP codes           | `12345-6789`              |\n| 🏦 | Bank accounts       | `1234567890123456`        |\n| 🔗 | URLs                | `https://example.com`     |\n| 📅 | Dates of birth      | `01/15/1990`              |\n\n> 💡 URLs are detected but **not** removed by default — pass `{ url: { remove: true } }` if you want them gone too.\n\n---\n\n## 📦 What you get back\n\nEvery function takes a `text` string and an optional `options` object. The shape of the return value depends on which function you call:\n\n```js\n// Simple replacement\nremovePII(text)                   // → string\n\n// Cleaned text + metadata\nremovePIIDetailed(text)           // → { cleanedText, removedItems, originalLength, cleanedLength, reductionPercentage }\n\n// Locate without changing\ndetectPII(text)                   // → { text, detectedItems, hasPII, totalMatches, types }\n\n// Full analysis + risk scoring\nanalyzePII(text)                  // → { original, cleaned, pii, risk }\n\n// Compliance check\nvalidatePIICompliance(text)       // → { isCompliant, violations, violationCount, riskLevel, riskScore, recommendations }\n\n// Array of strings\nprocessBatch(texts)               // → BatchResult[]\n```\n\nHere's what a `removePIIDetailed` result actually looks like:\n\n```js\n{\n  cleanedText: 'Email: [email removed]',\n  removedItems: [\n    {\n      type: 'email',\n      count: 1,\n      items: ['john@example.com'],\n      description: 'Email addresses'\n    }\n  ],\n  originalLength: 23,\n  cleanedLength: 20,\n  reductionPercentage: 13\n}\n```\n\n---\n\n## 📚 API reference\n\n### `removePII(text, options?)`\nThe main function — returns the cleaned string.\n\n```js\nconst cleaned = removePII(\"Email: john@example.com, Phone: 123-456-7890\");\n// \"Email: [email removed], Phone: [phone removed]\"\n```\n\n### `removePIIDetailed(text, options?)`\nLike `removePII` but also tells you **what** was removed.\n\n```js\nconst result = removePIIDetailed(\"Email: john@example.com\");\n// {\n//   cleanedText: \"Email: [email removed]\",\n//   removedItems: [{ type: 'email', count: 1, items: ['john@example.com'] }],\n//   originalLength: 23,\n//   cleanedLength: 20,\n//   reductionPercentage: 13\n// }\n```\n\n### `detectPII(text, options?)`\nFind PII **without** changing the text. Each detected item includes `positions` (`start` / `end` / `value`) so you can highlight matches in a UI.\n\n```js\nconst analysis = detectPII(\"Email: john@example.com, Phone: 123-456-7890\");\n// {\n//   text: \"Email: john@example.com, Phone: 123-456-7890\",\n//   hasPII: true,\n//   totalMatches: 2,\n//   types: ['email', 'phone'],\n//   detectedItems: [...]\n// }\n```\n\n### `analyzePII(text, options?)`\nThe full picture — detection + removal + risk scoring all at once. Great for dashboards.\n\n```js\nconst analysis = analyzePII(\"Email: john@example.com, SSN: 123-45-6789\");\n// {\n//   original: { text: \"...\", length: 45, wordCount: 6 },\n//   cleaned:  { text: \"...\", length: 35, wordCount: 6 },\n//   pii:      { detected: [...], totalCount: 2, types: ['email', 'ssn'] },\n//   risk:     { level: 'medium', score: 13 }\n// }\n```\n\n### `validatePIICompliance(text, options?)`\nYes/no compliance check with human-readable recommendations.\n\n```js\nconst compliance = validatePIICompliance(\"Email: john@example.com\");\n// {\n//   isCompliant: false,\n//   violations: [{ type: 'email', count: 1 }],\n//   riskLevel: 'low',\n//   recommendations: ['📧 Email detected - Consider using hashed or masked emails']\n// }\n```\n\n### `processBatch(texts, options?)`\nRuns `removePIIDetailed` over an array. One bad input won't abort the batch — errors come back as `{ success: false, error }`.\n\n### `getAvailableTypes()`\nLists every built-in PII type with its description and default replacement.\n\n### `createCustomPattern(type, pattern, replacement, description)`\nHelper for building a custom-pattern options entry (see [Custom patterns](#-custom-patterns) below).\n\n---\n\n## 🎨 Customization\n\n### Basic configuration\n\nPass an `options` object to enable/disable types and customize replacements. Anything you don't mention keeps its default.\n\n```js\nconst options = {\n  email: { remove: true, replacement: \"[EMAIL HIDDEN]\" },\n  phone: { remove: false },\n  ssn:   { remove: true, replacement: \"[SSN REDACTED]\" }\n};\n\nconst cleaned = removePII(text, options);\n```\n\n### Privacy levels\n\n#### 🔒 High privacy — lock it all down\n\n```js\nconst highPrivacy = {\n  email:          { remove: true },\n  phone:          { remove: true },\n  ssn:            { remove: true },\n  creditCard:     { remove: true },\n  address:        { remove: true },\n  passport:       { remove: true },\n  driversLicense: { remove: true },\n  ipAddress:      { remove: true },\n  zipCode:        { remove: true },\n  bankAccount:    { remove: true },\n  url:            { remove: true },\n  dateOfBirth:    { remove: true }\n};\n```\n\n#### 🛡️ Moderate privacy — financials only\n\n```js\nconst moderatePrivacy = {\n  ssn:         { remove: true },\n  creditCard:  { remove: true },\n  bankAccount: { remove: true },\n  address:     { remove: true },\n  email:       { remove: false },\n  phone:       { remove: false }\n};\n```\n\n#### 🎨 Custom replacements\n\n```js\nconst customReplacements = {\n  email:   { replacement: \"📧 [CONTACT INFO]\" },\n  phone:   { replacement: \"📞 [PHONE NUMBER]\" },\n  address: { replacement: \"🏠 [LOCATION]\" }\n};\n```\n\n### 🧩 Custom patterns\n\nNeed to redact something the library doesn't know about? Drop in your own regex:\n\n```js\nimport { removePII, createCustomPattern } from '@coffeeandfun/remove-pii';\n\nconst options = createCustomPattern(\n  'employeeId',\n  /\\bEMP-\\d{6}\\b/g,\n  '[employee id removed]',\n  'Internal employee IDs'\n);\n\nremovePII('Ticket raised by EMP-123456', options);\n// 'Ticket raised by [employee id removed]'\n```\n\n---\n\n## 🔧 Advanced features\n\n### 📚 Batch processing\n\n```js\nimport { processBatch } from '@coffeeandfun/remove-pii';\n\nconst texts = [\n  \"Email: john@example.com\",\n  \"Phone: 123-456-7890\",\n  \"Regular text\"\n];\n\nconst results = processBatch(texts);\n// [{ index: 0, success: true, cleanedText: ..., removedItems: [...] }, ...]\n```\n\n### ⚖️ Risk assessment\n\n```js\nconst compliance = validatePIICompliance(text);\n\nconsole.log(`Risk Level: ${compliance.riskLevel}`);      // 'low' | 'medium' | 'high' | 'critical'\nconsole.log(`Risk Score: ${compliance.riskScore}`);      // weighted numeric score\nconsole.log(`Recommendations:`, compliance.recommendations);\n```\n\n### 📖 Inspect available types\n\n```js\nimport { getAvailableTypes } from '@coffeeandfun/remove-pii';\n\ngetAvailableTypes().forEach(t => {\n  console.log(`${t.type}: ${t.description}`);\n});\n```\n\n---\n\n## 🎭 Real-world examples\n\n### 🧽 Log sanitization\n\n```js\nimport { removePIIDetailed } from '@coffeeandfun/remove-pii';\n\nexport function sanitize(entry) {\n  const { cleanedText, removedItems } = removePIIDetailed(entry);\n  if (removedItems.length > 0) {\n    console.debug(`🔒 Sanitized ${removedItems.length} PII item(s)`);\n  }\n  return cleanedText;\n}\n```\n\n### 🌐 Express middleware\n\n```js\nimport express from 'express';\nimport { removePII } from '@coffeeandfun/remove-pii';\n\nconst app = express();\napp.use(express.json());\n\napp.post('/logs', (req, res) => {\n  console.log(removePII(req.body.message));\n  res.sendStatus(204);\n});\n```\n\n### 🔄 API response scrubbing\n\n```js\nimport { analyzePII } from '@coffeeandfun/remove-pii';\n\nexport function scrubResponse(body) {\n  const result = analyzePII(JSON.stringify(body));\n  return result.pii.totalCount > 0\n    ? JSON.parse(result.cleaned.text)\n    : body;\n}\n```\n\n### 🧼 Data-cleaning pipeline\n\n```js\nimport { removePII, validatePIICompliance } from '@coffeeandfun/remove-pii';\n\nfunction cleanUserData(input) {\n  const compliance = validatePIICompliance(input);\n  if (!compliance.isCompliant) {\n    console.warn(`⚠️ PII detected: ${compliance.violationCount} violations`);\n    return removePII(input);\n  }\n  return input;\n}\n```\n\n---\n\n## 🧪 Testing\n\n```bash\nnpm test\n```\n\nThe suite covers:\n- ✅ Every built-in PII type and pattern\n- ✅ Edge cases and error handling\n- ✅ Performance and consistency\n- ✅ Batch processing\n- ✅ Custom configurations\n\n---\n\n## 🤝 Contributing\n\nWe welcome contributions!\n\n1. 🐛 **Report issues** — found a bug or a missing PII type?\n2. 💡 **Suggest features** — ideas for better privacy protection?\n3. 🔧 **Submit PRs** — code improvements welcome!\n\n### Dev setup\n\n```bash\ngit clone https://github.com/coffee-and-fun/remove-pii\ncd remove-pii\nnpm install\nnpm test\n```\n\n---\n\n## 📄 License\n\n[MIT](./LICENSE) — feel free to use this in your projects.\n\n---\n\n## 🙏 Credits\n\n**Created with ❤️ by:**\n- **Robert James Gabriel** — Lead Developer\n\n**Originally developed for:**\n- **[Helperbird](https://helperbird.com)** — an accessibility extension making the web more inclusive for everyone\n\n---\n\n## 📞 Support\n\nNeed help protecting privacy in your applications?\n\n- 🐛 **Bug reports:** [GitHub Issues](https://github.com/coffee-and-fun/remove-pii/issues)\n- 💡 **Feature requests:** [GitHub Discussions](https://github.com/coffee-and-fun/remove-pii/discussions)\n- 🔐 **Security issues:** see [SECURITY.md](./SECURITY.md)\n\n**Stay privacy-focused! 🔒**\n","readmeFilename":"README.md"}