From e3b8f7188f56b974babee734a57491991481bd96 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Thu, 25 Dec 2025 10:28:12 -0500 Subject: [PATCH] Hoist regex to module scope --- script.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/script.js b/script.js index 4e632ad..b8479be 100644 --- a/script.js +++ b/script.js @@ -187,6 +187,8 @@ const resolveTerm = (term) => { return candidates.find((candidate) => entryMap.has(candidate)) || null; }; +const CAPS_TERM_REGEX = /\b[A-Z][A-Z0-9''\-]*(?:\s+[A-Z][A-Z0-9''\-]*)*\b/g; + const linkifyTextNode = (node) => { const text = node.nodeValue; if (!text || !/[A-Z]{2}/.test(text)) { @@ -194,9 +196,9 @@ const linkifyTextNode = (node) => { } const matches = []; - const regex = /\b[A-Z][A-Z0-9'’\-]*(?:\s+[A-Z][A-Z0-9'’\-]*)*\b/g; + CAPS_TERM_REGEX.lastIndex = 0; let match; - while ((match = regex.exec(text)) !== null) { + while ((match = CAPS_TERM_REGEX.exec(text)) !== null) { const raw = match[0]; const cleaned = cleanTerm(raw); const resolved = resolveTerm(cleaned);