This repository was archived by the owner on Mar 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
106 lines (92 loc) · 2.63 KB
/
Copy pathapp.js
File metadata and controls
106 lines (92 loc) · 2.63 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var fs = require('fs');
/* Location lists */
var locationPrefixes = makeList("./lists/location-prefixes.txt");
var adjectives = makeList("./lists/adjectives.txt");
var locations = makeList("./lists/locations.txt");
var locationSuffixes = makeList("./lists/location-suffixes.txt");
/* Username lists */
var prefixes = makeList("./lists/prefixes.txt");
prefixes = prefixes.concat(adjectives);
var firstnames = makeList("./lists/firstnames.txt");
var nicknames = makeList("./lists/nicknames.txt");
var lastnames = makeList("./lists/lastnames.txt");
var suffixes = makeList("./lists/suffixes.txt");
function makeList(file) {
return fs.readFileSync(file).toString().trim().split("\n");
}
var random = {
"inRange": function(min, max) {
return min + Math.random() * (max - min);
},
"from": function(array) {
return array[Math.floor(Math.random() * array.length)];
}
};
function generateName(parts) {
var names = [];
for (var i = 0; i < parts.length; i++) {
if (parts[i].probability) {
if (random.inRange(0, 1) < parts[i].probability) {
names.push(random.from(parts[i].list));
}
} else {
names.push(random.from(parts[i].list));
}
}
return names.join(" ");
}
module.exports = {
location: generateLocation,
username: generateUsername
}
function generateLocation() {
return generateName(
[
{ list: locationPrefixes, probability: 0.5 },
{ list: adjectives, probability: 1 },
{ list: locations, probability: 1 },
{ list: locationSuffixes, probability: 0.2 }
]
)
}
function generateUsername() {
return generateName(
[
{ list: prefixes, probability: 1 },
{ list: adjectives, probability: 0.5 },
{ list: firstnames, probability: 1 },
{ list: lastnames, probability: 1 }
]
);
}
/* For testing purposes only
Logs a sample group of names to the console
*/
var results = 10;
console.log("Locations:\n```");
for (var i = 0; i < results; i++) {
var locationName = generateName(
[
{ list: locationPrefixes, probability: 0.7 },
{ list: adjectives, probability: 1 },
{ list: locations, probability: 1 },
{ list: locationSuffixes, probability: 0.5 }
]
);
console.log(locationName);
}
console.log("```\nUsers:\n```");
for (var i = 0; i < results; i++) {
var userName = generateName(
[
{ list: prefixes, probability: 1 },
{ list: adjectives, probability: 0.1 },
{ list: firstnames, probability: 1 },
{ list: nicknames, probability: 0.05 },
{ list: lastnames, probability: 1 },
{ list: suffixes, probability: 0.2 }
]
);
console.log(userName);
}
console.log("```");