Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const renderNode = (node, { stripTags = false }) => {
if (!node) return '';
const type = typeof node;
if (type === 'string' || type === 'number') {
return node;
}
if (type === 'object') {
if (stripTags === true) {
// eslint-disable-next-line no-use-before-define
return renderNodes(node.content, { stripTags });
}
if (node.content === null) {
return [START_TAG, node.tag, attrsToString(node.attrs), SELFCLOSE_END_TAG].join('');
}
// eslint-disable-next-line no-use-before-define
return [START_TAG, node.tag, attrsToString(node.attrs), END_TAG, renderNodes(node.content), CLOSE_START_TAG, node.tag, END_TAG].join('');
}
if (Array.isArray(node)) {
// eslint-disable-next-line no-use-before-define
return renderNodes(node, { stripTags });
}
return '';
};