-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
333 lines (303 loc) · 9.71 KB
/
script.js
File metadata and controls
333 lines (303 loc) · 9.71 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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
// Define constants for reference units
const UNIT_RATIOS = {
length: {
kilometers: 0.001,
meters: 1,
centimeters: 100,
miles: 0.000621371,
inches: 39.3701,
yards: 1.09361,
feet: 3.28084,
cuadras: 0.01
},
weight: { // Unit is grams
kilograms: 1/1000,
grams: 1,
pounds: 0.00220462,
ounces: 1/28.3495,
"troy ounces":1/31.1034768,
"metric tonnes":1/1000000,
arrobas: 1/12500
},
capacity: {
litres: 1,
millilitres: 1000,
gallons: 0.264172,
// GRAIN
"kilograms of grain": 2/3, // Reference unit is kilograms, also below
"grams of grain": 1000 * (2/3), // 1Kg is equal to 1000 grams
"pounds of grain": 2.20462 * (2/3), // 1Kg is equal to 2.20462 pounds
"arrobas of grain": (1/12.5) * (2/3), // 1Kg is equal to 1/12.5 arrobas
// FLOUR
"kilograms of flour": 0.5, // Half a kilogram in a litre
"grams of flour": 1000 * 0.5,
"pounds of flour": 2.20462 * 0.5,
"arrobas of flour": (1/12.5) * 0.5,
}
};
// Function to generate conversions
function generateConversions(referenceValue, category) {
const categoryRatios = UNIT_RATIOS[category];
if (!categoryRatios) {
throw new Error(`Unknown category: ${category}`);
}
const conversions = {};
for (const [unit, ratio] of Object.entries(categoryRatios)) {
conversions[unit] = referenceValue * ratio;
}
return conversions;
}
// Length always in metres
const CUBIT_IN_METRES = 0.5;
const FINGER_IN_METRES = CUBIT_IN_METRES/24;
const HANDBREADTH_IN_METRES = CUBIT_IN_METRES/6;
const SPAN_IN_METRES = CUBIT_IN_METRES/2;
const LONG_CUBIT_IN_METRES = 7 * HANDBREADTH_IN_METRES;
const REED_IN_METRES = 6 * LONG_CUBIT_IN_METRES;
const GMD_CUBIT_IN_METRES = CUBIT_IN_METRES;
const NT_CUBIT_IN_METRES = LONG_CUBIT_IN_METRES;
const FATHOM_IN_METRES = 1.8;
const STADE_IN_METRES = 185;
const SHABBATHS_DAY_WALK_IN_METRES = 200 * NT_CUBIT_IN_METRES;
const ROMAN_MILE_IN_METRES = 1497;
// Capacity always in litres
const PREEXILIC_EPHAH_IN_LITRES = 10;
const PREEXILIC_BATH_IN_LITRES = 22;
const POSTEXILIC_EPHAH_IN_LITRES = 39;
const LOG_IN_LITRES = PREEXILIC_BATH_IN_LITRES / 72;
const KAV_IN_LITRES = PREEXILIC_EPHAH_IN_LITRES / 18;
const OMER_IN_LITRES = PREEXILIC_EPHAH_IN_LITRES / 10;
const ISSARON_IN_LITRES = OMER_IN_LITRES;
const PREEXILIC_HIN_IN_LITRES = 4;
const POSTEXILIC_BATH_IN_LITRES = POSTEXILIC_EPHAH_IN_LITRES;
const POSTEXILIC_HIN_IN_LITRES = POSTEXILIC_BATH_IN_LITRES / 6;
const PREEXILIC_SEAH_IN_LITRES = PREEXILIC_EPHAH_IN_LITRES / 3;
const POSTEXILIC_SEAH_IN_LITRES = POSTEXILIC_EPHAH_IN_LITRES / 3;
const DOUBLE_BATH_IN_LITRES = 39;
const PREEXILIC_DRY_HOMER_IN_LITRES = 10 * PREEXILIC_EPHAH_IN_LITRES;
const PREEXILIC_LIQUID_HOMER_IN_LITRES = 10 * PREEXILIC_BATH_IN_LITRES;
const POSTEXILIC_HOMER_IN_LITRES = 10 * POSTEXILIC_EPHAH_IN_LITRES;
const PREEXILIC_DRY_KOR_IN_LITRES = PREEXILIC_DRY_HOMER_IN_LITRES;
const PREEXILIC_LIQUID_KOR_IN_LITRES = PREEXILIC_LIQUID_HOMER_IN_LITRES;
const POSTEXILIC_KOR_IN_LITRES = POSTEXILIC_HOMER_IN_LITRES;
const LETEK_IN_LITRES = PREEXILIC_DRY_HOMER_IN_LITRES / 2;
const NT_SEAH_IN_LITRES = POSTEXILIC_SEAH_IN_LITRES;
const NT_BATH_IN_LITRES = POSTEXILIC_BATH_IN_LITRES;
const NT_KOR_IN_LITRES = POSTEXILIC_KOR_IN_LITRES;
const CHOINIX_IN_LITRES = 1;
const METRITIS_IN_LITRES = NT_BATH_IN_LITRES;
// Weight always in grams
const SHEKEL_IN_GRAMS = 12;
const GERAH_IN_GRAMS = SHEKEL_IN_GRAMS / 20;
const BEKAH_IN_GRAMS = SHEKEL_IN_GRAMS / 2;
const MINA_IN_GRAMS = 50 * SHEKEL_IN_GRAMS;
const TALENT_IN_GRAMS = 35000;
const PIM_IN_GRAMS = 2 * SHEKEL_IN_GRAMS / 3;
const LITRA_IN_GRAMS = 327;
const REVELATION_TALENT_IN_GRAMS = 40 * 1000;
// Conversion equivalence table
const conversionTable = {
// Length
cubit: {
category: "length",
conversions: generateConversions(CUBIT_IN_METRES, "length")
},
"long cubit": {
category: "length",
conversions: generateConversions(LONG_CUBIT_IN_METRES, "length")
},
finger: {
category: "length",
conversions: generateConversions(FINGER_IN_METRES, "length")
},
"GMD cubit": {
category: "length",
conversions: generateConversions(GMD_CUBIT_IN_METRES, "length")
},
span: {
category: "length",
conversions: generateConversions(SPAN_IN_METRES, "length")
},
handbreadth: {
category: "length",
conversions: generateConversions(HANDBREADTH_IN_METRES, "length")
},
reed: {
category: "length",
conversions: generateConversions(REED_IN_METRES, "length")
},
"Shabbath's day walk": {
category: "length",
conversions: generateConversions(SHABBATHS_DAY_WALK_IN_METRES, "length")
},
fathom: {
category: "length",
conversions: generateConversions(FATHOM_IN_METRES, "length")
},
"New Testament cubit": {
category: "length",
conversions: generateConversions(NT_CUBIT_IN_METRES, "length")
},
stade: {
category: "length",
conversions: generateConversions(STADE_IN_METRES, "length")
},
"Roman mile": {
category: "length",
conversions: generateConversions(ROMAN_MILE_IN_METRES, "length")
},
// Capacity
"pre-exilic ephah": {
category: "capacity",
conversions: generateConversions(PREEXILIC_EPHAH_IN_LITRES, "capacity")
},
"pre-exilic bath": {
category: "capacity",
conversions: generateConversions(PREEXILIC_BATH_IN_LITRES, "capacity")
},
"post-exilic ephah": {
category: "capacity",
conversions: generateConversions(POSTEXILIC_EPHAH_IN_LITRES, "capacity")
},
"log": {
category: "capacity",
conversions: generateConversions(LOG_IN_LITRES, "capacity")
},
"kav": {
category: "capacity",
conversions: generateConversions(KAV_IN_LITRES, "capacity")
},
"omer": {
category: "capacity",
conversions: generateConversions(OMER_IN_LITRES, "capacity")
},
"issaron": {
category: "capacity",
conversions: generateConversions(ISSARON_IN_LITRES, "capacity")
},
"pre-exilic hin": {
category: "capacity",
conversions: generateConversions(PREEXILIC_HIN_IN_LITRES, "capacity")
},
"post-exilic bath": {
category: "capacity",
conversions: generateConversions(POSTEXILIC_BATH_IN_LITRES, "capacity")
},
"post-exilic hin": {
category: "capacity",
conversions: generateConversions(POSTEXILIC_HIN_IN_LITRES, "capacity")
},
"pre-exilic seah": {
category: "capacity",
conversions: generateConversions(PREEXILIC_SEAH_IN_LITRES, "capacity")
},
"post-exilic seah": {
category: "capacity",
conversions: generateConversions(POSTEXILIC_SEAH_IN_LITRES, "capacity")
},
"double bath": {
category: "capacity",
conversions: generateConversions(DOUBLE_BATH_IN_LITRES, "capacity")
},
"pre-exilic dry homer": {
category: "capacity",
conversions: generateConversions(PREEXILIC_DRY_HOMER_IN_LITRES, "capacity")
},
"pre-exilic liquid homer": {
category: "capacity",
conversions: generateConversions(PREEXILIC_LIQUID_HOMER_IN_LITRES, "capacity")
},
"post-exilic homer": {
category: "capacity",
conversions: generateConversions(POSTEXILIC_HOMER_IN_LITRES, "capacity")
},
"pre-exilic dry kor": {
category: "capacity",
conversions: generateConversions(PREEXILIC_DRY_KOR_IN_LITRES, "capacity")
},
"pre-exilic liquid kor": {
category: "capacity",
conversions: generateConversions(PREEXILIC_LIQUID_KOR_IN_LITRES, "capacity")
},
"post-exilic kor": {
category: "capacity",
conversions: generateConversions(POSTEXILIC_KOR_IN_LITRES, "capacity")
},
"letek": {
category: "capacity",
conversions: generateConversions(LETEK_IN_LITRES, "capacity")
},
"New Testament seah": {
category: "capacity",
conversions: generateConversions(NT_SEAH_IN_LITRES, "capacity")
},
"New Testament bath": {
category: "capacity",
conversions: generateConversions(NT_BATH_IN_LITRES, "capacity")
},
"New Testament kor": {
category: "capacity",
conversions: generateConversions(NT_KOR_IN_LITRES, "capacity")
},
"choinix": {
category: "capacity",
conversions: generateConversions(CHOINIX_IN_LITRES, "capacity")
},
"metritis": {
category: "capacity",
conversions: generateConversions(METRITIS_IN_LITRES, "capacity")
},
// Weight
"shekel": {
category: "weight",
conversions: generateConversions(SHEKEL_IN_GRAMS, "weight")
},
"beka": {
category: "weight",
conversions: generateConversions(BEKAH_IN_GRAMS, "weight")
},
"mina": {
category: "weight",
conversions: generateConversions(MINA_IN_GRAMS, "weight")
},
"talent": {
category: "weight",
conversions: generateConversions(TALENT_IN_GRAMS, "weight")
},
"pim": {
category: "weight",
conversions: generateConversions(PIM_IN_GRAMS, "weight")
},
"litra": {
category: "weight",
conversions: generateConversions(LITRA_IN_GRAMS, "weight")
},
"Revelation's talent": {
category: "weight",
conversions: generateConversions(REVELATION_TALENT_IN_GRAMS, "weight")
},
};
function convert() {
const inputValue = parseFloat(document.getElementById('input-value').value);
const inputUnit = document.getElementById('input-unit').value;
if (isNaN(inputValue)) {
document.getElementById('result').innerHTML = '<p>Please enter a valid number.</p>';
return;
}
const unitData = conversionTable[inputUnit];
if (!unitData) {
document.getElementById('result').innerHTML = '<p>Conversion not supported.</p>';
return;
}
const results = [];
for (const [modernUnit, conversionRate] of Object.entries(unitData.conversions)) {
const convertedValue = inputValue * conversionRate;
results.push(`${convertedValue.toFixed(2)} ${modernUnit}`);
}
document.getElementById('result').innerHTML = `
<h3>Conversions for ${inputValue} ${inputUnit}(s):</h3>
<ul>
${results.map(result => `<li>${result}</li>`).join('')}
</ul>
`;
}