MCPcopy Create free account
hub / github.com/dailydotdev/apps / findFirstHighlightedKeyword

Function findFirstHighlightedKeyword

packages/shared/src/lib/brand.ts:78–99  ·  view source on GitHub ↗
(
  text: string,
  keywords: string[] | undefined,
)

Source from the content-addressed store, hash-verified

76 * Returns null when no keyword matches.
77 */
78export const findFirstHighlightedKeyword = (
79 text: string,
80 keywords: string[] | undefined,
81): KeywordMatch | null => {
82 if (!keywords?.length || !text) {
83 return null;
84 }
85
86 const pattern = keywords.map(escapeRegex).join('|');
87 const regex = new RegExp(`\\b(?:${pattern})\\b`, 'i');
88 const match = text.match(regex);
89
90 if (!match || match.index === undefined) {
91 return null;
92 }
93
94 return {
95 keyword: match[0],
96 start: match.index,
97 end: match.index + match[0].length,
98 };
99};

Callers 2

HighlightedBrandTextFunction · 0.90
brand.spec.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected