forked from yiyuezhuo/stellaris-visualization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyaml_parser.js
41 lines (30 loc) · 809 Bytes
/
yaml_parser.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
yaml_parser = (function(){
// Paradox like unstandard yaml file? right ...
function parse(doc){
var sl = doc.split('\n');
var objName = sl[0].split(':')[0];
var objMap = {}
sl.slice(1).forEach(function(line){
line = line.trim();
index = line.indexOf("#");
if(index!=-1){
line = line.slice(0,index);
}
var index = line.indexOf(":");
if(index==-1){
return;//continue;
}
var key = line.slice(0,index);
var value = line.slice(index+1);
index = value.indexOf(" ");
var num = Number(value.slice(0,index));
var content = value.slice(index+1);
content = content.slice(1,content.length-1); // remove quote
objMap[key] = [num,content];
});
var res = {};
res[objName] = objMap;
return res
}
return {parse : parse};
}());