guardz-event
Version:
Type-safe event handling with runtime validation using guardz for unsafe data from 3rd parties
42 lines • 1.41 kB
TypeScript
import type { ErrorContext } from '../../utils/safe-event-never-throws';
/**
* Utility functions for event handling
*/
export declare class EventUtils {
/**
* Create a standardized error context
*/
static createErrorContext(type: ErrorContext['type'], eventType: string, options?: Partial<Omit<ErrorContext, 'type' | 'eventType'>>): ErrorContext;
/**
* Check if an event is null or undefined
*/
static isNullEvent(event: unknown): event is null | undefined;
/**
* Check if data is null or undefined
*/
static isNullData(data: unknown): data is null | undefined;
/**
* Extract event type safely
*/
static getEventType(event: Event | MessageEvent | CustomEvent | StorageEvent): string;
/**
* Extract origin safely from MessageEvent
*/
static getOrigin(event: MessageEvent): string | undefined;
/**
* Validate security origins
*/
static validateOrigin(origin: string | undefined, allowedOrigins: string[] | undefined): {
isValid: boolean;
error?: string;
};
/**
* Create a standardized error message
*/
static createErrorMessage(baseMessage: string, identifier?: string, details?: string): string;
/**
* Safely extract error message from unknown error
*/
static extractErrorMessage(error: unknown): string;
}
//# sourceMappingURL=EventUtils.d.ts.map