el-beeswarm
Version:
<div style="display: flex; padding: 1rem; flex-direction: column; align-items: center; justify-content: center; height: 100vh; text-align: center; display: flex;
30 lines (24 loc) • 615 B
JavaScript
module.exports = toString
// Get the text content of a node.
// Prefer the node’s plain-text fields, otherwise serialize its children,
// and if the given value is an array, serialize the nodes in it.
function toString(node) {
return (
(node &&
(node.value ||
node.alt ||
node.title ||
('children' in node && all(node.children)) ||
('length' in node && all(node)))) ||
''
)
}
function all(values) {
var result = []
var index = -1
while (++index < values.length) {
result[index] = toString(values[index])
}
return result.join('')
}