// Load an HTML file consthtmlContent = fs.readFileSync("./path/to/your/file.html", "utf-8");
// Example 1: Using PRESET_FAST for maximum token reduction // This is ideal when you need to minimize token usage and don't need formatting constfastResult = htmlToAiReady(htmlContent, PRESET_FAST); console.log("FAST MODE RESULT:"); console.log(fastResult); console.log(`Token reduction: ${((fastResult.length/htmlContent.length) *100).toFixed(2)}% of original size`);
// Example 2: Using PRESET_QUALITY for better readability // This preserves more formatting like bold, italic, lists, and headings constqualityResult = htmlToAiReady(htmlContent, PRESET_QUALITY); console.log("\nQUALITY MODE RESULT:"); console.log(qualityResult); console.log(`Token reduction: ${((qualityResult.length/htmlContent.length) *100).toFixed(2)}% of original size`);
// Example 3: Custom configuration, beta! no proper type support yet // You can create your own configuration to fine-tune the behavior constcustomConfig = { // Tags to completely remove with their content tags: ["script", "style", "noscript", "iframe", "svg", "video", "audio", "canvas", "footer"],
// Whether to use simplified markdown formatting useMarkdown:true,
constcustomResult = htmlToAiReady(htmlContent, customConfig); console.log("\nCUSTOM CONFIG RESULT:"); console.log(customResult); console.log(`Token reduction: ${((customResult.length/htmlContent.length) *100).toFixed(2)}% of original size`);
// Example 4: Comparing token usage for AI context functionestimateTokens(text: string): number { // Rough estimate: ~4 characters per token for English text returnMath.ceil(text.length / 4); }
Converts HTML content to a format optimized for AI processing.
This function performs several transformations:
Example