-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgetAnnotationsString.js
More file actions
44 lines (34 loc) · 1.09 KB
/
getAnnotationsString.js
File metadata and controls
44 lines (34 loc) · 1.09 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
const { wrapComment } = require('./general');
/**
* @typedef {{
* annotationName?: string
* annotationValue?: string
* }} Annotation
*/
/**
* Generates annotations string.
* @param {function} prepareName
* @returns {(annotations: Annotation[]) => string} - returns Annotations string (e.g: "\nANNOTATIONS (...)") or ''.
*/
const getAnnotationsString = prepareName => annotations => {
if (!Array.isArray(annotations) || annotations.length === 0) {
return '';
}
const wrapValue = value => wrapComment(value);
const annotationsItems = annotations
.filter(annotation => annotation?.annotationName?.trim())
.map(annotation => {
const { annotationName, annotationValue } = annotation;
const name = prepareName(annotationName.trim());
let finalValue = '';
if (annotationValue !== undefined && annotationValue.trim() !== '') {
finalValue = ' ' + wrapValue(annotationValue.trim());
}
return `${name}${finalValue}`;
});
if (annotationsItems.length > 0) {
return `ANNOTATIONS (${annotationsItems.join(', ')})`;
}
return '';
};
module.exports = { getAnnotationsString };