mirror of
https://github.com/flarum/framework.git
synced 2024-11-29 04:33:47 +08:00
16 lines
365 B
JavaScript
16 lines
365 B
JavaScript
/**
|
|
* 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('');
|
|
} else if (typeof vdom === 'object') {
|
|
return extractText(vdom.children);
|
|
} else {
|
|
return vdom;
|
|
}
|
|
}
|