Files
30-seconds-of-code/node_modules/mdast-util-to-string/index.js
2019-08-20 15:52:05 +02:00

21 lines
516 B
JavaScript

'use strict'
module.exports = toString
// Get the text content of a node. If the node itself does not expose
// plain-text fields, `toString` will recursivly try its children.
function toString(node) {
return (
valueOf(node) ||
(node.children && node.children.map(toString).join('')) ||
''
)
}
// Get the value of `node`. Checks, `value`, `alt`, and `title`, in that order.
function valueOf(node) {
return (
(node && node.value ? node.value : node.alt ? node.alt : node.title) || ''
)
}