${escapeHtml(p.title)}
${escapeHtml(p.description)}
$${p.price.toFixed(2)}- ${tags}
// Server-side HTML rendering: template literals, escaping, joins, and // conditional fragments over a list of typed view models. interface Product { id: number; title: string; description: string; price: number; tags: string[]; inStock: boolean; rating: number; } let seed = 31337; function random(): number { seed = (Math.imul(seed, 1103515245) + 12345) >>> 0; return seed / 4294967296; } const words = ["fast", "durable", "bold", "eco", '"quoted"', "light", "smart", "R&D", "classic", "modern"]; function sentence(n: number): string { const parts: string[] = []; for (let i = 0; i < n; i++) parts.push(words[Math.floor(random() * words.length)]!); return parts.join(" "); } function makeProducts(count: number): Product[] { const products: Product[] = []; for (let i = 0; i < count; i++) { products.push({ id: i, title: sentence(3), description: sentence(20), price: Math.round(random() * 100000) / 100, tags: [words[i % words.length]!, words[(i * 7) % words.length]!], inStock: random() < 0.8, rating: Math.round(random() * 50) / 10, }); } return products; } function escapeHtml(text: string): string { return text.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """); } function stars(rating: number): string { let out = ""; for (let i = 1; i <= 5; i++) out += i <= Math.round(rating) ? "*" : "-"; return out; } function renderProduct(p: Product): string { const tags = p.tags.map((t) => `
${escapeHtml(p.description)}
$${p.price.toFixed(2)}