26 lines
647 B
TypeScript
26 lines
647 B
TypeScript
export function normalizeMarketCountry(
|
|
value: string | null | undefined
|
|
): string | null | undefined {
|
|
const cleaned = typeof value === "string" ? value.trim() : undefined;
|
|
if (!cleaned) {
|
|
return undefined;
|
|
}
|
|
|
|
const normalized = cleaned.toUpperCase();
|
|
if (!/^[A-Z]{2}$/.test(normalized)) {
|
|
throw new Error(
|
|
`Invalid marketCountry "${value}". Use an ISO 3166-1 alpha-2 uppercase country code such as "TH" or "DE".`
|
|
);
|
|
}
|
|
|
|
return normalized;
|
|
}
|
|
|
|
export function isPlausibleEmail(value: string | null | undefined): boolean {
|
|
if (!value) {
|
|
return false;
|
|
}
|
|
|
|
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
|
}
|