* properly render html responses * My empty commit with a message * My empty commit with a message * Remove package, use custom function Co-authored-by: Adeoluwa Ayangade <adeoluwaayangade@Adeoluwas-MacBook-Pro.local>
12 lines
362 B
TypeScript
12 lines
362 B
TypeScript
export const isHtml = (str: string) => {
|
|
const fragment = document.createRange().createContextualFragment(str);
|
|
|
|
// remove all non text nodes from fragment
|
|
fragment
|
|
.querySelectorAll("*")
|
|
.forEach((el: any) => el.parentNode.removeChild(el));
|
|
|
|
// if there is textContent, then its not a pure HTML
|
|
return !(fragment.textContent || "").trim();
|
|
};
|