当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript doctrine.parse函数代码示例

本文整理汇总了TypeScript中doctrine.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: parseJsdoc

export function parseJsdoc(docs:string):Annotation {
  docs = _removeLeadingAsterisks(docs);
  var d = doctrine.parse(docs, {
    unwrap: false,
    lineNumber: true,
    preserveWhitespace: true
  });
  return {
    description: d.description,
    tags: _tagsToHydroTags(d.tags)
  };
}
开发者ID:1hemant,项目名称:Test00,代码行数:12,代码来源:jsdoc.ts

示例2: parseJsdoc

export function parseJsdoc(docs: string): doctrine.Annotation {
  docs = removeLeadingAsterisks(docs);
  const d = doctrine.parse(docs, {
    unwrap: false,
    // lineNumbers: true,
    preserveWhitespace: true,
  });
  // Strip any leading and trailing newline characters in the
  // description of multiline comments for readibility.
  // TODO(rictic): figure out if we can trim() here or not. Something something
  //     markdown?
  const description = d.description && d.description.replace(/^\n+|\n+$/g, '');
  return {description, tags: parseCustomTags(d.tags)};
}
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:14,代码来源:jsdoc.ts

示例3: test

test('parse all options', (t: test.Test) => {
  let res = d.parse('/* this is a test\n * @param {number} bees the number of bees\n */', {
    unwrap: true,
    tags: null,
    recoverable: true,
    sloppy: true,
    lineNumbers: true
  });
  t.plan(10);
  t.equal(res.description, 'this is a test');
  t.equal(res.tags.length, 1);
  t.equal(res.tags[0].title, 'param');
  t.equal(res.tags[0].name, 'bees');
  t.equal(res.tags[0].description, 'the number of bees');
  t.equal(res.tags[0].type.type, d.Syntax.NameExpression);
  let resType = res.tags[0].type as d.NameExpression;
  t.equal(resType.name, 'number');
  t.equal(res.tags[0].lineNumber, 1);
  t.false(res.tags[0].errors);
  t.false(res.tags[0].caption);
  t.end();
});
开发者ID:kazimuth,项目名称:typed-doctrine,代码行数:22,代码来源:test.ts

示例4: yn

export const extractMetadata = (code: string) => {
  const match = code.match(JSDocCommentRegex)
  const metadata: ActionMetadata = {
    title: '',
    category: '',
    description: '',
    author: '',
    hidden: false,
    params: []
  }

  if (!match) {
    return metadata
  }

  const extracted = doctrine.parse(match[0], {
    recoverable: true,
    sloppy: true,
    unwrap: true,
    strict: false,
    preserveWhitespace: false
  })

  metadata.description = extracted.description

  const author = _.find(extracted.tags, { title: 'author' })
  if (author) {
    metadata.author = (author as any).description || ''
  }

  const category = _.find(extracted.tags, { title: 'category' })
  if (category) {
    metadata.category = (category as any).description || ''
  }

  const title = _.find(extracted.tags, { title: 'title' })
  if (title) {
    metadata.title = (title as any).description || ''
  }

  const hidden = _.find(extracted.tags, { title: 'hidden' })
  if (hidden) {
    metadata.hidden = yn((hidden as any).description)
  }

  metadata.params = _.filter(extracted.tags, { title: 'param' }).map(tag => {
    const type: string = _.get(tag, 'type.name', '')
    const required = _.get(tag, 'type.type') !== doctrine.type.Syntax.OptionalType
    const def = _.get(tag, 'default', '')
    const name = _.get(tag, 'name', '')

    return {
      description: (tag as any).description || '',
      type,
      default: def,
      required,
      name
    }
  })

  return metadata
}
开发者ID:alexsandrocruz,项目名称:botpress,代码行数:62,代码来源:metadata.ts

示例5:

import * as doctrine from 'doctrine';

let string: string = 'string';
let strings: string[];
let tags: doctrine.Tag[] = [];
let annotation: doctrine.Annotation;

annotation = doctrine.parse(string);
string = annotation.description;
tags = annotation.tags;

annotation = doctrine.parse(string, {});
annotation = doctrine.parse(string, {
  unwrap: true,
  tags: ['foo', 'bar', 'baz'],
  recoverable: false,
  sloppy: false,
  strict: true,
  preserveWhitespace: false,
  lineNumbers: true
});

tags.forEach((tag) => {
  string = doctrine.type.stringify({type: 'NullableLiteral'});
  string = tag.title;
  string = tag.description || '';
  string = tag.kind || '';
  string = tag.name || '';
  strings = tag.errors || [];
  if (tag.type && tag.type.type === 'NameExpression') {
    string = tag.type.name;
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:doctrine-tests.ts


注:本文中的doctrine.parse函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。