Skip to content

muescha/unist-util-trace

Repository files navigation

unist-util-trace

Chat

unist utility to trace changes while processing

Install

npm:

npm install unist-util-trace

Usage

Minimal usage

To achieve optimal usage, employ the () => syntax. Apply these tracepoints to the chain. Upon the initial call, only the tree is stored for comparison. Upon subsequent calls, it displays a diff relative to the previously saved unist tree.

.use(() => unistUtilTrace.diff()) // first call: save tree
//...
.use(() => unistUtilTrace.diff()) // second call: show diff
const { unistUtilTrace } = require("unist-util-trace")
const traceDiffSettings = {
  reporter: ["unist-diff"]
}
module.exports = {
  plugins: [
    ["remark-frontmatter", "yaml"],
    [
      "remark-retext",
      unified()
        .use(require("retext-english"))
        .use(require("retext-syntax-urls"))
        .use(() => unistUtilTrace.diff(traceDiffSettings))  // first to set tracepoint
        .use(require("retext-syntax-mentions"), { style: /^@[\w-]{1,40}$/ })
        .use(() => unistUtilTrace.diff(traceDiffSettings)) // second to see diffs from mentions
        .use(require("retext-emoji"))
        .use(() => unistUtilTrace.diff(traceDiffSettings)) // third to see diffs in retext-emoji

Reporter

available reporters:

const traceDiffSettings = {
  reporter: [ "unist-diff", 
              "diff-json", 
              "diff-inspect-full", 
              "diff-inspect-plain", 
              "json-diff-patch"
            ]
}

Reporter unist-diff

using unist-diff

Reporter diff-json

using diff.json

Reporter diff-inspect-full

using unist-util-inspect without options and then diff.diffLines

Reporter diff-inspect-plain

using unist-util-inspect with options for less noise and then diff.diffLines

Reporter json-diff-patch

using jsondiffpatch with the console formatter

Logger

Logger logDot

show a dot for each file

new line after 100 items

Logger logFileName

show current file name

  • newLine: false -> change current line
  • newLine: true -> each name on a new line

Logger logNodeInspect

log all nodeType nodes with inspect

Logger logTreeeInspect

run inspect on the current tree

API

Related

License

MIT © Michael Nietzold / Muescha