comment-parser 0.3.2 → 0.5.0
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/.eslintignore +1 -0
- package/.eslintrc +11 -0
- package/.travis.yml +2 -4
- package/CHANGELOG.md +9 -0
- package/README.md +24 -5
- package/index.js +31 -34
- package/package.json +11 -6
- package/parser.js +180 -246
- package/parsers.js +100 -0
- package/tests/custom-parsers.spec.js +90 -99
- package/tests/files.spec.js +45 -46
- package/tests/fixtures/sample.js +15 -15
- package/tests/parse.js +18 -0
- package/tests/parse.spec.js +787 -534
- package/.jshintrc +0 -11
- package/.npmignore +0 -15
package/.eslintignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
node_modules/*
|
package/.eslintrc
ADDED
package/.travis.yml
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
# v0.5.0
|
|
2
|
+
- line wrapping control with `opts.join`
|
|
3
|
+
|
|
4
|
+
# v0.4.2
|
|
5
|
+
- tolerate inconsistent lines alignment within block
|
|
6
|
+
|
|
7
|
+
# v0.4.1
|
|
8
|
+
- refactored parsing, allow to not start lines with "* " inside block
|
|
9
|
+
|
|
1
10
|
# v0.3.2
|
|
2
11
|
- fix RegExp for `description` extraction to allow $ char
|
|
3
12
|
|
package/README.md
CHANGED
|
@@ -66,7 +66,29 @@ this would be parsed into following
|
|
|
66
66
|
|
|
67
67
|
By default dotted names like `name.subname.subsubname` will be expanded into nested sections, this can be prevented by passing `opts.dotted_names = false`.
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
Below are examples of acceptable comment formats
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
/** online comment */
|
|
73
|
+
|
|
74
|
+
/** first line
|
|
75
|
+
* second line */
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
No *s on middle lines is acceptable too
|
|
79
|
+
which might be convenient for writing big
|
|
80
|
+
chunks of text.
|
|
81
|
+
|
|
82
|
+
* keeping *s on some lines
|
|
83
|
+
* would work either
|
|
84
|
+
|
|
85
|
+
left bound is dermined by opening marker position
|
|
86
|
+
and white space will be trimmed as there was '* '
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Comments starting with `/***` and `/*` are ignored.
|
|
70
92
|
|
|
71
93
|
Also you can parse entire file with `parse.file('path/to/file', callback)` or acquire an instance of [Transform](http://nodejs.org/api/stream.html#stream_class_stream_transform) stream with `parse.stream()`.
|
|
72
94
|
|
|
@@ -134,11 +156,8 @@ This would produce following:
|
|
|
134
156
|
|
|
135
157
|
## Contributors
|
|
136
158
|
|
|
137
|
-
|
|
138
159
|
- [Alexej Yaroshevich](https://github.com/zxqfox)
|
|
139
160
|
- [Evgeny Reznichenko](https://github.com/zxcabs)
|
|
140
161
|
- [Jordan Harband](https://github.com/ljharb)
|
|
141
162
|
- [Sergii Iavorskyi](https://github.com/yavorskiy)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
Happy coding :)
|
|
163
|
+
- [tengattack](https://github.com/tengattack)
|
package/index.js
CHANGED
|
@@ -1,64 +1,61 @@
|
|
|
1
1
|
|
|
2
|
-
'use strict'
|
|
2
|
+
'use strict'
|
|
3
3
|
|
|
4
|
-
var fs
|
|
5
|
-
var stream = require('readable-stream')
|
|
6
|
-
var util
|
|
4
|
+
var fs = require('fs')
|
|
5
|
+
var stream = require('readable-stream')
|
|
6
|
+
var util = require('util')
|
|
7
7
|
|
|
8
|
-
var parse
|
|
8
|
+
var parse = require('./parser')
|
|
9
9
|
|
|
10
|
-
module.exports = parse
|
|
10
|
+
module.exports = parse
|
|
11
11
|
|
|
12
12
|
/* ------- Transform stream ------- */
|
|
13
13
|
|
|
14
|
-
function Parser(opts) {
|
|
15
|
-
opts = opts || {}
|
|
16
|
-
stream.Transform.call(this, {objectMode: true})
|
|
17
|
-
this._extract = parse.mkextract(opts)
|
|
14
|
+
function Parser (opts) {
|
|
15
|
+
opts = opts || {}
|
|
16
|
+
stream.Transform.call(this, {objectMode: true})
|
|
17
|
+
this._extract = parse.mkextract(opts)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
util.inherits(Parser, stream.Transform)
|
|
20
|
+
util.inherits(Parser, stream.Transform)
|
|
21
21
|
|
|
22
|
-
Parser.prototype._transform = function transform(data, encoding, done) {
|
|
23
|
-
|
|
24
|
-
var
|
|
25
|
-
var lines = data.toString().split(/\n/);
|
|
22
|
+
Parser.prototype._transform = function transform (data, encoding, done) {
|
|
23
|
+
var block
|
|
24
|
+
var lines = data.toString().split(/\n/)
|
|
26
25
|
|
|
27
26
|
while (lines.length) {
|
|
28
|
-
block = this._extract(lines.shift())
|
|
27
|
+
block = this._extract(lines.shift())
|
|
29
28
|
if (block) {
|
|
30
|
-
this.push(block)
|
|
29
|
+
this.push(block)
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
done()
|
|
35
|
-
}
|
|
33
|
+
done()
|
|
34
|
+
}
|
|
36
35
|
|
|
37
|
-
module.exports.stream = function stream(opts) {
|
|
38
|
-
return new Parser(opts)
|
|
39
|
-
}
|
|
36
|
+
module.exports.stream = function stream (opts) {
|
|
37
|
+
return new Parser(opts)
|
|
38
|
+
}
|
|
40
39
|
|
|
41
40
|
/* ------- File parser ------- */
|
|
42
41
|
|
|
43
|
-
module.exports.file = function file(file_path, done) {
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
var collected = [];
|
|
42
|
+
module.exports.file = function file (file_path, done) {
|
|
43
|
+
var opts = {}
|
|
44
|
+
var collected = []
|
|
47
45
|
|
|
48
46
|
if (arguments.length === 3) {
|
|
49
|
-
opts = done
|
|
50
|
-
done = arguments[2]
|
|
47
|
+
opts = done
|
|
48
|
+
done = arguments[2]
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
return fs.createReadStream(file_path, {encoding: 'utf8'})
|
|
54
52
|
.on('error', done)
|
|
55
53
|
.pipe(new Parser(opts))
|
|
56
54
|
.on('error', done)
|
|
57
|
-
.on('data', function(data) {
|
|
58
|
-
collected.push(data)
|
|
55
|
+
.on('data', function (data) {
|
|
56
|
+
collected.push(data)
|
|
59
57
|
})
|
|
60
58
|
.on('finish', function () {
|
|
61
|
-
done(null, collected)
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
|
|
59
|
+
done(null, collected)
|
|
60
|
+
})
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comment-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Generic JSDoc-like comment parser. ",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -11,14 +11,19 @@
|
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"chai": "~1.9.0",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
14
|
+
"eslint": "^4.7.1",
|
|
15
|
+
"eslint-config-standard": "^10.2.1",
|
|
16
|
+
"eslint-plugin-import": "^2.7.0",
|
|
17
|
+
"eslint-plugin-node": "^5.1.1",
|
|
18
|
+
"eslint-plugin-promise": "^3.5.0",
|
|
19
|
+
"eslint-plugin-standard": "^3.0.1",
|
|
20
|
+
"mocha": "^3.5.3",
|
|
17
21
|
"nodemon": "^1.2.1"
|
|
18
22
|
},
|
|
19
23
|
"scripts": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
24
|
+
"pretest": "eslint .",
|
|
25
|
+
"test": "mocha tests",
|
|
26
|
+
"watch": "nodemon -q -i node_modules -x npm test"
|
|
22
27
|
},
|
|
23
28
|
"repository": {
|
|
24
29
|
"type": "git",
|