This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
203 lines (155 loc) · 4.53 KB
/
util.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
let articleDict = [ '传记 Biography', '故事 Story', '漫画 Manga' ];
let Moment = require('moment');
let util = {
firstUpCase: function(str) {
return str.toLowerCase().replace(/( |^)[a-z]/g, function (head) { return head.toUpperCase(); } );
},
// 混合句子
makeSent: function(cnSents = [], enSents = []) {
let result = [];
let max = cnSents.length > enSents.length ? cnSents.length : enSents.length;
for(let i=0; i<max; i++) {
let cnSent = (cnSents[i] || '').trim();
let enSent = (enSents[i] || '').trim();
if(!cnSent && !enSent) {
continue;
}
result.push('>');
if(cnSent) {
result.push(cnSent.replace(/^/, '> ').replace(/$/, '。 '));
}
if(enSent) {
result.push(enSent.replace(/^/, '> ').replace(/$/, '. '));
}
}
result.shift();
return result;
},
// 混合段落
makePara: function(cnParas = [], enParas = [], isCount = false, isMakeCata = false, numCataWrap) {
let max = cnParas.length > enParas.length ? cnParas.length : enParas.length;
let result = [];
let numCata = numCataWrap ? numCataWrap.start : 0;
for(let i=0; i<max; i++) {
let cnPara = (cnParas[i] || '').trim();
let enPara = (enParas[i] || '').trim();
if(!cnPara && !enPara) {
continue;
}
if(i != 0) { result.push(''); }
if(isCount || isMakeCata) {
result.push('#### '+ ('00'+(++numCata)).slice(-2));
}
let cnSents;
let enSents;
if(cnPara) {
cnSents = cnPara.replace(/^<p>/, '').replace(/^<i>|<\/i>$/g, '').split(/[.。]/);
}
if(enPara) {
enSents = enPara.replace(/^<p>/, '').replace(/^<i>|<\/i>$/g, '').split(/[.。]/);
}
result = result.concat(util.makeSent(cnSents, enSents));
}
if(numCataWrap) {
numCataWrap.start = numCata;
}
if(isMakeCata) {
result = util.makeCata().concat(result);
}
return result;
},
makeHara: function(cnHaras = [], enHaras = [], isCount = false, isMakeCata = false, numHaraWrap) {
let max = cnHaras.length > enHaras.length ? cnHaras.length : enHaras.length;
let result = [];
let numHara = numHaraWrap ? numHaraWrap.start : 0;
for(let i=0; i<max; i++) {
let cnPara = (cnHaras[i] || '').trim();
let enPara = (enHaras[i] || '').trim();
if(!cnPara && !enPara) {
continue;
}
if(i != 0) { result.push(''); }
if(isCount || isMakeCata) {
result.push('#### '+ ('00'+(++numHara)).slice(-2));
}
let cnParas;
let enParas;
if(cnPara) {
cnParas = cnPara.trim().split(/<\/p>/);
}
if(enPara) {
enParas = enPara.trim().split(/<\/p>/);
}
result = result.concat(util.makePara(cnParas, enParas));
}
if(numHaraWrap) {
numHaraWrap.start = numHara;
}
if(isMakeCata) {
result = util.makeCata(numHara).concat(result);
}
return result;
},
// 传记引述
makeQuote: function(cnQuote = '', cnAuthor = '', enQuote = '', enAuthor = '') {
let result = [];
result.push(`#### 引述 Quote by ${cnAuthor} (${enAuthor})`);
result = result.concat(util.makeSent(cnQuote.replace(/[“”"]/g, '').split(/[.。]/), enQuote.replace(/[“”"]/g, '').split(/[.。]/)));
result.push('');
return result;
},
// 传记简介
makeShort: function(cnShort = '', enShort = '') {
let result = [];
result.push('#### 简介 Short');
result = result.concat(util.makeSent(cnShort.split(/[.。]/), enShort.split(/[.。]/)));
result.push('');
return result;
},
makeCata: function(count = 0) {
let result = [ '#### 目录 Catalog' ];
// 插入目录
let catalog = '> ';
for(let i=1; i<count+1; i++) {
let text = ('00'+i).slice(-2);
catalog += `[${text}](#${text}) | `;
if(!(i % 20)) {
catalog = catalog.replace(/ \| $/, ' \r\n> ');
}
else if(!(i % 10)) {
catalog = catalog.replace(/ \| $/, ' || ');
}
}
if(count) {
result = result.concat(catalog.replace(/( \| | {2}\r\n> )$/, '').split('\r\n'));
}
result.push('');
return result;
},
makeHead: function() {
return [
'● Runeterra Compare ',
'***',
''
];
},
makeTran: function() {
return [
'',
'***',
'● 可供参考的直译 ',
'> 1: ',
];
},
makeTail: function(type = 0) {
return [
'',
'***',
'● github.com/LOLArranger/Runeterra-Compare ',
`● ${articleDict[type]} `,
`● Version ${Moment().format('YYYY.MM.DD')} `,
'● All Based on League of Legends Universe(英雄联盟宇宙) ',
];
}
};
module.exports = util;