-
Notifications
You must be signed in to change notification settings - Fork 194
/
index.d.ts
165 lines (158 loc) · 5.67 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
declare module "dox" {
export interface ParseCommentOptions {
skipSingleStar?: boolean;
skipPrefixes?: string[];
raw?: boolean;
}
export interface CommentDescription {
full: string;
summary: string;
body: string;
}
export interface Comment {
/** array of tag objects */
tags: Tag[];
/** the first line of the comment */
description: CommentDescription;
/** true when "@api private" is used */
isPrivate: boolean;
isConstructor: boolean;
line: number;
/** lines following the description */
body: any;
/** both the description and the body */
content: any;
codeStart: number;
code: string;
ctx: ContextPatternMatchersCtx;
ignore: boolean;
}
export interface Tag {
string: string;
/** from "@param"/"@property"/"@template", name of parameter/property */
name?: string;
/** text after various tags */
description?: string;
/** from "@see", everything before "http" */
title?: string;
/** from "@see" */
url?: string;
/** from "@see" */
local?: string;
/** when "@api private" this field will be "private" (what is after "@api") and in case of "@protected"/"@public"/"@private" will be the tag itself */
visibility?: string;
/** the string after "@memberOf"/"@lends" */
parent?: string;
/** the string after "@extends"/"@implements"/"@augments" */
otherClass?: string;
/** from "@borrows" */
otherMemberName?: string;
/** from "@borrows" */
thisMemberName?: string;
/** all parsed types from tags that support it, like "@param" */
types?: string[];
/** from "@description" */
full?: string;
/** from "@description" */
summary?: string;
/** from "@description" */
body?: string;
typesDescription?: string;
/**
* "true" when the property is marked optional
* @example
* @param {string} [optionalProperty]
* @param {string} nonOptionalProperty
*/
optional?: boolean;
/**
* "true" when the property is marked nullable
* @example
* @param {?string} nullable
* @param {string} normal
* @param {!string} nonNullable
*/
nullable?: boolean;
/**
* "true" when the property is marked non-nullable
* @example
* @param {?string} nullable
* @param {string} normal
* @param {!string} nonNullable
*/
nonNullable?: boolean;
/**
* "true" when using the spread type
* @example
* @param {...string} spread
* @param {string} nonSpread
*/
variable?: boolean;
}
export function api(comments: Comment[]): string;
/** Parse comments in the given string of `js`. */
export function parseComments(js: string, options: ParseCommentOptions): Comment[];
/** Removes excess indentation from string of code. */
export function trimIndentation(str: string): string;
/**
* Parse the given comment `str`.
*
* The comment object returned contains the following
*/
export function parseComment(str: string, options: ParseCommentOptions): any;
/**
* Extracts different parts of a tag by splitting string into pieces separated by whitespace. If the white spaces are
* somewhere between curly braces (which is used to indicate param/return type in JSDoc) they will not be used to split
* the string. This allows to specify jsdoc tags without the need to eliminate all white spaces i.e. {number | string}
*/
export function extractTagParts(str: any): string[];
/** Parse tag string "@param {Array} name description" etc. */
export function parseTag(str: any): Tag;
/**
* Parse tag type string "{Array|Object}" etc.
* This function also supports complex type descriptors like in jsDoc or even the enhanced syntax used by the
* [google closure compiler](https://developers.google.com/closure/compiler/docs/js-for-compiler#types)
*
* The resulting array from the type descriptor `{number|string|{name:string,age:number|date}}` would look like this:
*/
export function parseTagTypes(str: string, tag: Tag): string[];
/**
* Determine if a parameter is optional.
*
* Examples:
* JSDoc: {Type} [name]
* Google: {Type=} name
* TypeScript: {Type?} name
*/
export function parseParamOptional(tag: Tag): boolean;
/**
* Parse the context from the given `str` of js.
*
* This method attempts to discover the context
* for the comment based on it's code. Currently
* supports:
*
* - classes
* - class constructors
* - class methods
* - function statements
* - function expressions
* - prototype methods
* - prototype properties
* - methods
* - properties
* - declarations
*/
export function parseCodeContext(str: string, parentContext?: any | undefined): any;
export interface ContextPatternMatchersCtx {
type: 'class' | 'constructor' | 'method' | 'function' | 'property' | 'prototype' | 'declaration';
constructor?: string;
cons?: string;
name: string;
string: string;
extends?: string;
value?: string;
}
export type ContextPatternMatchersFn = (str: string, parentContext?: ContextPatternMatchersCtx) => ContextPatternMatchersCtx;
export let contextPatternMatchers: ContextPatternMatchersFn[];
}