Detectors
Built-in detector registry and custom detector creation.
Built-in detectors
pii-mask ships with 31 built-in detectors across seven categories:
- gov-id — SSN, NIN, BVN, Aadhaar, PAN, SA ID, NIK, CPF, Passport, SIN, and more
- financial — credit cards, IBANs
- contact — email, phone numbers (20+ country local formats)
- secret — API keys, JWTs, bcrypt hashes, hex secrets, AWS keys, GitHub PATs, Slack/Stripe tokens
- biometric — dates of birth
- network — IPv4, IPv6, MAC addresses
- identity — person names, addresses, UUIDs, MongoDB ObjectIds, VINs
Registry
All detectors self-register on import. The registry is a singleton shared across the process.
import { registry } from '@pii-mask/core';
const allDetectors = registry.list();
console.log(allDetectors.map((d) => d.id));Custom detectors
import { createMasker, registry } from '@pii-mask/core';
import type { PIIDetector, MaskMode, MaskContext } from '@pii-mask/core';
import { PIICategory, getOrCreateToken } from '@pii-mask/core';
const myDetector: PIIDetector = {
id: 'custom-id',
label: 'Custom ID',
category: PIICategory.GOV_ID,
detect(value) {
return /^CUSTOM-\d{8}$/.test(value);
},
mask(value, mode, ctx) {
if (mode === 'redact') return '[REDACTED]';
if (mode === 'tokenize') return getOrCreateToken(value, ctx);
return `CUSTOM-****${value.slice(-4)}`;
},
};
const masker = createMasker({
mode: 'mask',
extend: [myDetector],
});