词光 · Word Atlas — Illustrated IELTS vocabulary with 7,298 words, UK/US audio and FSRS review. Open-source app + CC BY 4.0 dataset.
TypeScript chinesedatasetenglish-learningflashcardsfsrsieltslanguage-learningpwareactspaced-repetitionvocabularywebgl
/** Irregular forms that a stem match would miss ("teach" → "taught"). */
const IRREGULAR = new Map(
"arise arose arisen|awake awoke awoken|bear bore borne born|beat beat beaten|become became|begin began begun beginn|bend bent|bet bet|bind bound|bite bit bitten|bleed bled|blow blew blown|break broke broken|breed bred|bring brought|broadcast broadcast|build built|burn burnt burned|burst burst|buy bought|catch caught|choose chose chosen|cling clung|come came|cost cost|creep crept|cut cut cutt|deal dealt|dig dug|do did done does|draw drew drawn|dream dreamt dreamed|drink drank drunk|drive drove driven|eat ate eaten|fall fell fallen|feed fed|feel felt|fight fought|find found|flee fled|fling flung|fly flew flown flies|forbid forbade forbidden|forget forgot forgotten|forgive forgave forgiven|freeze froze frozen|get got gotten gett|give gave given|go went gone goes|grind ground|grow grew grown|hang hung|have had has|hear heard|hide hid hidden|hit hit hitt|hold held|hurt hurt|keep kept|kneel knelt|know knew known|lay laid|lead led|lean leant leaned|leap leapt leaped|learn learnt learned|leave left|lend lent|let let|lie lay lain|light lit|lose lost|make made|mean meant|meet met|pay paid|prove proved proven|put put putt|quit quit|read read|ride rode ridden|ring rang rung|rise rose risen|run ran runn|say said|see saw seen|seek sought|sell sold|send sent|set set|sew sewed sewn|shake shook shaken|shed shed|shine shone|shoot shot|show showed shown|shrink shrank shrunk|shut shut|sing sang sung|sink sank sunk|sit sat sitt|sleep slept|slide slid|sling slung|speak spoke spoken|speed sped|spend spent|spill spilt spilled|spin spun spinn|spy spied spies|mislead misled|spit spat|split split|spread spread|spring sprang sprung|stand stood|steal stole stolen|stick stuck|sting stung|stink stank stunk|stride strode|strike struck|string strung|strive strove striven|swear swore sworn|sweep swept|swell swelled swollen|swim swam swum swimm|swing swung|take took taken|teach taught|tear tore torn|tell told|think thought|throw threw thrown|tread trod trodden|understand understood|undertake undertook undertaken|upset upset|wake woke woken|wear wore worn|weave wove woven|weep wept|win won winn|wind wound|withdraw withdrew withdrawn|write wrote written|be was were been is are am|child children|man men|woman women|foot feet|tooth teeth|mouse mice|person people|good better best|bad worse worst|far further farther furthest"
.split("|")
.map((row) => row.split(" "))
.map(([base, ...forms]) => [base, forms] as const),
);
/** Find the headword (or an inflected form) inside an example sentence. */
export function headwordPattern(word: string) {
const w = word.trim().toLowerCase();
const esc = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
if (/\s/.test(w)) return new RegExp(`(?<![A-Za-z])(${w.split(/\s+/).map(esc).join("\\s+")})(?![A-Za-z])`, "i");
const irregular = IRREGULAR.get(w);
if (irregular) return new RegExp(`(?<![A-Za-z])((?:${[w, ...irregular].map(esc).join("|")})[a-z]{0,3})(?![A-Za-z])`, "i");
let stem = w;
if (w.length > 3 && /[^aeiou]y$|e$/.test(w)) stem = w.slice(0, -1);
// spin → spinning, stop → stopped
const double = /[^aeiou][aeiou][bdgmnprt]$/.test(w) ? `${esc(w.slice(-1))}?` : "";
return new RegExp(`(?<![A-Za-z])(${esc(stem)}${double}[a-z]{0,4})(?![A-Za-z])`, "i");
}
export function splitHighlight(sentence: string, word: string): [string, string, string] | null {
const m = headwordPattern(word).exec(sentence);
if (!m) return null;
return [sentence.slice(0, m.index), m[0], sentence.slice(m.index + m[0].length)];
}
export function gap(sentence: string, word: string) {
const parts = splitHighlight(sentence, word);
return parts ? { before: parts[0], hidden: parts[1], after: parts[2] } : null;
}
export const normalize = (s: string) =>
s
.normalize("NFKC")
.replace(/[’‘]/g, "'")
.replace(/[‐‑–—]/g, "-")
.replace(/\s+/g, " ")
.trim()
.toLowerCase();
export function shuffle<T>(xs: T[], seed = Math.random() * 2 ** 31): T[] {
const out = [...xs];
let x = Math.floor(seed) || 1;
for (let i = out.length - 1; i > 0; i--) {
x = (Math.imul(1664525, x) + 1013904223) >>> 0;
const j = x % (i + 1);
[out[i], out[j]] = [out[j], out[i]];
}
return out;
}
export function hashSeed(s: string) {
let h = 2166136261;
for (let i = 0; i < s.length; i++) h = Math.imul(h ^ s.charCodeAt(i), 16777619);
return h >>> 0;
}
/** Collocations are stored as "english|中文". */
export const splitPair = (s: string) => {
const [en, zh] = s.split(/[||]/);
return { en: (en || "").trim(), zh: (zh || "").trim() };
};
export const plural = (n: number) => n.toLocaleString("en-US");