dbl-utils
Version:
Utilities for dbl, adba and others projects
16 lines (15 loc) • 439 B
JavaScript
import React from "react";
export const extractNodeString = (obj) => {
if (typeof obj === 'string')
return obj;
else if (Array.isArray(obj)) {
return obj.map(e => extractNodeString(e)).filter(n => !!n).flat().join(' ');
}
else if (React.isValidElement(obj)) {
obj = obj;
return extractNodeString(obj.props.children);
}
else if (!obj)
return '';
return obj.toString();
};