xshell 1.1.25 → 1.1.26
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/builder.d.ts +2 -2
- package/builder.js +1 -1
- package/file.d.ts +1 -2
- package/file.js +15 -16
- package/io.browser.d.ts +22 -0
- package/io.browser.js +537 -0
- package/io.d.ts +22 -0
- package/io.js +537 -0
- package/net.browser.d.ts +1 -30
- package/net.browser.js +6 -53
- package/net.d.ts +1 -30
- package/net.js +6 -53
- package/package.json +1 -1
- package/process.js +1 -0
- package/prototype.browser.d.ts +19 -6
- package/prototype.browser.js +20 -6
- package/prototype.d.ts +19 -6
- package/prototype.js +20 -6
- package/server.d.ts +2 -2
- package/server.js +17 -17
- package/utils.browser.d.ts +7 -1
- package/utils.browser.js +19 -2
- package/utils.d.ts +10 -4
- package/utils.js +23 -5
package/utils.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type Vinyl from 'vinyl';
|
|
|
5
5
|
import { type Mapper } from './prototype.ts';
|
|
6
6
|
/** `180` 输出字符宽度 */
|
|
7
7
|
export declare const output_width = 180;
|
|
8
|
+
export declare const url_width = 52;
|
|
8
9
|
export declare function set_inspect_options(colors?: boolean): void;
|
|
9
10
|
export declare function assert<T>(assertion: T, message?: string): T;
|
|
10
11
|
/** 做参数校验,逻辑检查 */
|
|
@@ -35,7 +36,9 @@ export declare function map_values<TValue, TNewValue>(obj: {
|
|
|
35
36
|
};
|
|
36
37
|
/** 过滤对象中的 keys, 返回新对象 */
|
|
37
38
|
export declare function filter_keys<TObj>(obj: TObj, filter: (key: string) => any): TObj;
|
|
38
|
-
/** 过滤对象中的 values, 返回新对象
|
|
39
|
+
/** 过滤对象中的 values, 返回新对象
|
|
40
|
+
- obj
|
|
41
|
+
- filter?: `not_empty` */
|
|
39
42
|
export declare function filter_values<TObj extends Record<string, any>>(obj: TObj, filter?: (value: TObj[string]) => any): TObj;
|
|
40
43
|
/** 忽略对象中的 keys, 返回新对象 */
|
|
41
44
|
export declare function omit<TObj>(obj: TObj, omit_keys: string[]): TObj;
|
|
@@ -48,6 +51,7 @@ export declare function vercmp(l: string, r: string, loose?: boolean): number;
|
|
|
48
51
|
/** 过滤符合 pattern 的行 */
|
|
49
52
|
export declare function grep(str: string, pattern: string | RegExp): string;
|
|
50
53
|
/** 模糊过滤字符串列表或对象列表,常用于根据用户输入补全或搜索过滤
|
|
54
|
+
如果有完全匹配的,只返回那一项的数组
|
|
51
55
|
- query: 查询字符串,要求为全小写
|
|
52
56
|
- list: 要过滤的列表
|
|
53
57
|
- list_lower?: 要过滤的列表对应的全小写字符串列表形式,传入时可复用缓存,加快搜索速度 */
|
|
@@ -56,7 +60,7 @@ export declare function get<TReturn = any>(obj: any, keypath: string): TReturn;
|
|
|
56
60
|
export declare function global_get<TReturn = any>(keypath: string): TReturn;
|
|
57
61
|
export declare function invoke<TReturn = any>(obj: any, funcpath: string, args: any[]): TReturn;
|
|
58
62
|
/** 拼接 TypedArrays 生成一个完整的 Uint8Array */
|
|
59
|
-
export declare function concat(arrays: ArrayBufferView[]):
|
|
63
|
+
export declare function concat(arrays: ArrayBufferView[]): Buffer<ArrayBuffer>;
|
|
60
64
|
export declare function typed_array_to_buffer(view: ArrayBufferView): Buffer<ArrayBufferLike>;
|
|
61
65
|
/** 时间间隔 (milliseconds) 格式化 */
|
|
62
66
|
export declare function delta2str(delta: number): string;
|
|
@@ -141,8 +145,8 @@ export declare class Lock<TResource = void> {
|
|
|
141
145
|
在 signal aborted 时抛出错误结束等待,且由内部实现自动释放资源 */
|
|
142
146
|
request<TResult>(action: LockedAction<TResource, TResult>, signal?: AbortSignal): Promise<TResult>;
|
|
143
147
|
}
|
|
144
|
-
|
|
145
|
-
export declare function
|
|
148
|
+
export declare function encode(str: string): Buffer<ArrayBuffer>;
|
|
149
|
+
export declare function encode_into(str: string, buf: Uint8Array): TextEncoderEncodeIntoResult;
|
|
146
150
|
/** 将 utf-8 buffer (Uint8Array) 简单的解码为 string。
|
|
147
151
|
在流式处理 (buffer 可能不完整) 时,应使用独立的 TextDecoder 实例调用 decode(buffer, { stream: true }) */
|
|
148
152
|
export declare function decode(buffer: Uint8Array): string;
|
|
@@ -204,3 +208,5 @@ export declare function consume_stream(stream: Readable, ignore_error?: boolean)
|
|
|
204
208
|
- range: 取值为逗号分割的多个可用值或值区间 (不能含有空格),比如:`8321,8322,8300-8310,11000-11999`
|
|
205
209
|
- reverse?: `false` 在 range 内从后往前生成 */
|
|
206
210
|
export declare function range_to_numbers(range: string, reverse?: boolean): Generator<number, void, unknown>;
|
|
211
|
+
/** 大于 n 的最小的 2 的幂次 */
|
|
212
|
+
export declare function ceil2(n: number): number;
|
package/utils.js
CHANGED
|
@@ -5,6 +5,7 @@ import { t } from "./i18n/instance.js";
|
|
|
5
5
|
import { build_mapper, not_empty, is_key_type, noop, ident } from "./prototype.js";
|
|
6
6
|
/** `180` 输出字符宽度 */
|
|
7
7
|
export const output_width = 180;
|
|
8
|
+
export const url_width = 52;
|
|
8
9
|
export function set_inspect_options(colors = true) {
|
|
9
10
|
util.inspect.defaultOptions.maxArrayLength = 40;
|
|
10
11
|
util.inspect.defaultOptions.maxStringLength = 10000;
|
|
@@ -95,7 +96,9 @@ export function filter_keys(obj, filter) {
|
|
|
95
96
|
return Object.fromEntries(Object.entries(obj)
|
|
96
97
|
.filter(([key]) => filter(key)));
|
|
97
98
|
}
|
|
98
|
-
/** 过滤对象中的 values, 返回新对象
|
|
99
|
+
/** 过滤对象中的 values, 返回新对象
|
|
100
|
+
- obj
|
|
101
|
+
- filter?: `not_empty` */
|
|
99
102
|
export function filter_values(obj, filter = not_empty) {
|
|
100
103
|
return Object.fromEntries(Object.entries(obj)
|
|
101
104
|
.filter(([, value]) => filter(value)));
|
|
@@ -141,6 +144,7 @@ export function grep(str, pattern) {
|
|
|
141
144
|
.join_lines();
|
|
142
145
|
}
|
|
143
146
|
/** 模糊过滤字符串列表或对象列表,常用于根据用户输入补全或搜索过滤
|
|
147
|
+
如果有完全匹配的,只返回那一项的数组
|
|
144
148
|
- query: 查询字符串,要求为全小写
|
|
145
149
|
- list: 要过滤的列表
|
|
146
150
|
- list_lower?: 要过滤的列表对应的全小写字符串列表形式,传入时可复用缓存,加快搜索速度 */
|
|
@@ -151,11 +155,14 @@ export function fuzzyfilter(query, list, mapper = ident, list_lower, single_char
|
|
|
151
155
|
mapper = build_mapper(mapper);
|
|
152
156
|
mapper ??= ident;
|
|
153
157
|
list_lower ??= list.map(item => mapper(item).toLowerCase());
|
|
158
|
+
const query_lower = query.toLowerCase();
|
|
159
|
+
let ifullmatch;
|
|
160
|
+
if ((ifullmatch = list_lower.indexOf(query_lower)) !== -1)
|
|
161
|
+
return [list[ifullmatch]];
|
|
154
162
|
if (single_char_startswith && query.length === 1) {
|
|
155
163
|
const c = query[0];
|
|
156
164
|
return list.filter((_, i) => list_lower[i].startsWith(c));
|
|
157
165
|
}
|
|
158
|
-
const query_lower = query.toLowerCase();
|
|
159
166
|
return list.filter((_, i) => {
|
|
160
167
|
const str_lower = list_lower[i];
|
|
161
168
|
let j = 0;
|
|
@@ -188,7 +195,7 @@ export function concat(arrays) {
|
|
|
188
195
|
let length = 0;
|
|
189
196
|
for (const a of arrays)
|
|
190
197
|
length += a.byteLength;
|
|
191
|
-
let buf =
|
|
198
|
+
let buf = Buffer.allocUnsafe(length);
|
|
192
199
|
let offset = 0;
|
|
193
200
|
for (const a of arrays) {
|
|
194
201
|
const uint8view = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
@@ -419,9 +426,13 @@ export class Lock {
|
|
|
419
426
|
}
|
|
420
427
|
// ------------ text
|
|
421
428
|
let encoder = new TextEncoder();
|
|
422
|
-
/** 将字符串简单的编码为 utf-8 的 buffer (Uint8Array)。高频使用或者在流式处理时,考虑使用 TextEncoder 的 encodeInto 方法 */
|
|
423
429
|
export function encode(str) {
|
|
424
|
-
|
|
430
|
+
// 用 Buffer.from 是因为可以利用 buffer pool,避免 encoder.encode 创建大量小且独立的 array buffer
|
|
431
|
+
return Buffer.from(str);
|
|
432
|
+
}
|
|
433
|
+
export function encode_into(str, buf) {
|
|
434
|
+
// 这个是直接用 v8 String::WriteUtf8 最高效的方法了
|
|
435
|
+
return encoder.encodeInto(str, buf);
|
|
425
436
|
}
|
|
426
437
|
let decoder = new TextDecoder();
|
|
427
438
|
/** 将 utf-8 buffer (Uint8Array) 简单的解码为 string。
|
|
@@ -676,4 +687,11 @@ export function* range_to_numbers(range, reverse = false) {
|
|
|
676
687
|
yield i;
|
|
677
688
|
}
|
|
678
689
|
}
|
|
690
|
+
/** 大于 n 的最小的 2 的幂次 */
|
|
691
|
+
export function ceil2(n) {
|
|
692
|
+
let power = 1;
|
|
693
|
+
for (; power <= n; power <<= 1)
|
|
694
|
+
;
|
|
695
|
+
return power;
|
|
696
|
+
}
|
|
679
697
|
//# sourceMappingURL=utils.js.map
|