Public
Script
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

js-yaml

YAML is a popular format for data which is an alternative to JSON. In contrast to JSON,

  • YAML can look more user-friendly: you can write text without worrying about quoting strings
  • You can write comments in YAML
  • But, on the other side, it's more possible to write YAML that is parsed in an unexpected way. JSON is more explicit and predictable.

js-yaml is the most popular YAML parser for JavaScript.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { fetch } from "https://esm.town/v/std/fetch";
export let jsYAMLExample = (async () => {
// Import the YAML parser
const jsYaml = await import("npm:js-yaml");
// Fetch a YAML file
const yaml = await fetch(
"https://raw.githubusercontent.com/docker/engine/8955d8da8951695a98eb7e15bead19d402c6eb27/api/swagger.yaml",
).then((r) => r.text());
// parse the fetched file
const obj = jsYaml.load(yaml);
// Return part of the file
return obj.info;
})();
October 23, 2023