How to use the jsdoctypeparser.Builder function in jsdoctypeparser

To help you get started, we’ve selected a few jsdoctypeparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jscs-dev / jscs-jsdoc / lib / jsdoc.js View on Github external
var assert = require('assert');
var commentParser = require('comment-parser');

var TypeParser = require('jsdoctypeparser').Parser;
var TypeBuilder = require('jsdoctypeparser').Builder;

var getNodeColumn = require('./utils').getNodeColumn;
var getLineInfo = require('./utils').getLineInfo;

// wtf but it needed to stop writing warnings to stdout
// and revert exceptions functionality
TypeBuilder.ENABLE_EXCEPTIONS = true;

// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var PARSERS = {
    tag: commentParser.PARSERS.parse_tag,
    type: commentParser.PARSERS.parse_type,
    description: commentParser.PARSERS.parse_description,
};
// jscs:enable
var RE_SPACE = /\s/;
github tj / dox / lib / dox.js View on Github external
exports.parseTagTypes = function(str, tag) {
  if (!str) {
    if(tag) {
      tag.types = [];
      tag.typesDescription = "";
      tag.optional = tag.nullable = tag.nonNullable = tag.variable = false;
    }
    return [];
  }
  var Parser = require('jsdoctypeparser').Parser;
  var Builder = require('jsdoctypeparser').Builder;
  var result = new Parser().parse(str.substr(1, str.length - 2));

  var types = (function transform(type) {
    if(type instanceof Builder.TypeUnion) {
      return type.types.map(transform);
    } else if(type instanceof Builder.TypeName) {
      return type.name;
    } else if(type instanceof Builder.RecordType) {
      return type.entries.reduce(function(obj, entry) {
        obj[entry.name] = transform(entry.typeUnion);
        return obj;
      }, {});
    } else {
      return type.toString();
    }
  }(result));