import type { Login } from '@/types.ts' export function toLogin({ firstname, lastname, }: { firstname: string lastname: string }): Login { return `${sanitizeString(firstname)}.${sanitizeString(lastname)}` } export function sanitizeString(str: string): string { return str.toLocaleLowerCase().split('').map(sanitizeChar).join('') } function sanitizeChar(char: string): string { //decompose unicode and remove diacritical marks char = char.normalize('NFD').replace(/[\u0300-\u036f]/g, '') if (char.match(/[a-zA-Z0-9]|-|_/)) return char return '_' } export const regex = { uuidV4: /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/, isoDateString: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z$/, mailAddress: /\S+@\S+\.\S+/, }