email-scrubber-core
Version:
A privacy-focused email sanitizer that removes trackers and cleans URLs, powered by the ClearURLs ruleset.
106 lines • 3.52 kB
TypeScript
/**
* A generic interface representing an element that can be sanitized.
* This allows the logic to work with different HTML parsing backends,
* such as `linkedom` for buffered parsing and `HTMLRewriter` for streaming.
*/
export interface SanitizableElement {
getAttribute(name: string): string | null;
hasAttribute(name: string): boolean;
removeAttribute(name: string): void;
setAttribute(name: string, value: string): void;
remove(): void;
}
/**
* Configuration options for the TrackerPixelRemover.
*/
export interface TrackerPixelRemoverOptions {
/**
* Maximum width/height in pixels to consider as a tracking pixel.
* Default: 2
*/
maxPixelSize?: number;
/**
* Known tracking domains to remove images from.
*/
trackingDomains?: string[];
/**
* Query parameters that indicate tracking.
*/
trackingParams?: string[];
/**
* Whether to remove images with no alt text (common for tracking pixels).
* Default: true
*/
removeNoAltImages?: boolean;
/**
* Whether to remove transparent images (common for tracking pixels).
* Default: true
*/
removeTransparentImages?: boolean;
}
/**
* A class for removing tracking pixels from email HTML content.
*/
export declare class TrackerPixelRemover {
private readonly options;
/**
* Creates an instance of the TrackerPixelRemover.
* @param options Configuration options for the tracker pixel remover.
*/
constructor(options?: TrackerPixelRemoverOptions);
/**
* Removes tracking pixels from a DOM document.
* @param document The DOM document to clean.
* @returns The number of tracking pixels removed.
*/
clean(document: Document): number;
/**
* Determines if an image element is likely a tracking pixel.
* @param img The image element to analyze.
* @returns True if the image is likely a tracking pixel.
*/
isTrackingPixel(img: SanitizableElement): boolean;
/**
* Checks if an image has tracking pixel dimensions.
* @param img The image element to check.
* @returns True if the image has tracking pixel dimensions.
*/
private hasTrackingPixelDimensions;
/**
* Checks if an image source contains a known tracking domain.
* @param img The image element to check.
* @returns True if the image source contains a tracking domain.
*/
private hasTrackingDomain;
/**
* Checks if an image URL contains tracking parameters.
* @param img The image element to check.
* @returns True if the image URL contains tracking parameters.
*/
private hasTrackingParameters;
/**
* Checks if an image has no alt text.
* @param img The image element to check.
* @returns True if the image has no alt text.
*/
private hasNoAltText;
/**
* Checks if an image appears to be transparent.
* @param img The image element to check.
* @returns True if the image appears to be transparent.
*/
private isTransparent;
/**
* Checks if an image is hidden via CSS.
* @param img The image element to check.
* @returns True if the image is hidden.
*/
private isHidden;
/**
* Parses a dimension string and returns a number or null.
* @param dimension The dimension string to parse.
* @returns The parsed dimension or null if invalid.
*/
private getDimension;
}
//# sourceMappingURL=TrackerPixelRemover.d.ts.map