Sha256: b15d8119a4112d3d9a27cae9ea277d4f006437af1d6e7dbc4433dfdfd6a19be3

Contents?: true

Size: 1.55 KB

Versions: 112

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 (null !== map) {
    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 (-1 === TYPE_CONSTRUCTOR_OPTIONS.indexOf(name)) {
      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 (-1 === YAML_NODE_KINDS.indexOf(this.kind)) {
    throw new YAMLException('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
  }
}

module.exports = Type;

Version data entries

112 entries across 105 versions & 6 rubygems

Version Path
opal-0.10.6 stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type.js
opal-0.10.6.beta stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type.js
opal-0.10.5 stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type.js
opal-0.10.4 stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
opal-0.10.3 stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type.js
opal-0.10.2 stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type.js