-
Notifications
You must be signed in to change notification settings - Fork 0
/
mermaidParser.js
39 lines (31 loc) · 1.33 KB
/
mermaidParser.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
// mermaidParser.js
const { skipMetadataAndCommentLines, determineDiagramType } = require('./utils/utils');
const { parseClassDiagram } = require('./parsers/classDiagramParser');
const { parseERDiagram } = require('./parsers/erDiagramParser');
const { parseSequenceDiagram } = require('./parsers/sequenceDiagramParser');
// Main function to parse Mermaid code to JSON structure
function convertToUML(mermaidCode) {
const lines = mermaidCode.split('\n').map(line => line.trim());
// Filter out metadata and comment lines
const filteredLines = skipMetadataAndCommentLines(lines);
// Initialize the parsed data object with the diagram type
const jsonResult = { type: '' };
// Determine the type of diagram from the filtered lines
jsonResult.type = determineDiagramType(filteredLines);
// Call the appropriate parser based on diagram type
switch (jsonResult.type) {
case 'classDiagram':
parseClassDiagram(filteredLines, jsonResult);
break;
case 'erDiagram':
parseERDiagram(filteredLines, jsonResult);
break;
case 'sequenceDiagram':
parseSequenceDiagram(filteredLines, jsonResult);
break;
default:
throw new Error("Unsupported diagram type.");
}
return jsonResult;
}
module.exports = { convertToUML };