MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / highlightWords

Function highlightWords

console/src/components/Highlight.tsx:50–64  ·  view source on GitHub ↗
({
  text,
  query,
  caseSensitive = false,
}: HighlightOptions)

Source from the content-addressed store, hash-verified

48}
49
50function 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}
65function useHighlight({ text, query, caseSensitive }: UseHighlightProps) {
66 return useMemo(
67 () => highlightWords({ text, query, caseSensitive }),

Callers 1

useHighlightFunction · 0.85

Calls 5

buildRegexFunction · 0.85
filterMethod · 0.45
splitMethod · 0.45
mapMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected