Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
509 B
1
Indexable
// 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