-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
54 lines (43 loc) · 1.79 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var fs = require("fs");
var data = JSON.parse(fs.readFileSync('data.json', 'utf8'));
Array.prototype.random = function (x) {
let n = rnd(0,this.length);
return this[n];
};
Array.prototype.contains = function (x) {
return this.indexOf(x) > -1;
};
String.prototype.capitalize = function() {
return this.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
function rnd(min, max)
{
return Math.floor(Math.random() * (max - min) + min);
}
console.clear();
const consonants = "bcdfghjklmnpqrstvwxyz";
const nonlatinconsonants = "çņšȚțșśńźСмирнвИКуклЛНМтВьйГгБćĐđčžñ-ıŞÇ";
const vowels = "aeiou";
const nonlatinvowels = "üøäéèáÓēūīļāîóąłÁõúо́азецПпбдёсЗíöÖ";
function mutatename(name, i = -1 /* i = letterIndex */){
name = name.toLowerCase();
for(var j = 0; j < rnd(1,3); j++){
// pick a random letter in this name, detect whether a vowel or consonant, and shift italics
if (i == -1) i = rnd(0, name.length);
if (consonants.match(name[i]))
return (name.replace(name[i],consonants[Math.floor(Math.random()*consonants.length)])).capitalize()
else if (vowels.match(name[i]))
return (name.replace(name[i],vowels[Math.floor(Math.random()*vowels.length)])).capitalize()
}
}
// generate a random male and female name
for (var i = 0; i < 5; i++) {
let maleFirstName = mutatename(data.male.random());
let maleSurname = mutatename(data.surnames.random());
console.log(`Male: ${maleFirstName} ${maleSurname}`);
}
for (var i = 0; i < 5; i++) {
let femaleFirstName = mutatename(data.female.random());
let femaleSurname = mutatename(data.surnames.random());
console.log(`Female: ${femaleFirstName} ${femaleSurname}`);
}