@activecollab/components
Version:
ActiveCollab Components
13 lines • 625 B
JavaScript
export const findHighlightedSearch = (searchValue, target) => {
if (searchValue && target) {
const purifiedTarget = target == null ? void 0 : target.replace(/<script.*?>.*?<\/script>/gi, "");
const parser = new DOMParser();
const doc = parser.parseFromString(purifiedTarget, "text/html");
const text = doc.body.textContent || "";
const checkValidSearchChars = searchValue.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const regex = new RegExp("(" + checkValidSearchChars + ")", "gi");
return text.replace(regex, "<mark>$1</mark>");
}
return "";
};
//# sourceMappingURL=findHighlightedSearch.js.map