import { upperFirst } from "@noya-app/noya-utils"; const animals = [ "cat", "dog", "owl", "fish", "horse", "rabbit", "snake", "lion", "bear", "wolf", "fox", "elephant", "giraffe", "zebra", "panda", "monkey", "penguin", "koala", "kangaroo", "whale", "shark", "turtle", "crocodile", "hippo", ] as const; const adjectives = [ "happy", "sleepy", "hungry", "thirsty", "healthy", "rich", "funky", "cool", "awesome", "amazing", "fantastic", "incredible", "super", "mega", "ultra", ] as const; function randomElement(array: readonly T[]) { return array[Math.floor(Math.random() * array.length)]; } export type ClientAnimal = (typeof animals)[number]; export function getClientImageUrl(animal: ClientAnimal) { return `https://avatars.noya.site/animals/animals_${animal}.svg`; } export function randomClientIdentity() { const animal = randomElement(animals); const name = `${upperFirst(randomElement(adjectives))} ${upperFirst(animal)}`; return { name, animal, image: getClientImageUrl(animal), }; } export function getClientAnimalFromName( name: string ): ClientAnimal | undefined { const parts = name.trim().split(/\s+/); const possibleAnimal = parts[parts.length - 1]?.toLowerCase(); if (!possibleAnimal) return undefined; return animals.includes(possibleAnimal as ClientAnimal) ? (possibleAnimal as ClientAnimal) : undefined; } export function randomName() { return randomClientIdentity().name; }