Sha256: 11d7ff8e46ecc9ef8b5334aa491973ee95a5f43841afa27e14a0594cca464170

Contents?: true

Size: 1.81 KB

Versions: 72

Compression:

Stored size: 1.81 KB

Contents

'use strict';

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

var TYPE_CONSTRUCTOR_OPTIONS = [
  'kind',
  'multi',
  'resolve',
  'construct',
  'instanceOf',
  'predicate',
  'represent',
  'representName',
  '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.options       = options; // keep original options in case user wants to extend this type later
  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.representName = options['representName'] || null;
  this.defaultStyle  = options['defaultStyle']  || null;
  this.multi         = options['multi']         || false;
  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

72 entries across 71 versions & 5 rubygems

Version Path
fattureincloud_ruby_sdk-2.1.1 scripts/node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.51 node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.50 node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.49 node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.48 node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.47 node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.46 node_modules/js-yaml/lib/type.js
pcp-server-ruby-sdk-0.0.6 node_modules/js-yaml/lib/type.js
pcp-server-ruby-sdk-0.1.0 node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.45 node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.44 node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.43 node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.42 node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.41 node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.40 node_modules/js-yaml/lib/type.js
fattureincloud_ruby_sdk-2.1.0 scripts/node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.39 node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.38 node_modules/js-yaml/lib/type.js
decidim-0.26.10 packages/webpacker/node_modules/js-yaml/lib/type.js
immosquare-cleaner-0.1.32 node_modules/js-yaml/lib/type.js