fosrl.pangolin/server/db/names.ts

18 lines
657 B
TypeScript
Raw Normal View History

2024-10-14 21:59:35 -04:00
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import { readFileSync } from 'fs';
// Get the directory name of the current module
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Load the names from the names.json file
const file = join(__dirname, 'names.json');
export const names = JSON.parse(readFileSync(file, 'utf-8'));
export function getUniqueName(): string {
return (
2024-10-14 22:26:32 -04:00
names.descriptors[Math.floor(Math.random() * names.descriptors.length)] + "-" +
names.animals[Math.floor(Math.random() * names.animals.length)]
).toLowerCase().replace(/\s/g, '-');
2024-10-14 21:59:35 -04:00
}