@himorishige/noren-core
Version:
Core PII detection, masking, and tokenization library built on Web Standards
17 lines (16 loc) • 527 B
JavaScript
export function defaultMask(h, keepLast4) {
if (keepLast4) {
if (h.type === 'credit_card') {
const last4 = h.value.replace(/\D/g, '').slice(-4);
return `**** **** **** ${last4}`;
}
else {
// For other types, preserve last 4 characters
const last4 = h.value.slice(-4);
return `[REDACTED:${h.type}]${last4}`;
}
}
if (h.type === 'phone_e164')
return h.value.replace(/\d/g, '•');
return `[REDACTED:${h.type}]`;
}