How to use the js-yaml.DEFAULT_SAFE_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 jessica-taylor / hashlattice / lib / yaml.js View on Github external
state.result = new FileRef(fn, datatype, filename);
      return true;
    },
    dumpInstanceOf: FileRef,
    dumpPredicate: function(fref) {
      return fref.fn == fn && fref.datatype == datatype;
    },
    dumpRepresenter: function(fref) {
      return fref.filename;
    }
  });
};

// YAML binary type
var BINARY_TYPE =
  JsYaml.DEFAULT_SAFE_SCHEMA.compiledTypeMap['tag:yaml.org,2002:binary']

// YAML schema used for YAML files containing file references.
var fileRefSchema = JsYaml.Schema.create(
    [JsYaml.JSON_SCHEMA],
    [BINARY_TYPE, 
     createFileRefType('!includeYaml', 'include', 'yaml'),
     createFileRefType('!includeBinary', 'include', 'binary'),
     createFileRefType('!hashYaml', 'hash', 'yaml'), 
     createFileRefType('!hashBinary', 'hash', 'binary')]);

// Reads YAML and handles file references.
function YamlReader() {
  // Maps from data type + file name to file data.
  this.dataMap = {yaml: {}, binary: {}};
  // Maps from data type + file name to boolean of whether or not this file
  // currently being loaded.  This can detect circular dependencies.
github jessica-taylor / hashlattice / src / lib / yaml.js View on Github external
state.result = new FileRef(fn, datatype, filename);
      return true;
    },
    dumpInstanceOf: FileRef,
    dumpPredicate: function(fref) {
      return fref.fn == fn && fref.datatype == datatype;
    },
    dumpRepresenter: function(fref) {
      return fref.filename;
    }
  });
};

// YAML binary type
var BINARY_TYPE =
  JsYaml.DEFAULT_SAFE_SCHEMA.compiledTypeMap['tag:yaml.org,2002:binary']

// YAML schema used for YAML files containing file references.
var fileRefSchema = JsYaml.Schema.create(
    [JsYaml.JSON_SCHEMA],
    [BINARY_TYPE, 
     createFileRefType('!includeYaml', 'include', 'yaml'),
     createFileRefType('!includeBinary', 'include', 'binary'),
     createFileRefType('!hashYaml', 'hash', 'yaml'), 
     createFileRefType('!hashBinary', 'hash', 'binary')]);

// Reads YAML and handles file references.
class YamlReader {
  constructor() {
    // Maps from data type + file name to file data.
    this.dataMap = {yaml: {}, binary: {}};
    // Maps from data type + file name to boolean of whether or not this file
github blackflux / js-gardener / src / subtasks / yamllint.js View on Github external
files.forEach((file) => {
    const content = fs.readFileSync(path.join(cwd, file), 'utf-8');
    try {
      yaml.loadAll(content, () => {}, { schema: yaml.DEFAULT_SAFE_SCHEMA });
    } catch (e) {
      logger.error(`An error has occurred in: ${file}`);
      logger.error(e.message);
      result = false;
    }
  });
  return result ? resolve() : reject();
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 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 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 netlify / netlify-cms / src / formats / yaml.js View on Github external
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 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 / 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
  }
}