From b7e79cacf18b0547623ec9724100a3660c93d034 Mon Sep 17 00:00:00 2001 From: Zach Russell Date: Thu, 20 Mar 2025 20:39:46 -0600 Subject: [PATCH] display pound sign if fallback is phone --- web/src/api/media.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/web/src/api/media.ts b/web/src/api/media.ts index d6f12d3..ff20468 100644 --- a/web/src/api/media.ts +++ b/web/src/api/media.ts @@ -74,8 +74,15 @@ function getFallbackCharacter(from: unknown, idx: number): string { if (!from || typeof from !== "string" || from.length <= idx) { return "" } + // Array.from appears to be the only way to handle Unicode correctly - return Array.from(from.slice(0, (idx + 1) * 2))[idx]?.toUpperCase().toWellFormed() ?? "" + const fallbackCharacter = Array.from(from.slice(0, (idx + 1) * 2))[idx]?.toUpperCase().toWellFormed() ?? ""; + + // if it's a phone number, return "#" + // * - Any digit (`\d`) - phone numbers + // * - `(` - US Area Codes can start with parens + // * - `+` - international phone numbers + return fallbackCharacter.match(/[\d(+]/) ? "#" : fallbackCharacter } export const getAvatarURL = (