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

Function readAttributeByTarget

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

Source from the content-addressed store, hash-verified

289}
290
291export function readAttributeByTarget(
292 html: string,
293 target: PatchTarget,
294 attr: string,
295): string | undefined {
296 const match = findTagByTarget(html, target);
297 if (!match) return undefined;
298
299 const fullAttr = attr.startsWith("data-") ? attr : `data-${attr}`;
300 const valueMatch = new RegExp(`\\b${fullAttr}=(["'])([^"']*)\\1`).exec(match.tag);
301 return valueMatch?.[2] != null ? unescapeHtmlAttribute(valueMatch[2]) : undefined;
302}
303
304export function readTagSnippetByTarget(html: string, target: PatchTarget): string | undefined {
305 const match = findTagByTarget(html, target);

Callers 3

Calls 2

findTagByTargetFunction · 0.85
unescapeHtmlAttributeFunction · 0.85

Tested by

no test coverage detected