Hacker News new | ask | show | jobs
by monkpit 1202 days ago

  const thingies = ["a", "b"];
  const thingToYaml = thing => 
    yaml`- thing: ${thing}`
  const thingiesYaml =
    thingies.map(thingToYaml)

  const config = yaml`
    - foo
    - bar
    - baz
    - thingies: ${thingiesYaml}
  `;
It doesn’t have to be hard to read
1 comments

In this example, why use YAML at all?...

    const thingies = ["a", "b"];
    const config = [
      "foo",
      "bar",
      "baz",
      {
        thingies: thingies.map(thing => ({ thing })),
      },
    ]
    // config = ["foo", "bar", "baz", { "thingies": [{"thing": "a"}, {"thing": "b"}] }]
Right, it's not a great example since yaml is intentionally equivalent to JS objects.