-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathparser.js
More file actions
151 lines (126 loc) · 3.16 KB
/
Copy pathparser.js
File metadata and controls
151 lines (126 loc) · 3.16 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
var _ = require('lodash');
/**
* Checks if a method has a specific tag
* @method hasTag
* @private
* @param {Object} methods
* @return {Boolean} Returns a boolean
* @example hasTag(methods, 'deprecated', callback)
*/
function hasTag(methods, tag, cb) {
return methods.map(method => {
_.each(method.tags, tag => {
if (tag.tag === tag) {
return method;
}
});
});
}
module.exports = {
getDeprecated: function getDeprecated(methods) {
methods.forEach(method => {
_.each(method.tags, tag => {
if (tag.tag === 'deprecated') {
method.deprecated = true;
}
});
});
return methods;
},
/**
* Adds the name to each method
* @method getMethodNames
* @group Parser
* @deprecated
* @param {object} methods
* @return {object} returns the methods with method names
*/
getMethodNames: function getMethodNames(methods) {
methods.forEach(method => {
_.each(method.tags, function (tag) {
if (tag.tag === 'method') {
method.name = tag.name;
}
});
});
return methods;
},
getDescriptions: function(methods) {
methods.forEach(method => {
_.each(method.tags, function (tag) {
if (tag.tag === 'description') {
method.description = tag.source.replace('@description ', '');
}
});
});
return methods;
},
/**
* Gets each method parameter
* @method getParameters
* @group Parser
* @param {Object} methods
* @return {Object} returns the methods with parameters
*/
getParameters: function getParameters(methods) {
var tags;
methods.forEach(method => {
method.params = [];
tags = method.tags;
_.each(tags, function (tag) {
if (tag.tag === 'param') {
method.params.push(tag);
}
});
});
return methods;
},
/**
* Gets examples for each method
* @method getExamples
* @group Parser
* @param {Object} methods
* @return {Object} returns the methods
*/
getExamples: function getExamples(methods) {
methods.forEach(method => {
_.each(method.tags, function (tag) {
if (tag.tag === 'example') {
method.example = tag.source.replace('@example ', '');
}
});
});
return methods;
},
/**
* Groups the methods based on their "@group" tag
* @method groupMethods
* @group parser
* @param {Object} methods
* @return {Object} Returns the grouped and ungrouped methods
*/
groupMethods: function groupMethods(methods) {
var grouped = {};
var ungrouped = [];
methods.forEach(method => {
// Method is grouped
if (_.some(method.tags, { tag: 'name' })) {
_.each(method.tags, tag => {
if (tag.tag === 'name') {
tagName = tag.name.toLowerCase();
if (grouped.hasOwnProperty(tagName)) {
grouped[tagName].push(method);
} else {
grouped[tagName] = [];
grouped[tagName].push(method);
}
}
});
// Method is ungrouped
} else {
ungrouped.push(method);
}
});
return { grouped };
},
};