xshell 1.2.57 → 1.2.59
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/net.browser.d.ts +2 -27
- package/net.browser.js +2 -12
- package/net.common.d.ts +28 -0
- package/net.common.js +13 -0
- package/net.d.ts +3 -27
- package/net.js +2 -12
- package/package.json +3 -3
- package/prototype.browser.d.ts +1 -252
- package/prototype.browser.js +78 -643
- package/prototype.common.d.ts +253 -0
- package/prototype.common.js +583 -0
- package/prototype.d.ts +8 -252
- package/prototype.js +9 -584
- package/server.js +1 -1
- package/utils.browser.d.ts +2 -130
- package/utils.browser.js +3 -389
- package/utils.common.d.ts +141 -0
- package/utils.common.js +405 -0
- package/utils.d.ts +13 -145
- package/utils.js +28 -399
package/net.browser.d.ts
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { type Message } from './io.browser.ts';
|
|
2
2
|
import { Lock } from './utils.browser.ts';
|
|
3
|
+
import { type BasicAuth, type BearerAuth, type RemoteKeeperOptions } from './net.common.ts';
|
|
4
|
+
export * from './net.common.ts';
|
|
3
5
|
export interface FullResponse<TBody extends ArrayBuffer | string> {
|
|
4
6
|
status: number;
|
|
5
7
|
headers: Headers;
|
|
6
8
|
body: TBody;
|
|
7
9
|
}
|
|
8
|
-
export interface BasicAuth {
|
|
9
|
-
type: 'basic';
|
|
10
|
-
username: string;
|
|
11
|
-
password: string;
|
|
12
|
-
}
|
|
13
|
-
export interface BearerAuth {
|
|
14
|
-
type: 'bearer';
|
|
15
|
-
token: string;
|
|
16
|
-
}
|
|
17
10
|
export interface RequestOptions {
|
|
18
11
|
method?: 'GET' | 'POST' | 'PUT' | 'HEAD' | 'DELETE' | 'PATCH';
|
|
19
12
|
queries?: Record<string, any>;
|
|
@@ -69,7 +62,6 @@ export declare class WebSocketConnectionError extends Error {
|
|
|
69
62
|
name: "WebSocketConnectionError";
|
|
70
63
|
url: string;
|
|
71
64
|
protocols?: string[];
|
|
72
|
-
websocket: WebSocket;
|
|
73
65
|
event: CloseEvent | /* error 事件时的 event,没有 event.error */ Event;
|
|
74
66
|
type: 'close' | 'error';
|
|
75
67
|
code?: number;
|
|
@@ -102,23 +94,6 @@ export declare function connect_websocket(url: string | URL, { protocols, on_mes
|
|
|
102
94
|
/** 接收到消息后的处理函数
|
|
103
95
|
返回值会自动被 await,然后可能被封装为 message 回传 */
|
|
104
96
|
export type MessageHandler<TData = any> = (message: Message<TData>, websocket?: WebSocket) => void | any | Promise<void | any>;
|
|
105
|
-
/** 自动保持 remote 连接,只对 initiator 且传入 url 有效,
|
|
106
|
-
- 在未连接,或 websocket on_error 检测到连接断开后以 reconnect_interval 间隔尝试 remote.call(func) 重连
|
|
107
|
-
- 在连接状态下以 heartbeat_interval 间隔发送心跳包确保连接状态
|
|
108
|
-
|
|
109
|
-
配置选项:
|
|
110
|
-
- func?: 连接后调用的函数,通常为某个 register 函数,将自身注册到 server
|
|
111
|
-
- args?: 连接后调用函数时传递的参数,与 func 配合使用
|
|
112
|
-
- reconnect_interval?: `1000 * 5` 首次重连失败后的后续尝试间隔 (单位: ms)
|
|
113
|
-
- heartbeat_interval?: `1000 * 60` 发送心跳包确保连接的间隔 (单位: ms)
|
|
114
|
-
- error_delay?: `2000` 遇到错误时首次尝试重连的延时 (单位: ms) */
|
|
115
|
-
export interface RemoteKeeperOptions {
|
|
116
|
-
func?: string;
|
|
117
|
-
args?: any[];
|
|
118
|
-
reconnect_interval?: number;
|
|
119
|
-
heartbeat_interval?: number;
|
|
120
|
-
error_delay?: number;
|
|
121
|
-
}
|
|
122
97
|
/** 通过创建 remote 对象对 websocket rpc 进行抽象
|
|
123
98
|
创建 remote 对象时传入 funcs 注册处理函数,使得对端能通过 (rpc message).func 调用
|
|
124
99
|
使用 remote.handle 方法处理对端发来的 websocket message,对于 websocket 连接接收方需要手动绑定 websocket message 事件到 remote.handle
|
package/net.browser.js
CHANGED
|
@@ -2,17 +2,8 @@ import { t } from "./i18n/instance.js";
|
|
|
2
2
|
import { rethrow } from "./prototype.browser.js"; // to_time_str()
|
|
3
3
|
import { message_symbol, pack, parse } from "./io.browser.js";
|
|
4
4
|
import { assert, genid, delay, Lock, timeout, check } from "./utils.browser.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// sec-*
|
|
8
|
-
'accept-charset',
|
|
9
|
-
'connection',
|
|
10
|
-
'content-length',
|
|
11
|
-
'keep-alive',
|
|
12
|
-
'trailer',
|
|
13
|
-
'transfer-encoding',
|
|
14
|
-
'upgrade',
|
|
15
|
-
]);
|
|
5
|
+
import { drop_request_headers } from "./net.common.js";
|
|
6
|
+
export * from "./net.common.js";
|
|
16
7
|
async function fetch_retry(url, options, timeout, retries = 0, count = 0) {
|
|
17
8
|
try {
|
|
18
9
|
// 旧的浏览器可能没有这个函数
|
|
@@ -156,7 +147,6 @@ export class WebSocketConnectionError extends Error {
|
|
|
156
147
|
// 这里不保留 websocket 引用,防止循环引用导致 JSON 序列化失败
|
|
157
148
|
url;
|
|
158
149
|
protocols;
|
|
159
|
-
websocket;
|
|
160
150
|
event;
|
|
161
151
|
type;
|
|
162
152
|
code;
|
package/net.common.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** 对于 request() 函数来说无意义的 headers,会自动过滤掉 */
|
|
2
|
+
export declare const drop_request_headers: Set<string>;
|
|
3
|
+
export interface BasicAuth {
|
|
4
|
+
type: 'basic';
|
|
5
|
+
username: string;
|
|
6
|
+
password: string;
|
|
7
|
+
}
|
|
8
|
+
export interface BearerAuth {
|
|
9
|
+
type: 'bearer';
|
|
10
|
+
token: string;
|
|
11
|
+
}
|
|
12
|
+
/** 自动保持 remote 连接,只对 initiator 且传入 url 有效,
|
|
13
|
+
- 在未连接,或 websocket on_error 检测到连接断开后以 reconnect_interval 间隔尝试 remote.call(func) 重连
|
|
14
|
+
- 在连接状态下以 heartbeat_interval 间隔发送心跳包确保连接状态
|
|
15
|
+
|
|
16
|
+
配置选项:
|
|
17
|
+
- func?: 连接后调用的函数,通常为某个 register 函数,将自身注册到 server
|
|
18
|
+
- args?: 连接后调用函数时传递的参数,与 func 配合使用
|
|
19
|
+
- reconnect_interval?: `1000 * 5` 首次重连失败后的后续尝试间隔 (单位: ms)
|
|
20
|
+
- heartbeat_interval?: `1000 * 60` 发送心跳包确保连接的间隔 (单位: ms)
|
|
21
|
+
- error_delay?: `2000` 遇到错误时首次尝试重连的延时 (单位: ms) */
|
|
22
|
+
export interface RemoteKeeperOptions {
|
|
23
|
+
func?: string;
|
|
24
|
+
args?: any[];
|
|
25
|
+
reconnect_interval?: number;
|
|
26
|
+
heartbeat_interval?: number;
|
|
27
|
+
error_delay?: number;
|
|
28
|
+
}
|
package/net.common.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** 对于 request() 函数来说无意义的 headers,会自动过滤掉 */
|
|
2
|
+
export const drop_request_headers = new Set([
|
|
3
|
+
// : 开头的 key
|
|
4
|
+
// sec-*
|
|
5
|
+
'accept-charset',
|
|
6
|
+
'connection',
|
|
7
|
+
'content-length',
|
|
8
|
+
'keep-alive',
|
|
9
|
+
'trailer',
|
|
10
|
+
'transfer-encoding',
|
|
11
|
+
'upgrade',
|
|
12
|
+
]);
|
|
13
|
+
//# sourceMappingURL=net.common.js.map
|
package/net.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type { Cookie, CookieJar, MemoryCookieStore } from 'tough-cookie';
|
|
|
4
4
|
import { type Message } from './io.ts';
|
|
5
5
|
import type { Encoding } from './file.ts';
|
|
6
6
|
import { inspect, Lock } from './utils.ts';
|
|
7
|
+
import { type BasicAuth, type BearerAuth, type RemoteKeeperOptions } from './net.common.ts';
|
|
8
|
+
export * from './net.common.ts';
|
|
7
9
|
export type { WebSocket };
|
|
8
10
|
export declare const WebSocketConnecting = 0;
|
|
9
11
|
export declare const WebSocketOpen = 1;
|
|
@@ -34,15 +36,6 @@ export interface FullResponse<TBody extends Buffer | string> {
|
|
|
34
36
|
headers: Record<string, string>;
|
|
35
37
|
body: TBody;
|
|
36
38
|
}
|
|
37
|
-
export interface BasicAuth {
|
|
38
|
-
type: 'basic';
|
|
39
|
-
username: string;
|
|
40
|
-
password: string;
|
|
41
|
-
}
|
|
42
|
-
export interface BearerAuth {
|
|
43
|
-
type: 'bearer';
|
|
44
|
-
token: string;
|
|
45
|
-
}
|
|
46
39
|
export interface RequestOptions {
|
|
47
40
|
method?: 'GET' | 'POST' | 'PUT' | 'HEAD' | 'DELETE' | 'PATCH';
|
|
48
41
|
queries?: Record<string, any>;
|
|
@@ -167,23 +160,6 @@ on_message, on_error, on_close, proxy, print, }: {
|
|
|
167
160
|
/** 接收到消息后的处理函数
|
|
168
161
|
返回值会自动被 await,然后可能被封装为 message 回传 */
|
|
169
162
|
export type MessageHandler<TData = any> = (message: Message<TData>, websocket?: WebSocket) => void | any | Promise<void | any>;
|
|
170
|
-
/** 自动保持 remote 连接,只对 initiator 且传入 url 有效,
|
|
171
|
-
- 在未连接,或 websocket on_error 检测到连接断开后以 reconnect_interval 间隔尝试 remote.call(func) 重连
|
|
172
|
-
- 在连接状态下以 heartbeat_interval 间隔发送心跳包确保连接状态
|
|
173
|
-
|
|
174
|
-
配置选项:
|
|
175
|
-
- func?: 连接后调用的函数,通常为某个 register 函数,将自身注册到 server
|
|
176
|
-
- args?: 连接后调用函数时传递的参数,与 func 配合使用
|
|
177
|
-
- reconnect_interval?: `1000 * 5` 首次重连失败后的后续尝试间隔 (单位: ms)
|
|
178
|
-
- heartbeat_interval?: `1000 * 60` 发送心跳包确保连接的间隔 (单位: ms)
|
|
179
|
-
- error_delay?: `2000` 遇到错误时首次尝试重连的延时 (单位: ms) */
|
|
180
|
-
export interface RemoteKeeperOptions {
|
|
181
|
-
func?: string;
|
|
182
|
-
args?: any[];
|
|
183
|
-
reconnect_interval?: number;
|
|
184
|
-
heartbeat_interval?: number;
|
|
185
|
-
error_delay?: number;
|
|
186
|
-
}
|
|
187
163
|
/** 通过创建 remote 对象对 websocket rpc 进行抽象
|
|
188
164
|
创建 remote 对象时传入 funcs 注册处理函数,使得对端能通过 (rpc message).func 调用
|
|
189
165
|
使用 remote.handle 方法处理对端发来的 websocket message,对于 websocket 连接接收方需要手动绑定 websocket message 事件到 remote.handle
|
|
@@ -300,5 +276,5 @@ export declare class RemoteClient {
|
|
|
300
276
|
[inspect.custom](): {
|
|
301
277
|
remote: string;
|
|
302
278
|
websocket: string;
|
|
303
|
-
} & Omit<this, typeof import("util").inspect.custom | "call" | "websocket" | "
|
|
279
|
+
} & Omit<this, "remote" | typeof import("util").inspect.custom | "call" | "websocket" | "send">;
|
|
304
280
|
}
|
package/net.js
CHANGED
|
@@ -5,6 +5,8 @@ import { t } from "./i18n/instance.js";
|
|
|
5
5
|
import { rethrow } from "./prototype.js";
|
|
6
6
|
import { message_symbol, pack, parse } from "./io.js";
|
|
7
7
|
import { inspect, assert, genid, delay, Lock, pipe_with_error, map_values, unique, timeout, check, colored } from "./utils.js";
|
|
8
|
+
import { drop_request_headers } from "./net.common.js";
|
|
9
|
+
export * from "./net.common.js";
|
|
8
10
|
export const WebSocketConnecting = 0;
|
|
9
11
|
export const WebSocketOpen = 1;
|
|
10
12
|
export const WebSocketClosing = 2;
|
|
@@ -28,18 +30,6 @@ export const cookies = {
|
|
|
28
30
|
this.jar = new CookieJar(this.store = new MemoryCookieStore());
|
|
29
31
|
},
|
|
30
32
|
};
|
|
31
|
-
/** 对于 request() 函数来说无意义的 headers,会自动过滤掉 */
|
|
32
|
-
const drop_request_headers = new Set([
|
|
33
|
-
// : 开头的 key
|
|
34
|
-
// sec-*
|
|
35
|
-
'accept-charset',
|
|
36
|
-
'connection',
|
|
37
|
-
'content-length',
|
|
38
|
-
'keep-alive',
|
|
39
|
-
'trailer',
|
|
40
|
-
'transfer-encoding',
|
|
41
|
-
'upgrade',
|
|
42
|
-
]);
|
|
43
33
|
let agents = {};
|
|
44
34
|
async function request_retry(url, options, _timeout, retries = 0, count = 0, print) {
|
|
45
35
|
const { default: undici } = await import('undici');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xshell",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.59",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"eslint-plugin-import": "^2.32.0",
|
|
70
70
|
"eslint-plugin-react": "^7.37.5",
|
|
71
71
|
"https-proxy-agent": "^7.0.6",
|
|
72
|
-
"i18next": "^25.3.
|
|
72
|
+
"i18next": "^25.3.1",
|
|
73
73
|
"i18next-scanner": "^4.6.0",
|
|
74
74
|
"koa": "^3.0.0",
|
|
75
75
|
"koa-compress": "^5.1.1",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"map-stream": "^0.0.7",
|
|
78
78
|
"mime-types": "^3.0.1",
|
|
79
79
|
"react": "^19.1.0",
|
|
80
|
-
"react-i18next": "^15.
|
|
80
|
+
"react-i18next": "^15.6.0",
|
|
81
81
|
"resolve-path": "^1.4.0",
|
|
82
82
|
"sass": "^1.89.2",
|
|
83
83
|
"sass-loader": "^16.0.5",
|
package/prototype.browser.d.ts
CHANGED
|
@@ -1,252 +1 @@
|
|
|
1
|
-
|
|
2
|
-
declare global {
|
|
3
|
-
interface String {
|
|
4
|
-
readonly width: number;
|
|
5
|
-
/** 截取字符串不超过 width 显示宽度的部分,并保留颜色
|
|
6
|
-
找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted
|
|
7
|
-
若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + …
|
|
8
|
-
否则 返回 this
|
|
9
|
-
*/
|
|
10
|
-
truncate(this: string, width: number): string;
|
|
11
|
-
/** pad string to `<width>`
|
|
12
|
-
- character?: `' '`
|
|
13
|
-
- position?: `'right'` */
|
|
14
|
-
pad(this: string, width: number, { character, position }?: {
|
|
15
|
-
character?: string;
|
|
16
|
-
position?: 'left' | 'right';
|
|
17
|
-
}): string;
|
|
18
|
-
limit(this: string, width: number, { character, position }?: {
|
|
19
|
-
character?: string;
|
|
20
|
-
position?: 'left' | 'right';
|
|
21
|
-
}): string;
|
|
22
|
-
to_regexp(this: string, preservations?: string, flags?: string): RegExp;
|
|
23
|
-
to_snake_case(this: string): string;
|
|
24
|
-
/** 字符串模式替换
|
|
25
|
-
- pattern: 匹配部分的格式
|
|
26
|
-
- pattern_: 替换后的格式
|
|
27
|
-
- preservations?: `''` 保留的正则表达式字符
|
|
28
|
-
- flags?: `''` 正则匹配选项
|
|
29
|
-
- transformer?: `(name, matched) => matched || ''` placeholder transformer
|
|
30
|
-
- pattern_placeholder?: `/\{.*?\}/g`
|
|
31
|
-
|
|
32
|
-
```ts
|
|
33
|
-
'g:/acgn/海贼王/[Skytree][海贼王][One_Piece][893][GB_BIG5_JP][X264_AAC][1080P][CRRIP][天空树双语字幕组].mkv'.refmt(
|
|
34
|
-
'{dirp}/[Skytree][海贼王][{ en_name: \\w+ }][{ episode: \\d+ }][GB_BIG5_JP][{encoding}_AAC][1080P][CRRIP][天空树双语字幕组].{format}',
|
|
35
|
-
'g:/acgn/海贼王/{episode} {encoding}.{format}',
|
|
36
|
-
'\\+',
|
|
37
|
-
'i',
|
|
38
|
-
(name, value) => name === 'episode' ? String(+value + 1) : value.toLowerCase()
|
|
39
|
-
)
|
|
40
|
-
```
|
|
41
|
-
*/
|
|
42
|
-
refmt(this: string, pattern: string, pattern_: string, preservations?: string, flags?: string, transformer?: (name: string, value: string, placeholders: {
|
|
43
|
-
[name: string]: string;
|
|
44
|
-
}) => string, pattern_placeholder?: RegExp): string;
|
|
45
|
-
/** 字符串模式搜索
|
|
46
|
-
```ts
|
|
47
|
-
'git+https://github.com/tamino-martinius/node-ts-dedent-123.git'.find(
|
|
48
|
-
'^{protocol:[\\w+]+}://{hostname:[\\w\\.]+}/{username}/{project}-{index:\\d+}.{suffix}', '^', 'i'
|
|
49
|
-
)
|
|
50
|
-
{
|
|
51
|
-
protocol: 'git+https',
|
|
52
|
-
hostname: 'github.com',
|
|
53
|
-
...
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
为空时返回 { }
|
|
58
|
-
|
|
59
|
-
- preservations?: `''` 保留的正则表达式字符
|
|
60
|
-
- flags?: `''` 正则匹配选项
|
|
61
|
-
- pattern_placeholder?: `/\{.*?\}/g` */
|
|
62
|
-
find(this: string, pattern: string, preservations?: string, flags?: string, pattern_placeholder?: RegExp): Record<string, string>;
|
|
63
|
-
/** 查找子串或字符出现的次数 */
|
|
64
|
-
count(this: string, search: string): number;
|
|
65
|
-
/** - type?: `'single'` 引号类型 */
|
|
66
|
-
quote(this: string, type?: keyof typeof quotes | 'psh'): string;
|
|
67
|
-
/** - shape?: `'parenthesis'` */
|
|
68
|
-
bracket(this: string, shape?: keyof typeof brackets): string;
|
|
69
|
-
surround(this: string, left: string, right?: string): string;
|
|
70
|
-
surround_tag(this: string, tag_name: string): string;
|
|
71
|
-
to_lf(this: string): string;
|
|
72
|
-
/** 'xxx'.replace(/pattern/g, '')
|
|
73
|
-
如果 pattern 是 string 则在创建 RegExp 时自动加上 flags (默认 'g'), 否则忽略 flags */
|
|
74
|
-
rm(this: string, pattern: string | RegExp, flags?: string): string;
|
|
75
|
-
/** 将 string 划分为行,并去掉最后一个 \n 之后的 '' */
|
|
76
|
-
split_lines(this: string): string[];
|
|
77
|
-
split_indent(this: string): {
|
|
78
|
-
indent: number;
|
|
79
|
-
text: string;
|
|
80
|
-
};
|
|
81
|
-
/** 将 string 根据首个找到的 splitter 拆分 string 为两个部分
|
|
82
|
-
- spitter: 不会包含在结果中
|
|
83
|
-
- options?:
|
|
84
|
-
- last?: `false` 为 true 时从后往前找 splitter
|
|
85
|
-
- optional?: `false`
|
|
86
|
-
- false: 必须包含 splitter,否则抛出错误
|
|
87
|
-
- true: 允许不存在 splitter, 返回的数组为 [this] */
|
|
88
|
-
split2(this: string, splitter: string, options?: {
|
|
89
|
-
last?: boolean;
|
|
90
|
-
optional?: boolean;
|
|
91
|
-
}): [string, string?];
|
|
92
|
-
space(this: string): string;
|
|
93
|
-
/** 返回去掉 prefix 开头的字符串
|
|
94
|
-
- validate?: `false` 传 true 时确保字符串以 prefix 开头(失败时抛出错误) */
|
|
95
|
-
strip_start(this: string, prefix: string, validate?: boolean): string;
|
|
96
|
-
/** 返回去掉 prefix 开头的字符串,如果没有以 prefix 开头则返回原字符串 */
|
|
97
|
-
strip_if_start(this: string, prefix: string): string;
|
|
98
|
-
/** 返回去掉 suffix 结尾的字符串
|
|
99
|
-
- validate?: `false` 传 true 时确保字符串以 suffix 结尾(失败时抛出错误) */
|
|
100
|
-
strip_end(this: string, suffix: string, validate?: boolean): string;
|
|
101
|
-
/** 返回去掉 suffix 结尾的字符串,如果没有以 suffix 结尾则返回原字符串 */
|
|
102
|
-
strip_if_end(this: string, suffix: string): string;
|
|
103
|
-
/** 确保字符串以 prefix 开头,否则在头部追加 prefix */
|
|
104
|
-
ensure_start(this: string, prefix: string): string;
|
|
105
|
-
/** 确保字符串以 suffix (默认 '\n') 结尾,否则在尾部追加 suffix */
|
|
106
|
-
ensure_end(this: string, suffix?: string): string;
|
|
107
|
-
/** 从 search 字符串出现的位置开始截取到最后
|
|
108
|
-
- options?:
|
|
109
|
-
- include?: `false` 传 true 时包括 search 部分
|
|
110
|
-
- last?: `false` true 时从最后一次出现的地方开始截取,否则默认从第一次出现的地方开始截取
|
|
111
|
-
- optional?: `false` 传 true 时允许不存在 search,此时返回完整的 this */
|
|
112
|
-
slice_from(this: string, search: string, options?: SliceOptions): string;
|
|
113
|
-
/** 从 search 字符串出现的位置开始截断,去掉尾部
|
|
114
|
-
- options?:
|
|
115
|
-
- include?: `false` 传 true 时包括 search 部分
|
|
116
|
-
- last?: `false` 传 true 时截取到最后一次出现的地方,否则默认截取到第一次出现的地方
|
|
117
|
-
- optional?: `false` 传 true 时允许不存在 search,此时返回完整的 this */
|
|
118
|
-
slice_to(this: string, search: string, options?: SliceOptions): string;
|
|
119
|
-
/** 等价于 .endsWith('/') */
|
|
120
|
-
isdir: boolean;
|
|
121
|
-
/** 转换为以 `/` 分割的路径,可能以 / 结尾 */
|
|
122
|
-
fp: string;
|
|
123
|
-
/** 转换为以 `/` 分割的文件夹路径,一定以 / 结尾 */
|
|
124
|
-
fpd: string;
|
|
125
|
-
/** 父文件夹路径,一定以 `/` 结尾,或为空
|
|
126
|
-
特殊情况:
|
|
127
|
-
- '/'.fdir === ''
|
|
128
|
-
- 'D:/'.fdir === '' */
|
|
129
|
-
fdir: string;
|
|
130
|
-
/** 文件或文件夹名, 保留结尾的 /
|
|
131
|
-
常规情况:
|
|
132
|
-
- D:/0/aaa.txt -> aaa.txt
|
|
133
|
-
- D:/aaa/ -> aaa/
|
|
134
|
-
特殊情况:
|
|
135
|
-
- '/'.fname === '/'
|
|
136
|
-
- 'D:/'.fname === 'D:/' */
|
|
137
|
-
fname: string;
|
|
138
|
-
/** 文件后缀名,不带点,如: txt, zip,没有后缀时返回空字符串
|
|
139
|
-
特殊情况: .aaa 的 fext 为 '' */
|
|
140
|
-
fext: string;
|
|
141
|
-
}
|
|
142
|
-
interface Date {
|
|
143
|
-
/** - ms?: `false` 显示到 ms */
|
|
144
|
-
to_str(this: Date, ms?: boolean): string;
|
|
145
|
-
/** 格式化为 2024.01.01 这样的日期 */
|
|
146
|
-
to_date_str(this: Date): string;
|
|
147
|
-
/** 格式化为 早上 09:00:00 这样的十二小时制可读友好的时间
|
|
148
|
-
- ms?: `false` 显示到 ms */
|
|
149
|
-
to_time_str(this: Date, ms?: boolean): string;
|
|
150
|
-
/** 格式化为 17.00.00 这样的时间 */
|
|
151
|
-
to_dot_time_str(this: Date, ms?: boolean): string;
|
|
152
|
-
/** 格式化为 2024.01.01 17.00.00 这样的时间 */
|
|
153
|
-
to_dot_str(this: Date, ms?: boolean): string;
|
|
154
|
-
/** 格式化为 17:00:00 这样的时间 */
|
|
155
|
-
to_formal_time_str(this: Date, ms?: boolean): string;
|
|
156
|
-
/** 格式化为 2024.01.01 17:00:00 这样的时间 */
|
|
157
|
-
to_formal_str(this: Date, ms?: boolean): string;
|
|
158
|
-
}
|
|
159
|
-
interface Number {
|
|
160
|
-
/** 12.4 kb (1 kb = 1024 b) */
|
|
161
|
-
to_fsize_str(this: number): string;
|
|
162
|
-
to_bin_str(this: number): string;
|
|
163
|
-
/** 转换为 0x???? 这样的十六进制形式
|
|
164
|
-
- length?: 位数自动对齐到 4 的倍数 */
|
|
165
|
-
to_hex_str(this: number, length?: number): string;
|
|
166
|
-
to_oct_str(this: number): string;
|
|
167
|
-
}
|
|
168
|
-
interface Array<T> {
|
|
169
|
-
/** 等价于 .at(-1) */
|
|
170
|
-
last: T;
|
|
171
|
-
indent(this: string[], width?: number, c?: string): string[];
|
|
172
|
-
/** 对数组中所有元素求和 (+), 返回结果,可传入 mapper 计算出某个值,用作求和 */
|
|
173
|
-
sum<TKey extends keyof T>(this: T[], zero: T[TKey], mapper: TKey): T[TKey];
|
|
174
|
-
sum<TMapper extends Mapper<T>>(this: T[], zero: ReturnType<TMapper>, mapper: TMapper): ReturnType<TMapper>;
|
|
175
|
-
sum<TReturn = T>(this: T[], zero: TReturn, mapper?: keyof T | Mapper<T>): TReturn;
|
|
176
|
-
/** 查找数组中最大的元素,可传入 mapper 计算出某个值,用作大小比较 */
|
|
177
|
-
max(this: T[], mapper?: keyof T | Mapper<T>): T;
|
|
178
|
-
/** 查找数组中最小的元素,可传入 mapper 计算出某个值,用作大小比较 */
|
|
179
|
-
min(this: T[], mapper?: keyof T | Mapper<T>): T;
|
|
180
|
-
/** 去除重复元素(可按 mapper 选择或计算某个值来去重),重复值保留最后出现的那个
|
|
181
|
-
- mapper?: 可以是 key (string, number, symbol) 或 (obj: any) => any */
|
|
182
|
-
unique(this: T[], mapper?: keyof T | Mapper<T>): T[];
|
|
183
|
-
/**
|
|
184
|
-
- trim_line?: `true`
|
|
185
|
-
- rm_empty_lines?: `true`
|
|
186
|
-
- rm_last_empty_lines?: `false`
|
|
187
|
-
*/
|
|
188
|
-
trim_lines(this: string[], { trim_line, rm_empty_lines, rm_last_empty_lines }?: {
|
|
189
|
-
trim_line?: boolean;
|
|
190
|
-
rm_empty_lines?: boolean;
|
|
191
|
-
rm_last_empty_lines?: boolean;
|
|
192
|
-
}): string[];
|
|
193
|
-
/** - append?: `this.length` 是否在 join 之后增加 \n */
|
|
194
|
-
join_lines(append?: boolean): string;
|
|
195
|
-
}
|
|
196
|
-
interface BigInt {
|
|
197
|
-
/** 12.4 kb (1 kb = 1024 b) */
|
|
198
|
-
to_fsize_str(this: bigint): string;
|
|
199
|
-
toJSON(this: bigint): string;
|
|
200
|
-
}
|
|
201
|
-
interface Error {
|
|
202
|
-
toJSON(this: Error): string;
|
|
203
|
-
}
|
|
204
|
-
interface Set<T> {
|
|
205
|
-
map<TResult>(mapper: (value: T, index: number) => TResult): TResult[];
|
|
206
|
-
}
|
|
207
|
-
interface Uint8Array<TArrayBuffer extends ArrayBufferLike> {
|
|
208
|
-
dataview: DataView<TArrayBuffer>;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
interface SliceOptions {
|
|
212
|
-
include?: boolean;
|
|
213
|
-
last?: boolean;
|
|
214
|
-
optional?: boolean;
|
|
215
|
-
}
|
|
216
|
-
export declare const emoji_regex: RegExp;
|
|
217
|
-
export declare const noop: () => void;
|
|
218
|
-
export declare const ident: <T>(x: T) => T;
|
|
219
|
-
export declare const select: <TObj = any, TKey extends keyof TObj = keyof TObj>(key: TKey) => (obj: TObj) => TObj[TKey];
|
|
220
|
-
export type Mapper<TObj = any, TKey extends keyof TObj = keyof TObj> = (obj: TObj) => TObj[TKey];
|
|
221
|
-
/** value 不为 null 或 undefined */
|
|
222
|
-
export declare const not_empty: (value: any) => boolean;
|
|
223
|
-
export declare const empty: (value: any) => boolean;
|
|
224
|
-
export declare const is_key_type: IsKeyType;
|
|
225
|
-
type IsKeyType = (key: any) => key is string | number | symbol;
|
|
226
|
-
export declare function rethrow(error: Error): void;
|
|
227
|
-
export declare function to_snake_case(str: string): string;
|
|
228
|
-
export declare function to_method_property_descriptors(methods: {
|
|
229
|
-
[name: string]: Function;
|
|
230
|
-
}): PropertyDescriptorMap;
|
|
231
|
-
export declare function to_getter_property_descriptors(getters: {
|
|
232
|
-
[name: string]: Function;
|
|
233
|
-
}): PropertyDescriptorMap;
|
|
234
|
-
export declare const cjk = "([\u2E80-\u9FFF\uF900-\uFAFF])";
|
|
235
|
-
export declare const quotes: {
|
|
236
|
-
single: string;
|
|
237
|
-
double: string;
|
|
238
|
-
backtick: string;
|
|
239
|
-
};
|
|
240
|
-
export declare const brackets: {
|
|
241
|
-
readonly round: readonly ["(", ")"];
|
|
242
|
-
readonly square: readonly ["[", "]"];
|
|
243
|
-
readonly curly: readonly ["{", "}"];
|
|
244
|
-
readonly pointy: readonly ["<", ">"];
|
|
245
|
-
readonly corner: readonly ["「", "」"];
|
|
246
|
-
readonly fat: readonly ["【", "】"];
|
|
247
|
-
readonly tortoise_shell: readonly ["〔", "〕"];
|
|
248
|
-
};
|
|
249
|
-
export declare function to_json(obj: any, replacer?: any): string;
|
|
250
|
-
export declare function is_codepoint_fullwidth(codepoint: number): boolean;
|
|
251
|
-
export declare function byte_size(bytes: number | bigint): string;
|
|
252
|
-
export {};
|
|
1
|
+
export * from './prototype.common.ts';
|