-
Notifications
You must be signed in to change notification settings - Fork 0
/
words.js
executable file
·55 lines (49 loc) · 1.56 KB
/
words.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
var fs = require('fs');
// Files that we load
var wordlists = ['normal', 'disney'];
function loadList(list) {
var words = fs.readFileSync('wordlists/'+list+'.txt').toString().toLowerCase().split("\n");
// Clean up the list
words = cleanList(words, true);
return words;
}
function cleanList(words, showDebug) {
for (var i = 0; i < words.length; i++) {
// Trim whitespace
words[i] = words[i].trim();
if(words[i] == "") {
words.splice(i,1);
i--;
continue;
}
if(words[i].charAt(0) == "#") {
words.splice(i,1);
i--;
continue;
}
}
var results = [];
var sorted_words = words.slice().sort();
for (var i = 0; i < words.length - 1; i++) {
if (sorted_words[i + 1] == sorted_words[i]) {
words.splice(words.indexOf(sorted_words[i]),1);
if(showDebug) console.log("Removing dupe: "+sorted_words[i])
}
}
return words;
}
var lists = {};
for(var listIterator = 0; listIterator < wordlists.length; listIterator++) {
lists[wordlists[listIterator]] = loadList(wordlists[listIterator]);
}
// Create all list
var listNames = Object.keys(lists);
lists["all"] = [];
for(var i = 0; i< listNames.length; i++) {
lists["all"] = lists["all"].concat(lists[listNames[i]]);
}
lists["all"] = cleanList(lists["all"], false);
listNames.unshift("all");
console.log(listNames.length + " lists loaded");
console.log(lists.all.length + " total words loaded");
module.exports = {wordLists: listNames, lists: lists};