/** * Generates a randomized, two-word, alliterated animal name. * * ```ts * import { expect } from "jsr:@std/expect"; * * const name = await generateRandomName(); * * expect(name.split(" ")).toHaveLength(2); * * const [adjective, animal] = name.split(" "); * * expect(adjective[0]).toEqual(animal[0]); * ``` */ export async function generateRandomName(): Promise { const [{ default: adjectives }, { default: animals }] = await Promise.all([ import("./data/adjectives.json", { with: { type: "json" } }), import("./data/animals.json", { with: { type: "json" } }), ]); const animal = animals[Math.floor(Math.random() * animals.length)]; const letter = animal[0].toUpperCase() as keyof typeof adjectives; const options = adjectives[letter]; const adjective = options[Math.floor(Math.random() * options.length)]; return `${adjective} ${animal}`; }