Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
509 B
1
Indexable
Never
// Helper function to check if the text content matches the target text
const isTextContent = (
  content: string | undefined,
  node: Element | undefined,
  targetText: string
): boolean => {
  const hasText = (element: Element) => element.textContent === targetText;
  const nodeHasText = node && hasText(node);
  const childrenDontHaveText = Array.from((node?.children ?? []) as Element[]).every(
    (child) => !hasText(child)
  );

  return Boolean(nodeHasText && childrenDontHaveText);
};
Leave a Comment