/* Player-name normalization (Session 46, completed Session 47) — frontend copy of src/utils/playerName.js (the Next bundle can't import from src/). Keep the two IDENTICAL; a test cross-checks they agree. CommonJS so .tsx imports it AND Jest requires it directly. */ const SUFFIXES = new Set(['jr', 'sr', 'ii', 'iii', 'iv', 'v']); const NICKNAMES = { matt: 'matthew', mike: 'michael', chris: 'christopher', jake: 'jacob', josh: 'joshua', nick: 'nicholas', nate: 'nathaniel', dan: 'daniel', danny: 'daniel', dave: 'david', rob: 'robert', bob: 'robert', joe: 'joseph', joey: 'joseph', jon: 'jonathan', johnny: 'john', tony: 'anthony', alex: 'alexander', andy: 'andrew', drew: 'andrew', ben: 'benjamin', will: 'william', bill: 'william', billy: 'william', willy: 'william', zach: 'zachary', zack: 'zachary', tom: 'thomas', tommy: 'thomas', ty: 'tyler', ed: 'edward', eddie: 'edward', teddy: 'theodore', charlie: 'charles', chuck: 'charles', rick: 'richard', dick: 'richard', jim: 'james', jimmy: 'james', ray: 'raymond', fred: 'frederick', kenny: 'kenneth', sam: 'samuel', pat: 'patrick', greg: 'gregory', steve: 'steven', tim: 'timothy', frank: 'francis', }; function normalizeName(raw) { const display = String(raw == null ? '' : raw) .replace(/\s*\([^)]*\)\s*/g, ' ') .replace(/\./g, '') .replace(/\s+/g, ' ') .trim(); const folded = display.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase(); const key = folded.split(' ').filter((t) => t && !SUFFIXES.has(t)).join(' '); return { display, key }; } function nameKey(raw) { const { key } = normalizeName(raw); const parts = key.split(/\s+/).filter(Boolean); if (parts.length >= 2 && NICKNAMES[parts[0]]) parts[0] = NICKNAMES[parts[0]]; return parts.join(' '); } module.exports = { normalizeName, nameKey, SUFFIXES, NICKNAMES };