mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-19 18:13:41 -05:00
display pound sign if fallback is phone
This commit is contained in:
parent
295d1f156e
commit
b7e79cacf1
1 changed files with 8 additions and 1 deletions
|
@ -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 = (
|
||||
|
|
Loading…
Add table
Reference in a new issue