mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 07:19:41 +02:00
Replace 'var ' with 'const '
This commit is contained in:
@@ -59,9 +59,9 @@ describe('when using mermaid and ', function () {
|
|||||||
it('it should handle edges with text', function () {
|
it('it should handle edges with text', function () {
|
||||||
flowParser.parser.parse('graph TD;A-->|text ex|B;')
|
flowParser.parser.parse('graph TD;A-->|text ex|B;')
|
||||||
flowParser.parser.yy.getVertices()
|
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) {
|
setEdge: function (start, end, options) {
|
||||||
expect(start).toBe('A')
|
expect(start).toBe('A')
|
||||||
expect(end).toBe('B')
|
expect(end).toBe('B')
|
||||||
@@ -76,9 +76,9 @@ describe('when using mermaid and ', function () {
|
|||||||
it('should handle edges without text', function () {
|
it('should handle edges without text', function () {
|
||||||
flowParser.parser.parse('graph TD;A-->B;')
|
flowParser.parser.parse('graph TD;A-->B;')
|
||||||
flowParser.parser.yy.getVertices()
|
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) {
|
setEdge: function (start, end, options) {
|
||||||
expect(start).toBe('A')
|
expect(start).toBe('A')
|
||||||
expect(end).toBe('B')
|
expect(end).toBe('B')
|
||||||
@@ -92,9 +92,9 @@ describe('when using mermaid and ', function () {
|
|||||||
it('should handle open-ended edges', function () {
|
it('should handle open-ended edges', function () {
|
||||||
flowParser.parser.parse('graph TD;A---B;')
|
flowParser.parser.parse('graph TD;A---B;')
|
||||||
flowParser.parser.yy.getVertices()
|
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) {
|
setEdge: function (start, end, options) {
|
||||||
expect(start).toBe('A')
|
expect(start).toBe('A')
|
||||||
expect(end).toBe('B')
|
expect(end).toBe('B')
|
||||||
@@ -108,9 +108,9 @@ describe('when using mermaid and ', function () {
|
|||||||
it('should handle edges with styles defined', 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.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;')
|
||||||
flowParser.parser.yy.getVertices()
|
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) {
|
setEdge: function (start, end, options) {
|
||||||
expect(start).toBe('A')
|
expect(start).toBe('A')
|
||||||
expect(end).toBe('B')
|
expect(end).toBe('B')
|
||||||
@@ -124,9 +124,9 @@ describe('when using mermaid and ', function () {
|
|||||||
it('should handle edges with interpolation defined', function () {
|
it('should handle edges with interpolation defined', function () {
|
||||||
flowParser.parser.parse('graph TD;A---B; linkStyle 0 interpolate basis')
|
flowParser.parser.parse('graph TD;A---B; linkStyle 0 interpolate basis')
|
||||||
flowParser.parser.yy.getVertices()
|
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) {
|
setEdge: function (start, end, options) {
|
||||||
expect(start).toBe('A')
|
expect(start).toBe('A')
|
||||||
expect(end).toBe('B')
|
expect(end).toBe('B')
|
||||||
@@ -140,9 +140,9 @@ describe('when using mermaid and ', function () {
|
|||||||
it('should handle edges with text and styles defined', 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.parse('graph TD;A---|the text|B; linkStyle 0 stroke:val1,stroke-width:val2;')
|
||||||
flowParser.parser.yy.getVertices()
|
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) {
|
setEdge: function (start, end, options) {
|
||||||
expect(start).toBe('A')
|
expect(start).toBe('A')
|
||||||
expect(end).toBe('B')
|
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 () {
|
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.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2;')
|
||||||
flowParser.parser.yy.getVertices()
|
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) {
|
setEdge: function (start, end, options) {
|
||||||
expect(start).toBe('A')
|
expect(start).toBe('A')
|
||||||
expect(end).toBe('B')
|
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 () {
|
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.parse('graph TD;A---B; linkStyle 0 stroke:val1,stroke-width:val2,fill:blue;')
|
||||||
flowParser.parser.yy.getVertices()
|
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) {
|
setEdge: function (start, end, options) {
|
||||||
expect(start).toBe('A')
|
expect(start).toBe('A')
|
||||||
expect(end).toBe('B')
|
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 () {
|
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' +
|
'Alice->Bob: Hello Bob, how are you?\n\n' +
|
||||||
'%% Comment\n' +
|
'%% Comment\n' +
|
||||||
'Note right of Bob: Bob thinks\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 () {
|
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' +
|
'Alice:->Bob: Hello Bob, how are you?\n\n' +
|
||||||
'%% Comment\n' +
|
'%% Comment\n' +
|
||||||
'Note right of Bob: Bob thinks\n' +
|
'Note right of Bob: Bob thinks\n' +
|
||||||
|
@@ -58,7 +58,7 @@ const themes = {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
var config = {
|
const config = {
|
||||||
theme: defaultTheme,
|
theme: defaultTheme,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -251,8 +251,8 @@ var config = {
|
|||||||
setLogLevel(config.logLevel)
|
setLogLevel(config.logLevel)
|
||||||
|
|
||||||
function parse (text) {
|
function parse (text) {
|
||||||
var graphType = utils.detectType(text)
|
const graphType = utils.detectType(text)
|
||||||
var parser
|
let parser
|
||||||
|
|
||||||
switch (graphType) {
|
switch (graphType) {
|
||||||
case 'gitGraph':
|
case 'gitGraph':
|
||||||
@@ -303,21 +303,21 @@ export const version = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const encodeEntities = function (text) {
|
export const encodeEntities = function (text) {
|
||||||
var txt = text
|
let txt = text
|
||||||
|
|
||||||
txt = txt.replace(/style.*:\S*#.*;/g, function (s) {
|
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
|
return innerTxt
|
||||||
})
|
})
|
||||||
txt = txt.replace(/classDef.*:\S*#.*;/g, function (s) {
|
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
|
return innerTxt
|
||||||
})
|
})
|
||||||
|
|
||||||
txt = txt.replace(/#\w+;/g, function (s) {
|
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) {
|
if (isInt) {
|
||||||
return 'fl°°' + innerTxt + '¶ß'
|
return 'fl°°' + innerTxt + '¶ß'
|
||||||
} else {
|
} else {
|
||||||
@@ -329,7 +329,7 @@ export const encodeEntities = function (text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const decodeEntities = function (text) {
|
export const decodeEntities = function (text) {
|
||||||
var txt = text
|
let txt = text
|
||||||
|
|
||||||
txt = txt.replace(/fl°°/g, function () {
|
txt = txt.replace(/fl°°/g, function () {
|
||||||
return '&#'
|
return '&#'
|
||||||
@@ -352,8 +352,8 @@ export const decodeEntities = function (text) {
|
|||||||
* startOnLoad:true
|
* startOnLoad:true
|
||||||
* });
|
* });
|
||||||
* $(function(){
|
* $(function(){
|
||||||
* var graphDefinition = 'graph TB\na-->b';
|
* const graphDefinition = 'graph TB\na-->b';
|
||||||
* var cb = function(svgGraph){
|
* const cb = function(svgGraph){
|
||||||
* console.log(svgGraph);
|
* console.log(svgGraph);
|
||||||
* };
|
* };
|
||||||
* mermaidAPI.render('id1',graphDefinition,cb);
|
* 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
|
* provided a hidden div will be inserted in the body of the page instead. The element will be removed when rendering is
|
||||||
* completed.
|
* completed.
|
||||||
*/
|
*/
|
||||||
var render = function (id, txt, cb, container) {
|
const render = function (id, txt, cb, container) {
|
||||||
if (typeof container !== 'undefined') {
|
if (typeof container !== 'undefined') {
|
||||||
container.innerHTML = ''
|
container.innerHTML = ''
|
||||||
|
|
||||||
@@ -395,8 +395,8 @@ var render = function (id, txt, cb, container) {
|
|||||||
window.txt = txt
|
window.txt = txt
|
||||||
txt = encodeEntities(txt)
|
txt = encodeEntities(txt)
|
||||||
|
|
||||||
var element = d3.select('#d' + id).node()
|
const element = d3.select('#d' + id).node()
|
||||||
var graphType = utils.detectType(txt)
|
const graphType = utils.detectType(txt)
|
||||||
switch (graphType) {
|
switch (graphType) {
|
||||||
case 'gitGraph':
|
case 'gitGraph':
|
||||||
config.flowchart.arrowMarkerAbsolute = config.arrowMarkerAbsolute
|
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')
|
d3.select('#d' + id).selectAll('foreignobject div').attr('xmlns', 'http://www.w3.org/1999/xhtml')
|
||||||
|
|
||||||
var url = ''
|
let url = ''
|
||||||
if (config.arrowMarkerAbsolute) {
|
if (config.arrowMarkerAbsolute) {
|
||||||
url = window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search
|
url = window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.search
|
||||||
url = url.replace(/\(/g, '\\(')
|
url = url.replace(/\(/g, '\\(')
|
||||||
@@ -457,7 +457,7 @@ svg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fix for when the base tag is used
|
// 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)
|
svgCode = decodeEntities(svgCode)
|
||||||
|
|
||||||
@@ -467,7 +467,7 @@ svg {
|
|||||||
logger.warn('CB = undefined!')
|
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') {
|
if (node !== null && typeof node.remove === 'function') {
|
||||||
d3.select('#d' + id).node().remove()
|
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
|
// Top level initially mermaid, gflow, sequenceDiagram and gantt
|
||||||
var lvl1Keys = Object.keys(cnf)
|
const lvl1Keys = Object.keys(cnf)
|
||||||
var i
|
for (let i = 0; i < lvl1Keys.length; i++) {
|
||||||
for (i = 0; i < lvl1Keys.length; i++) {
|
|
||||||
if (typeof cnf[lvl1Keys[i]] === 'object') {
|
if (typeof cnf[lvl1Keys[i]] === 'object') {
|
||||||
var lvl2Keys = Object.keys(cnf[lvl1Keys[i]])
|
const lvl2Keys = Object.keys(cnf[lvl1Keys[i]])
|
||||||
|
|
||||||
var j
|
for (let j = 0; j < lvl2Keys.length; j++) {
|
||||||
for (j = 0; j < lvl2Keys.length; j++) {
|
|
||||||
logger.debug('Setting conf ', lvl1Keys[i], '-', lvl2Keys[j])
|
logger.debug('Setting conf ', lvl1Keys[i], '-', lvl2Keys[j])
|
||||||
if (typeof config[lvl1Keys[i]] === 'undefined') {
|
if (typeof config[lvl1Keys[i]] === 'undefined') {
|
||||||
config[lvl1Keys[i]] = {}
|
config[lvl1Keys[i]] = {}
|
||||||
|
Reference in New Issue
Block a user