xshell 1.2.89 → 1.3.0
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/antd.sass +4 -31
- package/builder.js +5 -14
- package/file.d.ts +2 -2
- package/file.js +1 -1
- package/i18n/dict.json +12 -0
- package/i18n/scanner/index.d.ts +1 -0
- package/i18n/scanner/index.js +14 -5
- package/net.browser.d.ts +1 -142
- package/net.browser.js +1 -408
- package/net.common.d.ts +178 -0
- package/net.common.js +564 -0
- package/net.d.ts +2 -173
- package/net.js +1 -466
- package/package.json +29 -30
- package/path.d.ts +2 -2
- package/platform.browser.js +9 -1
- package/platform.common.d.ts +9 -0
- package/platform.js +11 -1
- package/prototype.common.d.ts +2 -2
- package/prototype.common.js +8 -8
- package/react.development.js +9199 -6036
- package/react.development.js.map +1 -1
- package/react.production.js +4958 -4306
- package/react.production.js.map +1 -1
- package/repl.js +5 -1
- package/server.d.ts +26 -11
- package/server.js +203 -65
- package/utils.browser.d.ts +1 -1
- package/utils.browser.js +3 -1
- package/utils.common.d.ts +11 -9
- package/utils.common.js +50 -35
- package/utils.js +7 -1
- package/i18n/utils.d.ts +0 -1
- package/i18n/utils.js +0 -11
package/utils.common.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t } from "./i18n/instance.js";
|
|
2
|
-
import {
|
|
2
|
+
import { is_key_type, noop, not_empty, select, to_snake_case } from "./prototype.common.js";
|
|
3
3
|
import { platform } from "./platform.common.js";
|
|
4
4
|
export async function delay(milliseconds, options) {
|
|
5
5
|
return platform.delay(milliseconds, options);
|
|
@@ -70,14 +70,14 @@ export function sort_keys(obj) {
|
|
|
70
70
|
}
|
|
71
71
|
/** 比较 1.10.02 这种版本号
|
|
72
72
|
- l, r: 两个版本号字符串
|
|
73
|
-
- loose?: 宽松模式,允许两个版本号格式(位数)不一致 */
|
|
73
|
+
- loose?: `false` 宽松模式,允许两个版本号格式(位数)不一致 */
|
|
74
74
|
export function vercmp(l, r, loose = false) {
|
|
75
75
|
const lparts = l.split('.').map(x => Number(x));
|
|
76
76
|
const rparts = r.split('.').map(x => Number(x));
|
|
77
77
|
if (!loose && lparts.length !== rparts.length)
|
|
78
78
|
throw new Error('传入 vercmp 的两个版本号格式不一致');
|
|
79
|
-
|
|
80
|
-
for (let i = 0; i < minlen; i
|
|
79
|
+
const minlen = Math.min(lparts.length, rparts.length);
|
|
80
|
+
for (let i = 0; i < minlen; ++i) {
|
|
81
81
|
const l = lparts[i];
|
|
82
82
|
const r = rparts[i];
|
|
83
83
|
check(!isNaN(l) && !isNaN(r), '传入 vercmp 的版本非法');
|
|
@@ -184,9 +184,9 @@ export function buffer_equals(left, right) {
|
|
|
184
184
|
- milliseconds: 限时毫秒数
|
|
185
185
|
- action?: 要等待运行的任务, async function 或 promise
|
|
186
186
|
- on_timeout?: 超时后调用的函数
|
|
187
|
-
-
|
|
188
|
-
-
|
|
189
|
-
- print?: 打印已超时任务的错误 */
|
|
187
|
+
- 若传: 调用 on_timeout,参数为 TimeoutError,然后 timeout 函数正常返回 null
|
|
188
|
+
- 若不传: 抛出 TimeoutError
|
|
189
|
+
- print?: `true` 打印已超时任务的错误 */
|
|
190
190
|
export async function timeout(milliseconds, action, on_timeout, print = true) {
|
|
191
191
|
const error = new TimeoutError();
|
|
192
192
|
return new Promise((resolve, reject) => {
|
|
@@ -197,7 +197,7 @@ export async function timeout(milliseconds, action, on_timeout, print = true) {
|
|
|
197
197
|
if (!done)
|
|
198
198
|
if (on_timeout)
|
|
199
199
|
try {
|
|
200
|
-
await on_timeout();
|
|
200
|
+
await on_timeout(error);
|
|
201
201
|
resolve(null);
|
|
202
202
|
}
|
|
203
203
|
catch (error) {
|
|
@@ -252,34 +252,42 @@ export async function poll(duration, times, action) {
|
|
|
252
252
|
return null;
|
|
253
253
|
}
|
|
254
254
|
/** 模糊过滤字符串列表或对象列表,常用于根据用户输入补全或搜索过滤
|
|
255
|
-
|
|
255
|
+
如果有完全匹配关键词的,只返回完全匹配关键词的候选项
|
|
256
256
|
- query: 查询字符串,要求为全小写
|
|
257
|
-
-
|
|
258
|
-
-
|
|
259
|
-
export function fuzzyfilter(query,
|
|
257
|
+
- items: TItem[], 要过滤的列表
|
|
258
|
+
- keywords: string[][] 每个 item 对应一个全小写字符串的关键词数组,用于实际筛选匹配 */
|
|
259
|
+
export function fuzzyfilter(query, items, keywords, single_char_startswith = false) {
|
|
260
260
|
if (!query)
|
|
261
|
-
return
|
|
262
|
-
if (
|
|
263
|
-
|
|
264
|
-
mapper ??= ident;
|
|
265
|
-
list_lower ??= list.map(item => mapper(item).toLowerCase());
|
|
261
|
+
return items;
|
|
262
|
+
if (!items.length)
|
|
263
|
+
return [];
|
|
266
264
|
const query_lower = query.toLowerCase();
|
|
267
|
-
let
|
|
268
|
-
|
|
269
|
-
|
|
265
|
+
let fullmatches = [];
|
|
266
|
+
keywords.forEach((words, index) => {
|
|
267
|
+
if (words.includes(query_lower))
|
|
268
|
+
fullmatches.push(items[index]);
|
|
269
|
+
});
|
|
270
|
+
if (fullmatches.length)
|
|
271
|
+
return fullmatches;
|
|
270
272
|
if (single_char_startswith && query.length === 1) {
|
|
271
273
|
const c = query[0];
|
|
272
|
-
return
|
|
274
|
+
return items.filter((_, i) => keywords[i].some(x => x.startsWith(c)));
|
|
273
275
|
}
|
|
274
|
-
return
|
|
275
|
-
const str_lower
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
276
|
+
return items.filter((_, i) => {
|
|
277
|
+
for (const str_lower of keywords[i]) {
|
|
278
|
+
let j = 0;
|
|
279
|
+
let not_found = false;
|
|
280
|
+
for (const c of query_lower) {
|
|
281
|
+
j = str_lower.indexOf(c, j) + 1;
|
|
282
|
+
if (!j) { // 找不到则 j === 0
|
|
283
|
+
not_found = true;
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (!not_found)
|
|
288
|
+
return true;
|
|
281
289
|
}
|
|
282
|
-
return
|
|
290
|
+
return false;
|
|
283
291
|
});
|
|
284
292
|
}
|
|
285
293
|
export function get(obj, keypath) {
|
|
@@ -326,16 +334,16 @@ export const date_format = 'YYYY.MM.DD';
|
|
|
326
334
|
/** 默认时间格式 */
|
|
327
335
|
export const time_format = 'HH:mm:ss';
|
|
328
336
|
export class Timer {
|
|
329
|
-
started =
|
|
330
|
-
ended;
|
|
337
|
+
started = Date.now();
|
|
338
|
+
ended = 0;
|
|
331
339
|
/** 停止秒表,保存读数 */
|
|
332
340
|
stop() {
|
|
333
|
-
this.ended =
|
|
341
|
+
this.ended = Date.now();
|
|
334
342
|
}
|
|
335
343
|
/** 如果秒表未停止,获取当前秒表读数;
|
|
336
344
|
如果秒表已停止,获取停止时的秒表读数; */
|
|
337
345
|
get() {
|
|
338
|
-
return (this.ended ||
|
|
346
|
+
return (this.ended || Date.now()) - this.started;
|
|
339
347
|
}
|
|
340
348
|
/** 获取时间表示字符串,如 1.2 s
|
|
341
349
|
- parenthesis?: `true` 字符串前后加上括号,如 (1.2 s) */
|
|
@@ -351,8 +359,8 @@ export class Timer {
|
|
|
351
359
|
}
|
|
352
360
|
/** 重置 started */
|
|
353
361
|
reset() {
|
|
354
|
-
this.started =
|
|
355
|
-
this.ended =
|
|
362
|
+
this.started = Date.now();
|
|
363
|
+
this.ended = 0;
|
|
356
364
|
}
|
|
357
365
|
get_and_reset() {
|
|
358
366
|
const result = this.get();
|
|
@@ -522,4 +530,11 @@ export function tomorrow(date) {
|
|
|
522
530
|
export function to_csv_field(str) {
|
|
523
531
|
return /[,"\n\r]/.test(str) ? str.replaceAll('"', '""').quote('double') : str;
|
|
524
532
|
}
|
|
533
|
+
/** 设置 error.message 同时更新 error.stack */
|
|
534
|
+
export function set_error_message(error, message) {
|
|
535
|
+
error.message = message;
|
|
536
|
+
error.stack = `${error.name}: ${message}\n` +
|
|
537
|
+
error.stack.slice_from('\n', { optional: true });
|
|
538
|
+
return error;
|
|
539
|
+
}
|
|
525
540
|
//# sourceMappingURL=utils.common.js.map
|
package/utils.js
CHANGED
|
@@ -40,7 +40,13 @@ export async function schedule_everyday(hour, action) {
|
|
|
40
40
|
// 等时间到
|
|
41
41
|
await delay(target.getTime() - now.getTime());
|
|
42
42
|
for (;;) {
|
|
43
|
-
|
|
43
|
+
try {
|
|
44
|
+
await action();
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
// 往上抛没什么意义,打印个日志算了
|
|
48
|
+
console.error(error);
|
|
49
|
+
}
|
|
44
50
|
// 等一天
|
|
45
51
|
await delay(1000 * 60 * 60 * 24);
|
|
46
52
|
}
|
package/i18n/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function try_load_dict(fp_dict: string): Promise<any>;
|
package/i18n/utils.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { fread_json } from "../file.js";
|
|
2
|
-
export async function try_load_dict(fp_dict) {
|
|
3
|
-
try {
|
|
4
|
-
return await fread_json(fp_dict, { print: false });
|
|
5
|
-
}
|
|
6
|
-
catch {
|
|
7
|
-
// console.error('未找到或解析错误,跳过加载:' + modpath)
|
|
8
|
-
return {};
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=utils.js.map
|