mirror of
https://github.com/flarum/core.git
synced 2025-07-25 18:51:40 +02:00
Move generic util into lib
Might come in handy for the admin section later on
This commit is contained in:
19
framework/core/js/lib/utils/extractText.js
Normal file
19
framework/core/js/lib/utils/extractText.js
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
Reference in New Issue
Block a user