diff --git a/src/mermaid.js b/src/mermaid.js index 4e2392190..05e7cb8d8 100644 --- a/src/mermaid.js +++ b/src/mermaid.js @@ -2,11 +2,12 @@ * Web page integration module for the mermaid framework. It uses the mermaidAPI for mermaid functionality and to render * the diagrams to svg code. */ -var he = require('he') +import he from 'he' + +import mermaidAPI from './mermaidAPI' var Logger = require('./logger') var log = Logger.Log -var mermaidAPI = require('./mermaidAPI') var nextId = 0 /** diff --git a/src/mermaidAPI.js b/src/mermaidAPI.js index 725cc5969..8ba27b40c 100644 --- a/src/mermaidAPI.js +++ b/src/mermaidAPI.js @@ -242,7 +242,7 @@ var config = { Logger.setLogLevel(config.logLevel) -var parse = function (text) { +function parse (text) { var graphType = utils.detectType(text) var parser @@ -284,7 +284,6 @@ var parse = function (text) { parser.parse(text) } -module.exports.parse = parse /** * ## version @@ -476,7 +475,7 @@ var render = function (id, txt, cb, container) { return svgCode } -module.exports.render = function (id, text, cb, containerElement) { +function render2 (id, text, cb, containerElement) { try { if (arguments.length === 1) { text = id @@ -517,7 +516,7 @@ var setConf = function (cnf) { } } -module.exports.initialize = function (options) { +function initialize (options) { log.debug('Initializing mermaidAPI') // Update default config with options supplied at initialization if (typeof options === 'object') { @@ -525,14 +524,17 @@ module.exports.initialize = function (options) { } Logger.setLogLevel(config.logLevel) } -module.exports.getConfig = function () { + +function getConfig () { return config } -global.mermaidAPI = { - render: module.exports.render, - parse: module.exports.parse, - initialize: module.exports.initialize, +const mermaidAPI = { + render: render2, + parse, + initialize, detectType: utils.detectType, - getConfig: module.exports.getConfig + getConfig } + +export default mermaidAPI diff --git a/src/mermaidAPI.spec.js b/src/mermaidAPI.spec.js index 0683a00c8..ff409da99 100644 --- a/src/mermaidAPI.spec.js +++ b/src/mermaidAPI.spec.js @@ -1,11 +1,5 @@ /* eslint-env jasmine */ -/** - * Created by knut on 14-11-26. - */ -/** - * Created by knut on 14-11-23. - */ -var api = require('./mermaidAPI.js') +import mermaidAPI from './mermaidAPI' describe('when using mermaidAPI and ', function () { describe('doing initialize ', function () { @@ -15,16 +9,16 @@ describe('when using mermaidAPI and ', function () { }) it('should copy a literal into the configuration', function () { - var orgConfig = api.getConfig() + var orgConfig = mermaidAPI.getConfig() expect(orgConfig.testLiteral).toBe(undefined) - api.initialize({ 'testLiteral': true }) - var config = api.getConfig() + mermaidAPI.initialize({ 'testLiteral': true }) + var config = mermaidAPI.getConfig() expect(config.testLiteral).toBe(true) }) it('should copy a an object into the configuration', function () { - var orgConfig = api.getConfig() + var orgConfig = mermaidAPI.getConfig() expect(orgConfig.testObject).toBe(undefined) var object = { @@ -32,9 +26,9 @@ describe('when using mermaidAPI and ', function () { test2: false } - api.initialize({ 'testObject': object }) - api.initialize({ 'testObject': { 'test3': true } }) - var config = api.getConfig() + mermaidAPI.initialize({ 'testObject': object }) + mermaidAPI.initialize({ 'testObject': { 'test3': true } }) + var config = mermaidAPI.getConfig() expect(config.testObject.test1).toBe(1) expect(config.testObject.test2).toBe(false) @@ -44,10 +38,10 @@ describe('when using mermaidAPI and ', function () { }) describe('checking validity of input ', function () { it('it should throw for an invalid definiton', function () { - expect(() => global.mermaidAPI.parse('this is not a mermaid diagram definition')).toThrow() + expect(() => mermaidAPI.parse('this is not a mermaid diagram definition')).toThrow() }) it('it should not throw for a valid definiton', function () { - expect(() => global.mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).not.toThrow() + expect(() => mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).not.toThrow() }) }) }) diff --git a/todo.md b/todo.md index 2cdfcd958..1115a7b1f 100644 --- a/todo.md +++ b/todo.md @@ -16,5 +16,6 @@ - Replace require with import - Replace module.exports with export default - Replace karma-webpack with karma-babel -- Webpack generate mermaid.js & mermaid.core.js - Stops working for mermaid-live-editor since 7.0.9 +- global.mermaid_config +- rewrite logger