mirror of
https://github.com/flarum/framework.git
synced 2024-12-01 14:20:47 +08:00
722058f2fb
Might come in handy for the admin section later on
20 lines
402 B
JavaScript
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;
|
|
}
|