From b8c956cadd29673b05713c6c836f0a8b6102aaa9 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 13 Oct 2024 21:09:09 +0200 Subject: [PATCH] hasPlaceholder method added. see #146 --- js/mzta-placeholders.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/js/mzta-placeholders.js b/js/mzta-placeholders.js index 52856fff..f1cfb3a0 100644 --- a/js/mzta-placeholders.js +++ b/js/mzta-placeholders.js @@ -134,4 +134,20 @@ export const placeholdersUtils = { }); }, + hasPlaceholder(text, placeholder = "") { + let regex; + + // If a specific placeholder is provided, we search for it + if (placeholder !== "") { + // Dynamically build the regex for the specific placeholder + regex = new RegExp(`{%\s*${placeholder}\s*%}`); + } else { + // Otherwise, we search for any placeholder in the format {% ... %} + regex = /{%\s*(.*?)\s*%}/; + } + + // Check if the specific or any placeholder is present in the text + return regex.test(text); + }, + } \ No newline at end of file