-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
100 lines (86 loc) · 2.74 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
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
const { sein, patp2hex, hex2patp, patq2hex, isValidPatq } = require('urbit-ob');
const checkWord = require('check-word');
const _cliProgress = require('cli-progress');
const fs = require('fs');
const inquirer = require('inquirer');
const words = checkWord('en'); // Sorry everyone else
const progress = new _cliProgress.Bar({
format: 'progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} | Found: {found}'
}, _cliProgress.Presets.shades_classic);
function generatePlanetNames({ parent, output }) {
const hex = patq2hex(parent);
let planets = [];
for (let i = 1; i <= 0xFFFF; i++) {
const s = i.toString(16).padStart(4, '0') + hex;
const p = hex2patp(s);
planets.push(p);
}
planets.sort();
progress.start(planets.length, 0);
let found = 0;
const outputs = {
all: planets => planets,
words: planets => planets.filter((planet, index) => {
const passes = planet
.replace('~', '')
.split('-')
.filter(part => words.check(part)).length;
if(passes) found++;
progress.update(index, { found });
return passes;
}),
lexical: planets => planets.filter((planet, index) => {
const passes = planet
.replace('~', '')
.split('-')
.filter(part => words.check(part)).length === 2;
if(passes) found++;
progress.update(index, { found });
return passes;
}),
double: planets => planets.filter((planet, index) => {
const parts = planet
.replace('~', '')
.split('-');
if ( parts[0] == parts[1] ) {
found++;
progress.update(index, { found });
return planet;
}
return false;
}),
default: planets => planets
};
const filteredPlanets = outputs[output] ? outputs[output](planets) : outputs.default(planets);
fs.writeFile(__dirname + "/planets.txt", filteredPlanets.join('\n'), function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
progress.stop();
}
inquirer
.prompt([
{
type: 'string',
message: 'Which star would you like to check?',
name: 'parent',
validate: function (input) {
return (isValidPatq(input) && input.length === 7) ? true : 'Invalid star name';
}
},
{
type: 'list',
name: 'output',
message: 'What kind of list would you like to output?',
default: 'all',
choices: [
{value: 'all', name: 'All possible planets'},
{value: 'words', name: 'Planets with English words in their names'},
{value: 'lexical', name: 'Planets only containing English words'},
{value: 'double', name: 'Planets only containing doubles like ~dopzod-dopzod'}
]
}
])
.then(generatePlanetNames);