本文整理汇总了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)
};
}
示例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)};
}
示例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();
});
示例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
}
示例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;