feat(chore): ✨ add utils
This commit is contained in:
parent
59bf2cd44d
commit
e2b44cb662
29
utils.ts
Normal file
29
utils.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { 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+/,
|
||||
}
|
Loading…
Reference in a new issue