orgast-util-to-string
Version:
uniorg (orgast) utility to get the plain text content of a node
29 lines • 665 B
JavaScript
/**
* 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.
*/
export function toString(node, _options = {}) {
return one(node);
}
function one(node) {
const n = node;
if (!n) {
return '';
}
if (Array.isArray(n)) {
return all(n);
}
if (typeof n.value === 'string') {
return n.value;
}
if ('children' in n) {
return all(n.children);
}
return '';
}
function all(values) {
return values.map(one).join('');
}
export default toString;
//# sourceMappingURL=index.js.map