How to use yaml

Comprehensive yaml code examples:

How to use yaml.createNode:

82
83
84
85
86
87
88
89
90
dotProp.set(this.dotWordupJson, key, value)

const newValue = dotProp.get(this.dotWordupJson, key)
const ymlLevels = key.split('.')
if(ymlLevels.length > 1){
  this.dotWordupYml.setIn(ymlLevels, YAML.createNode(newValue))
}else{
  this.dotWordupYml.set(key, YAML.createNode(newValue))
}

How to use yaml.Composer:

472
473
474
475
476
477
478
479
480
481

for(let compose_file of this.compose_files) {
  let body = fs.readFileSync(compose_file, 'utf8');

  const tokens = new Parser().parse(body);
  const docs = new Composer({merge : true}).compose(tokens);
  let doc = docs.next().value;

  if(doc.hasIn(path)) {
    doc.setIn(path, value);

How to use yaml.Document:

23
24
25
26
27
28
29
30
31
32
  // Send the GET request to the API endpoint and wait for the response
  const res = await k8sApi.readNamespacedDeployment(
    config.DEPLOYMENT_NAME,
    config.DEPLOYMENT_NAMESPACE
  );
  let doc = new YAML.Document();
  doc.contents = res.body;
  return doc;
} catch (error) {
  console.error(error);

How to use yaml.parseAllDocuments:

22
23
24
25
26
27
28
29
30
31
    method: 'GET',
  },
);

const txt = await response.text();
const manifest = YAML.parseAllDocuments(txt);

const [chartRef, pipelineRunner] = await Promise.all([
  jq.run(
    '..|objects| select(.metadata != null) | select( .metadata.name | contains("pipeline")) | .spec.chart.ref//empty',

How to use yaml.default:

16
17
18
19
20
21
22
23
24
25
var lodash_toarray_1 = __importDefault(require("lodash.toarray"));
var path_1 = __importDefault(require("path"));
var url_1 = require("url");
var yaml_1 = __importDefault(require("yaml"));
var partial_1 = require("./helper/partial");
var config = yaml_1.default.parse(fs_1.default.readFileSync(path_1.default.join(process.cwd(), '_config.yml')).toString());
var THEME_LOCATION = path_1.default.join(process.cwd(), 'themes', config.theme || 'landscape');
var _THEME_SCRIPTS = path_1.default.join(THEME_LOCATION, 'scripts');
// loadScripts(THEME_SCRIPTS);
/**

How to use yaml.parseDocument:

44
45
46
47
48
49
50
51
52
53
setUp() {

  if (fs.existsSync(this.getProjectPath('.wordup','config.yml'))) {

    try {
      this.dotWordupYml = YAML.parseDocument(fs.readFileSync(this.getProjectPath('.wordup','config.yml'), 'utf8'))
      this.dotWordupJson = this.dotWordupYml.toJSON()
    } catch (err) {
      this.error('Could not parse wordup config: '+err, {exit:1})
    }

How to use yaml.stringify:

64
65
66
67
68
69
70
    size: getFileSize(file),
    sha512: getFileSHA512(file),
  });
});


fs.writeFileSync(output_file, YAML.stringify(data));

How to use yaml.parse:

51
52
53
54
55
56
57
58
59
60
	path.resolve(__dirname, `../content/en/${url == '/' ? 'index' : url}.md`),
	{ encoding: 'utf8' }
);
const name = (route.name && route.name.en) || route.name;
const fm = (content.match(FRONT_MATTER_REG) || [])[1];
const meta = (fm && yaml.parse(`---\n${fm.replace(/^/gm, '  ')}\n`)) || {};
const contentBody = content.replace(FRONT_MATTER_REG, '');
let suffix = '';
for (let pattern in groups) {
	if (url.match(pattern)) {