Convert YAML (yet-another-markup-language) strings to JSON (JavaScript object notation).
import {
load,
DEFAULT_SCHEMA,
FAILSAFE_SCHEMA,
JSON_SCHEMA,
} from "https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/+esm"
export const take = [
{ type: "code", label: "YAML" },
{
type: "group",
label: "Options",
value: [
{
key: "space",
type: "dropdown",
label: "Indent",
options: [
{ label: "2 spaces", value: 2 },
{ label: "4 spaces", value: 4 },
{ label: "Tabs", value: "\t" },
{ label: "Compact" },
],
},
{
key: "schema",
label: "Schema",
type: "dropdown",
options: [
{ label: "Default", value: DEFAULT_SCHEMA },
{ label: "Failsafe", value: FAILSAFE_SCHEMA },
{ label: "JSON", value: JSON_SCHEMA },
],
},
{ key: "json", label: "JSON compatibility", type: "toggle" },
],
},
]
export const make = ([yaml, { schema, json, space }]) => {
const value = load(yaml, { schema, json })
return [{ type: "json", label: "JSON", value, space }]
}