framework/js/lib/utils/extractText.js

16 lines
382 B
JavaScript
Raw Normal View History

2015-07-17 16:13:28 +08:00
/**
* 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('');
2017-10-08 06:29:54 +08:00
} else if (typeof vdom === 'object' && vdom !== null) {
return extractText(vdom.children);
2015-07-17 16:13:28 +08:00
} else {
return vdom;
2015-07-17 16:13:28 +08:00
}
}