How to use js-yaml

Comprehensive js-yaml code examples:

How to use js-yaml.safeDump:

176
177
178
179
180
181
182
183
184
185
printSchema: function(value, toyaml) {
  if (!value) {
    return '';
  }
  
  var schemaString = toyaml ? yaml.safeDump(value, {skipInvalid:true}) : JSON.stringify(value, null, 2) 
    // Add an extra CRLR before the code so the postprocessor can determine
    // the correct line indent for the <pre> tag.
    
  var $ = cheerio.load(marked(toyaml ? "```yaml\r\n" + schemaString + "```" : "```json\r\n" + schemaString + "\n```"))

How to use js-yaml.safeLoad:

83
84
85
86
87
88
89
90
91
92
describe("verify other YAML files", function () {
  const files = ["backers.yml", "blocked-scopes.yml", "builtin.yml", "sponsors.yml", "topics.yml"];
  for (const file of files) {
    let absPath = path.resolve(dataDir, file);
    it("verify " + file, function() {
      const result = yaml.safeLoad(fs.readFileSync(absPath, "utf8"));
      result.should.not.be.undefined();
    });
  }
});

How to use js-yaml.load:

105
106
107
108
109
110
111
112
113
if (!data && !current_cfg) {
  return;
}

if (data) {
  let config = yaml.load(data, { filename: cfg_path });

  // Normalize config - convert all types to array
  config.type = config.type || {};

How to use js-yaml.dump:

156
157
158
159
160
161
162
163
164

        }

    }

    var ymlContent = yaml.dump(requestJson);
    var ymlBuffer = Buffer.from(ymlContent);
    requestYmlBase64 = ymlBuffer.toString('base64');
}