-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
50 lines (39 loc) · 1.67 KB
/
index.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
const { NodeHtmlMarkdown } = require('node-html-markdown');
const parseMessage = (message, option = {}) => {
const messageObj = {};
if (typeof message === 'string') {
if (option.html) {
message = NodeHtmlMarkdown.translate(message)
.replace(/\* \*\*/g, '- **')
.replace(/\*\* \n/g, '**\n')
.replace(/\n /g, '\n ')
}
const mutiLanguageMessage = message.split('##').filter((item) => item !== '');
mutiLanguageMessage.forEach(element => {
const structuredInformation = element.split('- ');
const tile = structuredInformation[0].replace(/\r\n/g, '');
const infos = structuredInformation.slice(1);
const language = tile.slice(tile.indexOf('(') + 1, tile.indexOf(')'));
messageObj[`${language}`] = {};
infos.forEach(info => {
const details = info.split(' ');
const subTitle = details[0].replace(/(?:\r\n|\*)/g, '');
const descriptions = details.slice(1).map(item => {
const detail = item.replace(/\r\n/g, '');
const deletAllWarp = _text => {
if (_text.endsWith('\n')) {
return deletAllWarp(_text.slice(0, -1));
} else {
return _text;
}
}
return deletAllWarp(detail);
});
messageObj[`${language}`][`${subTitle}`] = descriptions;
});
});
return messageObj;
}
return null;
}
module.exports = parseMessage;