How to use js-yaml - 10 common examples

To help you get started, we’ve selected a few js-yaml 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 ChainSafe / lodestar / packages / eth2.0-spec-test-util / src / yaml / schema.ts View on Github external
import {Schema} from "js-yaml";
import failsafe from "js-yaml/lib/js-yaml/schema/failsafe";
// @ts-ignore
import nullType from "js-yaml/lib/js-yaml/type/null";
// @ts-ignore
import boolType from "js-yaml/lib/js-yaml/type/bool";
// @ts-ignore
import floatType from "js-yaml/lib/js-yaml/type/float";
import {intType} from "./int";

export const schema = new Schema({
  include: [
    failsafe
  ],
  implicit: [
    nullType,
    boolType,
    intType,
    floatType
  ],
  explicit: [
  ]
});
github moleculerjs / awesome-moleculer / generate-modules-site.js View on Github external
async function main() {
	try {
		// Load module files
		const payload = await readFile(MODULES_PATH, { encoding: "utf8" });

		// Parse yaml payload
		const modules = yaml.safeLoad(payload, "utf8");

		// Transform into site acceptable format
		const siteModules = await transform(modules);

		// Store new file
		await writeFile(
			SITE_MODULES,
			yaml.safeDump(siteModules, { lineWidth: 500 })
		);
	} catch (error) {
		console.log(error);
		process.exit(1);
	}
}
github KubeOperator / kubeapps-plus / src / components / applications / apps.vue View on Github external
this.catalog.description = res.data.data.chart.metadata.description;
        this.catalog.icon = res.data.data.chart.metadata.icon;
        this.catalog.appv = res.data.data.chart.metadata.appVersion;
        this.catalog.releaseName = res.data.data.chart.metadata.name;
        this.catalog.chartv = res.data.data.chart.metadata.version;
        this.note = res.data.data.info.status.notes;
        this.aceEditor = ace.edit(this.$refs.ace, {
          maxLines: 30, // 最大行数,超过会自动出现滚动条
          minLines: 10, // 最小行数,还未到最大行数时,编辑器会自动伸缩大小
          fontSize: 14, // 编辑器内字体大小
          theme: this.themePath, // 默认设置的主题
          mode: this.modePath, // 默认设置的语言模式
          value: this.valuesYaml ? this.valuesYaml : "",
          tabSize: 4 // 制表符设置为 4 个空格大小
        });
        jsyaml.loadAll(res.data.data.manifest, function(doc) {
          try {
            if (doc.kind == "Secret") {
              _this.secrets.push({
                name: doc.metadata.name,
                type: doc.type
                // key: Base64.decode(doc.data["tls.crt"]),
                // crt: Base64.decode(doc.data["tls.key"])
              });
            } else if (doc.kind != "Deployment") {
              _this.resources.push({ name: doc.metadata.name, kind: doc.kind });
            } else if (doc.kind == "Deployment") {
              _this.services.push({ name: doc.metadata.name, kind: doc.kind });
            }
          } catch (error) {
            // console.log(error)
          }
github matrix-io / matrix-os / lib / service / application.js View on Github external
function updateConfigKey( options, cb ) {
    var configFile = Matrix.config.path.apps + '/' + options.name + '.matrix/config.yaml';
    var config = yaml.loadSafe( fs.readFileSync( configFile ) );
    if ( config.hasOwnProperty( 'configuration' ) ) {
    //FIXME: Depreciate this path
      console.warn( '`configuration` in app config', options );
      config.configuration[ options.key ] = options.value;
    } else {
    // this is the newness
      config.settings[ options.key ] = options.value;
    }
    var configJs = yaml.safeDump( config );
    fs.writeFile( configFile, configJs, cb );
  }
github taskcluster / taskcluster / libraries / config / src / schema.js View on Github external
const createType = (env, name, typeName, deserialize) => {
  return new yaml.Type(name, {
    kind: 'scalar', // Takes a string as input
    resolve: (data) => {
      return typeof data === 'string' && /^[A-Z0-9_]+$/.test(data);
    },
    // Deserialize the data, in the case we read the environment variable
    construct: (data) => {
      let value = env[data];
      if (value === undefined) {
        return value;
      }
      assert(typeof value === 'string', `${name} key env vars must be strings: ${data} is ${typeof value}`);
      return deserialize(value);
    },
  });
};
github yann-yinn / nuxt-gustave / lib / yaml.js View on Github external
// boolean. Interpret includes from https://www.npmjs.com/package/yaml-include
    includes: false,
    // parse multiple documents
    multiple: false
  }
  options = { ...defaultOptions, ...options }
  try {
    let yamlOptions = {}
    if (options.includes === true) {
      yamlOptions = {
        schema: yamlinc.YAML_INCLUDE_SCHEMA
      }
    }
    let resource = null
    if (options.multiple) {
      resource = yaml.safeLoadAll(
        fs.readFileSync(filepath, 'utf8'),
        yamlOptions
      )

      resource = resource.map(r => {
        if (r) {
          r.$filename = path.basename(filepath)
          return r
        }
        return r
      })
    } else {
      resource = yaml.safeLoad(fs.readFileSync(filepath, 'utf8'), yamlOptions)
      resource.$filename = path.basename(filepath)
    }
    //console.log('filename', resource.$filename)
github Surnet / swagger-jsdoc / bin / swagger-jsdoc.js View on Github external
fs.writeFile(fileName, swaggerSpec, err => {
    if (err) {
      throw err;
    }
    console.log('Swagger specification is ready.');
  });
}

function loadJsSpecification(data, resolvedPath) {
  // eslint-disable-next-line
  return require(resolvedPath);
}

const YAML_OPTS = {
  // OpenAPI spec mandates JSON-compatible YAML
  schema: jsYaml.JSON_SCHEMA,
};

function loadYamlSpecification(data) {
  return jsYaml.load(data, YAML_OPTS);
}

const LOADERS = {
  '.js': loadJsSpecification,
  '.json': JSON.parse,
  '.yml': loadYamlSpecification,
  '.yaml': loadYamlSpecification,
};

// Get an object of the definition file configuration.
function loadSpecification(defPath, data) {
  const resolvedPath = path.resolve(defPath);
github Surnet / swagger-jsdoc / bin / swagger-jsdoc.js View on Github external
function createSpecification(swaggerDefinition, apis, fileName) {
  // Options for the swagger docs
  const options = {
    // Import swaggerDefinitions
    swaggerDefinition,
    // Path to the API docs
    apis,
  };

  // Initialize swagger-jsdoc -> returns validated JSON or YAML swagger spec
  let swaggerSpec;
  const ext = path.extname(fileName);

  if (ext === '.yml' || ext === '.yaml') {
    swaggerSpec = jsYaml.dump(swaggerJSDoc(options), {
      schema: jsYaml.JSON_SCHEMA,
      noRefs: true,
    });
  } else {
    swaggerSpec = JSON.stringify(swaggerJSDoc(options), null, 2);
  }

  fs.writeFile(fileName, swaggerSpec, err => {
    if (err) {
      throw err;
    }
    console.log('Swagger specification is ready.');
  });
}
github greenkeeperio / greenkeeper / jobs / create-initial-branch.js View on Github external
async function travisTransform (config, travisyml) {
  try {
    var travis = yaml.safeLoad(travisyml, {
      schema: yaml.FAILSAFE_SCHEMA
    })
  } catch (e) {
    // ignore .travis.yml if it can not be parsed
    return
  }
  const onlyBranches = _.get(travis, 'branches.only')
  if (!onlyBranches || !Array.isArray(onlyBranches)) return

  const greenkeeperRule = onlyBranches.some(function (branch) {
    if (_.first(branch) !== '/' || _.last(branch) !== '/') return false
    try {
      const regex = new RegExp(branch.slice(1, -1))
      return regex.test(config.branchPrefix)
    } catch (e) {
      return false
    }
github awwright / magnode / t / runner.js View on Github external
function runFile(filename, callback){
	console.log('Run file: '+filename);
	// 1. Arrange
	// Connect to a database
	var dbName = 'magnode-test-' + new Date().valueOf();
	var requests = [];
	var requestNames = {};
	var defaultRequest = {};
	var fileFailures = 0;
	yaml.loadAll(fs.readFileSync(filename, 'utf-8').replace(/\t/g, '    '), function(v){ requests.push(v); });
	var db, child;
	var running = true;
	mongodb.connect('mongodb://localhost/'+dbName, function(err, _db){
		if(err) throw err;
		db = _db;
		runFileDb();
	});

	function runFileDb(){
		// Verify the database does not exist (is not populated with any data)
		db.collections(function(err, names){
			if(err) throw err;
			if(names.length) throw new Error('Database already exists!');
			//var data = fs.readFileSync(__dirname+'/../setup/mongodb/schema/Schema.json'), 'utf-8');
			var importList = [
				{file:__dirname+'/../setup/mongodb/schema/Schema.json', collection:'schema'}