[d565449] | 1 | [![NPM version][npm-image]][npm-url]
|
---|
| 2 | [![build status][travis-image]][travis-url]
|
---|
| 3 | [![Test coverage][coveralls-image]][coveralls-url]
|
---|
| 4 | [![Downloads][downloads-image]][downloads-url]
|
---|
| 5 | [![Join the chat at https://gitter.im/eslint/doctrine](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/eslint/doctrine?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
---|
| 6 |
|
---|
| 7 | # Doctrine
|
---|
| 8 |
|
---|
| 9 | Doctrine is a [JSDoc](http://usejsdoc.org) parser that parses documentation comments from JavaScript (you need to pass in the comment, not a whole JavaScript file).
|
---|
| 10 |
|
---|
| 11 | ## Installation
|
---|
| 12 |
|
---|
| 13 | You can install Doctrine using [npm](https://npmjs.com):
|
---|
| 14 |
|
---|
| 15 | ```
|
---|
| 16 | $ npm install doctrine --save-dev
|
---|
| 17 | ```
|
---|
| 18 |
|
---|
| 19 | Doctrine can also be used in web browsers using [Browserify](http://browserify.org).
|
---|
| 20 |
|
---|
| 21 | ## Usage
|
---|
| 22 |
|
---|
| 23 | Require doctrine inside of your JavaScript:
|
---|
| 24 |
|
---|
| 25 | ```js
|
---|
| 26 | var doctrine = require("doctrine");
|
---|
| 27 | ```
|
---|
| 28 |
|
---|
| 29 | ### parse()
|
---|
| 30 |
|
---|
| 31 | The primary method is `parse()`, which accepts two arguments: the JSDoc comment to parse and an optional options object. The available options are:
|
---|
| 32 |
|
---|
| 33 | * `unwrap` - set to `true` to delete the leading `/**`, any `*` that begins a line, and the trailing `*/` from the source text. Default: `false`.
|
---|
| 34 | * `tags` - an array of tags to return. When specified, Doctrine returns only tags in this array. For example, if `tags` is `["param"]`, then only `@param` tags will be returned. Default: `null`.
|
---|
| 35 | * `recoverable` - set to `true` to keep parsing even when syntax errors occur. Default: `false`.
|
---|
| 36 | * `sloppy` - set to `true` to allow optional parameters to be specified in brackets (`@param {string} [foo]`). Default: `false`.
|
---|
| 37 | * `lineNumbers` - set to `true` to add `lineNumber` to each node, specifying the line on which the node is found in the source. Default: `false`.
|
---|
| 38 | * `range` - set to `true` to add `range` to each node, specifying the start and end index of the node in the original comment. Default: `false`.
|
---|
| 39 |
|
---|
| 40 | Here's a simple example:
|
---|
| 41 |
|
---|
| 42 | ```js
|
---|
| 43 | var ast = doctrine.parse(
|
---|
| 44 | [
|
---|
| 45 | "/**",
|
---|
| 46 | " * This function comment is parsed by doctrine",
|
---|
| 47 | " * @param {{ok:String}} userName",
|
---|
| 48 | "*/"
|
---|
| 49 | ].join('\n'), { unwrap: true });
|
---|
| 50 | ```
|
---|
| 51 |
|
---|
| 52 | This example returns the following AST:
|
---|
| 53 |
|
---|
| 54 | {
|
---|
| 55 | "description": "This function comment is parsed by doctrine",
|
---|
| 56 | "tags": [
|
---|
| 57 | {
|
---|
| 58 | "title": "param",
|
---|
| 59 | "description": null,
|
---|
| 60 | "type": {
|
---|
| 61 | "type": "RecordType",
|
---|
| 62 | "fields": [
|
---|
| 63 | {
|
---|
| 64 | "type": "FieldType",
|
---|
| 65 | "key": "ok",
|
---|
| 66 | "value": {
|
---|
| 67 | "type": "NameExpression",
|
---|
| 68 | "name": "String"
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | ]
|
---|
| 72 | },
|
---|
| 73 | "name": "userName"
|
---|
| 74 | }
|
---|
| 75 | ]
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | See the [demo page](http://eslint.org/doctrine/demo/) more detail.
|
---|
| 79 |
|
---|
| 80 | ## Team
|
---|
| 81 |
|
---|
| 82 | These folks keep the project moving and are resources for help:
|
---|
| 83 |
|
---|
| 84 | * Nicholas C. Zakas ([@nzakas](https://github.com/nzakas)) - project lead
|
---|
| 85 | * Yusuke Suzuki ([@constellation](https://github.com/constellation)) - reviewer
|
---|
| 86 |
|
---|
| 87 | ## Contributing
|
---|
| 88 |
|
---|
| 89 | Issues and pull requests will be triaged and responded to as quickly as possible. We operate under the [ESLint Contributor Guidelines](http://eslint.org/docs/developer-guide/contributing), so please be sure to read them before contributing. If you're not sure where to dig in, check out the [issues](https://github.com/eslint/doctrine/issues).
|
---|
| 90 |
|
---|
| 91 | ## Frequently Asked Questions
|
---|
| 92 |
|
---|
| 93 | ### Can I pass a whole JavaScript file to Doctrine?
|
---|
| 94 |
|
---|
| 95 | No. Doctrine can only parse JSDoc comments, so you'll need to pass just the JSDoc comment to Doctrine in order to work.
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | ### License
|
---|
| 99 |
|
---|
| 100 | #### doctrine
|
---|
| 101 |
|
---|
| 102 | Copyright JS Foundation and other contributors, https://js.foundation
|
---|
| 103 |
|
---|
| 104 | Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 105 | you may not use this file except in compliance with the License.
|
---|
| 106 | You may obtain a copy of the License at
|
---|
| 107 |
|
---|
| 108 | http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 109 |
|
---|
| 110 | Unless required by applicable law or agreed to in writing, software
|
---|
| 111 | distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 112 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 113 | See the License for the specific language governing permissions and
|
---|
| 114 | limitations under the License.
|
---|
| 115 |
|
---|
| 116 | #### esprima
|
---|
| 117 |
|
---|
| 118 | some of functions is derived from esprima
|
---|
| 119 |
|
---|
| 120 | Copyright (C) 2012, 2011 [Ariya Hidayat](http://ariya.ofilabs.com/about)
|
---|
| 121 | (twitter: [@ariyahidayat](http://twitter.com/ariyahidayat)) and other contributors.
|
---|
| 122 |
|
---|
| 123 | Redistribution and use in source and binary forms, with or without
|
---|
| 124 | modification, are permitted provided that the following conditions are met:
|
---|
| 125 |
|
---|
| 126 | * Redistributions of source code must retain the above copyright
|
---|
| 127 | notice, this list of conditions and the following disclaimer.
|
---|
| 128 |
|
---|
| 129 | * Redistributions in binary form must reproduce the above copyright
|
---|
| 130 | notice, this list of conditions and the following disclaimer in the
|
---|
| 131 | documentation and/or other materials provided with the distribution.
|
---|
| 132 |
|
---|
| 133 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
---|
| 134 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 135 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
| 136 | ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
---|
| 137 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
| 138 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
| 139 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
| 140 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 141 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 142 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | #### closure-compiler
|
---|
| 146 |
|
---|
| 147 | some of extensions is derived from closure-compiler
|
---|
| 148 |
|
---|
| 149 | Apache License
|
---|
| 150 | Version 2.0, January 2004
|
---|
| 151 | http://www.apache.org/licenses/
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 | ### Where to ask for help?
|
---|
| 155 |
|
---|
| 156 | Join our [Chatroom](https://gitter.im/eslint/doctrine)
|
---|
| 157 |
|
---|
| 158 | [npm-image]: https://img.shields.io/npm/v/doctrine.svg?style=flat-square
|
---|
| 159 | [npm-url]: https://www.npmjs.com/package/doctrine
|
---|
| 160 | [travis-image]: https://img.shields.io/travis/eslint/doctrine/master.svg?style=flat-square
|
---|
| 161 | [travis-url]: https://travis-ci.org/eslint/doctrine
|
---|
| 162 | [coveralls-image]: https://img.shields.io/coveralls/eslint/doctrine/master.svg?style=flat-square
|
---|
| 163 | [coveralls-url]: https://coveralls.io/r/eslint/doctrine?branch=master
|
---|
| 164 | [downloads-image]: http://img.shields.io/npm/dm/doctrine.svg?style=flat-square
|
---|
| 165 | [downloads-url]: https://www.npmjs.com/package/doctrine
|
---|