add telephone link
This commit is contained in:
@@ -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}` : "";
|
||||
}
|
||||
Reference in New Issue
Block a user