import catalogData from './tool-catalog.json'; import popularData from '../home/home-popular.json'; import { toolStatus } from './tool-status'; import { WORDSTAR_EXTENSIONS, isAmiPro, looksWordStar } from '../works-viewer/old-text-sniff'; import { STAR_EXTENSIONS, headHasStarStream, isCompoundFile } from '../works-viewer/star-sniff'; /** * The words people use for each tool, the file types it opens, when it was * added and where to go next. Feeds the site search, the Open a file page, the * home page rows and the Next step links. Where a tool does its work is in * tool-status.json, which is small enough to ship on every page. */ export interface CatalogEntry { path: string; name: string; /** One short line, for a search result. */ summary: string; /** File types the tool opens, lowercase with the dot. */ extensions: string[]; /** Words people type when looking for it, beyond its own name. */ aliases: string[]; /** When the tool went into the repo (YYYY-MM-DD), for Recently added on the home page. */ added: string; /** Tools to carry on with, and why, shown above the tool's notes. */ next?: { path: string; why: string }[]; } export const CATALOG = catalogData as CatalogEntry[]; const BY_PATH = new Map(CATALOG.map((e) => [e.path, e])); export function catalogEntry(path: string): CatalogEntry | undefined { return BY_PATH.get(path); } /** * Pages merged into the tool that does the same job (1 Nov 2026), old route to * new. The old addresses redirect (nginx.conf, app.routes.ts); this keeps an * old What's new line naming the tool it now belongs to. */ export const MERGED: Readonly> = { 'mp3-cutter': 'audio-trimmer', 'key-changer': 'pitch-changer', 'open-file/vmdk': 'open-file/vhd', 'open-file/djvu': 'djvu-to-pdf', 'xps-to-pdf': 'open-file/xps', 'pdf-to-png': 'pdf-to-jpg', 'json-to-csv': 'json-to-excel', 'xml-to-excel': 'json-to-excel', 'excel-to-json': 'json-to-excel', 'mp4-to-mp3': 'video-converter', 'video-to-gif': 'video-converter', 'gif-to-mp4': 'video-converter', 'compress-video-for-discord': 'video-converter', 'ringtone-maker': 'audio-trimmer', 'bank-statement-converter': 'pdf-to-excel', 'pdf-to-mp3': 'text-to-speech', 'compress-pdf': 'pdf-toolkit', 'unlock-pdf': 'pdf-toolkit', 'remove-blank-pages-from-pdf': 'pdf-toolkit', 'bates-numbering': 'pdf-toolkit', 'pdf-booklet': 'pdf-toolkit', 'jpg-to-pdf': 'pdf-toolkit', 'repair-pdf': 'pdf-toolkit', 'compare-pdf': 'pdf-toolkit', 'pdf-to-tiff': 'pdf-to-jpg', 'tiff-to-pdf': 'open-file/tiff', 'create-fillable-pdf': 'sign-pdf', 'excel-to-pdf': 'excel-viewer', 'mic-test': 'webcam-test', }; /** * Generic tools retired on 12 Nov 2026 (no traffic, and they made the site * read as a pile of generic utilities rather than file tools), old route to * where it now goes: a category page, or the nearest file tool. Unlike a * merged page, nothing of the old tool lives on at the target, so its visitors * are not counted there. The components stay in the repo, unrouted; the old * addresses redirect (nginx.conf, app.routes.ts) and have left the catalog, * groups, menu, home cards, families and seo-data. */ export const RETIRED: Readonly> = { 'voice-recorder': 'audio-tools', 'metronome': 'audio-tools', 'guitar-tuner': 'audio-tools', 'remove-silence': 'audio-trimmer', 'image-resizer': 'image-tools', 'svg-to-png': 'image-tools', 'webp-to-gif': 'image-tools', 'blur-background': 'blur-faces', 'address-labels': 'text-tools', 'timesheet-calculator': 'text-tools', 'word-cloud': 'text-tools', 'citation-generator': 'text-tools', 'wheel-spinner': 'developer-tools', }; /** * The names the retired tools went by, for old What's new lines about them: * they have left the catalog, so currentEntry() finds nothing. The line's link * still goes to the old address, which redirects (RETIRED), as a merged page's * line does. */ export const RETIRED_NAMES: Readonly> = { 'voice-recorder': 'Voice Recorder', 'metronome': 'Metronome', 'guitar-tuner': 'Guitar Tuner', 'remove-silence': 'Remove Silence', 'image-resizer': 'Image Resizer', 'svg-to-png': 'SVG to PNG', 'webp-to-gif': 'WebP to GIF', 'blur-background': 'Blur Background', 'address-labels': 'Address Labels', 'timesheet-calculator': 'Timesheet Calculator', 'word-cloud': 'Word Cloud Generator', 'citation-generator': 'Citation Generator', 'wheel-spinner': 'Wheel Spinner', }; /** The name an old What's new line shows: the tool now, or a retired tool's old name. */ export function toolLabel(path: string): string { return currentEntry(path)?.name ?? RETIRED_NAMES[path] ?? `/${path}`; } /** The catalog entry for a route, following a merged page to its tool. */ export function currentEntry(path: string): CatalogEntry | undefined { return BY_PATH.get(MERGED[path] ?? path); } /** * The home page's Popular row: the tools with the most visitors (bots left * out) over the last 30 days, written to home/home-popular.json by * scripts/order-tools.mjs (fed by scripts/refresh-popular.ps1). Read at build * time, so the prerendered home page already shows it. */ const POPULAR: string[] = popularData.tools; export const POPULAR_TOOLS = POPULAR.map((p) => BY_PATH.get(p)).filter((e): e is CatalogEntry => !!e); /** * The main tool for the common types several tools take (a .docx is read by * the DOC Viewer, not repaired by Repair Office File): where the home page's * drop box sends a file, and first in "Open in…". */ const OPEN_WITH: Record = { pdf: 'pdf-toolkit', doc: 'doc-viewer', docx: 'doc-viewer', rtf: 'doc-viewer', odt: 'doc-viewer', xls: 'excel-viewer', xlsx: 'excel-viewer', xlsm: 'excel-viewer', ods: 'excel-viewer', csv: 'csv-toolkit', tsv: 'csv-toolkit', ppt: 'pptx-viewer', pps: 'pptx-viewer', pot: 'pptx-viewer', pptx: 'pptx-viewer', odp: 'pptx-viewer', jpg: 'image-toolkit', jpeg: 'image-toolkit', png: 'image-toolkit', webp: 'image-toolkit', gif: 'image-toolkit', bmp: 'image-toolkit', avif: 'image-toolkit', tif: 'image-toolkit', tiff: 'image-toolkit', heic: 'heic-to-jpg', heif: 'heic-to-jpg', svg: 'svg-optimizer', mp4: 'video-cutter', mov: 'video-cutter', m4v: 'video-cutter', mkv: 'video-cutter', webm: 'video-cutter', avi: 'video-converter', wmv: 'video-converter', flv: 'video-converter', mp3: 'audio-trimmer', wav: 'audio-trimmer', m4a: 'audio-trimmer', flac: 'audio-trimmer', ogg: 'audio-trimmer', opus: 'audio-trimmer', aac: 'audio-trimmer', wma: 'audio-trimmer', mts: 'video-converter', m2ts: 'video-converter', aif: 'video-converter', aiff: 'video-converter', amr: 'video-converter', '3ga': 'video-converter', zip: 'archive-toolkit', rar: 'archive-toolkit', '7z': 'archive-toolkit', tar: 'archive-toolkit', gz: 'archive-toolkit', json: 'json-toolkit', jsonl: 'json-to-excel', ndjson: 'json-to-excel', md: 'markdown-toolkit', txt: 'text-toolkit', html: 'html-to-markdown', htm: 'html-to-markdown', xml: 'format-converter', // A .bin is as often firmware or a program's data as a disc image: the File Opener looks at its bytes first. bin: 'open-file', eml: 'msg-viewer', ics: 'ics-viewer', sqlite: 'sql-playground', db: 'sql-playground', srt: 'subtitle-fixer', vtt: 'subtitle-fixer', }; /** * Extensions two unrelated formats share, where only the first bytes say * which it is: a DJI drone's low-resolution .lrf copy is an MP4, a Sony * Reader's .lrf a BBeB e-book (L\0R\0F\0). A tool listing one takes the file by * its name only when the bytes are its kind; with no bytes to go by (the home * page's drop box, an Open in menu) it is left to the File Opener, which looks. */ const BYTES_DECIDE: Record boolean> = { '.lrf': (h) => h.length >= 8 && h[4] === 0x66 && h[5] === 0x74 && h[6] === 0x79 && h[7] === 0x70, // A Palm database that is an e-book (Kindle, PalmDOC, zTXT, eReader), not a Windows debug .pdb or another Palm app's data. '.pdb': (h) => h.length >= 78 && /^(BOOKMOBI|TEXtREAd|TEXtTlDc|zTXTGPlm|PNRdPPrs|DataPPrs)$/.test(String.fromCharCode(...h.subarray(60, 68))), // A Psion text e-book: "!!8-Bit!!" first. '.tcr': (h) => String.fromCharCode(...h.subarray(0, 9)) === '!!8-Bit!!', // A Lotus Ami Pro document ("[ver]" ... "[sty]"), not a genomics alignment (Sequence Alignment/Map) file. '.sam': isAmiPro, // WordStar: its 5.0+ header, or WordStar's marks in the text (works-viewer/old-text-sniff.ts); never plain text. ...Object.fromEntries(WORDSTAR_EXTENSIONS.map((x) => [x, (h: Uint8Array) => looksWordStar(h, true, x)])), // StarOffice 3-5.2 files are compound (OLE) files; a text .sdc is a Synopsys design-constraints file. // A .vor is also a StarDraw or StarImpress template, which the Works Viewer does not open: its directory must name a Writer or Calc stream. ...Object.fromEntries(STAR_EXTENSIONS.map((x) => [x, x === '.vor' ? headHasStarStream : isCompoundFile])), }; /** Whether the file's name is one of BYTES_DECIDE's, and its first bytes (if known) are not that tool's kind. */ export function nameMisleads(fileName: string, head?: Uint8Array | null): boolean { const name = fileName.trim().toLowerCase(); const test = Object.entries(BYTES_DECIDE).find(([x]) => name.endsWith(x))?.[1]; return !!test && !(head && test(head)); } /** The tool a file goes to by default: the main one for its type, else the first that opens it. */ export function primaryToolPath(fileName: string, head?: Uint8Array | null): string | undefined { const name = fileName.trim().toLowerCase(); const ext = name.includes('.') ? name.slice(name.lastIndexOf('.') + 1) : ''; if (nameMisleads(name, head)) return undefined; return OPEN_WITH[ext] ?? CATALOG.find((c) => c.extensions.includes('.' + ext))?.path; } /** * The newest tools, newest first, for Recently added. Format pages under * /open-file/ are left out: they are kept off the home page by design, and * reached from /open-file instead. */ export function recentTools(count: number): CatalogEntry[] { return CATALOG.filter((e) => toolStatus(e.path)?.processing !== 'download' && !e.path.startsWith('open-file/')) .sort((a, b) => b.added.localeCompare(a.added) || a.name.localeCompare(b.name)) .slice(0, count); } export interface SearchHit { entry: CatalogEntry; /** The alias or file type that matched, when the name and summary did not. */ via: string; } const words = (text: string) => text.toLowerCase().split(/[^a-z0-9+#.]+/).filter(Boolean); /** * Words people type around what they need ("my pdf is locked", "the file won't * open") that name no tool. Search needs every word to match, so these are left * out first; "to" stays, since "pdf to word" and "word to pdf" differ by it. */ const FILLER = new Set([ 'a', 'an', 'the', 'my', 'i', 'me', 'is', 'are', 'was', 'it', 'its', 'this', 'that', 'of', 'for', 'with', 'in', 'on', 'and', 'or', 'how', 'do', 'does', 'can', 'cant', 'cannot', 'won', 'wont', 'don', 'dont', 'doesn', 'doesnt', 'isn', 'isnt', 't', 's', 'not', 'too', 'very', 'need', 'want', 'please', 'help', 'file', 'files', 'online', 'free', ]); /** "pdfs" finds PDF tools and "duplicates" finds "remove duplicate lines". */ const singular = (term: string) => (term.length > 3 && term.endsWith('s') && !term.endsWith('ss') ? term.slice(0, -1) : term); /** * How well one word of a query fits a tool: the start of a word in the name, * a file type (with or without the dot), an alias or the summary, in that * order of weight. 0 when it fits nowhere. */ function fit(entry: CatalogEntry, term: string): { score: number; via: string } { const nameWords = words(entry.name); let best = 0; let via = ''; if (nameWords.some((w) => w === term)) best = 12; else if (nameWords.some((w) => w.startsWith(term))) best = 10; const ext = entry.extensions.find((x) => x.slice(1) === term); if (ext && best < 9) [best, via] = [9, ext]; for (const alias of entry.aliases) { const s = alias === term ? 8 : words(alias).some((w) => w.startsWith(term)) ? 6 : 0; if (s > best) [best, via] = [s, alias]; } if (!best && words(entry.summary).some((w) => w.startsWith(term))) best = 3; return { score: best, via }; } /** * Tools matching every meaningful word of the query, best first. Each word is * tried as typed and without a plural s, so "pages" still finds .pages files. */ export function searchCatalog(query: string): SearchHit[] { const typed = words(query).map((t) => t.replace(/^\.+/, '')).filter(Boolean); if (!typed.length) return []; // A query of nothing but filler ("file") is still searched as typed. const meaningful = typed.filter((t) => !FILLER.has(t)); const terms = meaningful.length ? meaningful : typed; const hits: (SearchHit & { score: number })[] = []; for (const entry of CATALOG) { let score = 0; let via = ''; let all = true; for (const term of terms) { const asTyped = fit(entry, term); const one = singular(term); const best = one !== term ? [asTyped, fit(entry, one)].reduce((a, b) => (b.score > a.score ? b : a)) : asTyped; if (!best.score) { all = false; break; } score += best.score; if (best.via && !via) via = best.via; } // A phrase alias typed in full ("open pst without outlook") beats its parts. const phrase = typed.join(' '); if (all && entry.aliases.includes(phrase)) score += 5; if (all) hits.push({ entry, via, score }); } return hits.sort((a, b) => b.score - a.score || a.entry.name.localeCompare(b.entry.name)); } /** * The tools that open a file with this name. Matched on the end of the name, * so .fit.gz counts. `head`, the file's first bytes: given (or null, when * they cannot be known), a name whose bytes decide (BYTES_DECIDE) is not * matched unless they agree; left out, every tool listing the name counts * (a search for ".lrf"). */ export function toolsForFile(fileName: string, head?: Uint8Array | null): CatalogEntry[] { const name = fileName.trim().toLowerCase(); const misleads = head !== undefined && nameMisleads(name, head); return CATALOG.filter((e) => e.extensions.some((x) => name.endsWith(x) && !(misleads && x in BYTES_DECIDE))); } /** Tools listed in the menu before it would get long. */ const MAX_TOOLS = 6; /** * The tools a file can be opened in here: the main one for its type first * (the one the home page's drop box picks), then the popular ones, then the * more specialised (fewer file types) before the general, and never the tool * the file is in already. The File Opener, which works out any file's type * from its contents, is offered beside them by the button. `head`: the * file's first bytes, when known (toolsForFile). */ export function toolsFor(name: string, exclude: string[] = [], head: Uint8Array | null = null): CatalogEntry[] { const popular = new Set(POPULAR_TOOLS.map((t) => t.path)); const main = primaryToolPath(name, head); const takes = toolsForFile(name, head); // The main tool for a type can take it without listing it (the Text Toolkit and .txt). const first = main && BY_PATH.get(main); if (first && !takes.includes(first)) takes.unshift(first); return takes .filter((t) => !exclude.includes(t.path)) .sort((a, b) => Number(b.path === main) - Number(a.path === main) || Number(popular.has(b.path)) - Number(popular.has(a.path)) || a.extensions.length - b.extensions.length || a.name.localeCompare(b.name)) .slice(0, MAX_TOOLS); } /** * ".pst" from "Archive 2019.PST", or "" when there is none. A two-part type * a tool lists (.fit.gz) wins over its last part. */ export function extensionOf(fileName: string): string { const name = fileName.trim().toLowerCase(); const known = CATALOG.flatMap((e) => e.extensions).filter((x) => name.endsWith(x) && name !== x); if (known.length) return known.reduce((a, b) => (b.length > a.length ? b : a)); const m = /(\.[a-z0-9]+)$/.exec(name); return m ? m[1] : ''; }