Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

vertex-text.ts

41 lines1.1 KB

1/** Shared text helpers for the Agent Platform docs parsers. */
2​
3const ENTITIES: Record<string, string> = {
4 amp: '&',
5 lt: '<',
6 gt: '>',
7 quot: '"',
8 '#39': "'",
9 apos: "'",
10 nbsp: ' ',
12​
13/** Tags stripped, entities decoded, whitespace collapsed. */
14export function htmlText(html: string): string {
15 return html
16 .replace(/<script[\s\S]*?<\/script>/gi, ' ')
17 .replace(/<style[\s\S]*?<\/style>/gi, ' ')
18 .replace(/<sup[\s\S]*?<\/sup>/gi, '')
19 .replace(/<[^>]+>/g, ' ')
20 .replace(/&([a-z]+|#\d+);/gi, (match, name: string) => {
21 return ENTITIES[name.toLowerCase()] ?? match
22 })
23 .replace(/\s+/g, ' ')
24 .trim()
26​
27/**
28 * Display name → comparison key. Drops preview, parentheticals, and a
29 * trailing introductory-price window so a card title matches its price row.
30 */
31export function normModelName(name: string): string {
32 return name
33 .toLowerCase()
34 .replace(/\*/g, '')
35 .replace(/\([^)]*\)/g, ' ')
36 .replace(/\b(?:through|starting)\b[\s\S]*$/i, ' ')
37 .replace(/\bpreview\b/g, ' ')
38 .replace(/[^a-z0-9]+/g, ' ')
39 .replace(/\s+/g, ' ')
40 .trim()