houser-js-utils
Version:
A comprehensive collection of TypeScript utility functions for common development tasks including array manipulation, string processing, date handling, random number generation, validation, and much more.
95 lines (94 loc) • 3.15 kB
TypeScript
/**
* @module PerformanceUtils
* @description A collection of utility functions for performance monitoring, timing, and optimization.
* @example
* ```typescript
* import { PerformanceUtils } from 'houser-js-utils';
*
* // Measure execution time
* const timer = PerformanceUtils.startTimer();
* // ... some operation
* const elapsed = PerformanceUtils.endTimer(timer);
*
* // Get memory usage
* const memoryInfo = PerformanceUtils.getMemoryUsage();
* ```
*/
export declare const PerformanceUtils: {
/**
* Clears all performance marks and measures
*/
clearMarksAndMeasures(): void;
/**
* Creates a performance observer
* @param callback - Function to call when performance entries are observed
* @param entryTypes - Types of entries to observe
* @returns Performance observer
*/
createPerformanceObserver(callback: (entries: PerformanceObserverEntryList) => void, entryTypes: string[]): PerformanceObserver;
/**
* Gets the cumulative layout shift
* @returns Promise resolving to CLS score
*/
getCumulativeLayoutShift(): Promise<number>;
/**
* Gets the DOM content loaded time
* @returns Promise resolving to DOM content loaded time in milliseconds
*/
getDomContentLoadedTime(): Promise<number>;
/**
* Gets the first contentful paint time
* @returns Promise resolving to FCP time in milliseconds
*/
getFirstContentfulPaint(): Promise<number>;
/**
* Gets the first input delay
* @returns Promise resolving to FID time in milliseconds
*/
getFirstInputDelay(): Promise<number>;
/**
* Gets the largest contentful paint time
* @returns Promise resolving to LCP time in milliseconds
*/
getLargestContentfulPaint(): Promise<number>;
/**
* Gets the page load time
* @returns Promise resolving to page load time in milliseconds
*/
getPageLoadTime(): Promise<number>;
/**
* Gets the time to first byte (TTFB)
* @returns Promise resolving to TTFB in milliseconds
*/
getTimeToFirstByte(): Promise<number>;
/**
* Creates a performance mark
* @param name - Name of the mark
*/
mark(name: string): void;
/**
* Measures the execution time of a function
* @param fn - Function to measure
* @param iterations - Number of iterations to run
* @returns Object containing execution time statistics
*/
measureExecutionTime<T>(fn: () => T, iterations?: number): {
result: T;
time: number;
averageTime: number;
};
/**
* Measures the time between two marks
* @param startMark - Name of the start mark
* @param endMark - Name of the end mark
* @returns Object containing measurement details
*/
measure(startMark: string, endMark: string): PerformanceEntry | null;
/**
* Throttles a function
* @param fn - Function to throttle
* @param limit - Time limit in milliseconds
* @returns Throttled function
*/
throttle<T extends (...args: any[]) => any>(fn: T, limit: number): (...args: Parameters<T>) => void;
};