-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
93 lines (79 loc) · 2.14 KB
/
index.js
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
/*!
* extract-comments <https://github.com/jonschlinkert/extract-comments>
*
* Copyright (c) 2014-present, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
const Extractor = require('./lib/extractor');
/**
* Extract comments from the given `string`.
*
* ```js
* const extract = require('extract-comments');
* console.log(extract(string, options));
* ```
* @param {String} `string`
* @param {Object} `options` Pass `first: true` to return after the first comment is found.
* @param {Function} `tranformFn` (optional) Tranform function to modify each comment
* @return {Array} Returns an array of comment objects
* @api public
*/
function extract(str, options, tranformFn) {
let extractor = new Extractor(options, tranformFn);
return extractor.extract(str);
}
/**
* Extract block comments from the given `string`.
*
* ```js
* console.log(extract.block(string, options));
* ```
* @name .block
* @param {String} `string`
* @param {Object} `options` Pass `first: true` to return after the first comment is found.
* @return {String}
* @api public
*/
extract.block = (str, options) => {
return extract(str, Object.assign({}, options, { line: false }));
};
/**
* Extract line comments from the given `string`.
*
* ```js
* console.log(extract.line(string, options));
* ```
* @name .line
* @param {String} `string`
* @param {Object} `options` Pass `first: true` to return after the first comment is found.
* @return {String}
* @api public
*/
extract.line = (str, options) => {
return extract(str, Object.assign({}, options, { block: false }));
};
/**
* Extract the first comment from the given `string`.
*
* ```js
* console.log(extract.first(string, options));
* ```
* @name .first
* @param {String} `string`
* @param {Object} `options` Pass `first: true` to return after the first comment is found.
* @return {String}
* @api public
*/
extract.first = (str, options) => {
return extract(str, Object.assign({}, options, { first: true }));
};
/**
* Expose `Extractor` constructor, to
* allow custom plugins to be registered.
*/
extract.Extractor = Extractor;
/**
* Expose `extract`
*/
module.exports = extract;