({
text,
query,
caseSensitive = false,
}: HighlightOptions)
| 48 | } |
| 49 | |
| 50 | function highlightWords({ |
| 51 | text, |
| 52 | query, |
| 53 | caseSensitive = false, |
| 54 | }: HighlightOptions): Chunk[] { |
| 55 | const regex = buildRegex( |
| 56 | Array.isArray(query) ? query : [query], |
| 57 | caseSensitive, |
| 58 | ); |
| 59 | if (!regex) { |
| 60 | return [{ text, match: false }]; |
| 61 | } |
| 62 | const result = text.split(regex).filter(Boolean); |
| 63 | return result.map((str) => ({ text: str, match: regex.test(str) })); |
| 64 | } |
| 65 | function useHighlight({ text, query, caseSensitive }: UseHighlightProps) { |
| 66 | return useMemo( |
| 67 | () => highlightWords({ text, query, caseSensitive }), |
no test coverage detected