forked from hbunke/BibsOnGitHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonify.js
54 lines (48 loc) · 1.33 KB
/
jsonify.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
#!/usr/bin/env node
/*
* Copyright 2018 Philipp Zumstein
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
var fs = require("fs")
function jsonifyList() {
var data = fs.readFileSync('list.md');
var lines = data.toString().split('\n\n');
var subsection = 0;// counter for the subsections
var ret = {
org: [],
people: []
};
for (let i=0; i<lines.length; i++) {
if (lines[i].includes('---')) {
subsection++;
} else {
let splitLine = lines[i].split("(https://github.com/");
if (splitLine.length==2) {
let label = splitLine[0].replace(/\[[^\]]*\]$/, '').trim();
let githubName = splitLine[1].replace(/\)\s*$/, '');
let object = {
label: label,
githubName: githubName
};
if (subsection==1) ret.org.push(object);
if (subsection==2) {
let labelSplit = object.label.split('(');
if (labelSplit.length==2) {
object.label = labelSplit[0].trim();
object.affiliation = labelSplit[1].replace(/\)$/, '');
}
ret.people.push(object);
}
}
}
}
return ret;
}
module.exports = {
jsonifyList: jsonifyList
}
if (require.main === module) {
console.log(JSON.stringify(jsonifyList(), null, 2));
}