Files
crm/apps/api/src/contacts/normalize.ts
T

19 lines
641 B
TypeScript

export function emptyToNull(value?: string | null): string | null {
if (value == null) return null;
const trimmed = value.trim();
return trimmed.length ? trimmed : null;
}
export function normalizeEmail(value?: string | null): string | null {
const v = emptyToNull(value);
return v ? v.toLowerCase() : null;
}
/** Keep digits and leading + for Iranian/international numbers. */
export function normalizePhone(value?: string | null): string | null {
const v = emptyToNull(value);
if (!v) return null;
const cleaned = v.replace(/[^\d+]/g, '');
return cleaned.length ? cleaned : null;
}