@stacktrace-lite/core
Version:
> Parse, filter, and format JavaScript stack traces with plugins for browsers and Node.js.
38 lines (37 loc) • 1.55 kB
TypeScript
import type { StackFrame } from '../parser.js';
/**
* A plugin that masks any detected email addresses in `StackFrame` properties.
*
* @remarks
* This plugin replaces any substring matching a simple email regular expression
* (like `user@example.com`) with a `[email]` placeholder. It operates on:
* - `fileName`
* - `functionName`
*
* Use this to help prevent accidentally logging sensitive email identifiers
* when reporting or transmitting stack frames. While this is a basic approach,
* it’s often sufficient to reduce direct exposure of personal data.
*
* **Note:** Masking PII (Personally Identifiable Information) is part of good
* data handling hygiene, especially when logs may be collected or shared.
* Industry resources confirm that masking PII helps prevent unintended disclosure
* while preserving useful structure.:contentReference[oaicite:1]{index=1}
*
* @param frames - The array of parsed {@link StackFrame} entries.
* @returns A new array of `StackFrame` where any email addresses in the
* `fileName` or `functionName` fields are replaced with `[email]`.
*
* @example
* ```ts
* import { parseStack } from './parser';
* import { piiMaskPlugin } from './plugins';
*
* const frames = parseStack(someError);
* const masked = piiMaskPlugin(frames);
*
* // Example: If a frame.fileName was "src/user/john.doe@example.com.ts",
* // after plugin it becomes "src/user/[email].ts"
* console.log(masked.map(f => f.fileName));
* ```
*/
export declare function piiMaskPlugin(frames: StackFrame[]): StackFrame[];