syntax-tree / mdast-util-frontmatter

Compare 400bfe0 ... +1 ... 15eba4f

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 5 files from the diff.
Other files ignored by Codecov
package.json has changed.
test.js has changed.
.gitignore has changed.

@@ -1,8 +1,27 @@
Loading
1 -
import matters from 'micromark-extension-frontmatter/lib/matters.js'
1 +
/**
2 +
 * @typedef {import('mdast').Literal} Literal
3 +
 * @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
4 +
 * @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle
5 +
 * @typedef {import('mdast-util-to-markdown/lib/types.js').Options} ToMarkdownExtension
6 +
 * @typedef {import('mdast-util-to-markdown/lib/types.js').Handle} ToMarkdownHandle
7 +
 * @typedef {import('mdast-util-to-markdown/lib/util/indent-lines.js').Map} Map
8 +
 *
9 +
 * @typedef {import('micromark-extension-frontmatter/matters.js').Options} Options
10 +
 * @typedef {import('micromark-extension-frontmatter/matters.js').Matter} Matter
11 +
 * @typedef {import('micromark-extension-frontmatter/matters.js').Info} Info
12 +
 */
2 13
14 +
import {matters} from 'micromark-extension-frontmatter/matters.js'
15 +
16 +
/**
17 +
 * @param {Options} [options]
18 +
 * @returns {FromMarkdownExtension}
19 +
 */
3 20
export function frontmatterFromMarkdown(options) {
4 21
  const settings = matters(options)
22 +
  /** @type {FromMarkdownExtension['enter']} */
5 23
  const enter = {}
24 +
  /** @type {FromMarkdownExtension['exit']} */
6 25
  const exit = {}
7 26
  let index = -1
8 27
@@ -16,27 +35,41 @@
Loading
16 35
  return {enter, exit}
17 36
}
18 37
38 +
/**
39 +
 * @param {Matter} matter
40 +
 * @returns {FromMarkdownHandle} enter
41 +
 */
19 42
function opener(matter) {
20 43
  return open
44 +
  /** @type {FromMarkdownHandle} */
21 45
  function open(token) {
46 +
    // @ts-expect-error: custom.
22 47
    this.enter({type: matter.type, value: ''}, token)
23 48
    this.buffer()
24 49
  }
25 50
}
26 51
52 +
/** @type {FromMarkdownHandle} */
27 53
function close(token) {
28 54
  const data = this.resume()
29 55
  // Remove the initial and final eol.
30 56
  this.exit(token).value = data.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '')
31 57
}
32 58
59 +
/** @type {FromMarkdownHandle} */
33 60
function value(token) {
34 61
  this.config.enter.data.call(this, token)
35 62
  this.config.exit.data.call(this, token)
36 63
}
37 64
65 +
/**
66 +
 * @param {Options} [options]
67 +
 * @returns {ToMarkdownExtension}
68 +
 */
38 69
export function frontmatterToMarkdown(options) {
70 +
  /** @type {ToMarkdownExtension['unsafe']} */
39 71
  const unsafe = []
72 +
  /** @type {ToMarkdownExtension['handlers']} */
40 73
  const handlers = {}
41 74
  const settings = matters(options)
42 75
  let index = -1
@@ -50,23 +83,42 @@
Loading
50 83
  return {unsafe, handlers}
51 84
}
52 85
86 +
/**
87 +
 * @param {Matter} matter
88 +
 * @returns {(node: Literal) => string} enter
89 +
 */
53 90
function handler(matter) {
54 91
  const open = fence(matter, 'open')
55 92
  const close = fence(matter, 'close')
56 93
57 94
  return handle
58 95
96 +
  /**
97 +
   * @type {ToMarkdownHandle}
98 +
   * @param {Literal} node
99 +
   */
59 100
  function handle(node) {
60 101
    return open + (node.value ? '\n' + node.value : '') + '\n' + close
61 102
  }
62 103
}
63 104
105 +
/**
106 +
 * @param {Matter} matter
107 +
 * @param {'open'|'close'} prop
108 +
 * @returns {string}
109 +
 */
64 110
function fence(matter, prop) {
65 111
  return matter.marker
66 112
    ? pick(matter.marker, prop).repeat(3)
67 -
    : pick(matter.fence, prop)
113 +
    : // @ts-expect-error: They’re mutually exclusive.
114 +
      pick(matter.fence, prop)
68 115
}
69 116
117 +
/**
118 +
 * @param {Info|string} schema
119 +
 * @param {'open'|'close'} prop
120 +
 * @returns {string}
121 +
 */
70 122
function pick(schema, prop) {
71 123
  return typeof schema === 'string' ? schema : schema[prop]
72 124
}

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.
Files Coverage
index.js 100.00%
Project Totals (1 files) 100.00%
Loading