-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getBuiltinComment.ts
32 lines (31 loc) · 1012 Bytes
/
getBuiltinComment.ts
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
const BEG_OF_FILE_COMMENT_PATTERN = "@";
const START_OF_COMMENT = "{";
const END_OF_FILE_COMMENT_PATTERN = "}";
const START_COMMENT_IN_PROJECT = " # ";
/** Will get a builtin comment in format of @Preview{
* comment } out of a file
* @param {string} content The content of the file
* @param {string} keyword The Keyword to find the comments with
* @returns {string} The comment
*/
export const getBuiltinComment = (
content: string,
keyword: string = "Preview"
): string => {
const startKeyWord = `${BEG_OF_FILE_COMMENT_PATTERN}${keyword}${START_OF_COMMENT}`;
const startOFComment = content.indexOf(startKeyWord);
const endOfComment = content.indexOf(
END_OF_FILE_COMMENT_PATTERN,
startOFComment
);
if (startOFComment > -1 && endOfComment > -1) {
const comment = content.substring(
startOFComment + startKeyWord.length,
endOfComment - 1
);
return START_COMMENT_IN_PROJECT + comment.trim();
} else {
return "";
}
};
export default getBuiltinComment;