@magnusbag/livets-core
Version:
TypeScript API layer for LiveTS framework
78 lines • 2.53 kB
TypeScript
/**
* Utility functions for LiveTS
*/
import type { ComponentId } from './types';
/**
* Escapes HTML to prevent XSS attacks
*/
export declare function escapeHtml(unsafe: string): string;
/**
* Generates a CSS class string from an object
*/
export declare function classNames(classes: Record<string, boolean>): string;
/**
* Creates a reactive template function for rendering
*/
export declare function html(strings: TemplateStringsArray, ...values: any[]): string;
/**
* Marks HTML as safe (bypasses escaping)
*/
export declare function raw(html: string): SafeHtml;
declare class SafeHtml {
private html;
constructor(html: string);
toString(): string;
}
/**
* Debounces a function call
*/
export declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number): (...args: Parameters<T>) => void;
/**
* Throttles a function call
*/
export declare function throttle<T extends (...args: any[]) => any>(func: T, limit: number): (...args: Parameters<T>) => void;
/**
* Deep merges two objects
*/
export declare function deepMerge<T extends Record<string, any>>(target: T, source: Partial<T>): T;
/**
* Validates that a string is a valid CSS selector
*/
export declare function isValidSelector(selector: string): boolean;
/**
* Extracts data attributes from an element
*/
export declare function extractDataAttributes(attributes: Record<string, string>): Record<string, any>;
/**
* Generates a unique ID
*/
export declare function generateId(prefix?: string): string;
/**
* Checks if code is running in the browser
*/
export declare function isBrowser(): boolean;
/**
* Checks if code is running on the server
*/
export declare function isServer(): boolean;
/**
* Injects data-ts-selector attributes into reactive HTML elements
* Identifies elements with ts-on: attributes and common reactive patterns
*/
export declare function injectReactiveSelectors(html: string, componentId: ComponentId): string;
/**
* Enhanced version that also marks elements likely to contain reactive content
* This should be called with component instance context for better detection
*/
export declare function injectReactiveSelectorsSmart(html: string, componentId: ComponentId, stateKeys?: string[]): string;
/**
* Calculates size savings from using compact format
*/
export declare function calculateSavings(verbose: any[], compact: string[]): {
verboseSize: number;
compactSize: number;
savings: number;
percentage: number;
};
export {};
//# sourceMappingURL=utils.d.ts.map