1 import { normalize } from '@proton/shared/lib/helpers/string';
4 * Returns a formatted JSX with all matches wrapped with <b></b>
6 export const getMatch = (
7 input: string | undefined,
9 getHighlightedText = (str: string) => <mark className="is-light">{str}</mark>
14 const parts = normalize(input, true).split(match);
15 if (parts.length < 2) {
18 const { result } = parts.reduce(
19 (acc, part, partIndex) => {
23 {input.substring(acc.currentIdx, acc.currentIdx + part.length)}
24 {partIndex !== parts.length - 1 && getHighlightedText(match)}
27 return { result: matchPart, currentIdx: acc.currentIdx + part.length + match.length };
29 { result: <></>, currentIdx: 0 }