-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
63 lines (58 loc) · 1.66 KB
/
index.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
55
56
57
58
59
60
61
62
63
const boys = require("./data/boys.json");
const girls = require("./data/girls.json");
const girl_prefixes = require("./data/girls-prefix.json");
const boy_prefixes = require("./data/boys-prefix.json");
const boyNames = [];
const girlNames = [];
const girlPrefixes = [];
const boyPrefixes = [];
function loadJsonData() {
Object.keys(boys).forEach((name) => {
boyNames.push(name);
});
Object.keys(girls).forEach((name) => {
//console.log(name, ":", boys[name].source);
girlNames.push(name);
});
Object.keys(girl_prefixes).forEach((name) => {
girlPrefixes.push(name);
});
Object.keys(boy_prefixes).forEach((name) => {
boyPrefixes.push(name);
});
}
function getRandomNumber(gender) {
let length;
if (gender === "female") {
length = girlNames.length;
} else {
length = boyNames.length;
}
return Math.floor(Math.random() * length);
}
function generateUsername(count, gender, prefix = false) {
let username, random;
const username_list = [];
for (let i = 0; i < count; i++) {
let rand = getRandomNumber(gender);
if (gender === "male") {
username = boyNames[rand];
} else if (gender === "female") {
username = girlNames[rand];
}
if (prefix) {
if (gender === "female") {
random = Math.floor(Math.random() * girlPrefixes.length);
random_prefix = girlPrefixes[random];
} else if (gender === "male") {
random = Math.floor(Math.random() * boyPrefixes.length);
random_prefix = boyPrefixes[random];
}
username = random_prefix.concat(username);
}
username_list.push(username);
}
return username_list;
}
loadJsonData();
module.exports = generateUsername;