Skip to content

Is there an example of using parseDocument to update the values in a yaml and then convert it back to a yaml string while preserving comments? #538

Closed Answered by tyler-dunkel
tyler-dunkel asked this question in Q&A
Discussion options

You must be logged in to vote

Nvm I figured this out. If anyone else wants an example here ya go:

import * as YAML from "yaml";

const yamlString = `
# values is a required top-level key
values:
  example:
    setting: changeme
  example2:
    setting: test
  example3:
    setting: changeagain
    setting2: changingit
  # ---------------------------------------------------------------------------------------
  # Big blcok comment
  # ---------------------------------------------------------------------------------------

  # Some other comment
  otherVars:
    EXAMPLE_SETTING: mytestval
  # some comment
  someConfig:
    example: mytestval
`;

const out = YAML.parseDocument(yamlString);
const edited = {
  values: {
  …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tyler-dunkel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant