framework/js/old/common/utils/extractText.js

16 lines
384 B
JavaScript
Raw Normal View History

2015-07-17 17:43:28 +09:30
/**
* Extract the text nodes from a virtual element.
*
* @param {VirtualElement} vdom
* @return {String}
*/
export default function extractText(vdom) {
if (vdom instanceof Array) {
2020-04-17 11:57:55 +02:00
return vdom.map((element) => extractText(element)).join('');
2017-10-08 08:59:54 +10:30
} else if (typeof vdom === 'object' && vdom !== null) {
return extractText(vdom.children);
2015-07-17 17:43:28 +09:30
} else {
return vdom;
2015-07-17 17:43:28 +09:30
}
}