UNPKG

6.86 kBMarkdownView Raw
1doctrine ([doctrine](http://github.com/Constellation/doctrine)) is JSDoc parser.
2
3[![Build Status](https://travis-ci.org/Constellation/doctrine.svg?branch=master)](https://travis-ci.org/Constellation/doctrine)
4[![Coverage Status](https://img.shields.io/coveralls/Constellation/doctrine.svg)](https://coveralls.io/r/Constellation/doctrine?branch=master)
5[![Dependency Status](https://david-dm.org/Constellation/doctrine.svg)](https://david-dm.org/Constellation/doctrine)
6[![devDependency Status](https://david-dm.org/Constellation/doctrine/dev-status.svg)](https://david-dm.org/Constellation/doctrine#info=devDependencies)
7[![Gitter chat](https://badges.gitter.im/Constellation/doctrine.png)](https://gitter.im/Constellation/doctrine)
8
9It is now used by content assist system of [Eclipse Orion](http://www.eclipse.org/orion/) ([detail](http://planetorion.org/news/2012/10/orion-1-0-release/)). And used as JSDoc validator in [ESLint](http://eslint.org/).
10
11Doctrine can be used in a web browser with using browserify.
12or in a Node.js application via the package manager:
13
14 npm install doctrine
15
16simple example:
17
18 doctrine.parse(
19 [
20 "/**",
21 " * This function comment is parsed by doctrine",
22 " * @param {{ok:String}} userName",
23 "*/"
24 ].join('\n'), { unwrap: true });
25
26and gets following information
27
28 {
29 "description": "This function comment is parsed by doctrine",
30 "tags": [
31 {
32 "title": "param",
33 "description": null,
34 "type": {
35 "type": "RecordType",
36 "fields": [
37 {
38 "type": "FieldType",
39 "key": "ok",
40 "value": {
41 "type": "NameExpression",
42 "name": "String"
43 }
44 }
45 ]
46 },
47 "name": "userName"
48 }
49 ]
50 }
51
52see [demo page](http://constellation.github.com/doctrine/demo/index.html) more detail.
53
54### Options
55
56#### doctrine.parse
57We can pass options to `doctrine.parse(comment, options)`.
58```js
59{
60 unwrap: boolean, // default: false
61 tags: [ string ] | null, // default: null
62 recoverable: boolean, // default: false
63 sloppy: boolean, // default: false
64 lineNumbers: boolean // default: false
65}
66```
67
68##### unwrap
69
70When `unwrap` is `true`, doctrine attempt to unwrap comment specific string from a provided comment text. (removes `/**`, `*/` and `*`)
71For example, `unwrap` transforms
72```
73/**
74 * @param use
75 */
76```
77to
78```
79@param use
80```
81If a provided comment has these comment specific strings, you need to specify this `unwrap` option to `true`.
82
83##### tags
84
85When `tags` array is specified, doctrine only produce tags that is specified in this array.
86For example, if you specify `[ 'param' ]`, doctrine only produces `param` tags.
87If null is specified, doctrine produces all tags that doctrine can recognize.
88
89##### recoverable
90
91When `recoverable` is `true`, doctrine becomes `recoverable` - When failing to parse jsdoc comment, doctrine recovers its state and attempt to continue parsing.
92
93##### sloppy
94
95When `sloppy` is `true`,
96```
97@param String [foo]
98```
99's `[foo]` is interpreted as a optional parameter, not interpreted as a name of this `@param`.
100
101##### lineNumbers
102
103When `lineNumbers` is `true`, parsed tags will include a `lineNumber` property indicating the line (relative to the start of the comment block) where each tag is located in the source. So, given the following comment:
104```
105/**
106 * @param {String} foo
107 * @return {number}
108 */
109```
110The `@param` tag will have `lineNumber: 1`, and the `@return` tag will have `lineNumber: 2`.
111
112
113### License
114
115#### doctrine
116
117Copyright (C) 2012 [Yusuke Suzuki](http://github.com/Constellation)
118 (twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors.
119
120Redistribution and use in source and binary forms, with or without
121modification, are permitted provided that the following conditions are met:
122
123 * Redistributions of source code must retain the above copyright
124 notice, this list of conditions and the following disclaimer.
125
126 * Redistributions in binary form must reproduce the above copyright
127 notice, this list of conditions and the following disclaimer in the
128 documentation and/or other materials provided with the distribution.
129
130THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
131AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
132IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
133ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
134DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
135(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
136LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
137ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
138(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
139THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
140
141#### esprima
142
143some of functions is derived from esprima
144
145Copyright (C) 2012, 2011 [Ariya Hidayat](http://ariya.ofilabs.com/about)
146 (twitter: [@ariyahidayat](http://twitter.com/ariyahidayat)) and other contributors.
147
148Redistribution and use in source and binary forms, with or without
149modification, are permitted provided that the following conditions are met:
150
151 * Redistributions of source code must retain the above copyright
152 notice, this list of conditions and the following disclaimer.
153
154 * Redistributions in binary form must reproduce the above copyright
155 notice, this list of conditions and the following disclaimer in the
156 documentation and/or other materials provided with the distribution.
157
158THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
159AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
160IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
161ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
162DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
163(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
164LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
165ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
166(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
167THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
168
169
170#### closure-compiler
171
172some of extensions is derived from closure-compiler
173
174Apache License
175Version 2.0, January 2004
176http://www.apache.org/licenses/