From 26d9a1004215a2fa6665e28a2891d41065368cfd Mon Sep 17 00:00:00 2001 From: cvillasenor Date: Thu, 11 Jul 2024 14:22:02 -0600 Subject: [PATCH] fix(menu-item): update regex 'containsHexCode' function --- src/js/menu/menu-item.js | 5 +---- src/js/utils/str.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/js/menu/menu-item.js b/src/js/menu/menu-item.js index 90daf923f..112fc9f68 100644 --- a/src/js/menu/menu-item.js +++ b/src/js/menu/menu-item.js @@ -4,6 +4,7 @@ import ClickableComponent from '../clickable-component.js'; import Component from '../component.js'; import {createEl} from '../utils/dom.js'; +import { containsHexCode } from '../utils/str.js'; /** @import Player from '../player' */ @@ -74,10 +75,6 @@ class MenuItem extends ClickableComponent { textContent: this.localize(this.options_.label) }); - const containsHexCode = (s) => { - return /\w*(&#x...)\w*/.test(s); - }; - if (containsHexCode(menuItemEl.textContent)) { // Replacement that allows innerHTML to be render properly. menuItemEl.innerHTML = menuItemEl.textContent; diff --git a/src/js/utils/str.js b/src/js/utils/str.js index 3eb3ee814..d45386210 100644 --- a/src/js/utils/str.js +++ b/src/js/utils/str.js @@ -52,3 +52,15 @@ export const toTitleCase = function(string) { export const titleCaseEquals = function(str1, str2) { return toTitleCase(str1) === toTitleCase(str2); }; + +/** + * + * @param {string} string + * The string that will be tested + * + * @return {boolean} + * Whether the string contains a Hex Code + */ +export const containsHexCode = (string) => { + return /\w*(&#x.{2,4};)\w*/.test(string); +};