Sha256: d5b6c6eea1f9f1e05425c44413e4dd192001b06914d8f978aa326e4754b37249

Contents?: true

Size: 1.55 KB

Versions: 117

Compression:

Stored size: 1.55 KB

Contents

'use strict';

var YAMLException = require('./exception');

var TYPE_CONSTRUCTOR_OPTIONS = [
  'kind',
  'resolve',
  'construct',
  'instanceOf',
  'predicate',
  'represent',
  'defaultStyle',
  'styleAliases'
];

var YAML_NODE_KINDS = [
  'scalar',
  'sequence',
  'mapping'
];

function compileStyleAliases(map) {
  var result = {};

  if (map !== null) {
    Object.keys(map).forEach(function (style) {
      map[style].forEach(function (alias) {
        result[String(alias)] = style;
      });
    });
  }

  return result;
}

function Type(tag, options) {
  options = options || {};

  Object.keys(options).forEach(function (name) {
    if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
      throw new YAMLException('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
    }
  });

  // TODO: Add tag format check.
  this.tag          = tag;
  this.kind         = options['kind']         || null;
  this.resolve      = options['resolve']      || function () { return true; };
  this.construct    = options['construct']    || function (data) { return data; };
  this.instanceOf   = options['instanceOf']   || null;
  this.predicate    = options['predicate']    || null;
  this.represent    = options['represent']    || null;
  this.defaultStyle = options['defaultStyle'] || null;
  this.styleAliases = compileStyleAliases(options['styleAliases'] || null);

  if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
    throw new YAMLException('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
  }
}

module.exports = Type;

Version data entries

117 entries across 102 versions & 17 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/js-yaml/lib/js-yaml/type.js
disco_app-0.18.0 test/dummy/node_modules/js-yaml/lib/js-yaml/type.js
disco_app-0.18.2 test/dummy/node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.72.2 ./node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.72.1 ./node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.72.0 ./node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.71.0 ./node_modules/js-yaml/lib/js-yaml/type.js
disco_app-0.16.1 test/dummy/node_modules/js-yaml/lib/js-yaml/type.js
disco_app-0.16.1 test/dummy/node_modules/@rails/webpacker/node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.70.2 ./node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.70.1 ./node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.70.0 ./node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.69.0 ./node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.68.2 ./node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.68.1 ./node_modules/js-yaml/lib/js-yaml/type.js
disco_app-0.15.2 test/dummy/node_modules/@rails/webpacker/node_modules/js-yaml/lib/js-yaml/type.js
disco_app-0.15.2 test/dummy/node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.68.0 ./node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.67.1 ./node_modules/js-yaml/lib/js-yaml/type.js
appmap-0.67.0 ./node_modules/js-yaml/lib/js-yaml/type.js