MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / findTagByClass

Function findTagByClass

packages/studio/src/utils/sourcePatcher.ts:245–267  ·  view source on GitHub ↗
(html: string, target: PatchTarget)

Source from the content-addressed store, hash-verified

243}
244
245function findTagByClass(html: string, target: PatchTarget): TagMatch | null {
246 const classMatch = target.selector?.match(/^\.([a-zA-Z0-9_-]+)$/);
247 if (!classMatch) return null;
248 const cls = classMatch[1];
249 const pattern = new RegExp(
250 `(<[^>]*\\bclass=(["'])[^"']*\\b${escapeRegex(cls)}\\b[^"']*\\2[^>]*)>`,
251 "gi",
252 );
253 const selectorIndex = target.selectorIndex ?? 0;
254 let match: RegExpExecArray | null;
255 let currentIndex = 0;
256 while ((match = pattern.exec(html)) !== null) {
257 if (currentIndex === selectorIndex && match.index != null) {
258 return {
259 tag: match[1],
260 start: match.index,
261 end: match.index + match[1].length,
262 };
263 }
264 currentIndex += 1;
265 }
266 return null;
267}
268
269export function findTagByTarget(html: string, target: PatchTarget): TagMatch | null {
270 if (target.hfId) {

Callers 1

findTagByTargetFunction · 0.85

Calls 1

escapeRegexFunction · 0.70

Tested by

no test coverage detected