react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / lib / js-yaml / type.js
80698 views'use strict';12var YAMLException = require('./exception');34var TYPE_CONSTRUCTOR_OPTIONS = [5'kind',6'resolve',7'construct',8'instanceOf',9'predicate',10'represent',11'defaultStyle',12'styleAliases'13];1415var YAML_NODE_KINDS = [16'scalar',17'sequence',18'mapping'19];2021function compileStyleAliases(map) {22var result = {};2324if (null !== map) {25Object.keys(map).forEach(function (style) {26map[style].forEach(function (alias) {27result[String(alias)] = style;28});29});30}3132return result;33}3435function Type(tag, options) {36options = options || {};3738Object.keys(options).forEach(function (name) {39if (-1 === TYPE_CONSTRUCTOR_OPTIONS.indexOf(name)) {40throw new YAMLException('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');41}42});4344// TODO: Add tag format check.45this.tag = tag;46this.kind = options['kind'] || null;47this.resolve = options['resolve'] || function () { return true; };48this.construct = options['construct'] || function (data) { return data; };49this.instanceOf = options['instanceOf'] || null;50this.predicate = options['predicate'] || null;51this.represent = options['represent'] || null;52this.defaultStyle = options['defaultStyle'] || null;53this.styleAliases = compileStyleAliases(options['styleAliases'] || null);5455if (-1 === YAML_NODE_KINDS.indexOf(this.kind)) {56throw new YAMLException('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');57}58}5960module.exports = Type;616263