import { frenchWordListCatalog } from "./index.js"; import type { PolyglotWordListItem } from "@polyglot-bundles/word-list-base"; /** A word entry with a guaranteed stable id */ export type VocabEntry = PolyglotWordListItem & { id: string }; /** Look up a word by its canonical id across all sets in this catalog. */ export async function getVocabById(id: string): Promise { for (const descriptor of frenchWordListCatalog.descriptors) { const set = await descriptor.load(); const word = set.words.find((w) => w.id === id); if (word?.id) return word as VocabEntry; } return undefined; } /** Return all unique vocab entries across all sets, deduped by id. */ export async function getAllVocabEntries(): Promise { const seen = new Set(); const entries: VocabEntry[] = []; for (const descriptor of frenchWordListCatalog.descriptors) { const set = await descriptor.load(); for (const word of set.words) { if (word.id && !seen.has(word.id)) { seen.add(word.id); entries.push(word as VocabEntry); } } } return entries; }