3 var YAMLException = require('./exception');
5 var TYPE_CONSTRUCTOR_OPTIONS = [
16 var YAML_NODE_KINDS = [
22 function compileStyleAliases(map) {
26 Object.keys(map).forEach(function (style) {
27 map[style].forEach(function (alias) {
28 result[String(alias)] = style;
36 function Type(tag, options) {
37 options = options || {};
39 Object.keys(options).forEach(function (name) {
40 if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
41 throw new YAMLException('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
45 // TODO: Add tag format check.
47 this.kind = options['kind'] || null;
48 this.resolve = options['resolve'] || function () { return true; };
49 this.construct = options['construct'] || function (data) { return data; };
50 this.instanceOf = options['instanceOf'] || null;
51 this.predicate = options['predicate'] || null;
52 this.represent = options['represent'] || null;
53 this.defaultStyle = options['defaultStyle'] || null;
54 this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
56 if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
57 throw new YAMLException('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
61 module.exports = Type;