diff --git a/src/mermaid.spec.js b/src/mermaid.spec.js index d6266c98f..433ba8863 100644 --- a/src/mermaid.spec.js +++ b/src/mermaid.spec.js @@ -59,9 +59,9 @@ describe('when using mermaid and ', function () { it('it should handle edges with text', function () { flowParser.parser.parse('graph TD;A-->|text ex|B;') flowParser.parser.yy.getVertices() - var edges = flowParser.parser.yy.getEdges() + const edges = flowParser.parser.yy.getEdges() - var mockG = { + const mockG = { setEdge: function (start, end, options) { expect(start).toBe('A') expect(end).toBe('B') @@ -76,9 +76,9 @@ describe('when using mermaid and ', function () { it('should handle edges without text', function () { flowParser.parser.parse('graph TD;A-->B;') flowParser.parser.yy.getVertices() - var edges = flowParser.parser.yy.getEdges() + const edges = flowParser.parser.yy.getEdges() - var mockG = { + const mockG = { setEdge: function (start, end, options) { expect(start).toBe('A') expect(end).toBe('B') @@ -92,9 +92,9 @@ describe('when using mermaid and ', function () { it('should handle open-ended edges', function () { flowParser.parser.parse('graph TD;A---B;') flowParser.parser.yy.getVertices() - var edges = flowParser.parser.yy.getEdges() + const edges = flowParser.parser.yy.getEdges() - var mockG = { + const mockG = { setEdge: function (start, end, options) { expect(start).toBe('A') expect(end).toBe('B') @@ -108,9 +108,9 @@ describe('when using mermaid and ', function () { it('should handle edges with styles defined', function () { flowParser.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;') flowParser.parser.yy.getVertices() - var edges = flowParser.parser.yy.getEdges() + const edges = flowParser.parser.yy.getEdges() - var mockG = { + const mockG = { setEdge: function (start, end, options) { expect(start).toBe('A') expect(end).toBe('B') @@ -124,9 +124,9 @@ describe('when using mermaid and ', function () { it('should handle edges with interpolation defined', function () { flowParser.parser.parse('graph TD;A---B; linkStyle 0 interpolate basis') flowParser.parser.yy.getVertices() - var edges = flowParser.parser.yy.getEdges() + const edges = flowParser.parser.yy.getEdges() - var mockG = { + const mockG = { setEdge: function (start, end, options) { expect(start).toBe('A') expect(end).toBe('B') @@ -140,9 +140,9 @@ describe('when using mermaid and ', function () { it('should handle edges with text and styles defined', function () { flowParser.parser.parse('graph TD;A---|the text|B; linkStyle 0 stroke:val1,stroke-width:val2;') flowParser.parser.yy.getVertices() - var edges = flowParser.parser.yy.getEdges() + const edges = flowParser.parser.yy.getEdges() - var mockG = { + const mockG = { setEdge: function (start, end, options) { expect(start).toBe('A') expect(end).toBe('B') @@ -158,9 +158,9 @@ describe('when using mermaid and ', function () { it('should set fill to "none" by default when handling edges', function () { flowParser.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;') flowParser.parser.yy.getVertices() - var edges = flowParser.parser.yy.getEdges() + const edges = flowParser.parser.yy.getEdges() - var mockG = { + const mockG = { setEdge: function (start, end, options) { expect(start).toBe('A') expect(end).toBe('B') @@ -175,8 +175,8 @@ describe('when using mermaid and ', function () { it('should not set fill to none if fill is set in linkStyle', function () { flowParser.parser.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2,fill:blue;') flowParser.parser.yy.getVertices() - var edges = flowParser.parser.yy.getEdges() - var mockG = { + const edges = flowParser.parser.yy.getEdges() + const mockG = { setEdge: function (start, end, options) { expect(start).toBe('A') expect(end).toBe('B') @@ -202,7 +202,7 @@ describe('when using mermaid and ', function () { }) it('it should not throw for a valid sequenceDiagram definition', function () { - var text = 'sequenceDiagram\n' + + const text = 'sequenceDiagram\n' + 'Alice->Bob: Hello Bob, how are you?\n\n' + '%% Comment\n' + 'Note right of Bob: Bob thinks\n' + @@ -215,7 +215,7 @@ describe('when using mermaid and ', function () { }) it('it should throw for an invalid sequenceDiagram definition', function () { - var text = 'sequenceDiagram\n' + + const text = 'sequenceDiagram\n' + 'Alice:->Bob: Hello Bob, how are you?\n\n' + '%% Comment\n' + 'Note right of Bob: Bob thinks\n' + diff --git a/src/mermaidAPI.js b/src/mermaidAPI.js index 1196a8833..2a45de781 100644 --- a/src/mermaidAPI.js +++ b/src/mermaidAPI.js @@ -58,7 +58,7 @@ const themes = { * }); * ``` */ -var config = { +const config = { theme: defaultTheme, /** @@ -251,8 +251,8 @@ var config = { setLogLevel(config.logLevel) function parse (text) { - var graphType = utils.detectType(text) - var parser + const graphType = utils.detectType(text) + let parser switch (graphType) { case 'gitGraph': @@ -303,21 +303,21 @@ export const version = function () { } export const encodeEntities = function (text) { - var txt = text + let txt = text txt = txt.replace(/style.*:\S*#.*;/g, function (s) { - var innerTxt = s.substring(0, s.length - 1) + const innerTxt = s.substring(0, s.length - 1) return innerTxt }) txt = txt.replace(/classDef.*:\S*#.*;/g, function (s) { - var innerTxt = s.substring(0, s.length - 1) + const innerTxt = s.substring(0, s.length - 1) return innerTxt }) txt = txt.replace(/#\w+;/g, function (s) { - var innerTxt = s.substring(1, s.length - 1) + const innerTxt = s.substring(1, s.length - 1) - var isInt = /^\+?\d+$/.test(innerTxt) + const isInt = /^\+?\d+$/.test(innerTxt) if (isInt) { return 'fl°°' + innerTxt + '¶ß' } else { @@ -329,7 +329,7 @@ export const encodeEntities = function (text) { } export const decodeEntities = function (text) { - var txt = text + let txt = text txt = txt.replace(/fl°°/g, function () { return '&#' @@ -352,8 +352,8 @@ export const decodeEntities = function (text) { * startOnLoad:true * }); * $(function(){ - * var graphDefinition = 'graph TB\na-->b'; - * var cb = function(svgGraph){ + * const graphDefinition = 'graph TB\na-->b'; + * const cb = function(svgGraph){ * console.log(svgGraph); * }; * mermaidAPI.render('id1',graphDefinition,cb); @@ -366,7 +366,7 @@ export const decodeEntities = function (text) { * provided a hidden div will be inserted in the body of the page instead. The element will be removed when rendering is * completed. */ -var render = function (id, txt, cb, container) { +const render = function (id, txt, cb, container) { if (typeof container !== 'undefined') { container.innerHTML = '' @@ -395,8 +395,8 @@ var render = function (id, txt, cb, container) { window.txt = txt txt = encodeEntities(txt) - var element = d3.select('#d' + id).node() - var graphType = utils.detectType(txt) + const element = d3.select('#d' + id).node() + const graphType = utils.detectType(txt) switch (graphType) { case 'gitGraph': config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute @@ -449,7 +449,7 @@ svg { d3.select('#d' + id).selectAll('foreignobject div').attr('xmlns', 'http://www.w3.org/1999/xhtml') - var url = '' + let url = '' if (config.arrowMarkerAbsolute) { url = window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search url = url.replace(/\(/g, '\\(') @@ -457,7 +457,7 @@ svg { } // Fix for when the base tag is used - var svgCode = d3.select('#d' + id).node().innerHTML.replace(/url\(#arrowhead/g, 'url(' + url + '#arrowhead', 'g') + let svgCode = d3.select('#d' + id).node().innerHTML.replace(/url\(#arrowhead/g, 'url(' + url + '#arrowhead', 'g') svgCode = decodeEntities(svgCode) @@ -467,7 +467,7 @@ svg { logger.warn('CB = undefined!') } - var node = d3.select('#d' + id).node() + const node = d3.select('#d' + id).node() if (node !== null && typeof node.remove === 'function') { d3.select('#d' + id).node().remove() } @@ -493,16 +493,14 @@ function render2 (id, text, cb, containerElement) { } } -var setConf = function (cnf) { +const setConf = function (cnf) { // Top level initially mermaid, gflow, sequenceDiagram and gantt - var lvl1Keys = Object.keys(cnf) - var i - for (i = 0; i < lvl1Keys.length; i++) { + const lvl1Keys = Object.keys(cnf) + for (let i = 0; i < lvl1Keys.length; i++) { if (typeof cnf[lvl1Keys[i]] === 'object') { - var lvl2Keys = Object.keys(cnf[lvl1Keys[i]]) + const lvl2Keys = Object.keys(cnf[lvl1Keys[i]]) - var j - for (j = 0; j < lvl2Keys.length; j++) { + for (let j = 0; j < lvl2Keys.length; j++) { logger.debug('Setting conf ', lvl1Keys[i], '-', lvl2Keys[j]) if (typeof config[lvl1Keys[i]] === 'undefined') { config[lvl1Keys[i]] = {}