-
Notifications
You must be signed in to change notification settings - Fork 0
/
numbers.js
201 lines (184 loc) · 6.12 KB
/
numbers.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
const express = require('express');
const fs = require('fs');
const os = require('os');
const router = express.Router();
const encode = require('./encoder').encode;
root = "/faas";
console.log(os.hostname());
if (os.hostname().indexOf("Omoikane") > -1)
root = "";
console.log(`Root: "${root}"`);
const header = fs.readFileSync('header.html', 'utf8').replaceAll("ROOT", root);
function GetNumber(original)
{
var original = parseInt(original);
if (isNaN(original))
{
res.status(400); return 'Not a number.';
}
let number = original.toString(16);
let negative = (parseInt(number, 16) < 0);
if (negative)
number = number.slice(1);
if (parseInt(number, 16) == 0)
number = '0';
var handleMyriad = function(num)
{
if (typeof(num) != 'string')
num = num.toString(16);
var ones = parseInt(num.slice(-1), 16);
if (ones > 15) {
res.status(400); return 'Ones digit is out of bounds.';
}
var words = [
'sarhi', 'erhi', 'karhi', 'henrhi', 'nemrhi',
'nesarhi', 'nenerhi', 'nekarhi', 'nehenrhi', 'nenemrhi',
'losarhi', 'lonerhi', 'lokarhi', 'lohenrhi', 'lonemrhi',
'chisarhi' ];
var longhand = words[ones];
if (num.length > 1) {
var tens = parseInt(num.slice(-2, -1), 16);
if (tens > 15) {
res.status(400); return 'Tens digit is out of bounds.';
}
if (ones == 0) {
words = [
'', 'tisarhi', 'tikarhi', 'tihenrhi', 'tinemrhi',
'tinesarhi', 'tinenerhi', 'tinekarhi', 'tinehenrhi', 'tinenemrhi',
'tilosarhi', 'tilonerhi', 'tilokarhi', 'tilohenrhi', 'tilonemrhi',
'ticharhi' ];
longhand = words[tens];
} else {
words = [
'', 'tie-', 'tika-', 'tihen-', 'tina-',
'tines-', 'tinene-', 'tineka-', 'tinehen-', 'tinenem-',
'tinesa-', 'tilone-', 'tiloka-', 'tilohen-', 'tilonem-',
'ticha-' ];
longhand = words[tens] + longhand;
}
}
if (num.length > 2) {
var hundreds = parseInt(num.slice(-3, -2), 16);
if (hundreds > 15) {
res.status(400); return 'Hundreds digit is out of bounds.';
}
if (ones == 0 && tens == 0) {
words = [
'', 'sha-erhi', 'shakarhi', 'shahenrhi', 'shanemrhi',
'shanesarhi', 'shanenerhi', 'shanekarhi', 'shanehenrhi', 'shanenemrhi',
'shalosarhi', 'shalonerhi', 'shalokarhi', 'shalohenrhi', 'shalonemrhi',
'shachisarhi' ];
longhand = words[hundreds];
} else {
words = [
'', 'sha\'e-', 'shaka-', 'shahene-', 'shana-',
'shanes-', 'shana\'e-', 'shanaka-', 'shanahen-', 'shanana-',
'shales-', 'shalo\'e-', 'shaloka-', 'shalohen-', 'shalona-',
'shachisa-', ];
longhand = words[hundreds] + longhand;
}
}
if (num.length > 3) {
var thousands = parseInt(num.slice(-4, -3), 16);
if (thousands > 15) {
res.status(400); return 'Thousands digit is out of bounds.';
return;
}
if (ones == 0 && tens == 0 && hundreds == 0) {
words = [
'', 'esresarhi', 'eskarhi', 'eshenrhi', 'esnemrhi',
'esnasarhi', 'esnanerhi', 'esnekarhi', 'esnehenrhi', 'esnenemrhi',
'eslosarhi', 'eslonerhi', 'eslokarhi', 'eslohenrhi', 'eslonemrhi',
'eschisarhi', ];
longhand = words[thousands];
} else {
words = [
'', 'esre-', 'eska-', 'eshen-', 'esnem-',
'esne-', 'esnene-', 'esneka-', 'esnehen-', 'esnenem-',
'eslosa-', 'eslone-', 'esloka-', 'eslohen-', 'eslonem-',
'eschisa-' ];
longhand = words[thousands] + longhand;
}
}
return longhand;
}
var longhand = '';
if (number.length > 4)
{
longhand = handleMyriad(parseInt(number.slice(-4), 16));
if (longhand == 'sarhi')
longhand = '';
var num = number;
while (num.length > 4)
{
num = num.slice(0,-4);
var myriad = parseInt(num.slice(-4), 16);
if (myriad == 0)
longhand = 'setiksre ' + longhand;
else
longhand = handleMyriad(myriad) + '-tiksre ' + longhand;
}
longhand = longhand.replace(/tiksre se/g, 'tik-se');
}
else
longhand += handleMyriad(number);
if (negative)
longhand = 'ut-' + longhand;
longhand = longhand.trim();
var feldigits = original.toString(16).toUpperCase();
feldigits = feldigits.replace(/C/g, 'c');
feldigits = feldigits.replace(/F/g, 'I');
return {
'dec': original,
'hex': number,
'fel': longhand,
'code': encode(longhand, 1),
'ipa': encode(longhand, 2),
'fhx': feldigits,
};
}
router.get('/number/md', function(req, res) {
var md = '| Decimal | Hex | Pronounciation |\n';
md += '| ------- | ------- | ---------------------------- |\n';
for (var i = 0; i < 0x40; i++)
{
var num = GetNumber(i);
md += `| ${num['dec'].toString().padEnd(7)} | ${num['fhx'].toString().padEnd(7)} | ${num['fel'].toString().padEnd(28)} |\n`;
}
for (var i = 0x40; i < 0x100; i += 0x10)
{
var num = GetNumber(i);
md += `| ${num['dec'].toString().padEnd(7)} | ${num['fhx'].toString().padEnd(7)} | ${num['fel'].toString().padEnd(28)} |\n`;
}
for (var i = 0x100; i <= 0x600; i += 0x20)
{
var num = GetNumber(i);
md += `| ${num['dec'].toString().padEnd(7)} | ${num['fhx'].toString().padEnd(7)} | ${num['fel'].toString().padEnd(28)} |\n`;
}
for (var i = 0x1000; i <= 0x2000; i += 0x100)
{
var num = GetNumber(i);
md += `| ${num['dec'].toString().padEnd(7)} | ${num['fhx'].toString().padEnd(7)} | ${num['fel'].toString().padEnd(28)} |\n`;
}
var num = GetNumber(0x4444);
md += `| ${num['dec'].toString().padEnd(7)} | ${num['fhx'].toString().padEnd(7)} | ${num['fel'].toString().padEnd(28)} |\n`;
res.type('.md');
res.send(md);
});
router.get('/number/:num/json', express.json(), function(req, res) {
res.json(GetNumber(req.params['num'] || 1));
});
router.get('/number/:num', function(req, res) {
num = GetNumber(req.params['num'] || 1);
var html = header;
html += '<table>\n';
html += `\t<tr><th>Dec</th><td>${num['dec']}</td></tr>\n`;
html += `\t<tr><th rowspan=2>Hex</th><td>0x${num['hex'].toUpperCase()}</td></tr>\n`;
html += `\t<tr><td class="felinese">${num['fhx']}</td></tr>\n`;
html += `\t<tr><th rowspan=2>Fel</th><td>${num['fel']}</td></tr>\n`;
html += `\t<tr><td class="felinese">${num['code']}</td></tr>\n`;
html += `\t<tr><th>IPA</th><td>${num['ipa']}</td></tr>\n`;
html += '</table>';
res.send(html);
});
module.exports = router;