comment-parser 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/index.d.ts +152 -4
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -2,28 +2,176 @@
|
|
|
2
2
|
// Project: comment-parser
|
|
3
3
|
// Definitions by: Javier "Ciberman" Mora <https://github.com/jhm-ciberman/>
|
|
4
4
|
|
|
5
|
-
declare namespace
|
|
5
|
+
declare namespace parse {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* In case you need to parse tags in a different way you can specify custom parsers here.
|
|
9
|
+
* Each parser function takes string left after previous parsers were applied and the data produced by them.
|
|
10
|
+
* It should return either `undefined` or the new object, where `source` is the consumed substring.
|
|
11
|
+
*/
|
|
12
|
+
export type Parser = (str: string, data: any) => { source: string, data: any };
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents a parsed doc comment.
|
|
16
|
+
*/
|
|
6
17
|
export interface Comment {
|
|
18
|
+
/**
|
|
19
|
+
* A list of tags that are present in this doc comment.
|
|
20
|
+
*/
|
|
7
21
|
tags: Tag[];
|
|
22
|
+
/**
|
|
23
|
+
* The starting line in the source code of this doc comment.
|
|
24
|
+
*/
|
|
8
25
|
line: number;
|
|
26
|
+
/**
|
|
27
|
+
* The description of this doc comment. Empty string if no description was specified.
|
|
28
|
+
*/
|
|
9
29
|
description: string;
|
|
30
|
+
/**
|
|
31
|
+
* The source of this doc comment, exactly as it appeared in the doc comment before parsing.
|
|
32
|
+
*/
|
|
10
33
|
source: string;
|
|
11
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Represents a parsed tag. A tag has the following format:
|
|
38
|
+
* > @tag {type} [name=default] description
|
|
39
|
+
*/
|
|
12
40
|
export interface Tag {
|
|
41
|
+
/**
|
|
42
|
+
* The tag's kind, eg `param` or `return`.
|
|
43
|
+
*/
|
|
13
44
|
tag: string;
|
|
45
|
+
/**
|
|
46
|
+
* The name of this tag, ie the first word after the tag. Empty string if no name was specified.
|
|
47
|
+
*/
|
|
14
48
|
name: string;
|
|
49
|
+
/**
|
|
50
|
+
* `true` if the tag is optional (tag name enclosed in brackets), `false` otherwise.
|
|
51
|
+
*/
|
|
15
52
|
optional: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* The type declaration of this tag that is enclosed in curly braces. Empty string if no type was specified.
|
|
55
|
+
*/
|
|
16
56
|
type: string;
|
|
57
|
+
/**
|
|
58
|
+
* The description of this tag that comes after the name. Empty string if no description was specified.
|
|
59
|
+
*/
|
|
17
60
|
description: string;
|
|
61
|
+
/**
|
|
62
|
+
* The line number where this tag starts
|
|
63
|
+
*/
|
|
18
64
|
line: number;
|
|
65
|
+
/**
|
|
66
|
+
* The source of this tag, exactly as it appeared in the doc comment before parsing.
|
|
67
|
+
*/
|
|
19
68
|
source: string;
|
|
69
|
+
/**
|
|
70
|
+
* The default value for this tag. `undefined` in case no default value was specified.
|
|
71
|
+
*/
|
|
72
|
+
default?: string;
|
|
73
|
+
/**
|
|
74
|
+
* A list of errors that occurred during the parsing of this tag. `undefined` if not error occurred.
|
|
75
|
+
*/
|
|
76
|
+
errors? : string[];
|
|
77
|
+
/**
|
|
78
|
+
* If `dotted_names` was set to `true`, a list of sub tags. `undefined` if `dotted_names` was set to `false` or if
|
|
79
|
+
* no sub tags exist.
|
|
80
|
+
*/
|
|
81
|
+
tags?: Tag[];
|
|
20
82
|
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Options for parsing doc comments.
|
|
86
|
+
*/
|
|
21
87
|
export interface Options {
|
|
22
|
-
|
|
23
|
-
|
|
88
|
+
/**
|
|
89
|
+
* In case you need to parse tags in a different way you can specify custom parsers here.
|
|
90
|
+
* Each parser function takes string left after previous parsers were applied and the data produced by them.
|
|
91
|
+
* It should return either `undefined` or the new object, where `source` is the consumed substring.
|
|
92
|
+
*
|
|
93
|
+
* If you specify custom parsers, the default parsers are overwritten, but you can access them via the constant
|
|
94
|
+
* `PARSERS`.
|
|
95
|
+
*/
|
|
96
|
+
parsers: Parser[];
|
|
97
|
+
/**
|
|
98
|
+
* By default dotted names like `name.subname.subsubname` will be expanded into nested sections, this can be
|
|
99
|
+
* prevented by passing `opts.dotted_names = false`.
|
|
100
|
+
*/
|
|
101
|
+
dotted_names: boolean;
|
|
102
|
+
join: string | number | boolean;
|
|
103
|
+
/**
|
|
104
|
+
* `true` to trim whitespace at the start of each line, `false` otherwise.
|
|
105
|
+
*/
|
|
106
|
+
trim: boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Options for turning a parsed doc comment back into a string.
|
|
111
|
+
*/
|
|
112
|
+
export interface StringifyOptions {
|
|
113
|
+
/**
|
|
114
|
+
* Indentation for each line. If a string is passed, that string is used verbatim to indent each line. If a number
|
|
115
|
+
* is passed, indents each line with that many whitespaces.
|
|
116
|
+
*/
|
|
117
|
+
indent: string | number;
|
|
24
118
|
}
|
|
119
|
+
|
|
120
|
+
export interface Stringify {
|
|
121
|
+
/**
|
|
122
|
+
* One may also convert comment-parser JSON structures back into strings using this stringify method.
|
|
123
|
+
*
|
|
124
|
+
* This method accepts the JSON as its first argument and an optional options object with an indent property set to
|
|
125
|
+
* either a string or a number that will be used to determine the number of spaces of indent. The indent of the start
|
|
126
|
+
* of the doc block will be one space less than the indent of each line of asterisks for the sake of alignment as per
|
|
127
|
+
* usual practice.
|
|
128
|
+
*
|
|
129
|
+
* The stringify export delegates to the specialized methods `stringifyBlocks`, `stringifyBlock`, and
|
|
130
|
+
* `stringifyTag`, which are available on the stringify function object.
|
|
131
|
+
* @param comment A tag, comment or a list of comments to stringify.
|
|
132
|
+
* @param options Options to control how the comment or comments are stringified.
|
|
133
|
+
* @return The stringified doc comment(s).
|
|
134
|
+
*/
|
|
135
|
+
(comment: Tag | Comment | Comment[], options?: Partial<StringifyOptions>): string;
|
|
136
|
+
/**
|
|
137
|
+
* Similar to `stringify`, but only accepts a list of doc comments.
|
|
138
|
+
* @param comments A list of comments to stringify.
|
|
139
|
+
* @param options Options to control how the comments are stringified.
|
|
140
|
+
* @return The stringified doc comment(s).
|
|
141
|
+
*/
|
|
142
|
+
stringifyBlocks(comments: Comment[], options?: Partial<StringifyOptions>): string;
|
|
143
|
+
/**
|
|
144
|
+
* Similar to `stringify`, but only accepts a single doc comment.
|
|
145
|
+
* @param comment A comment to stringify.
|
|
146
|
+
* @param options Options to control how the comment is stringified.
|
|
147
|
+
* @return The stringified doc comment(s).
|
|
148
|
+
*/
|
|
149
|
+
stringifyBlock(comment: Comment, options?: Partial<StringifyOptions>): string;
|
|
150
|
+
/**
|
|
151
|
+
* Similar to `stringify`, but only accepts a single tag.
|
|
152
|
+
* @param tag A tag to stringify.
|
|
153
|
+
* @param options Options to control how the tag is stringified.
|
|
154
|
+
* @return The stringified doc comment(s).
|
|
155
|
+
*/
|
|
156
|
+
stringifyTag(tag: Tag, options?: Partial<StringifyOptions>): string;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export const stringify: parse.Stringify;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The default list of parsers that is used to parse comments.
|
|
163
|
+
*/
|
|
164
|
+
export const PARSERS: Record<"parse_tag" | "parse_type" | "parse_description" | "parse_name", Parser>
|
|
25
165
|
}
|
|
26
166
|
|
|
27
|
-
|
|
167
|
+
/**
|
|
168
|
+
* The main method of this module which takes comment string and returns an array of objects with parsed data.
|
|
169
|
+
* It is not trying to detect relations between tags or somehow recognize their meaning. Any tag can be used, as long
|
|
170
|
+
* as it satisfies the format.
|
|
171
|
+
* @param str A string with doc comments and source code to parse.
|
|
172
|
+
* @param opts Options to control how the source string is parsed.
|
|
173
|
+
* @return The parsed list of doc comments.
|
|
174
|
+
*/
|
|
175
|
+
declare function parse(str: string, opts?: Partial<parse.Options>): [parse.Comment];
|
|
28
176
|
|
|
29
177
|
export = parse;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comment-parser",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Generic JSDoc-like comment parser. ",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"author": "Sergii Iavorskyi <yavorskiy.s@gmail.com> (https://github.com/yavorskiy)",
|
|
42
42
|
"contributors": [
|
|
43
43
|
"Alexej Yaroshevich (https://github.com/zxqfox)",
|
|
44
|
+
"Andre Wachsmuth (https://github.com/blutorange)",
|
|
44
45
|
"Brett Zamir (https://github.com/brettz9)",
|
|
45
46
|
"Dieter Oberkofler (https://github.com/doberkofler)",
|
|
46
47
|
"Evgeny Reznichenko (https://github.com/zxcabs)",
|