framework/js/lib/utils/extractText.js

16 lines
365 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('');
2015-07-17 16:13:28 +08:00
} else if (typeof vdom === 'object') {
return extractText(vdom.children);
2015-07-17 16:13:28 +08:00
} else {
return vdom;
2015-07-17 16:13:28 +08:00
}
}