How to use yaml-js - 10 common examples

To help you get started, we’ve selected a few yaml-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bbc / simorgh / src / app / dataValidator.jsx View on Github external
// disable "function-define-before-call" due to recursive nature of schema
/* eslint no-use-before-define: 0 */

const yaml = require('yaml-js'); // eslint-disable-line import/no-extraneous-dependencies
const fs = require('fs'); // eslint-disable-line import/no-extraneous-dependencies

const yamlSchema = fs.readFileSync('././data/schema.yaml', 'utf8');

const { components } = yaml.load(yamlSchema);
const { schemas } = components;

const log = message => {
  if (process.env.NODE_ENV !== 'test' && typeof jest === 'undefined') {
    console.log(message); // eslint-disable-line no-console
  }
};

const throwError = errorMsg => {
  throw errorMsg;
};

const validateRequired = (requireSchema, dataNode) => {
  log('- Required values successfully found:');

  requireSchema.forEach(requiredProp => {
github kevin-smets / caml / lib / caml.js View on Github external
function parse(yamlLines) {
  var yaml = yamlJs.load(yamlLines.join('\n'));
  var result = [{}];

  Object.keys(yaml).forEach(function (key) {
    if (yaml[key] !== null) {
      var obj = {};
      obj[key] = yaml[key];
      result.push(expand(obj));
    }
  });
  var jsonString = JSON.stringify(_.merge.apply(null, result));
  // Fix "enclosed.dotted.variables"
  jsonString = jsonString.replace(new RegExp(DOT_SUBSTITUTE, 'g'), '.');

  return JSON.parse(jsonString);
}
github bbc / simorgh / src / app / dataValidator / helpers / interpretSchema / getAllSchemas.js View on Github external
const yaml = require('yaml-js'); // eslint-disable-line import/no-extraneous-dependencies
const fs = require('fs'); // eslint-disable-line import/no-extraneous-dependencies

const yamlSchema = fs.readFileSync('./././data/schema.yaml', 'utf8');
const { components } = yaml.load(yamlSchema);
const { schemas } = components;

module.exports.getAllSchemas = () => schemas;
github GiraffeTools / GiraffeTools / app / porcupine / js / components / canvas / canvas.js View on Github external
const { user, repository, branch, commit } = project;
    if (!user || !repository || (!branch && !commit)) {
      console.log("No username, repository, or branch provided");
      return;
    }

    const baseName = `https://raw.githubusercontent.com/${user}/${repository}/${branch ||
      commit}`;
    const configFile = `${baseName}/GIRAFFE.yml`;

    const configuration = await fetch(configFile);
    if (!configuration.ok) {
      console.log("GiraffeTools configuration file cannot be loaded");
      return;
    }
    const yamlData = loadYaml(await configuration.text());
    const porkFile = yamlData.tools.porcupine.file[0];
    setPorkFile(porkFile);

    const porkData = await fetch(`${baseName}/${porkFile}`);
    if (!porkData.ok) {
      console.log("Pork file cannot be loaded");
    }
    const content = await porkData.json();
    try {
      await this.loadFromJson(content);
      this.graphview.current.handleZoomToFit();
    } catch (error) {
      console.log("Cannot load Porcupine Config file:");
      console.log(error);
      this.setPercent(-1);
    }
github GiraffeTools / GiraffeTools / frontend / armadillo / components / content.js View on Github external
setUser(username);
    setRepository(repository);
    const identifierString = branchOrCommit || 'master';
    const isCommit = isGitHash(branchOrCommit);
    setCommit(isCommit && identifierString);
    setBranch(!isCommit && identifierString);

    const baseName = `https://raw.githubusercontent.com/${username}/${repository}/${identifierString}`;
    const configFile = `${baseName}/GIRAFFE.yml`;

    const configuration = await fetch(configFile);
    if (!configuration.ok) {
      console.log('GiraffeTools configuration file cannot be loaded');
      return;
    }
    const yamlData = loadYaml(await configuration.text());
    const armadilloFile = yamlData.tools.armadillo.neurovault[0];
    this.setState({
      imageId: armadilloFile,
    });
  }
github GiraffeTools / GiraffeTools / frontend / porcupine / components / canvas / canvas.js View on Github external
await loadFromJson(content);
        clickItem(null);
        graphview.current.handleZoomToFit();
      } catch (error) {
        console.log("Cannot load Porcupine Config file:");
        console.log(error);
        setPercent(-1);
      }
    }
    async function loadCustomNodes(nodeFiles) {
      if (!nodeFiles || !nodeFiles.length) return;
      const nodes = await (await fetch(`${baseName}/${nodeFiles[0]}`)).json();
      addToolboxNodes(nodes.toolboxes);
    }

    const yamlData = loadYaml(await configuration.text());
    if (!yamlData || !yamlData.tools || !yamlData.tools.porcupine) return;

    const { file, files, nodes } = yamlData.tools.porcupine;
    Promise.all([loadContent(file || files), loadCustomNodes(nodes)]);
  }
github digsjs / digs / bin / digs.js View on Github external
.then((file) => {
      if (/\.json$/.test(filepath)) {
        debug('Attempting to parse config file as JSON...');
        return JSON.parse(file);
      }
      debug('Attempting to parse config file as YAML...');
      return yaml.load(file);
    })
    .tap(() => {
github GiraffeTools / GiraffeTools / app / porcupine / js / utils / loadData.js View on Github external
reader.read().then(({ done, value }) => {
          const configuration = loadYaml(
            new TextDecoder("utf-8").decode(value)
          );
          const porcupineFile = `${baseName}/${
            configuration.tools.porcupine.file[0]
          }`;

          fetch(porcupineFile)
            .then(result => result.json())
            .then(data => {
              this.loadFromJson(data);
              console.log("Porcupine Config file loaded from URL");
            })
            .catch(error => {
              console.log("Cannot load Porcupine Config file");
              this.setPercent(-1);
            });
github alibaba / G3D / devtools / website.js View on Github external
doc: pug.compile(
            fs.readFileSync(sourceDir + 'template/doc.pug'),
            {
                filename: sourceDir + 'template/doc.pug',
                pretty: true
            }
        )
    }

    const siteInfo = yaml.load(fs.readFileSync(sourceDir + 'site.yaml'));
    const siteInfoCn = yaml.load(fs.readFileSync(sourceDir + 'site.zh.yaml'));

    fs.outputFileSync(destDir + 'index.html', templates.index({ root: './', langcn: false, ...siteInfo }));
    fs.outputFileSync(destDirCn + 'index.html', templates.index({ root: './', langcn: true, ...siteInfoCn }));

    const docs = yaml.load(fs.readFileSync(sourceDir + 'doc.yaml')).docs;
    const docsPatchCn = yaml.load(fs.readFileSync(sourceDir + 'doc.patch.cn.yaml')).docs;

    function deal(root, k, scope) {

        const target = root[k];

        if (typeof target === 'string') {

            console.log(docDir, scope, k);

            const content = fs.readFileSync(`${docDir}/${scope}/${k}.md`, 'utf-8') || '  ';
            const contentcn = fs.existsSync(`${docDir}/${scope}/${k}.cn.md`) ?
                fs.readFileSync(`${docDir}/${scope}/${k}.cn.md`, 'utf-8') : content;

            if (content) {
github alibaba / G3D / devtools / website.js View on Github external
fs.readFileSync(sourceDir + 'template/index.pug', 'utf-8'),
            {
                filename: sourceDir + 'template/index.pug',
                pretty: true
            }
        ),
        doc: pug.compile(
            fs.readFileSync(sourceDir + 'template/doc.pug'),
            {
                filename: sourceDir + 'template/doc.pug',
                pretty: true
            }
        )
    }

    const siteInfo = yaml.load(fs.readFileSync(sourceDir + 'site.yaml'));
    const siteInfoCn = yaml.load(fs.readFileSync(sourceDir + 'site.zh.yaml'));

    fs.outputFileSync(destDir + 'index.html', templates.index({ root: './', langcn: false, ...siteInfo }));
    fs.outputFileSync(destDirCn + 'index.html', templates.index({ root: './', langcn: true, ...siteInfoCn }));

    const docs = yaml.load(fs.readFileSync(sourceDir + 'doc.yaml')).docs;
    const docsPatchCn = yaml.load(fs.readFileSync(sourceDir + 'doc.patch.cn.yaml')).docs;

    function deal(root, k, scope) {

        const target = root[k];

        if (typeof target === 'string') {

            console.log(docDir, scope, k);

yaml-js

Pure Javascript YAML loader and dumper, ported from PyYAML

WTFPL
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Popular yaml-js functions