add telephone link

This commit is contained in:
Timi
2026-08-03 01:27:46 +08:00
parent 2f9442e4a2
commit cd1b45eb24
13 changed files with 128 additions and 36 deletions
+25
View File
@@ -0,0 +1,25 @@
export function normalizeTelephone(value?: string): string {
if (!value) {
return "";
}
const trimmedValue = value.trim();
if (!trimmedValue) {
return "";
}
const normalizedValue = trimmedValue.startsWith("+")
? `+${trimmedValue.slice(1).replace(/\D/g, "")}`
: trimmedValue.replace(/\D/g, "");
return normalizedValue === "+" ? "" : normalizedValue;
}
export function canDialTelephone(value?: string): boolean {
const normalizedValue = normalizeTelephone(value);
return 2 < normalizedValue.replace("+", "").length;
}
export function buildTelephoneURL(value?: string): string {
const normalizedValue = normalizeTelephone(value);
return normalizedValue ? `tel:${normalizedValue}` : "";
}