src/random_name.js
function (name_type, gender, style) {
		if (typeof name_type === 'undefined' || name_type === '' || name_type === 'random') {
			// randomize a type...
			name_type = randomizer.rollRandom(Object.keys(namedata.options));
		}
		if (typeof style === 'undefined') { style = ''; }
		if (!namedata[name_type]) { return ''; }
		if (typeof gender === 'undefined' || (gender !== 'male' && gender !== 'female')) { gender = randomizer.rollRandom(['male', 'female']); }
		
		const mkey = `${name_type}_${gender}`;
		let lastname = '';
		let thename = '';
		
		if (!markov.memory) {
			markov = new MarkovGenerator({ order: 3 });
		}
		
		if (!markov.memory[mkey]) {
			// console.log('learn '+mkey);
			let namelist = [];
			if (gender === '') {
				namelist = namedata[name_type]['male'];
				namelist = namelist.concat(namedata[name_type]['female']);
			} else {
				namelist = namedata[name_type][gender];
			}
			namelist.forEach((v) => {
				markov.learn(mkey, v);
			});
		}
		
		if (style !== 'first' && !r_helpers.isEmpty(namedata[name_type]['surname'])) {
			const skey = name_type + '_last';
			if (!markov.memory[skey]) {
				// console.log('learn surname '+skey);
				const namelist = namedata[name_type]['surname'];
				namelist.forEach((v) => {
					markov.learn(skey, v);
				});
			}
			lastname = markov.generate(skey);
		}
		
		thename = `${markov.generate(mkey)} ${lastname}`;
		return capitalizeName(thename.trim());
	}
function (name_type, gender, style) {
		if (typeof name_type === 'undefined' || name_type === '' || name_type === 'random') {
			// randomize a type...
			name_type = randomizer.rollRandom(Object.keys(namedata.options));
		}
		if (typeof style === 'undefined') { style = ''; }
		if (!namedata[name_type]) { return ''; }
		if (typeof gender === 'undefined' || (gender !== 'male' && gender !== 'female')) { gender = randomizer.rollRandom(['male', 'female']); }
		
		const mkey = `${name_type}_${gender}`;
		let lastname = '';
		let thename = '';
		
		if (!markov.memory) {
			markov = new MarkovGenerator({ order: 3 });
		}
		
		if (!markov.memory[mkey]) {
			// console.log('learn '+mkey);
			let namelist = [];
			if (gender === '') {
				namelist = namedata[name_type]['male'];
				namelist = namelist.concat(namedata[name_type]['female']);
			} else {
				namelist = namedata[name_type][gender];
			}
			namelist.forEach((v) => {
				markov.learn(mkey, v);
			});
		}
		
		if (style !== 'first' && !r_helpers.isEmpty(namedata[name_type]['surname'])) {
			const skey = name_type + '_last';
			if (!markov.memory[skey]) {
				// console.log('learn surname '+skey);
				const namelist = namedata[name_type]['surname'];
				namelist.forEach((v) => {
					markov.learn(skey, v);
				});
			}
			lastname = markov.generate(skey);
		}
		
		thename = `${markov.generate(mkey)} ${lastname}`;
		return capitalizeName(thename.trim());
	}
function ( name_type , gender , style ) { if ( typeof name_type === 'undefined' || name_type === '' || name_type === 'random' ) { // randomize a type... name_type = randomizer . rollRandom ( Object . keys ( namedata . options ) ) ; } if ( typeof style === 'undefined' ) { style = '' ; } if ( ! namedata [ name_type ] ) { return '' ; } if ( typeof gender === 'undefined' || ( gender !== 'male' && gender !== 'female' ) ) { gender = randomizer . rollRandom ( [ 'male' , 'female' ] ) ; } const mkey = ` ${ name_type } ${ gender } ` ; let lastname = '' ; let thename = '' ; if ( ! markov . memory ) { markov = new MarkovGenerator ( { order : 3 } ) ; } if ( ! markov . memory [ mkey ] ) { // console.log('learn '+mkey); let namelist = [ ] ; if ( gender === '' ) { namelist = namedata [ name_type ] [ 'male' ] ; namelist = namelist . concat ( namedata [ name_type ] [ 'female' ] ) ; } else { namelist = namedata [ name_type ] [ gender ] ; } namelist . forEach ( ( v ) => { markov . learn ( mkey , v ) ; } ) ; } if ( style !== 'first' && ! r_helpers . isEmpty ( namedata [ name_type ] [ 'surname' ] ) ) { const skey = name_type + '_last' ; if ( ! markov . memory [ skey ] ) { // console.log('learn surname '+skey); const namelist = namedata [ name_type ] [ 'surname' ] ; namelist . forEach ( ( v ) => { markov . learn ( skey , v ) ; } ) ; } lastname = markov . generate ( skey ) ; } thename = ` ${ markov . generate ( mkey ) } ${ lastname } ` ; return capitalizeName ( thename . trim ( ) ) ; }
Create a name using Markov chains
@param {String} [name_type=random] what list/process to use
@param {String} [gender=random] male or female or both
@param {String} style first=first name only, else full name
@returns {String} a name
Create a name using Markov chains