-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (63 loc) · 1.84 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
import { readFileSync, writeFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import jsdom from 'jsdom';
const { JSDOM } = jsdom;
function htmlToJson(characterSlug) {
const inputPath = fileURLToPath(
new URL(`./resources/html/${characterSlug}.html`, import.meta.url),
);
const outputPath = fileURLToPath(
new URL(`./resources/json/${characterSlug}.json`, import.meta.url),
);
const html = readFileSync(inputPath, 'utf8');
const dom = new JSDOM(html);
const table = dom.window.document.querySelector('table');
const rows = Array.from(table.querySelectorAll('tbody tr'));
const json = rows.map((row) => {
const propertyColumns = Array.from(row.querySelectorAll('td'));
const [
commandColumn,
hitLevelColumn,
damageColumn,
startupFrameColumn,
blockFrameColumn,
hitFrameColumn,
counterFrameColumn,
notesColumn,
] = propertyColumns;
return {
command: commandColumn.textContent,
hitLevels: hitLevelColumn.textContent.split(','),
damage: damageColumn.textContent.split(','),
startupFrames: startupFrameColumn.textContent,
blockFrames: blockFrameColumn.textContent,
hitFrames: hitFrameColumn.textContent,
counterFrames: counterFrameColumn.textContent,
notes: notesColumn.textContent,
};
});
writeFileSync(outputPath, JSON.stringify(json, null, 2));
return json;
}
const characters = [
'asuka',
'azucena',
'bryan',
'claudio',
'dragunov',
'feng',
'jack-8',
'kazuya',
'jin',
'jun',
'law',
'leo',
'nina',
'paul',
'raven',
'reina',
'steve',
'victor',
'yoshimitsu',
];
characters.forEach(htmlToJson);