A comprehensive TypeScript/JavaScript library for handling Personally Identifiable Information (PII) with privacy-first design principles.
Privakit provides enterprise-grade tools for detecting, validating, masking, redacting, and managing personal data in compliance with GDPR, CCPA, and other privacy regulations.
- π Smart PII Detection - Automatically find 17+ types of PII in text using NLP and pattern matching
- β Robust Validation - Validate emails, phones, names, and addresses with international support
- π Safe Masking - Display-safe concealment while preserving usability
- π« Secure Redaction - Complete removal for logging and archival
- βοΈ Policy Engine - GDPR/CCPA compliance automation with audit trails
- π§ Data Normalization - Standardize formats across locales and providers
- π Zero Dependencies - No external API calls, completely local processing
- π¦ Tree Shakable - Import only what you need for optimal bundle size
//: ### Installation
//: npm install privakit # or yarn add privakit # or pnpm add privakit //: ```
import { detectPII, maskPII, createPolicyEngine } from "privakit";
// Detect PII in text
const text = "Contact John Doe at john@example.com or call (555) 123-4567";
const detection = detectPII(text);
console.log(detection.hasPII); // true
console.log(detection.detectedTypes); // ['name', 'email', 'phone']
// Apply safe masking for display
const maskedEmail = maskPII("john@example.com", "email");
console.log(maskedEmail.masked); // "j***@example.com"
// GDPR-compliant policy enforcement
const gdprEngine = createPolicyEngine("gdpr");
const decision = gdprEngine.evaluate("email", "log");
console.log(decision.allowed); // false (protects by default)Personally Identifiable Information (PII) is any data that can identify, contact, or locate an individual. This includes:
- Direct identifiers: Names, emails, phone numbers, SSNs, addresses
- Digital footprints: IP addresses, device IDs, online accounts
- Financial data: Credit cards, bank accounts, payment information
- Behavioral data: Location history, browsing patterns, preferences
-
Legal Compliance π
- GDPR: β¬20M+ fines for violations
- CCPA: $7,500 per violation
- HIPAA, SOX, PCI DSS requirements
-
Security Risks π
- Data breaches affecting millions
- Identity theft and fraud
- Social engineering attacks
-
Business Impact πΌ
- Customer trust and retention
- Reputation management
- Competitive advantage
Module
Purpose
Key Features
Find PII in text
17+ PII types, NLP-powered, confidence scoring
Verify PII correctness
International support, custom rules, batch processing
Hide PII safely
Preserve usability, configurable visibility, role-based
Remove PII completely
Logging safety, middleware, audit trails
Automate compliance
GDPR/CCPA ready, risk-based rules, audit logging
Standardize formats
Locale-aware, provider-specific, consistent data
- π Full Documentation - Complete API reference and guides
- π Quick Start Guide - Get up and running in minutes
- ποΈ Core Concepts - Understanding PII and privacy principles
- βοΈ Installation Guide - Setup for different environments
- π Integration Examples - Real-world usage patterns
- π§π· LGPD Guide (Brazil) - Brazilian data protection compliance
Privakit is built with privacy by design principles:
- No telemetry or tracking - Zero data collection
- Local processing only - No external API calls or network requests
- No data retention - Stateless processing, no persistent storage
- Secure by default - Conservative privacy settings out-of-the-box
- Memory safe - Automatic cleanup of sensitive data
- Error safe - No PII leaked in error messages or logs
- Audit ready - Comprehensive logging and compliance reporting
- Deterministic - Consistent, predictable results
- GDPR Article 25 - Privacy by design and by default
- CCPA Section 1798.100 - Consumer privacy rights
- ISO 27001 - Information security management
- SOC 2 Type II - Security, availability, and confidentiality
Privakit uses carefully selected, privacy-respecting dependencies:
Library
Version
License
Purpose
Privacy Impact
^13.12.0
MIT
Email validation
β Client-side only, no network calls
^1.11.19
MIT
Phone number validation
β Local processing, Google's offline data
^14.14.4
MIT
NLP for name detection
β Pure JavaScript, no remote API
- No Network Activity: All processing happens locally
- Open Source: Full transparency, auditable code
- Established Libraries: Well-maintained, widely used
- MIT Licensed: Compatible with commercial use
- Privacy Focused: No tracking or data collection
import { validateEmail, validatePhone, createPolicyEngine } from 'privakit';async function handleUserRegistration(formData: any) { const policy = createPolicyEngine('gdpr'); // Validate email const emailResult = validateEmail(formData.email); if (!emailResult.isValid) { throw new Error('Invalid email format'); } // Check if processing is allowed const emailDecision = policy.evaluate('email', 'store'); if (!emailDecision.allowed) { throw new Error('Email processing not permitted'); } // Safely store with encryption (as required by policy) if (emailDecision.requiresEncryption) { formData.email = await encryptPII(emailResult.normalized); } return saveUser(formData);}import { createSafeLogger } from "privakit"; // Create PII-safe loggerconst logger = createSafeLogger({ replacement: '[REDACTED]', strictMode: true});// All PII automatically redactedlogger.log('User john@example.com failed login from 192.168.1.100');// Output: "User [REDACTED] failed login from [REDACTED]"import { detectPII, processPII } from 'privakit';function moderateUserContent(content: string) { const result = processPII(content, { policy: createPolicyEngine('strict') }); if (result.policyViolations.length > 0) { return { approved: false, reason: 'Contains sensitive information', safeMasked: result.masked // Safe version for review }; } return { approved: true, content };}// Migrating from custom validation// Before:const isValidEmail = (email) => /S+@S+.S+/.test(email);// After:import { validateEmail } from 'privakit';const emailResult = validateEmail(email);const isValidEmail = emailResult.isValid;Privakit works seamlessly with all major frameworks:
import { detectPII, maskPII } from 'privakit';function UserProfile({ user }) { const maskedEmail = maskPII(user.email, 'email').masked; return ( <div> <span>{maskedEmail}</span> </div> );}<script setup>
import { detectPII, maskPII } from "privakit";
const email = ref("user@example.com");
const maskedEmail = computed(() => maskPII(email.value, "email").masked);
</script>import { detectPII, maskPII } from 'privakit';@Component({...})export class UserComponent { getMaskedEmail(email: string) { return maskPII(email, 'email').masked; }}import { createRedactionMiddleware } from "privakit";
app.use(
createRedactionMiddleware({
strictMode: process.env.NODE_ENV === "production",
}),
);π Complete Framework Guide - Detailed integration examples for React, Vue, Angular, Svelte, Next.js, Nuxt, and more.
- Core library: ~50KB gzipped
- Tree-shakeable: Import only what you need
- Zero runtime dependencies: All deps are for validation/NLP
- Memory efficient: No data retention between calls
- Fast processing: Optimized regex and NLP pipelines
// Minimal import for bundle optimization
import { validateEmail } from "privakit/validate/email";
import { maskEmail } from "privakit/mask";
// Only email validation and masking included in bundleExperience privakit in action with our comprehensive test application! The test app provides a visual interface to explore all privakit features.
Live Demo β (Auto-deployed from main branch)
# Clone the repository
git clone https://github.com/maribeiromendes/privakit.git
cd privakit
# Install dependencies
npm install
# Start the test app (builds and runs privakit + Vue test interface)
npm run dev:test-appThe test app will be available at http://localhost:5175
π§ͺ Interactive Testing Sections:
- π§ Validation & Normalization - Test email, phone, name validation with real-time feedback
- π PII Detection - Analyze text for personal information with confidence scoring
- π Masking & Redaction - Compare display-safe masking vs secure redaction
- βοΈ Policy Engine - Test GDPR/CCPA compliance with strict/permissive modes
- π Locales - International validation testing (phone validation via libphonenumber-js)
- βοΈ Compliance Engines - Test against 6 major privacy regulations with official law links
- π Complete Pipeline - End-to-end PII processing demonstration
- π‘ Examples - Real-world use case scenarios
π Built-in Documentation:
- Step-by-step usage guides for each feature
- Live links to official privacy regulation texts
- Implementation status transparency
- Pro tips and examples
β Fully Implemented:
- PII Detection - 17+ PII types with NLP and pattern matching
- Phone Validation - International support via libphonenumber-js (US, BR, CA, GB, DE, and more)
- Email Validation - Comprehensive validation with domain analysis
- Name Validation - Person name detection and normalization
- Address Validation - Basic address parsing and validation
- Masking & Redaction - Display-safe masking vs secure redaction
- Policy Engine - GDPR/CCPA compliance automation
- Compliance Testing - Multi-regulation validation (GDPR, LGPD, HIPAA, CCPA, PIPEDA, Privacy Act)
π§ In Development:
- Full Locale Support - Country-specific validation rules (currently
/src/locales/folders are placeholders) - Advanced Address Validation - Region-specific address formats
- Cultural Name Patterns - Locale-aware name validation beyond basic patterns
π Planned:
- Biometric Data Detection - Advanced pattern recognition
- Real-time Streaming - Processing live data streams
- Advanced Anonymization - k-anonymity and differential privacy
π We need your help to make privakit better!
π± Test the App:
- Try the test app and report any issues
- Test with real-world data from your use cases
- Suggest new features or improvements
π Deploy the Demo:
- Help us deploy the test app to Vercel, Netlify, or other platforms
- Share the live demo with your team
- Contribute deployment configurations
π» Contribute Code:
- Implement locale-specific validation rules
- Add new PII detection patterns
- Improve compliance engine accuracy
- Enhance documentation
π Get Started Contributing:
# Run the test app locally
npm run dev:test-app
# Run the test suite
npm test
# Check specific functionality
node dev-scripts/validation/test-privacy.jsWe welcome contributions! Please open an issue or submit a pull request.
git clone https://github.com/maribeiromendes/privakit.git
cd privakit
npm install
npm run dev # Start development mode
npm test # Run test suite
npm run build # Build for productionThe dev-scripts/ folder contains organized development and testing utilities:
dev-scripts/debug/- Component-specific debugging scriptsdev-scripts/validation/- Privacy compliance and dependency testingdev-scripts/research/- Pattern research and improvement scriptsdev-scripts/utils/- Build validation and utility scripts
Quick validation commands:
# Verify privacy compliance (CRITICAL before any release)
node dev-scripts/validation/test-privacy.js
# Test basic functionality
node dev-scripts/validation/test-simple.js
# Debug specific components
node dev-scripts/debug/test-phone-debug.jsSee dev-scripts/README.md for detailed documentation on all available scripts.
MIT License - see LICENSE file for details.
For security issues, please report them privately via the GitHub security tab.
Built with β€οΈ for developers who care about privacy.
Privakit - Making PII protection simple, automatic, and compliant.