From 0644fdfee60027faa86411e8e0a742f40e88aa15 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Sat, 12 Aug 2023 16:41:11 +0530 Subject: [PATCH] Match any function name in error --- packages/mermaid/src/mermaid.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/mermaid/src/mermaid.ts b/packages/mermaid/src/mermaid.ts index 5edc20a7f..a7720326d 100644 --- a/packages/mermaid/src/mermaid.ts +++ b/packages/mermaid/src/mermaid.ts @@ -271,13 +271,15 @@ if (typeof document !== 'undefined') { */ window.addEventListener('load', contentLoaded, false); window.addEventListener('error', ({ message }) => { - if (message.includes('mermaid.initialize is not a function')) { + // Get mermaid function called from error message with regex + const match = message.match(/mermaid\.(\w+) is not a function/); + if (match) { const notify = () => // eslint-disable-next-line no-console console.error(`------------------------------ Breaking change in Mermaid v11 ------------------------------ -Use mermaid.default.initialize() instead of mermaid.initialize() +Use mermaid.default.${match[1]}() instead of mermaid.${match[1]}() Read more: https://github.com/mermaid-js/mermaid/releases/tag/v11.0.0 `); notify();