Files
explore/lib/highlightText.ts
T
2023-09-06 03:30:44 +07:00

9 lines
262 B
TypeScript

import xss from 'xss';
import escapeRegExp from 'lib/escapeRegExp';
export default function highlightText(text: string, query: string) {
const regex = new RegExp('(' + escapeRegExp(query) + ')', 'gi');
return xss(text.replace(regex, '<mark>$1</mark>'));
}