@lacspace/redact
v1.0.3
Published
Redact secrets & PII from strings and objects before logging — masks sensitive keys and patterns (JWTs, API keys, emails, cards, IPs). Safe AWS/Mongo logs. Zero-dependency, isomorphic.
Maintainers
Readme
@lacspace/redact
Redact secrets & PII from strings and objects before you log them.
The last line of defence against leaking secrets into CloudWatch, Mongo logs or your error tracker. Masks values by sensitive key name (
password,token,authorization…) and by pattern (JWTs, API keys, emails, credit cards, IPs) — deeply, on strings and objects.
- 🕵️
redact()— deep, clones input, masks keys + patterns - 🧵
redactString()— scrub a single log line - 🎭
maskEmail/maskString - 🔧 Custom keys, disable specific patterns, custom mask
- ⚡ Zero dependencies · 🌍 isomorphic · fully typed
Install
npm install @lacspace/redactUsage
import { redact, redactString, createRedactor } from "@lacspace/redact";
redact({
email: "[email protected]",
password: "hunter2",
headers: { authorization: "Bearer eyJhbG.eyJz.sig" },
card: "4242 4242 4242 4242",
});
// { email: "j•••@example.com", password: "[REDACTED]",
// headers: { authorization: "[REDACTED]" }, card: "[REDACTED]" }
redactString("token=eyJhbG.eyJz.sig for user [email protected]");
// "token=[REDACTED_JWT] for user a•••@b.com"
// bind once, use as a logger serializer
const scrub = createRedactor({ keys: ["x-internal-token"] });
logger.info(scrub(requestContext));API
| Export | Description |
| --- | --- |
| redact(input, opts?) | deep-redact a string or object |
| redactString(str, opts?) | pattern-scrub a string |
| createRedactor(opts?) | pre-bound redactor |
| maskEmail / maskString | targeted masks |
| SENSITIVE_KEYS | the default key list (extend via opts.keys) |
The Lacspace Security Kit
| Package | For |
| --- | --- |
| @lacspace/crypto | AES encryption & hashing |
| @lacspace/password | Password hashing |
| @lacspace/jwt | JWTs & tokens |
| @lacspace/apikey | API keys |
| @lacspace/otp | TOTP/HOTP 2FA |
| @lacspace/webauthn | Passkeys / biometric |
| @lacspace/mfa | 2FA/3FA orchestration |
| @lacspace/lock | Account lockout |
| @lacspace/headers | Secure headers / CSP |
| @lacspace/redact | Log redaction (this package) |
Licensing
This package is free under the Lacspace Free Licence — MIT-equivalent freedoms. Use it in personal and commercial projects at no cost; just keep the notice.
Not every Lacspace package is free. We also offer Commercial (paid), Client-specific, and Private (proprietary) packages under separate terms. See the full Lacspace Licence Centre.
Part of the Lacspace ecosystem — 35 zero-dependency, isomorphic TypeScript packages.
