import {
dump,
DEFAULT_SCHEMA,
FAILSAFE_SCHEMA,
JSON_SCHEMA,
} from "https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/+esm"
export const take = () => [
{ type: "json", label: "JSON" },
{
type: "group",
label: "Options",
value: yamlOptions,
},
]
export const make = ([json, options]) => {
return [{ type: "code", label: "YAML", value: dump(json, options) }]
}
const yamlOptions = [
{
key: "schema",
label: "Schema",
type: "dropdown",
options: [
{ label: "Default", value: DEFAULT_SCHEMA },
{ label: "Failsafe", value: FAILSAFE_SCHEMA },
{ label: "JSON", value: JSON_SCHEMA },
],
},
{
key: "indent",
label: "Indentation",
type: "dropdown",
options: [
{ label: "2 spaces", value: 2 },
{ label: "4 spaces", value: 4 },
],
},
{
key: "quotingType",
label: "Quotes",
type: "dropdown",
options: [
{ label: "Double", value: '"' },
{ label: "Single", value: "'" },
],
},
{ key: "forceQuotes", label: "Always use quotes", type: "toggle" },
{ key: "sortKeys", label: "Sort keys alphabetically", type: "toggle" },
{ key: "noArrayIndent", label: "Remove array indentation", type: "toggle" },
{
key: "flowLevel",
label: "Flow nesting level",
type: "number",
min: -1,
value: -1,
max: 20,
detail: "When to switch from block to flow style for collections.",
},
{
key: "lineWidth",
label: "Line width",
type: "number",
min: -1,
max: 999,
value: 80,
detail: "The maximum line width. Use -1 for unlimited width.",
},
]