26 lines
708 B
TypeScript
26 lines
708 B
TypeScript
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}` : "";
|
|
}
|