UNPKG

@agentic-intelligence/dom-engine

Version:

Agentic DOM Intelligence - A lightweight TypeScript library for DOM analysis and manipulation, designed for web automation and AI agents

52 lines 1.84 kB
"use strict"; /** * General utilities for the DOM Engine library */ Object.defineProperty(exports, "__esModule", { value: true }); exports.generateUniqueId = generateUniqueId; exports.cleanText = cleanText; exports.filterValidProperties = filterValidProperties; exports.filterStylingClasses = filterStylingClasses; /** * Generates a unique ID using crypto.randomUUID() */ function generateUniqueId() { return crypto.randomUUID(); } /** * Cleans text by removing line breaks and multiple spaces * @param text - Text to clean * @returns Clean text or empty string if null/undefined */ function cleanText(text) { return text?.replace(/\s+/g, ' ').trim() || ''; } /** * Filters object properties by removing empty or null values * @param obj - Object to filter * @returns Object with only valid properties */ function filterValidProperties(obj) { return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== 'N/A' && value !== '' && value != null)); } /** * Filters CSS styling classes, keeping only semantic classes * @param className - CSS class to filter * @returns Filtered class without styles */ function filterStylingClasses(className) { if (!className) return ''; return className .split(' ') .filter(cls => { const trimmed = cls.trim(); // Filter classes that contain typical styling characters return !trimmed.match(/^[a-z]+-[a-z0-9/-]+$|^[a-z]+:\w+|^#[0-9a-f]{3,6}$|^(bg|text|border|w|h|p|m|flex|grid|absolute|relative|rounded|shadow|hover|focus|btn|card|container|row|col)-/) && !['flex', 'grid', 'block', 'hidden', 'visible', 'absolute', 'relative', 'fixed', 'sticky', 'primary', 'secondary', 'success', 'warning', 'error'].includes(trimmed); }) .join(' '); } //# sourceMappingURL=helpers.js.map