framework/js/lib/utils/extractText.js
2017-10-08 08:59:54 +10:30

16 lines
382 B
JavaScript

/**
* Extract the text nodes from a virtual element.
*
* @param {VirtualElement} vdom
* @return {String}
*/
export default function extractText(vdom) {
if (vdom instanceof Array) {
return vdom.map(element => extractText(element)).join('');
} else if (typeof vdom === 'object' && vdom !== null) {
return extractText(vdom.children);
} else {
return vdom;
}
}