-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmlConversion.js
More file actions
98 lines (92 loc) · 2.73 KB
/
xmlConversion.js
File metadata and controls
98 lines (92 loc) · 2.73 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
import fs from 'fs'
import {XMLBuilder} from 'fast-xml-parser'
function generateSpellId(name) {
return name.replace(/[^A-Za-z0-9]/g, '').toLowerCase()
}
function generateManeuverTuple(rawManeuver) {
return [
[generateSpellId(rawManeuver.name)],
{
"cast": {
"#text": 0,
"@@type": "number"
},
"castingtime": {
"#text": rawManeuver.initiationAction || "",
"@@type": "string"
},
"components": {
"#text": rawManeuver['prerequisiteS)'] || "",
"@@type": "string"
},
"cost": {
"#text": 0,
"@@type": "number"
},
"description": {
"p": [
rawManeuver.description || ""
],
"@@type": "formattedtext"
},
"duration": {
"#text": rawManeuver.duration || "",
"@@type": "string"
},
"effect": {
"#text": rawManeuver.target || "",
"@@type": "string"
},
"level": {
"#text": rawManeuver.level || "",
"@@type": "string"
},
"linkedspells": "",
"name": {
"#text": rawManeuver.name || "",
"@@type": "string"
},
"prepared": {
"#text": 0,
"@@type": "number"
},
"range": {
"#text": rawManeuver.range || "",
"@@type": "string"
},
"save": {
"#text": rawManeuver.savingThrow || "none",
"@@type": "string"
},
"school": {
"#text": rawManeuver.discipline || "",
"@@type": "string"
},
"shortdescription": {
"#text": rawManeuver.shortDesc || "",
"@@type": "string"
},
"sr": {
"#text": "no",
"@@type": "string"
}
}
]
}
export function convertManuversToXml(maneuvers) {
const convertedManeuvers = [Object.fromEntries(maneuvers.map(maneuver => generateManeuverTuple(maneuver)))]
const options = {
ignoreAttributes: false,
attributeNamePrefix: "@@",
format: true,
arrayNodeName: "spelldesc"
}
const builder = new XMLBuilder(options)
return builder.build(convertedManeuvers)
}
function main() {
const maneuvers = JSON.parse(fs.readFileSync("output.json"))
const output = convertManuversToXml(maneuvers)
fs.writeFileSync("output.xml", output)
}
main()