syntax-tree / mdast-util-to-string

Compare dcab685 ... +23 ... 8c5e180

Coverage Reach
index.js

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 10 files from the diff.
Other files ignored by Codecov

@@ -1,30 +1,61 @@
Loading
1 -
'use strict'
1 +
/**
2 +
 * @typedef {import('mdast').Root|import('mdast').Content} Node
3 +
 *
4 +
 * @typedef Options
5 +
 * @property {boolean} [includeImageAlt=true]
6 +
 */
2 7
3 -
module.exports = toString
8 +
/**
9 +
 * Get the text content of a node.
10 +
 * Prefer the node’s plain-text fields, otherwise serialize its children,
11 +
 * and if the given value is an array, serialize the nodes in it.
12 +
 *
13 +
 * @param {unknown} value
14 +
 * @param {Options} [options]
15 +
 * @returns {string}
16 +
 */
17 +
export function toString(value, options = {}) {
18 +
  const {includeImageAlt = true} = options
19 +
  return one(value, includeImageAlt)
20 +
}
4 21
5 -
// Get the text content of a node.
6 -
// Prefer the node’s plain-text fields, otherwise serialize its children,
7 -
// and if the given value is an array, serialize the nodes in it.
8 -
function toString(node) {
22 +
/**
23 +
 * @param {unknown} value
24 +
 * @param {boolean} includeImageAlt
25 +
 * @returns {string}
26 +
 */
27 +
function one(value, includeImageAlt) {
9 28
  return (
10 -
    (node &&
11 -
      (node.value ||
12 -
        node.alt ||
13 -
        node.title ||
14 -
        ('children' in node && all(node.children)) ||
15 -
        ('length' in node && all(node)))) ||
29 +
    (node(value) &&
30 +
      (('value' in value && value.value) ||
31 +
        (includeImageAlt && 'alt' in value && value.alt) ||
32 +
        ('children' in value && all(value.children, includeImageAlt)))) ||
33 +
    (Array.isArray(value) && all(value, includeImageAlt)) ||
16 34
    ''
17 35
  )
18 36
}
19 37
20 -
function all(values) {
21 -
  var result = []
22 -
  var length = values.length
23 -
  var index = -1
38 +
/**
39 +
 * @param {Array.<unknown>} values
40 +
 * @param {boolean} includeImageAlt
41 +
 * @returns {string}
42 +
 */
43 +
function all(values, includeImageAlt) {
44 +
  /** @type {Array.<string>} */
45 +
  const result = []
46 +
  let index = -1
24 47
25 -
  while (++index < length) {
26 -
    result[index] = toString(values[index])
48 +
  while (++index < values.length) {
49 +
    result[index] = one(values[index], includeImageAlt)
27 50
  }
28 51
29 52
  return result.join('')
30 53
}
54 +
55 +
/**
56 +
 * @param {unknown} value
57 +
 * @returns {value is Node}
58 +
 */
59 +
function node(value) {
60 +
  return Boolean(value && typeof value === 'object')
61 +
}

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.

25 Commits

Files Coverage
index.js 100.00%
Project Totals (1 files) 100.00%
Loading