How to use the js-yaml.Schema function in js-yaml

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 netlify / netlify-cms / src / formats / yaml.js View on Github external
const ImageType = new yaml.Type('image', {
  kind: 'scalar',
  instanceOf: AssetProxy,
  represent(value) {
    return `${ value.path }`;
  },
  resolve(value) {
    if (value === null) return false;
    if (value instanceof AssetProxy) return true;
    return false;
  },
});


const OutputSchema = new yaml.Schema({
  include: yaml.DEFAULT_SAFE_SCHEMA.include,
  implicit: [MomentType, ImageType].concat(yaml.DEFAULT_SAFE_SCHEMA.implicit),
  explicit: yaml.DEFAULT_SAFE_SCHEMA.explicit,
});

export default {
  fromFile(content) {
    return yaml.safeLoad(content);
  },

  toFile(data, sortedKeys = []) {
    return yaml.safeDump(data, { schema: OutputSchema, sortKeys: sortKeys(sortedKeys) });
  }
}
github teamdfir / sift-cli / sift-cli.js View on Github external
const request = require('request')
const openpgp = require('openpgp')
const username = require('username')
const readline = require('readline')
const split = require('split')
const semver = require('semver')

/**
 * Setup Custom YAML Parsing
 */
const yaml = require('js-yaml')
const PythonUnicodeType = new yaml.Type('tag:yaml.org,2002:python/unicode', {
  kind: 'scalar',
  construct: (data) => { return data !== null ? data : ''; }
})
const PYTHON_SCHEMA = new yaml.Schema({
  include: [yaml.DEFAULT_SAFE_SCHEMA],
  explicit: [PythonUnicodeType]
})

const currentUser = process.env.SUDO_USER || username.sync()

const doc = `
Usage:
  sift [options] list-upgrades [--pre-release]
  sift [options] install [--pre-release] [--version=] [--mode=] [--user=]
  sift [options] update
  sift [options] upgrade [--pre-release]
  sift [options] self-upgrade [--pre-release]
  sift [options] version
  sift [options] debug
  sift -h | --help | -v
github sigoden / htte / packages / htte / src / init-yamlloader.js View on Github external
module.exports = function(yamlTags) {
  let yamlTypes = yamlTags.map(tagToType);
  let schema = new yaml.Schema({
    include: [yaml.DEFAULT_SAFE_SCHEMA],
    explicit: yamlTypes
  });
  return function(file) {
    let content = fs.readFileSync(file, 'utf8');
    return yaml.load(content, { schema });
  };
};
github sigoden / htte / src / config.js View on Github external
schema() {
    if (this._schema) return this._schema
    let plugins = this._pluginM.list()

    this._schema = new yaml.Schema({
      include: [yaml.DEFAULT_SAFE_SCHEMA],
      explicit: plugins
    })
    return this._schema
  }
}
github netlify / netlify-cms / packages / netlify-cms-core / src / formats / yaml.js View on Github external
});

const ImageType = new yaml.Type('image', {
  kind: 'scalar',
  instanceOf: AssetProxy,
  represent(value) {
    return `${value.path}`;
  },
  resolve(value) {
    if (value === null) return false;
    if (value instanceof AssetProxy) return true;
    return false;
  },
});

const OutputSchema = new yaml.Schema({
  include: yaml.DEFAULT_SAFE_SCHEMA.include,
  implicit: [MomentType, ImageType].concat(yaml.DEFAULT_SAFE_SCHEMA.implicit),
  explicit: yaml.DEFAULT_SAFE_SCHEMA.explicit,
});

export default {
  fromFile(content) {
    return yaml.safeLoad(content);
  },

  toFile(data, sortedKeys = []) {
    return yaml.safeDump(data, { schema: OutputSchema, sortKeys: sortKeys(sortedKeys) });
  },
};
github gristlabs / yaml-cfn / index.js View on Github external
'Fn::Equals',
  'Fn::If',
  'Fn::Not',
  'Fn::Or',
];

let allTagTypes = [];
for (let name of supportedFunctions) {
  allTagTypes.push(...makeTagTypes(name));
}


/**
 * The actual js-yaml schema, extending the DEFAULT_SAFE_SCHEMA.
 */
const schema = new jsYaml.Schema({
  include: [ jsYaml.CORE_SCHEMA ],
  implicit: [],
  explicit: allTagTypes,
});
exports.schema = schema;


/**
 * Convenience function to parse the given yaml input.
 */
function yamlParse(input) {
  return jsYaml.safeLoad(input, { schema: schema });
}
exports.yamlParse = yamlParse;