-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.js
More file actions
30 lines (27 loc) · 811 Bytes
/
parse.js
File metadata and controls
30 lines (27 loc) · 811 Bytes
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
export default function parse(code) {
let firstLine = code.trim().split("\n")[0];
let commentContents;
if (firstLine.startsWith("#")) {
commentContents = firstLine.substring(1).trimStart();
} else if (firstLine.startsWith("//")) {
commentContents = firstLine.substring(2).trimStart();
} else if (firstLine.startsWith("/*")) {
commentContents = firstLine.substring(2).trimStart();
} else if (firstLine.startsWith("<!--")) {
commentContents = firstLine.substring(4).trimStart();
}
if (commentContents) {
let regex = /^(\S*\.\S+)?\s*(\(([^\)]+)\))?/;
let match = regex.exec(commentContents);
if (match) {
return {
filename: match[1] || "",
displayName: match[3] || "",
};
}
}
return {
filename: "",
displayName: "",
};
}