There are several fantasy name generators on NPM & Github, but none gave me exactly what I wanted in a format I could readily use in a project I'm developing.
I decided to build one of my own that's little more than a skin of the Markov-chain name generator code at the awesome Donjon site.
I also pulled names data file from Fantasy Content Generator. I like this generator a lot, but it has a pretty finite set of possible names it can generate. So, I used the names from this as a seed list for the Markov chains.
node i mcasto/5e-name-gen
or
yarn add mcasto/5e-name-gen
There are two functions exported by the module: nameGen and nameList.
nameGen
returns a single name. nameList
returns an array of names.
nameGen expects a payload object:
{
race: ['', 'dragonborn', 'dwarf','elf','gnome','halfElf','halfOrc','halfling','human','tiefling],
gender: ['','male','female'],
}
// Both settings default to ''. If race is '', the function will randomly select one. If gender is '', the function will randomly select on.
nameList expects a payload object:
{
race: ['', 'dragonborn', 'dwarf','elf','gnome','halfElf','halfOrc','halfling','human','tiefling],
gender: ['','male','female'],
num: 10
}
// num defaults to 10 and, like the nameGen function, if race and gender are undefined or empty strings, they will be randomly selected.
const {nameGen, nameList} = require('5e-name-gen');
console.log(nameGen({})); // generate a name with random race/gender
console.log(nameGen({ race: 'dwarf', gender: 'female' })); // generate a name for a female dwarf
console.log(nameList({})); // generate 10 names with random races/genders
console.log(nameList({race: 'elf', gender: 'male', num: 15})); // generate a list of 15 names for male elves
nameGen returns an object of { race, gender, name }
nameList returns an array of { race, gender, name } objects
I plan to add more seed names over time, and I might develop some more generators.