|
| 1 | +import {ApiDoc} from 'dgeni-packages/typescript/api-doc-types/ApiDoc'; |
| 2 | + |
| 3 | +/** |
| 4 | + * Type describing a collection of tags, matching with the objects |
| 5 | + * created by the Dgeni JSDoc processors. |
| 6 | + * |
| 7 | + * https://github.com/angular/dgeni-packages/blob/19e629c0d156572cbea149af9e0cc7ec02db7cb6/jsdoc/lib/TagCollection.js#L4 |
| 8 | + */ |
| 9 | +export interface TagCollection { |
| 10 | + /** List of tags. */ |
| 11 | + tags: Tag[]; |
| 12 | + /** Map which maps tag names to their tag instances. */ |
| 13 | + tagsByName: Map<string, Tag[]>; |
| 14 | + /** List of tags which are unkown, or have errors. */ |
| 15 | + badTags: Tag[]; |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + * Type describing a tag, matching with the objects created by the |
| 20 | + * Dgeni JSDoc processors. |
| 21 | + * |
| 22 | + * https://github.com/angular/dgeni-packages/blob/19e629c0d156572cbea149af9e0cc7ec02db7cb6/jsdoc/lib/Tag.js#L1 |
| 23 | + */ |
| 24 | +export interface Tag { |
| 25 | + /** Definition of the tag. Undefined if the tag is unknown. */ |
| 26 | + tagDef: undefined | TagDefinition; |
| 27 | + /** Name of the tag (excluding the `@`) */ |
| 28 | + tagName: string; |
| 29 | + /** Description associated with the tag. */ |
| 30 | + description: string; |
| 31 | + /** Source file line where this tag starts. */ |
| 32 | + startingLine: number; |
| 33 | + /** Optional list of errors that have been computed for this tag. */ |
| 34 | + errors?: string[]; |
| 35 | +} |
| 36 | + |
| 37 | +/** Type describing a tag definition for the Dgeni JSDoc processor. */ |
| 38 | +export interface TagDefinition { |
| 39 | + /** Name of the tag (excluding the `@`) */ |
| 40 | + name: string; |
| 41 | + /** Property where the tag information should be attached to. */ |
| 42 | + docProperty?: string; |
| 43 | + /** Whether multiple instances of the tag can be used in the same comment. */ |
| 44 | + multi?: boolean; |
| 45 | + /** Whether this tag is required for all API documents. */ |
| 46 | + required?: boolean; |
| 47 | +} |
| 48 | + |
| 49 | +/** Type describing an API doc with JSDoc tag information. */ |
| 50 | +export type ApiDocWithJsdocTags = ApiDoc & { |
| 51 | + /** Collection of JSDoc tags attached to this API document. */ |
| 52 | + tags: TagCollection; |
| 53 | +}; |
| 54 | + |
| 55 | +/** Whether the specified API document has JSDoc tag information attached. */ |
| 56 | +export function isApiDocWithJsdocTags(doc: ApiDoc): doc is ApiDocWithJsdocTags { |
| 57 | + return (doc as Partial<ApiDocWithJsdocTags>).tags !== undefined; |
| 58 | +} |
| 59 | + |
| 60 | +/** Finds the specified JSDoc tag within the given API doc. */ |
| 61 | +export function findJsDocTag(doc: ApiDoc, tagName: string): Tag | undefined { |
| 62 | + if (!isApiDocWithJsdocTags(doc)) { |
| 63 | + return undefined; |
| 64 | + } |
| 65 | + |
| 66 | + return doc.tags.tags.find(t => t.tagName === tagName); |
| 67 | +} |
| 68 | + |
| 69 | +/** Gets whether the specified API doc has a given JSDoc tag. */ |
| 70 | +export function hasJsDocTag(doc: ApiDoc, tagName: string): boolean { |
| 71 | + return findJsDocTag(doc, tagName) !== undefined; |
| 72 | +} |
0 commit comments