hasPlaceholder method added. see #146

This commit is contained in:
mic 2024-10-13 21:09:09 +02:00
parent 97faed5ac9
commit b8c956cadd

View file

@ -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);
},
}