yoastseo-dep
Version:
Yoast clientside page analysis
25 lines (21 loc) • 478 B
JavaScript
import { isEmpty } from "lodash-es";
/**
* Gathers the text content of the given node.
*
* @param {Object} node The node to gather the text content from.
*
* @returns {string} The text content.
*/
export default function innerText( node ) {
let text = "";
if ( ! isEmpty( node.childNodes ) ) {
node.childNodes.forEach( child => {
if ( child.name === "#text" ) {
text += child.value;
} else {
text += innerText( child );
}
} );
}
return text;
}