|
|
|
|
|
class PrenmaModel { |
|
|
|
|
|
|
|
|
|
|
|
static async getInstance(progress_callback = null) { |
|
|
return new PrenmaModel(); |
|
|
} |
|
|
|
|
|
|
|
|
async generate(options) { |
|
|
|
|
|
const vowels = 'aeiouy'; |
|
|
const consonants = 'bcdfghjklmnpqrstvwxyz'; |
|
|
const numbers = '0123456789'; |
|
|
|
|
|
|
|
|
const { length = 8, style = 'fantasy', includeNumbers = false } = options; |
|
|
|
|
|
function getRandomChar(str) { |
|
|
return str[Math.floor(Math.random() * str.length)]; |
|
|
} |
|
|
|
|
|
function generateFantasyName(len) { |
|
|
let name = ''; |
|
|
let lastCharType = Math.random() < 0.5 ? 'vowel' : 'consonant'; |
|
|
|
|
|
for (let i = 0; i < len; i++) { |
|
|
if (lastCharType === 'vowel') { |
|
|
name += getRandomChar(consonants); |
|
|
lastCharType = 'consonant'; |
|
|
} else { |
|
|
name += getRandomChar(vowels); |
|
|
lastCharType = 'vowel'; |
|
|
} |
|
|
} |
|
|
return name.charAt(0).toUpperCase() + name.slice(1); |
|
|
} |
|
|
|
|
|
function generateRealName() { |
|
|
const firstNames = ['Alex', 'Léa', 'Lucas', 'Emma', 'Hugo', 'Chloé', 'Théo', 'Manon', 'Louise', 'Clementine', 'charlotte', 'Nicole', 'Rose', 'Françoise', 'Elsa', 'Julie', 'Karine', 'Emylie', 'Sylvie', 'Antoine', 'Mïa', "Elena", 'Mathieu', 'Clemence', 'Xavier', 'Laura', 'Veronique', 'Gloria', 'Louna', 'Oceanne', 'Violetine', 'Nora', 'Leo', 'Valentina', 'Nina', 'Lora', 'Dania', 'Sandra', 'Anaselia', 'Anastasia', 'Vincent', 'Olga', 'Maya', 'Lucie', 'Sindy', 'Sandy', 'Wendy', 'Julien', 'Clementine', 'Xavier', 'Georgia']; |
|
|
const lastNames = ['Martin', 'Dubois', 'Thomas', 'Robert', 'Petit', 'Durand', 'Leroy', 'Moreau', 'Garcia', 'Bonnet', 'Castorina', 'Baril', 'Geneviere', 'Jonia', 'Mazoo', 'Noca', 'Cary', 'Astro', 'Grosiel', 'Lebois', 'Marte', 'Reno', 'Luminis', 'Zexir', 'Norza', 'Zilda', 'Kachallit', 'Vanilla', 'Durand', 'Bonnard', 'Le marseille', 'Nicotouche', 'Montaise', 'Dubeure', 'Carco', 'Tary']; |
|
|
const randomFirstName = firstNames[Math.floor(Math.random() * firstNames.length)]; |
|
|
const randomLastName = lastNames[Math.floor(Math.random() * lastNames.length)]; |
|
|
return randomFirstName + ' ' + randomLastName; |
|
|
} |
|
|
|
|
|
function addNumbers(name) { |
|
|
let numLength = Math.floor(Math.random() * 4) + 1; |
|
|
let numbersPart = ''; |
|
|
for (let i = 0; i < numLength; i++) { |
|
|
numbersPart += getRandomChar(numbers); |
|
|
} |
|
|
return name + numbersPart; |
|
|
} |
|
|
|
|
|
|
|
|
let generatedName; |
|
|
if (style === 'fantasy') { |
|
|
generatedName = generateFantasyName(length); |
|
|
} else { |
|
|
generatedName = generateRealName(); |
|
|
} |
|
|
|
|
|
if (includeNumbers) { |
|
|
generatedName = addNumbers(generatedName); |
|
|
} |
|
|
|
|
|
|
|
|
return [{ generated_text: generatedName }]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export default PrenmaModel; |