Link Search Menu Expand Document
Table of contents
  1. JSON
  2. JSON-JS
    1. Example with bigger JSON
  3. MD

Check out the original file to see the original source.

const obj = { a: 1 };
const str = "abc";
const num = 1234;
const bool = true;
const fn = () => 123;

JSON

The default printer. Values are stringified then formatted by prettier.

```ts eval --meta
obj;
```
obj;
{ "a": 1 }
```ts eval --out=json --meta
obj;
```
obj;
{ "a": 1 }
str;
"abc"
num;
1234
bool;
true
fn;
undefined

JSON-JS

Values are printed using node’s util.inspect.

```ts eval --out=jsonjs --meta
obj;
```
obj;
{ a: 1 }
str;
'abc'
num;
1234
bool;
true
fn;
[Function: fn]

Example with bigger JSON

const someJson = {
  glossary: {
    title: "example glossary",
    GlossDiv: {
      title: "S",
      GlossList: {
        GlossEntry: {
          ID: "SGML",
          SortAs: "SGML",
          GlossTerm: "Standard Generalized Markup Language",
          Acronym: "SGML",
          Abbrev: "ISO 8879:1986",
          GlossDef: {
            para: "A meta-markup language, used to create markup languages such as DocBook.",
            GlossSeeAlso: ["GML", "XML"],
          },
          GlossSee: "markup",
        },
      },
    },
  },
};
```ts eval --meta
someJson;
```
someJson;
{
  "glossary": {
    "title": "example glossary",
    "GlossDiv": {
      "title": "S",
      "GlossList": {
        "GlossEntry": {
          "ID": "SGML",
          "SortAs": "SGML",
          "GlossTerm": "Standard Generalized Markup Language",
          "Acronym": "SGML",
          "Abbrev": "ISO 8879:1986",
          "GlossDef": {
            "para": "A meta-markup language, used to create markup languages such as DocBook.",
            "GlossSeeAlso": ["GML", "XML"]
          },
          "GlossSee": "markup"
        }
      }
    }
  }
}
```ts eval --out=jsonjs --meta
someJson;
```
someJson;
{
  glossary: {
    title: 'example glossary',
    GlossDiv: { title: 'S', GlossList: [Object] }
  }
}

MD

Special kind of output language, as it skips the fences. Useful to return markdown from the typescript code.

It is used in this file to automatically have a link to the original file, and to avoid copying and pasting the table of contents markup template.

```ts eval --out=md --meta
import { Anchor, text } from "../../src/md-writer";

text(
    "Check out the",
    Anchor("original file", __meta.srcUrl + __meta.inputPath),
    "to see the original source."
);
```
import { Anchor, text } from "eval-md/lib/md-writer";
text(
  /* listOfStrings: */ "Check out the",
  Anchor(
    /* text: */ "original file",
    /* url: */ __meta.srcUrl + __meta.inputPath
  ),
  "to see the original source."
);

Check out the original file to see the original source.


This document used eval-md