2024-06-17 18:39:59 +02:00
|
|
|
import type { Login } from '@/types.ts'
|
2024-05-13 17:22:29 +02:00
|
|
|
|
|
|
|
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}$/,
|
2024-05-13 18:04:30 +02:00
|
|
|
isoDateString: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z$/,
|
2024-05-13 17:22:29 +02:00
|
|
|
mailAddress: /\S+@\S+\.\S+/,
|
|
|
|
}
|