xshell 0.0.15 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chalk.browser.d.ts +2 -0
- package/chalk.browser.js +21 -0
- package/chalk.browser.js.map +1 -0
- package/file.js +1 -2
- package/file.js.map +1 -1
- package/i18n/README.md +283 -0
- package/i18n/dict.d.ts +30 -0
- package/i18n/dict.js +34 -0
- package/i18n/dict.js.map +1 -0
- package/i18n/i18n-scan.d.ts +2 -0
- package/i18n/i18n-scan.js +21 -0
- package/i18n/i18n-scan.js.map +1 -0
- package/i18n/i18n.ico +0 -0
- package/i18n/index.d.ts +65 -0
- package/i18n/index.js +118 -0
- package/i18n/index.js.map +1 -0
- package/i18n/rwdict.d.ts +42 -0
- package/i18n/rwdict.js +110 -0
- package/i18n/rwdict.js.map +1 -0
- package/i18n/scanner/checker.d.ts +5 -0
- package/i18n/scanner/checker.js +73 -0
- package/i18n/scanner/checker.js.map +1 -0
- package/i18n/scanner/index.d.ts +52 -0
- package/i18n/scanner/index.js +319 -0
- package/i18n/scanner/index.js.map +1 -0
- package/i18n/scanner/parser.d.ts +3 -0
- package/i18n/scanner/parser.js +154 -0
- package/i18n/scanner/parser.js.map +1 -0
- package/i18n/utils.d.ts +1 -0
- package/i18n/utils.js +14 -0
- package/i18n/utils.js.map +1 -0
- package/myfont.sass +11 -0
- package/net.browser.d.ts +23 -0
- package/net.browser.js +70 -0
- package/net.browser.js.map +1 -0
- package/net.js +2 -4
- package/net.js.map +1 -1
- package/package.json +36 -7
- package/prototype.browser.d.ts +130 -0
- package/prototype.browser.js +421 -0
- package/prototype.browser.js.map +1 -0
- package/repl.js +4 -8
- package/repl.js.map +1 -1
- package/scroll-bar.sass +35 -0
- package/server.d.ts +1 -0
- package/server.js +2 -3
- package/server.js.map +1 -1
- package/toaster.browser.d.ts +9 -0
- package/toaster.browser.js +45 -0
- package/toaster.browser.js.map +1 -0
- package/toaster.sass +22 -0
- package/ufs.js +3 -3
- package/ufs.js.map +1 -1
- package/utils.browser.d.ts +3 -0
- package/utils.browser.js +27 -0
- package/utils.browser.js.map +1 -0
- package/extension.d.ts +0 -3
- package/extension.js +0 -68
- package/extension.js.map +0 -1
- package/net.browser.ts +0 -141
- package/prototype.browser.ts +0 -728
- package/tsconfig.json +0 -73
- package/utils.browser.ts +0 -25
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** 在浏览器端修改 prototype,需要更加小心 */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.is_codepoint_fullwidth = exports.to_json = exports.brackets = exports.quotes = exports.cjk = exports.to_getter_property_descriptors = exports.to_method_property_descriptors = exports.emoji_regex = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const emoji_regex_1 = (0, tslib_1.__importDefault)(require("emoji-regex"));
|
|
7
|
+
exports.emoji_regex = (0, emoji_regex_1.default)();
|
|
8
|
+
function to_method_property_descriptors(methods) {
|
|
9
|
+
return Object.fromEntries(Object.entries(methods)
|
|
10
|
+
.map(([name, value]) => ([name, {
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
enumerable: false,
|
|
14
|
+
value,
|
|
15
|
+
}])));
|
|
16
|
+
}
|
|
17
|
+
exports.to_method_property_descriptors = to_method_property_descriptors;
|
|
18
|
+
function to_getter_property_descriptors(getters) {
|
|
19
|
+
return Object.fromEntries(Object.entries(getters)
|
|
20
|
+
.map(([name, get]) => ([name, {
|
|
21
|
+
configurable: true,
|
|
22
|
+
enumerable: false,
|
|
23
|
+
get,
|
|
24
|
+
}])));
|
|
25
|
+
}
|
|
26
|
+
exports.to_getter_property_descriptors = to_getter_property_descriptors;
|
|
27
|
+
exports.cjk = '([\u2e80-\u9fff\uf900-\ufaff])';
|
|
28
|
+
exports.quotes = {
|
|
29
|
+
single: "'",
|
|
30
|
+
double: '"',
|
|
31
|
+
backtick: '`',
|
|
32
|
+
};
|
|
33
|
+
exports.brackets = {
|
|
34
|
+
round: ['(', ')'],
|
|
35
|
+
square: ['[', ']'],
|
|
36
|
+
curly: ['{', '}'],
|
|
37
|
+
pointy: ['<', '>'],
|
|
38
|
+
corner: ['「', '」'],
|
|
39
|
+
fat: ['【', '】'],
|
|
40
|
+
tortoise_shell: ['〔', '〕'],
|
|
41
|
+
};
|
|
42
|
+
// ------------------------------------ String.prototype
|
|
43
|
+
Object.defineProperties(String.prototype, {
|
|
44
|
+
...to_getter_property_descriptors({
|
|
45
|
+
width() {
|
|
46
|
+
const s = this.replace(exports.emoji_regex, ' ');
|
|
47
|
+
let width = 0;
|
|
48
|
+
for (let i = 0; i < s.length; i++) {
|
|
49
|
+
const code = s.codePointAt(i);
|
|
50
|
+
if ((code <= 0x1f || (code >= 0x7f && code <= 0x9f)) || // ignore control characters
|
|
51
|
+
code >= 0x300 && code <= 0x36f // ignore combining characters
|
|
52
|
+
)
|
|
53
|
+
continue;
|
|
54
|
+
// surrogates
|
|
55
|
+
if (code > 0xFFFF)
|
|
56
|
+
i++;
|
|
57
|
+
width += is_codepoint_fullwidth(code) ? 2 : 1;
|
|
58
|
+
}
|
|
59
|
+
return width;
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
62
|
+
// ------------ 文本处理工具方法
|
|
63
|
+
...to_method_property_descriptors({
|
|
64
|
+
/** 截取字符串不超过 width 显示宽度的部分,并保留颜色
|
|
65
|
+
找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted
|
|
66
|
+
- 若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + …
|
|
67
|
+
- 否则 返回 this
|
|
68
|
+
*/
|
|
69
|
+
truncate(width) {
|
|
70
|
+
const color_bak = this.startsWith('\u001b') ? this.slice(0, 5) : '';
|
|
71
|
+
if (width <= 2)
|
|
72
|
+
return this.slice(0, width);
|
|
73
|
+
let i_fitted = 0;
|
|
74
|
+
let fitted_width = 0;
|
|
75
|
+
let cur_width = 0;
|
|
76
|
+
for (let i = 0; i < this.length; i++) {
|
|
77
|
+
const code = this.codePointAt(i);
|
|
78
|
+
if ((code <= 0x1F || (code >= 0x7F && code <= 0x9F)) || // Ignore control characters
|
|
79
|
+
code >= 0x300 && code <= 0x36F // Ignore combining characters
|
|
80
|
+
)
|
|
81
|
+
continue;
|
|
82
|
+
// surrogates (codepoint 需要用两个 utf-16 编码单位表示,因此这里跳过第二个编码单位,防止重复计算显示宽度)
|
|
83
|
+
if (code > 0xFFFF)
|
|
84
|
+
i++;
|
|
85
|
+
const w = is_codepoint_fullwidth(code) ? 2 : 1;
|
|
86
|
+
if (cur_width + w + 2 <= width) {
|
|
87
|
+
i_fitted = i;
|
|
88
|
+
fitted_width += w;
|
|
89
|
+
}
|
|
90
|
+
cur_width += w;
|
|
91
|
+
if (cur_width > width) {
|
|
92
|
+
const i_fitted_next = i_fitted + 1;
|
|
93
|
+
const t = this.slice(0, i_fitted_next) + ' '.repeat(width - 2 - fitted_width) + '…';
|
|
94
|
+
return color_bak ? color_bak + t + '\u001b[39m' : t;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return this;
|
|
98
|
+
},
|
|
99
|
+
pad(width, { character = ' ', position = 'right' } = {}) {
|
|
100
|
+
const _width = this.width;
|
|
101
|
+
if (_width >= width)
|
|
102
|
+
return this;
|
|
103
|
+
if (position === 'right')
|
|
104
|
+
return this + character.repeat((width - _width) / character.width);
|
|
105
|
+
return character.repeat(width - _width) + this;
|
|
106
|
+
},
|
|
107
|
+
limit(width, { character = ' ', position = 'right' } = {}) {
|
|
108
|
+
return this.pad(width, { character, position }).truncate(width);
|
|
109
|
+
},
|
|
110
|
+
to_regx(preservations, flags = '') {
|
|
111
|
+
const preserved_chars = new Set(preservations);
|
|
112
|
+
const replace_chars = Array.prototype.filter.call('|\\{}()[]^$+*?.-', (c) => !preserved_chars.has(c))
|
|
113
|
+
.map((c) => c === ']' ? '\\]' : c).join('');
|
|
114
|
+
return new RegExp(this.replace(new RegExp(`[${replace_chars}]`, 'g'), '\\$&'), flags);
|
|
115
|
+
},
|
|
116
|
+
refmt(pattern, pattern_, preservations = '', flags = '', transformer = (name, value) => value || '', pattern_placeholder = /\{.*?\}/g) {
|
|
117
|
+
// --- 转换 pattern 为 pattern_regx
|
|
118
|
+
let last_end = 0;
|
|
119
|
+
// placeholder matched group indexes
|
|
120
|
+
let $placeholders = {};
|
|
121
|
+
let regx_parts = [];
|
|
122
|
+
function add_part(left, right) {
|
|
123
|
+
const part = pattern.slice(left, right);
|
|
124
|
+
if (part)
|
|
125
|
+
regx_parts.push(part.to_regx(preservations).source.bracket());
|
|
126
|
+
}
|
|
127
|
+
pattern.replace(pattern_placeholder, ($0, offset) => {
|
|
128
|
+
add_part(last_end, offset);
|
|
129
|
+
last_end = offset + $0.length;
|
|
130
|
+
const placeholder = $0.slice(1, -1);
|
|
131
|
+
let [placeholder_name, placeholder_pattern] = placeholder.split(':').map(s => s.trim());
|
|
132
|
+
let optional = false;
|
|
133
|
+
if (placeholder_name.endsWith('?')) {
|
|
134
|
+
placeholder_name = placeholder_name.slice(0, -1);
|
|
135
|
+
optional = true;
|
|
136
|
+
}
|
|
137
|
+
$placeholders[placeholder_name] = regx_parts.push(placeholder_pattern ?
|
|
138
|
+
`${placeholder_pattern.bracket()}${optional ? '?' : ''}`
|
|
139
|
+
:
|
|
140
|
+
'(.*?)');
|
|
141
|
+
return '';
|
|
142
|
+
});
|
|
143
|
+
add_part(last_end);
|
|
144
|
+
// 最后一个 (.*?) 改为贪心匹配,满足 .{suffix} 的需要
|
|
145
|
+
regx_parts = regx_parts.filter(part => part);
|
|
146
|
+
if (regx_parts.last === '(.*?)')
|
|
147
|
+
regx_parts[regx_parts.length - 1] = '(.*)';
|
|
148
|
+
const pattern_regx = new RegExp(regx_parts.join(''), flags);
|
|
149
|
+
// --- 根据 pattern_regx 去匹配原有字符串,获取匹配结果,生成 placeholders 词典
|
|
150
|
+
const matches = pattern_regx.exec(this);
|
|
151
|
+
if (!matches)
|
|
152
|
+
return this;
|
|
153
|
+
const placeholders = Object.fromEntries(Object.entries($placeholders)
|
|
154
|
+
.map(([name, $i]) => [
|
|
155
|
+
[name, matches[$i]],
|
|
156
|
+
[`${name}.before`, matches[$i - 1] || ''],
|
|
157
|
+
[`${name}.after`, matches[$i + 1] || ''],
|
|
158
|
+
])
|
|
159
|
+
.flat());
|
|
160
|
+
// --- 转换 pattern_ 为 replacement_str,如果有 transformer 则在遇到 placeholder 时应用
|
|
161
|
+
last_end = 0;
|
|
162
|
+
let replacement_parts = [];
|
|
163
|
+
pattern_.replace(pattern_placeholder, ($0, offset) => {
|
|
164
|
+
replacement_parts.push(pattern_.slice(last_end, offset));
|
|
165
|
+
last_end = offset + $0.length;
|
|
166
|
+
const placeholder_name = $0.slice(1, -1);
|
|
167
|
+
replacement_parts.push(transformer(placeholder_name, placeholders[placeholder_name], placeholders));
|
|
168
|
+
return '';
|
|
169
|
+
});
|
|
170
|
+
replacement_parts.push(pattern_.slice(last_end));
|
|
171
|
+
return this.replace(pattern_regx, replacement_parts.join(''));
|
|
172
|
+
},
|
|
173
|
+
find(pattern, preservations = '', flags = '', pattern_placeholder = /\{.*?\}/g) {
|
|
174
|
+
// --- 转换 pattern 为 pattern_regx
|
|
175
|
+
let last_end = 0;
|
|
176
|
+
// placeholder matched group index
|
|
177
|
+
let $placeholders = {};
|
|
178
|
+
let regx_parts = [];
|
|
179
|
+
function add_part(left, right) {
|
|
180
|
+
const part = pattern.slice(left, right);
|
|
181
|
+
if (part)
|
|
182
|
+
regx_parts.push(part.to_regx(preservations).source.bracket());
|
|
183
|
+
}
|
|
184
|
+
pattern.replace(pattern_placeholder, ($0, offset) => {
|
|
185
|
+
add_part(last_end, offset);
|
|
186
|
+
last_end = offset + $0.length;
|
|
187
|
+
const placeholder = $0.slice(1, -1);
|
|
188
|
+
let [placeholder_name, placeholder_pattern] = placeholder.split(':').map(s => s.trim());
|
|
189
|
+
let optional = false;
|
|
190
|
+
if (placeholder_name.endsWith('?')) {
|
|
191
|
+
placeholder_name = placeholder_name.slice(0, -1);
|
|
192
|
+
optional = true;
|
|
193
|
+
}
|
|
194
|
+
$placeholders[placeholder_name] = regx_parts.push(placeholder_pattern ?
|
|
195
|
+
`${placeholder_pattern.bracket()}${optional ? '?' : ''}`
|
|
196
|
+
:
|
|
197
|
+
'(.*?)');
|
|
198
|
+
return '';
|
|
199
|
+
});
|
|
200
|
+
add_part(last_end);
|
|
201
|
+
// 最后一个 (.*?) 改为贪心匹配,满足 .{suffix} 的需要
|
|
202
|
+
regx_parts = regx_parts.filter(part => part);
|
|
203
|
+
if (regx_parts[regx_parts.length - 1] === '(.*?)')
|
|
204
|
+
regx_parts[regx_parts.length - 1] = '(.*)';
|
|
205
|
+
const pattern_regx = new RegExp(regx_parts.join(''), flags);
|
|
206
|
+
// --- 根据 pattern_regx 去匹配原有字符串,获取匹配结果,生成 placeholders 词典
|
|
207
|
+
const matches = pattern_regx.exec(this);
|
|
208
|
+
if (!matches)
|
|
209
|
+
return {};
|
|
210
|
+
return Object.fromEntries(Object.entries($placeholders)
|
|
211
|
+
.map(([name, $i]) => [name, matches[$i] || '']));
|
|
212
|
+
},
|
|
213
|
+
quote(type = 'single') {
|
|
214
|
+
if (type === 'psh')
|
|
215
|
+
return '& ' + this.quote();
|
|
216
|
+
return this.surround(exports.quotes[type]);
|
|
217
|
+
},
|
|
218
|
+
bracket(shape = 'round') {
|
|
219
|
+
return this.surround(...exports.brackets[shape]);
|
|
220
|
+
},
|
|
221
|
+
surround(left, right) {
|
|
222
|
+
return left + this + (right || left);
|
|
223
|
+
},
|
|
224
|
+
surround_tag(tag_name) {
|
|
225
|
+
return '<' + tag_name + '>' + this + '</' + tag_name + '>';
|
|
226
|
+
},
|
|
227
|
+
to_lf() {
|
|
228
|
+
return this.replace(/\r\n/g, '\n');
|
|
229
|
+
},
|
|
230
|
+
to_crlf() {
|
|
231
|
+
return this.replace(/\n/g, '\r\n');
|
|
232
|
+
},
|
|
233
|
+
rm(pattern, flags = 'g') {
|
|
234
|
+
if (typeof pattern === 'string')
|
|
235
|
+
pattern = new RegExp(pattern, flags);
|
|
236
|
+
return this.replace(pattern, '');
|
|
237
|
+
},
|
|
238
|
+
split_lines(delimiter = /\r?\n/) {
|
|
239
|
+
let lines = this.split(delimiter);
|
|
240
|
+
if (lines.last === '')
|
|
241
|
+
lines.pop();
|
|
242
|
+
return lines;
|
|
243
|
+
},
|
|
244
|
+
split_indent() {
|
|
245
|
+
let i = 0;
|
|
246
|
+
let indent = 0;
|
|
247
|
+
for (; i < this.length; i++)
|
|
248
|
+
if (this[i] === ' ')
|
|
249
|
+
indent += 1;
|
|
250
|
+
else if (this[i] === '\t')
|
|
251
|
+
indent += 4;
|
|
252
|
+
else
|
|
253
|
+
break;
|
|
254
|
+
return {
|
|
255
|
+
indent,
|
|
256
|
+
text: this.slice(i)
|
|
257
|
+
};
|
|
258
|
+
},
|
|
259
|
+
space() {
|
|
260
|
+
if (!this)
|
|
261
|
+
return this;
|
|
262
|
+
let text_;
|
|
263
|
+
text_ = this
|
|
264
|
+
.replace(new RegExp(exports.cjk + `(['"])`, 'g'), '$1 $2')
|
|
265
|
+
.replace(new RegExp(`(['"])` + exports.cjk, 'g'), '$1 $2')
|
|
266
|
+
.replace(/(["']+)\s*(.+?)\s*(["']+)/g, '$1$2$3')
|
|
267
|
+
.replace(new RegExp(exports.cjk + '([\\+\\-\\*\\/=&\\\\\\|<>])([A-Za-z0-9])', 'g'), '$1 $2 $3')
|
|
268
|
+
.replace(new RegExp('([A-Za-z0-9])([\\+\\-\\*\\/=&\\\\\\|<>])' + exports.cjk, 'g'), '$1 $2 $3');
|
|
269
|
+
const textBak = text_;
|
|
270
|
+
text_ = text_.replace(new RegExp(exports.cjk + '([\\(\\[\\{<\u201c]+(.*?)[\\)\\]\\}>\u201d]+)' + exports.cjk, 'g'), '$1 $2 $4');
|
|
271
|
+
if (text_ === textBak)
|
|
272
|
+
text_ = text_
|
|
273
|
+
.replace(new RegExp(exports.cjk + '([\\(\\[\\{<\u201c>])', 'g'), '$1 $2')
|
|
274
|
+
.replace(new RegExp('([\\)\\]\\}>\u201d<])' + exports.cjk, 'g'), '$1 $2');
|
|
275
|
+
return text_
|
|
276
|
+
// eslint-disable-next-line no-useless-escape
|
|
277
|
+
.replace(/([\(\[\{<\u201c]+)(\s*)(.+?)(\s*)([\)\]\}>\u201d]+)/g, '$1$3$5')
|
|
278
|
+
.replace(new RegExp(exports.cjk + '([~!;:,\\.\\?\u2026])([A-Za-z0-9])', 'g'), '$1$2 $3')
|
|
279
|
+
.replace(new RegExp(exports.cjk + '([A-Za-z0-9`\\$%\\^&\\*\\-=\\+\\\\\\|\\/@\u00a1-\u00ff\u2022\u2027\u2150-\u218f])', 'g'), '$1 $2')
|
|
280
|
+
.replace(new RegExp('([A-Za-z0-9`\\$%\\^&\\*\\-=\\+\\\\\\|\\/@\u00a1-\u00ff\u2022\u2027\u2150-\u218f])' + exports.cjk, 'g'), '$1 $2');
|
|
281
|
+
},
|
|
282
|
+
to_slash() {
|
|
283
|
+
return this.replaceAll('\\', '/');
|
|
284
|
+
},
|
|
285
|
+
to_backslash() {
|
|
286
|
+
return this.replaceAll('/', '\\');
|
|
287
|
+
},
|
|
288
|
+
}),
|
|
289
|
+
});
|
|
290
|
+
// ------------------------------------ Date.prototype
|
|
291
|
+
Object.defineProperties(Date.prototype, to_method_property_descriptors({
|
|
292
|
+
to_str() {
|
|
293
|
+
return this.toLocaleString().replace(/(\d+)\/(\d+)\/(\d+) ?(上午|下午)(\d+):(\d{2}):(\d{2}).*/, (matches, year, month, day, ampm, hour, minute, second) => {
|
|
294
|
+
hour = Number(hour);
|
|
295
|
+
if (ampm === '上午' && hour === 12) {
|
|
296
|
+
hour = 0;
|
|
297
|
+
ampm = '凌晨';
|
|
298
|
+
}
|
|
299
|
+
else if (ampm === '上午' && hour <= 6)
|
|
300
|
+
ampm = '凌晨';
|
|
301
|
+
else if (ampm === '上午' && hour <= 8)
|
|
302
|
+
ampm = '早上';
|
|
303
|
+
else if (ampm === '上午' && hour <= 10)
|
|
304
|
+
ampm = '上午';
|
|
305
|
+
else if (ampm === '上午' && hour <= 11)
|
|
306
|
+
ampm = '中午';
|
|
307
|
+
else if (ampm === '下午' && hour === 12)
|
|
308
|
+
ampm = '中午';
|
|
309
|
+
else if (ampm === '下午' && hour <= 5)
|
|
310
|
+
ampm = '下午';
|
|
311
|
+
else
|
|
312
|
+
ampm = '晚上';
|
|
313
|
+
return year + '.' + month.pad(2, { character: '0', position: 'left' }) + '.' + day.pad(2, { character: '0', position: 'left' }) + ' ' +
|
|
314
|
+
ampm + ' ' + hour.toString().pad(2, { character: '0', position: 'left' }) + ':' + minute + ':' + second;
|
|
315
|
+
});
|
|
316
|
+
},
|
|
317
|
+
to_date_str() {
|
|
318
|
+
return this.to_str().split(' ')[0];
|
|
319
|
+
},
|
|
320
|
+
to_time_str() {
|
|
321
|
+
const [, ampm, time] = this.to_str().split(' ');
|
|
322
|
+
return ampm + ' ' + time;
|
|
323
|
+
},
|
|
324
|
+
}));
|
|
325
|
+
// ------------------------------------ Number.prototype
|
|
326
|
+
Object.defineProperties(Number.prototype, to_method_property_descriptors({
|
|
327
|
+
to_bin_str() {
|
|
328
|
+
return `0b${this.toString(2)}`;
|
|
329
|
+
},
|
|
330
|
+
to_hex_str(length) {
|
|
331
|
+
const s = this.toString(16);
|
|
332
|
+
// 长度自动对齐到 4 的倍数
|
|
333
|
+
if (!length)
|
|
334
|
+
length = Math.ceil(s.length / 4) * 4;
|
|
335
|
+
return `0x${'0'.repeat(length - s.length)}${s}`;
|
|
336
|
+
},
|
|
337
|
+
to_oct_str() {
|
|
338
|
+
return `0o${this.toString(8)}`;
|
|
339
|
+
},
|
|
340
|
+
}));
|
|
341
|
+
// ------------------------------------ Array.prototype
|
|
342
|
+
Object.defineProperties(Array.prototype, {
|
|
343
|
+
// --- 文本处理工具方法
|
|
344
|
+
...to_method_property_descriptors({
|
|
345
|
+
trim_lines({ trim_line = true, rm_empty_lines = true, rm_last_empty_lines = false } = {}) {
|
|
346
|
+
if (!this.length)
|
|
347
|
+
return this;
|
|
348
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
349
|
+
let lines = this;
|
|
350
|
+
if (trim_line)
|
|
351
|
+
lines = lines.map(line => line.trim());
|
|
352
|
+
if (rm_empty_lines)
|
|
353
|
+
return lines.filter(line => line);
|
|
354
|
+
if (rm_last_empty_lines) {
|
|
355
|
+
lines.reverse();
|
|
356
|
+
const i_not_empty = lines.findIndex(line => line);
|
|
357
|
+
if (i_not_empty !== -1)
|
|
358
|
+
lines = lines.slice(i_not_empty);
|
|
359
|
+
lines.reverse();
|
|
360
|
+
return lines;
|
|
361
|
+
}
|
|
362
|
+
return lines;
|
|
363
|
+
},
|
|
364
|
+
indent(width, character = ' ') {
|
|
365
|
+
return this.map(line => character.repeat(width) + line);
|
|
366
|
+
},
|
|
367
|
+
join_lines(append = true) {
|
|
368
|
+
return `${this.join('\n')}${append ? '\n' : ''}`;
|
|
369
|
+
}
|
|
370
|
+
})
|
|
371
|
+
});
|
|
372
|
+
function to_json(object, replacer) {
|
|
373
|
+
return JSON.stringify(object, replacer, 4);
|
|
374
|
+
}
|
|
375
|
+
exports.to_json = to_json;
|
|
376
|
+
function is_codepoint_fullwidth(codepoint) {
|
|
377
|
+
// Code points are derived from:
|
|
378
|
+
// http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
|
|
379
|
+
return (!Number.isNaN(codepoint) &&
|
|
380
|
+
codepoint >= 0x1100 &&
|
|
381
|
+
(codepoint <= 0x115F || // Hangul Jamo
|
|
382
|
+
codepoint === 0x2026 || // …
|
|
383
|
+
codepoint === 0x203B || // ※
|
|
384
|
+
// arrows
|
|
385
|
+
(0x2190 <= codepoint && codepoint <= 0x21ff) ||
|
|
386
|
+
codepoint === 0x2329 || // left-pointing angle bracket
|
|
387
|
+
codepoint === 0x232a || // right-pointing angle bracket
|
|
388
|
+
// ①
|
|
389
|
+
(0x2460 <= codepoint && codepoint <= 0x24ff) ||
|
|
390
|
+
// box drawing
|
|
391
|
+
(0x2500 <= codepoint && codepoint <= 0x257f) ||
|
|
392
|
+
// shapes, symbols, …
|
|
393
|
+
(0x2580 <= codepoint && codepoint <= 0x2bef) ||
|
|
394
|
+
// cjk radicals supplement .. enclosed cjk letters and months
|
|
395
|
+
(0x2e80 <= codepoint && codepoint <= 0x3247 && codepoint !== 0x303f) ||
|
|
396
|
+
// enclosed cjk letters and months .. cjk unified ideographs extension a
|
|
397
|
+
(0x3250 <= codepoint && codepoint <= 0x4dbf) ||
|
|
398
|
+
// cjk unified ideographs .. yi radicals
|
|
399
|
+
(0x4e00 <= codepoint && codepoint <= 0xa4c6) ||
|
|
400
|
+
// hangul jamo extended-a
|
|
401
|
+
(0xa960 <= codepoint && codepoint <= 0xa97c) ||
|
|
402
|
+
// hangul syllables
|
|
403
|
+
(0xac00 <= codepoint && codepoint <= 0xd7a3) ||
|
|
404
|
+
// cjk compatibility ideographs
|
|
405
|
+
(0xf900 <= codepoint && codepoint <= 0xfaff) ||
|
|
406
|
+
// vertical forms
|
|
407
|
+
(0xfe10 <= codepoint && codepoint <= 0xfe19) ||
|
|
408
|
+
// cjk compatibility forms .. small form variants
|
|
409
|
+
(0xfe30 <= codepoint && codepoint <= 0xfe6b) ||
|
|
410
|
+
// halfwidth and fullwidth forms
|
|
411
|
+
(0xff01 <= codepoint && codepoint <= 0xff60) ||
|
|
412
|
+
(0xffe0 <= codepoint && codepoint <= 0xffe6) ||
|
|
413
|
+
// kana supplement
|
|
414
|
+
(0x1b000 <= codepoint && codepoint <= 0x1b001) ||
|
|
415
|
+
// enclosed ideographic supplement
|
|
416
|
+
(0x1f200 <= codepoint && codepoint <= 0x1f251) ||
|
|
417
|
+
// cjk unified ideographs extension b .. tertiary ideographic plane
|
|
418
|
+
(0x20000 <= codepoint && codepoint <= 0x3fffd)));
|
|
419
|
+
}
|
|
420
|
+
exports.is_codepoint_fullwidth = is_codepoint_fullwidth;
|
|
421
|
+
//# sourceMappingURL=prototype.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prototype.browser.js","sourceRoot":"","sources":["prototype.browser.ts"],"names":[],"mappings":";AAAA,+BAA+B;;;;AAqJ/B,2EAAoC;AAEvB,QAAA,WAAW,GAAG,IAAA,qBAAU,GAAE,CAAA;AAGvC,SAAgB,8BAA8B,CAAE,OAAqC;IACjF,OAAO,MAAM,CAAC,WAAW,CACrB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SAClB,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;YAC5B,YAAY,EAAE,IAAI;YAClB,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,KAAK;YACjB,KAAK;SACc,CAAC,CAAC,CAC5B,CAAC,CAAA;AACV,CAAC;AAVD,wEAUC;AAGD,SAAgB,8BAA8B,CAAE,OAAqC;IACjF,OAAO,MAAM,CAAC,WAAW,CACrB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SAClB,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;YAC1B,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,KAAK;YACjB,GAAG;SACgB,CAAC,CAAC,CAC5B,CAAC,CAAA;AACV,CAAC;AATD,wEASC;AAGY,QAAA,GAAG,GAAG,gCAAgC,CAAA;AAEtC,QAAA,MAAM,GAAG;IAClB,MAAM,EAAI,GAAG;IACb,MAAM,EAAI,GAAG;IACb,QAAQ,EAAE,GAAG;CAChB,CAAA;AAEY,QAAA,QAAQ,GAAG;IACpB,KAAK,EAAG,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,KAAK,EAAG,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,MAAM,EAAE,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AM,CAAC;YAE5C,mBAAmB;YACnB,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,+BAA+B;YAC/B,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,iBAAiB;YACjB,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,iDAAiD;YACjD,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,gCAAgC;YAChC,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAC5C,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,kBAAkB;YAClB,CAAC,OAAO,IAAI,SAAS,IAAI,SAAS,IAAI,OAAO,CAAC;YAE9C,kCAAkC;YAClC,CAAC,OAAO,IAAI,SAAS,IAAI,SAAS,IAAI,OAAO,CAAC;YAE9C,mEAAmE;YACnE,CAAC,OAAO,IAAI,SAAS,IAAI,SAAS,IAAI,OAAO,CAAC,CACjD,CACJ,CAAA;AACL,CAAC;AAjED,wDAiEC","sourcesContent":["/** 在浏览器端修改 prototype,需要更加小心 */\n\ndeclare global {\n interface String {\n readonly width: number\n \n // --- 工具方法\n /** 截取字符串不超过 width 显示宽度的部分,并保留颜色 \n 找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted \n 若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + … \n 否则 返回 this \n */\n truncate (this: string, width: number): string\n \n pad (this: string, width: number, { character, position }?: { character?: string, position?: 'left' | 'right'}): string\n \n limit (this: string, width: number, { character, position }?: { character?: string, position?: 'left' | 'right'}): string\n \n to_regx (this: string, preservations?: string, flags?: string): RegExp\n \n /** ```ts\n 'g:/acgn/海贼王/[Skytree][海贼王][One_Piece][893][GB_BIG5_JP][X264_AAC][1080P][CRRIP][天空树双语字幕组].mkv'.refmt( \n '{dirp}/[Skytree][海贼王][{ en_name: \\\\w+ }][{ episode: \\\\d+ }][GB_BIG5_JP][{encoding}_AAC][1080P][CRRIP][天空树双语字幕组].{format}', \n 'g:/acgn/海贼王/{episode} {encoding}.{format}', \n '\\\\+', \n 'i', \n (name, value) => name === 'episode' ? String(+value + 1) : value.toLowerCase() \n )\n ```\n */\n refmt ( this: string,\n pattern: string,\n \n pattern_: string,\n \n /** `''` 保留的正则表达式字符 */\n preservations?: string,\n \n /** `''` 正则匹配选项 */\n flags?: string,\n \n /** `(name, matched) => matched || ''` placeholder transformer */\n transformer?: (name: string, value: string, placeholders: { [name: string]: string }) => string,\n \n /** `/\\{.*?\\}/g` */\n pattern_placeholder?: RegExp\n \n ): string\n \n \n /** 字符串模式搜索\n ```ts\n 'git+https://github.com/tamino-martinius/node-ts-dedent-123.git'.find(\n '^{protocol:[\\\\w+]+}://{hostname:[\\\\w\\\\.]+}/{username}/{project}-{index:\\\\d+}.{suffix}', '^', 'i'\n )\n {\n protocol: 'git+https',\n hostname: 'github.com',\n ...\n }\n ```\n \n - preservations?: `''` 保留的正则表达式字符\n - flags?: `''` 正则匹配选项\n - pattern_placeholder?: `/\\{.*?\\}/g`\n */\n find (this: string,\n \n pattern: string, \n \n preservations?: string, \n \n flags?: string, \n \n pattern_placeholder?: RegExp\n \n ): { [name: string]: string }\n \n \n /** - type?: `'single'` */\n quote (this: string, type?: keyof typeof quotes | 'psh'): string\n \n /** - shape?: `'parenthesis'` */\n bracket (this: string, shape?: keyof typeof brackets): string\n \n surround (this: string, left: string, right?: string): string\n \n surround_tag (this: string, tag_name: string): string\n \n to_lf (this: string): string\n \n to_crlf (this: string): string\n \n /** 'xxx'.replace(/pattern/g, '') \n 如果 pattern 是 string 则在创建 RegExp 时自动加上 flags (默认 'g'), 否则忽略 flags\n */\n rm (this: string, pattern: string | RegExp, flags?: string): string\n \n \n // --- 文本处理\n split_lines (this: string): string[]\n \n trim_doc_comment (this: string): string\n \n split_indent (this: string): { indent: number, text: string }\n \n \n space (this: string): string\n \n to_slash (this: string): string\n \n to_backslash (this: string): string\n }\n \n \n interface Date {\n to_str (this: Date): string\n \n to_date_str (this: Date): string\n \n to_time_str (this: Date): string\n }\n \n \n interface Number {\n to_bin_str (this: number): string\n \n to_hex_str (this: number): string\n \n to_oct_str (this: number): string\n }\n \n \n interface Array<T> {\n indent (this: string[], width: number, c?: string): string[]\n \n // --- 文本处理\n /**\n - trim_line?: `true`\n - rm_empty_lines?: `true`\n - rm_last_empty_lines?: `false`\n */\n trim_lines (this: string[], { trim_line, rm_empty_lines, rm_last_empty_lines }?: { trim_line?: boolean, rm_empty_lines?: boolean, rm_last_empty_lines?: boolean }): string[]\n \n join_lines (): string\n }\n}\n\n\nimport EmojiRegex from 'emoji-regex'\n\nexport const emoji_regex = EmojiRegex()\n\n\nexport function to_method_property_descriptors (methods: { [name: string]: Function }): PropertyDescriptorMap {\n return Object.fromEntries(\n Object.entries(methods)\n .map(([name, value]) => ([name, {\n configurable: true,\n writable: true,\n enumerable: false,\n value,\n } as PropertyDescriptor])\n ))\n}\n\n\nexport function to_getter_property_descriptors (getters: { [name: string]: Function }): PropertyDescriptorMap {\n return Object.fromEntries(\n Object.entries(getters)\n .map(([name, get]) => ([name, {\n configurable: true,\n enumerable: false,\n get,\n } as PropertyDescriptor])\n ))\n}\n\n\nexport const cjk = '([\\u2e80-\\u9fff\\uf900-\\ufaff])'\n\nexport const quotes = {\n single: \"'\",\n double: '\"',\n backtick: '`',\n}\n\nexport const brackets = {\n round: ['(', ')'],\n square: ['[', ']'],\n curly: ['{', '}'],\n pointy: ['<', '>'],\n corner: ['「', '」'],\n fat: ['【', '】'],\n tortoise_shell: ['〔', '〕'],\n} as const\n\n\n\n// ------------------------------------ String.prototype\nObject.defineProperties(String.prototype, {\n ... to_getter_property_descriptors({\n width (this: string) {\n const s = this.replace(emoji_regex, ' ')\n let width = 0\n for (let i = 0; i < s.length; i++) {\n const code = s.codePointAt(i)\n \n if (\n (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) || // ignore control characters\n code >= 0x300 && code <= 0x36f // ignore combining characters\n ) continue\n \n // surrogates\n if (code > 0xFFFF)\n i++\n \n width += is_codepoint_fullwidth(code) ? 2 : 1\n }\n return width\n }\n }),\n \n \n \n // ------------ 文本处理工具方法\n ... to_method_property_descriptors({\n /** 截取字符串不超过 width 显示宽度的部分,并保留颜色 \n 找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted \n - 若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + … \n - 否则 返回 this \n */\n truncate (this: string, width: number) {\n const color_bak = this.startsWith('\\u001b') ? this.slice(0, 5) : ''\n if (width <= 2) return this.slice(0, width)\n let i_fitted = 0\n let fitted_width = 0\n let cur_width = 0\n for (let i = 0; i < this.length; i++) {\n const code = this.codePointAt(i)\n \n if (\n (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) || // Ignore control characters\n code >= 0x300 && code <= 0x36F // Ignore combining characters\n ) continue\n \n // surrogates (codepoint 需要用两个 utf-16 编码单位表示,因此这里跳过第二个编码单位,防止重复计算显示宽度)\n if (code > 0xFFFF)\n i++\n \n const w = is_codepoint_fullwidth(code) ? 2 : 1\n \n if (cur_width + w + 2 <= width) {\n i_fitted = i\n fitted_width += w\n }\n \n cur_width += w\n \n if (cur_width > width) {\n const i_fitted_next = i_fitted + 1\n const t = this.slice(0, i_fitted_next) + ' '.repeat(width - 2 - fitted_width) + '…' \n return color_bak ? color_bak + t + '\\u001b[39m' : t\n }\n }\n return this\n },\n \n \n pad (this: string, width: number, { character = ' ', position = 'right' }: { character?: string, position?: 'left' | 'right'} = { }) {\n const _width = this.width\n if (_width >= width) return this\n if (position === 'right') return this + character.repeat( (width - _width) / character.width )\n return character.repeat(width - _width) + this\n },\n \n \n limit (this: string, width: number, { character = ' ', position = 'right' }: { character?: string, position?: 'left' | 'right'} = { }) {\n return this.pad(width, { character, position }).truncate(width)\n },\n \n \n to_regx (this: string, preservations: string, flags = ''): RegExp {\n const preserved_chars = new Set(preservations)\n const replace_chars: string = Array.prototype.filter.call('|\\\\{}()[]^$+*?.-', (c: string) => !preserved_chars.has(c))\n .map((c: string) =>\n c === ']' ? '\\\\]' : c\n ).join('')\n \n return new RegExp( this.replace(new RegExp(`[${replace_chars}]`, 'g'), '\\\\$&'), flags)\n },\n \n \n refmt (this: string, \n pattern : string,\n pattern_: string,\n preservations: string = '',\n flags = '',\n transformer: (name: string, value: string, placeholders: { [name: string]: string }) => string = (name, value) => value || '',\n pattern_placeholder = /\\{.*?\\}/g,\n ): string {\n // --- 转换 pattern 为 pattern_regx\n let last_end = 0\n \n // placeholder matched group indexes\n let $placeholders: Record<string, number> = { }\n \n let regx_parts = [ ]\n \n function add_part (left: number, right?: number) {\n const part = pattern.slice(left, right)\n if (part)\n regx_parts.push(\n part.to_regx(preservations).source.bracket()\n )\n }\n \n pattern.replace(pattern_placeholder, ($0, offset) => {\n add_part(last_end, offset)\n last_end = offset + $0.length\n \n const placeholder = $0.slice(1, -1)\n let [placeholder_name, placeholder_pattern] = placeholder.split(':').map(s => s.trim())\n let optional = false\n if (placeholder_name.endsWith('?')) {\n placeholder_name = placeholder_name.slice(0, -1)\n optional = true\n }\n $placeholders[placeholder_name] = regx_parts.push(placeholder_pattern ? \n `${placeholder_pattern.bracket()}${optional ? '?' : ''}`\n :\n '(.*?)'\n )\n return ''\n })\n \n add_part(last_end)\n \n // 最后一个 (.*?) 改为贪心匹配,满足 .{suffix} 的需要\n regx_parts = regx_parts.filter(part => part)\n if (regx_parts.last === '(.*?)')\n regx_parts[regx_parts.length - 1] = '(.*)'\n \n const pattern_regx = new RegExp(regx_parts.join(''), flags)\n \n \n // --- 根据 pattern_regx 去匹配原有字符串,获取匹配结果,生成 placeholders 词典\n const matches = pattern_regx.exec(this)\n \n if (!matches) return this\n \n const placeholders = Object.fromEntries(\n Object.entries($placeholders)\n .map(([name, $i]) => [\n [name, matches[$i]],\n [`${name}.before`, matches[$i - 1] || ''],\n [`${name}.after`, matches[$i + 1] || ''],\n ])\n .flat()\n )\n \n \n // --- 转换 pattern_ 为 replacement_str,如果有 transformer 则在遇到 placeholder 时应用\n last_end = 0\n let replacement_parts = [ ]\n \n pattern_.replace(pattern_placeholder, ($0, offset) => {\n replacement_parts.push(\n pattern_.slice(last_end, offset)\n )\n last_end = offset + $0.length\n \n const placeholder_name = $0.slice(1, -1)\n \n replacement_parts.push(\n transformer(placeholder_name, placeholders[placeholder_name], placeholders)\n )\n \n return ''\n })\n replacement_parts.push(\n pattern_.slice(last_end)\n )\n \n return this.replace(pattern_regx, replacement_parts.join(''))\n },\n \n \n find (this: string,\n pattern: string, \n preservations: string = '', \n flags = '', \n pattern_placeholder = /\\{.*?\\}/g\n ): { [name: string]: string } {\n // --- 转换 pattern 为 pattern_regx\n let last_end = 0\n \n // placeholder matched group index\n let $placeholders: Record<string, number> = { }\n \n let regx_parts = [ ]\n \n function add_part (left: number, right?: number) {\n const part = pattern.slice(left, right)\n if (part)\n regx_parts.push(\n part.to_regx(preservations).source.bracket()\n )\n }\n \n pattern.replace(pattern_placeholder, ($0, offset) => {\n add_part(last_end, offset)\n last_end = offset + $0.length\n \n const placeholder = $0.slice(1, -1)\n let [placeholder_name, placeholder_pattern] = placeholder.split(':').map(s => s.trim())\n let optional = false\n if (placeholder_name.endsWith('?')) {\n placeholder_name = placeholder_name.slice(0, -1)\n optional = true\n }\n \n $placeholders[placeholder_name] = regx_parts.push(\n placeholder_pattern ? \n `${placeholder_pattern.bracket()}${optional ? '?' : ''}`\n :\n '(.*?)'\n )\n return ''\n })\n \n add_part(last_end)\n \n // 最后一个 (.*?) 改为贪心匹配,满足 .{suffix} 的需要\n regx_parts = regx_parts.filter(part => part)\n if (regx_parts[ regx_parts.length - 1 ] === '(.*?)')\n regx_parts[regx_parts.length - 1] = '(.*)'\n \n const pattern_regx = new RegExp(regx_parts.join(''), flags)\n \n \n // --- 根据 pattern_regx 去匹配原有字符串,获取匹配结果,生成 placeholders 词典\n const matches = pattern_regx.exec(this)\n \n if (!matches) return { }\n \n return Object.fromEntries(\n Object.entries($placeholders)\n .map(([name, $i]) => \n [name, matches[$i] || '']\n )\n )\n },\n \n quote (this: string, type: keyof typeof quotes | 'psh' = 'single') {\n if (type === 'psh') return '& ' + this.quote()\n return this.surround(quotes[type])\n },\n \n \n bracket (this: string, shape: keyof typeof brackets = 'round') {\n return this.surround(...brackets[shape] as [string, string])\n },\n \n \n surround (this: string, left: string, right?: string) {\n return left + this + (right || left)\n },\n \n surround_tag (this: string, tag_name: string): string {\n return '<' + tag_name + '>' + this + '</' + tag_name + '>'\n },\n \n \n to_lf (this: string) {\n return this.replace(/\\r\\n/g, '\\n')\n },\n \n \n to_crlf (this: string) {\n return this.replace(/\\n/g, '\\r\\n')\n },\n \n \n rm (this: string, pattern: string | RegExp, flags: string = 'g') {\n if (typeof pattern === 'string')\n pattern = new RegExp(pattern, flags)\n \n return this.replace(pattern, '')\n },\n \n \n split_lines (this: string, delimiter: string | RegExp = /\\r?\\n/) {\n let lines = this.split(delimiter)\n if (lines.last === '')\n lines.pop()\n return lines\n },\n \n \n split_indent (this: string): { indent: number, text: string } {\n let i = 0\n let indent = 0\n for (; i < this.length; i++)\n if (this[i] === ' ')\n indent += 1\n else if (this[i] === '\\t')\n indent += 4\n else\n break\n \n return {\n indent,\n text: this.slice(i)\n }\n },\n \n \n space (this: string) {\n if (!this) return this\n let text_: string\n text_ = this\n .replace(new RegExp(cjk + `(['\"])`, 'g'), '$1 $2')\n .replace(new RegExp(`(['\"])` + cjk, 'g'), '$1 $2')\n \n .replace(/([\"']+)\\s*(.+?)\\s*([\"']+)/g, '$1$2$3')\n \n .replace(new RegExp(cjk + '([\\\\+\\\\-\\\\*\\\\/=&\\\\\\\\\\\\|<>])([A-Za-z0-9])', 'g'), '$1 $2 $3')\n .replace(new RegExp('([A-Za-z0-9])([\\\\+\\\\-\\\\*\\\\/=&\\\\\\\\\\\\|<>])' + cjk, 'g'), '$1 $2 $3')\n \n const textBak = text_\n \n text_ = text_.replace(new RegExp(cjk + '([\\\\(\\\\[\\\\{<\\u201c]+(.*?)[\\\\)\\\\]\\\\}>\\u201d]+)' + cjk, 'g'), '$1 $2 $4')\n \n if (text_ === textBak)\n text_ = text_\n .replace(new RegExp(cjk + '([\\\\(\\\\[\\\\{<\\u201c>])', 'g'), '$1 $2')\n .replace(new RegExp('([\\\\)\\\\]\\\\}>\\u201d<])' + cjk, 'g'), '$1 $2')\n \n return text_\n // eslint-disable-next-line no-useless-escape\n .replace(/([\\(\\[\\{<\\u201c]+)(\\s*)(.+?)(\\s*)([\\)\\]\\}>\\u201d]+)/g, '$1$3$5')\n .replace(new RegExp(cjk + '([~!;:,\\\\.\\\\?\\u2026])([A-Za-z0-9])', 'g'), '$1$2 $3')\n .replace(new RegExp(cjk + '([A-Za-z0-9`\\\\$%\\\\^&\\\\*\\\\-=\\\\+\\\\\\\\\\\\|\\\\/@\\u00a1-\\u00ff\\u2022\\u2027\\u2150-\\u218f])', 'g'), '$1 $2')\n .replace(new RegExp('([A-Za-z0-9`\\\\$%\\\\^&\\\\*\\\\-=\\\\+\\\\\\\\\\\\|\\\\/@\\u00a1-\\u00ff\\u2022\\u2027\\u2150-\\u218f])' + cjk, 'g'), '$1 $2')\n },\n \n to_slash (this: string) {\n return this.replaceAll('\\\\', '/')\n },\n \n to_backslash (this: string) {\n return this.replaceAll('/', '\\\\')\n },\n }),\n})\n\n\n// ------------------------------------ Date.prototype\nObject.defineProperties(Date.prototype, to_method_property_descriptors({\n to_str (this: Date) {\n return this.toLocaleString().replace(/(\\d+)\\/(\\d+)\\/(\\d+) ?(上午|下午)(\\d+):(\\d{2}):(\\d{2}).*/, (matches, year, month, day, ampm, hour, minute, second) => {\n hour = Number(hour)\n if (ampm === '上午' && hour === 12) {\n hour = 0\n ampm = '凌晨'\n }\n else if (ampm === '上午' && hour <= 6) ampm = '凌晨'\n else if (ampm === '上午' && hour <= 8 ) ampm = '早上'\n else if (ampm === '上午' && hour <= 10) ampm = '上午'\n else if (ampm === '上午' && hour <= 11) ampm = '中午'\n else if (ampm === '下午' && hour === 12) ampm = '中午'\n else if (ampm === '下午' && hour <= 5 ) ampm = '下午'\n else ampm = '晚上'\n \n return year + '.' + month.pad(2, { character: '0', position: 'left' }) + '.' + day.pad(2, { character: '0', position: 'left' }) + ' ' + \n ampm + ' ' + hour.toString().pad(2, { character: '0', position: 'left' }) + ':' + minute + ':' + second\n })\n },\n \n to_date_str (this: Date) {\n return this.to_str().split(' ')[0]\n },\n \n to_time_str (this: Date) {\n const [, ampm, time ] = this.to_str().split(' ')\n return ampm + ' ' + time\n },\n}))\n\n\n\n// ------------------------------------ Number.prototype\nObject.defineProperties(Number.prototype, to_method_property_descriptors({\n to_bin_str (this: number) {\n return `0b${this.toString(2)}`\n },\n \n to_hex_str (this: number, length?: number) {\n const s = this.toString(16)\n // 长度自动对齐到 4 的倍数\n if (!length)\n length = Math.ceil(s.length / 4) * 4\n return `0x${'0'.repeat(length - s.length)}${s}`\n },\n \n to_oct_str (this: number) {\n return `0o${this.toString(8)}`\n },\n}))\n\n\n\n// ------------------------------------ Array.prototype\nObject.defineProperties(Array.prototype, {\n // --- 文本处理工具方法\n ... to_method_property_descriptors({\n trim_lines (this: string[], { trim_line = true, rm_empty_lines = true, rm_last_empty_lines = false }: { trim_line?: boolean, rm_empty_lines?: boolean, rm_last_empty_lines?: boolean } = { }) {\n if (!this.length) return this\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n let lines = this\n \n if (trim_line)\n lines = lines.map(line => line.trim())\n \n if (rm_empty_lines)\n return lines.filter( line => line )\n \n if (rm_last_empty_lines) {\n lines.reverse()\n const i_not_empty = lines.findIndex( line => line )\n if (i_not_empty !== -1)\n lines = lines.slice(i_not_empty)\n lines.reverse()\n return lines\n }\n \n return lines\n },\n \n \n indent (this: string[], width?: number, character: string = ' ') {\n return this.map(line => \n character.repeat(width) + line\n )\n },\n \n \n join_lines (this: string[], append = true) {\n return `${this.join('\\n')}${append ? '\\n' : ''}`\n }\n })\n})\n\n\nexport function to_json (object: any, replacer?: any) {\n return JSON.stringify(object, replacer, 4)\n}\n\nexport function is_codepoint_fullwidth (codepoint: number) {\n // Code points are derived from:\n // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt\n return (\n !Number.isNaN(codepoint) &&\n codepoint >= 0x1100 &&\n (\n codepoint <= 0x115F || // Hangul Jamo\n \n codepoint === 0x2026 || // …\n codepoint === 0x203B || // ※\n \n // arrows\n (0x2190 <= codepoint && codepoint <= 0x21ff) ||\n \n codepoint === 0x2329 || // left-pointing angle bracket\n codepoint === 0x232a || // right-pointing angle bracket\n \n // ①\n (0x2460 <= codepoint && codepoint <= 0x24ff) ||\n \n // box drawing\n (0x2500 <= codepoint && codepoint <= 0x257f) ||\n \n // shapes, symbols, …\n (0x2580 <= codepoint && codepoint <= 0x2bef) ||\n \n // cjk radicals supplement .. enclosed cjk letters and months\n (0x2e80 <= codepoint && codepoint <= 0x3247 && codepoint !== 0x303f) ||\n \n // enclosed cjk letters and months .. cjk unified ideographs extension a\n (0x3250 <= codepoint && codepoint <= 0x4dbf) ||\n \n // cjk unified ideographs .. yi radicals\n (0x4e00 <= codepoint && codepoint <= 0xa4c6) ||\n \n // hangul jamo extended-a\n (0xa960 <= codepoint && codepoint <= 0xa97c) ||\n \n // hangul syllables\n (0xac00 <= codepoint && codepoint <= 0xd7a3) ||\n \n // cjk compatibility ideographs\n (0xf900 <= codepoint && codepoint <= 0xfaff) ||\n \n // vertical forms\n (0xfe10 <= codepoint && codepoint <= 0xfe19) ||\n \n // cjk compatibility forms .. small form variants\n (0xfe30 <= codepoint && codepoint <= 0xfe6b) ||\n \n // halfwidth and fullwidth forms\n (0xff01 <= codepoint && codepoint <= 0xff60) ||\n (0xffe0 <= codepoint && codepoint <= 0xffe6) ||\n \n // kana supplement\n (0x1b000 <= codepoint && codepoint <= 0x1b001) ||\n \n // enclosed ideographic supplement\n (0x1f200 <= codepoint && codepoint <= 0x1f251) ||\n \n // cjk unified ideographs extension b .. tertiary ideographic plane\n (0x20000 <= codepoint && codepoint <= 0x3fffd)\n )\n )\n}\n\n\n\n"]}
|
package/repl.js
CHANGED
|
@@ -93,10 +93,7 @@ function trans_import_2_require(import_decl) {
|
|
|
93
93
|
// var { element2: element2_, element3 } = __importDefault(require("mod"))
|
|
94
94
|
factory.createVariableStatement([], [factory.createVariableDeclaration(factory.createObjectBindingPattern(
|
|
95
95
|
// ImportSpecifier[] -> ObjectBindingPattern.BindingElement[]
|
|
96
|
-
import_clause.namedBindings.elements.map(import_specifier =>
|
|
97
|
-
var _a;
|
|
98
|
-
return factory.createBindingElement(undefined, import_specifier.propertyName, import_specifier.name, ((_a = import_specifier.propertyName) === null || _a === void 0 ? void 0 : _a.text) === 'default' ? require_module_stmt : undefined);
|
|
99
|
-
})), undefined, undefined, require_module_stmt)]),
|
|
96
|
+
import_clause.namedBindings.elements.map(import_specifier => factory.createBindingElement(undefined, import_specifier.propertyName, import_specifier.name, import_specifier.propertyName?.text === 'default' ? require_module_stmt : undefined))), undefined, undefined, require_module_stmt)]),
|
|
100
97
|
// Object.assign(global, { element2_, element3 })
|
|
101
98
|
factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('Object'), 'assign'), [],
|
|
102
99
|
// ImportSpecifier[] -> ObjectBindingPattern.BindingElement[]
|
|
@@ -111,13 +108,12 @@ function trans_import_2_require(import_decl) {
|
|
|
111
108
|
}
|
|
112
109
|
/** export function foo () { } */
|
|
113
110
|
function trans_export_stmt(stmt) {
|
|
114
|
-
var _a;
|
|
115
111
|
if (typescript_1.default.isExportAssignment(stmt))
|
|
116
112
|
return factory.createExpressionStatement(stmt.expression);
|
|
117
113
|
function is_export_modifier(modifier) {
|
|
118
114
|
return modifier.flags & ModifierFlags.Export || modifier.flags & ModifierFlags.ExportDefault || modifier.kind === SyntaxKind.ExportKeyword;
|
|
119
115
|
}
|
|
120
|
-
if (
|
|
116
|
+
if (stmt.modifiers?.some(modifier => is_export_modifier(modifier))) {
|
|
121
117
|
// @ts-ignore
|
|
122
118
|
stmt.modifiers = factory.createNodeArray(stmt.modifiers.filter(modifier => !is_export_modifier(modifier)));
|
|
123
119
|
return stmt;
|
|
@@ -349,9 +345,9 @@ async function exit() {
|
|
|
349
345
|
exports.exit = exit;
|
|
350
346
|
async function pollute_global() {
|
|
351
347
|
Object.assign(global, {
|
|
352
|
-
__importDefault: (mod) => ((mod
|
|
348
|
+
__importDefault: (mod) => ((mod?.__esModule) ? mod : { default: mod }),
|
|
353
349
|
__importStar: (mod) => {
|
|
354
|
-
if (mod
|
|
350
|
+
if (mod?.__esModule)
|
|
355
351
|
return mod;
|
|
356
352
|
let result = {};
|
|
357
353
|
if (mod != null)
|