1
0
mirror of https://github.com/flarum/core.git synced 2025-10-13 07:54:25 +02:00
Files
php-flarum/js/forum/src/utils/extractText.js
2015-07-17 17:43:28 +09:30

20 lines
402 B
JavaScript

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