-
Notifications
You must be signed in to change notification settings - Fork 3
/
typeString.js
44 lines (33 loc) · 1021 Bytes
/
typeString.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
var typeString = module.exports = function(obj, options) {
var type = obj.type || obj;
options = options || {};
var pointer = type.pointer || '';
if(options === '*') {
pointer = pointer.replace(options, '');
}
var str = type.name + pointer;
var parameters = ((obj.type && obj.type.parameters) ? (obj.type.parameters) : obj.parameters);
if(type.name.match(/\*/) && !options.onlyParameters) {
if(options.param) {
return type.name.replace('(*)', '(*' + options.param + ')');
}
return type.name;
}
if((!obj.functionPointer || options.onlyReturn) && !options.forceParams ) {
return str + (options.param?(' ' + options.param ):'');
}
if(!parameters) {
return str;
}
if(options.onlyParameters) {
str = "";
}
else {
str += '(*' + (options.param || '' )+ ')';
}
str += '(';
str += parameters.map(function(parameter) {
return typeString(parameter.type) + (options.withNames?' ' + parameter.name:'');
}).join(',');
return str + ')';
};