-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathsnippet_template.js
71 lines (64 loc) · 1.34 KB
/
snippet_template.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
const generateSnippetMark = (i) => {
return '<`' + i + ':description`>'
}
const formatParam = (param, i) => {
if (param.alias) {
if (param.name) {
return `{${param.alias}} ${param.name} - ` + generateSnippetMark(i++)
}
return param.alias
}
if (param.name) {
return `{${param.type}} ${param.name} - ` + generateSnippetMark(i++)
}
return `{${param.type}}`
}
const generateClassDoc = (doc) => {
const d =
doc.heritageClauses.length === 0
? `
/**
* ` + '<`0:name`>' + `
*/`
: `
/**
* ` + '<`0:name`>' + `
*
* @${doc.heritageClauses.map((h) => `${h.type} ${h.value}`).join('\n * @')}
*/`
return d.trim()
}
module.exports = {
generateClassDoc,
generateInterfaceDoc: generateClassDoc,
generatePropertyDoc: (doc) => {
return `
/**
* @type {${doc.returnType}}
*/`.trimLeft()
},
generateFunctionDoc: (doc) => {
const start =
doc.params.length === 0
? `
/**
* ` + '<`0:name`>'
: `
/**
* ` + '<`0:name`>' + `
*
* @param ${doc.params.map(formatParam).join('\n * @param ')}`
const delimiter =
doc.params.length === 0 && doc.returnType !== ''
? `
*`
: ``
const end = doc.returnType
? `
* @returns {${doc.returnType}} ` + '<`0:return value`>' + `
*/`
: `
*/`
return `${start.trimLeft()}${delimiter}${end.trimRight()}`
},
}