xshell 1.2.56 → 1.2.58
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 +2 -2
- package/path.d.ts +2 -2
- 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/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/prototype.d.ts
CHANGED
|
@@ -1,79 +1,14 @@
|
|
|
1
1
|
declare global {
|
|
2
2
|
var my_prototype_defined: boolean;
|
|
3
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
4
|
/** - type?: `'single'` 引号类型 */
|
|
68
5
|
quote_if_space(this: string, type?: keyof typeof quotes | 'psh'): string;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
如果 pattern 是 string 则在创建 RegExp 时自动加上 flags (默认 'g'), 否则忽略 flags */
|
|
76
|
-
rm(this: string, pattern: string | RegExp, flags?: string): string;
|
|
6
|
+
to_base64(this: string): string;
|
|
7
|
+
/** - buffer: `false` 直接返回 Buffer */
|
|
8
|
+
decode_base64(this: string): string;
|
|
9
|
+
decode_base64(this: string, buffer: true): Buffer;
|
|
10
|
+
decode_base64(this: string, buffer?: boolean): string | Buffer;
|
|
11
|
+
to_backslash(this: string): string;
|
|
77
12
|
readonly red: string;
|
|
78
13
|
readonly red_: string;
|
|
79
14
|
readonly green: string;
|
|
@@ -89,195 +24,16 @@ declare global {
|
|
|
89
24
|
readonly grey: string;
|
|
90
25
|
readonly underline: string;
|
|
91
26
|
strip_ansi(this: string): string;
|
|
92
|
-
/** 将 string 划分为行,并去掉最后一个 \n 之后的 '' */
|
|
93
|
-
split_lines(this: string): string[];
|
|
94
|
-
split_indent(this: string): {
|
|
95
|
-
indent: number;
|
|
96
|
-
text: string;
|
|
97
|
-
};
|
|
98
|
-
/** 将 string 根据首个找到的 splitter 拆分 string 为两个部分
|
|
99
|
-
- spitter: 不会包含在结果中
|
|
100
|
-
- options?:
|
|
101
|
-
- last?: `false` 为 true 时从后往前找 splitter
|
|
102
|
-
- optional?: `false`
|
|
103
|
-
- false: 必须包含 splitter,否则抛出错误
|
|
104
|
-
- true: 允许不存在 splitter, 返回的数组为 [this] */
|
|
105
|
-
split2(this: string, splitter: string, options?: {
|
|
106
|
-
last?: boolean;
|
|
107
|
-
optional?: boolean;
|
|
108
|
-
}): [string, string?];
|
|
109
|
-
to_base64(this: string): string;
|
|
110
|
-
/** - buffer: `false` 直接返回 Buffer */
|
|
111
|
-
decode_base64(this: string): string;
|
|
112
|
-
decode_base64(this: string, buffer: true): Buffer;
|
|
113
|
-
decode_base64(this: string, buffer?: boolean): string | Buffer;
|
|
114
|
-
space(this: string): string;
|
|
115
|
-
/** 返回去掉 prefix 开头的字符串
|
|
116
|
-
- validate?: `false` 传 true 时确保字符串以 prefix 开头(失败时抛出错误) */
|
|
117
|
-
strip_start(this: string, prefix: string, validate?: boolean): string;
|
|
118
|
-
/** 返回去掉 prefix 开头的字符串,如果没有以 prefix 开头则返回原字符串 */
|
|
119
|
-
strip_if_start(this: string, prefix: string): string;
|
|
120
|
-
/** 返回去掉 suffix 结尾的字符串
|
|
121
|
-
- validate?: `false` 传 true 时确保字符串以 suffix 结尾(失败时抛出错误) */
|
|
122
|
-
strip_end(this: string, suffix: string, validate?: boolean): string;
|
|
123
|
-
/** 返回去掉 suffix 结尾的字符串,如果没有以 suffix 结尾则返回原字符串 */
|
|
124
|
-
strip_if_end(this: string, suffix: string): string;
|
|
125
|
-
/** 确保字符串以 prefix 开头,否则在头部追加 prefix */
|
|
126
|
-
ensure_start(this: string, prefix: string): string;
|
|
127
|
-
/** 确保字符串以 suffix (默认 '\n') 结尾,否则在尾部追加 suffix */
|
|
128
|
-
ensure_end(this: string, suffix?: string): string;
|
|
129
|
-
/** 从 search 字符串出现的位置开始截取到最后
|
|
130
|
-
- options?:
|
|
131
|
-
- include?: `false` 传 true 时包括 search 部分
|
|
132
|
-
- last?: `false` true 时从最后一次出现的地方开始截取,否则默认从第一次出现的地方开始截取
|
|
133
|
-
- optional?: `false` 传 true 时允许不存在 search,此时返回完整的 this */
|
|
134
|
-
slice_from(this: string, search: string, options?: SliceOptions): string;
|
|
135
|
-
/** 从 search 字符串出现的位置开始截断,去掉尾部
|
|
136
|
-
- options?:
|
|
137
|
-
- include?: `false` 传 true 时包括 search 部分
|
|
138
|
-
- last?: `false` 传 true 时截取到最后一次出现的地方,否则默认截取到第一次出现的地方
|
|
139
|
-
- optional?: `false` 传 true 时允许不存在 search,此时返回完整的 this */
|
|
140
|
-
slice_to(this: string, search: string, options?: SliceOptions): string;
|
|
141
|
-
/** 等价于 .endsWith('/') */
|
|
142
|
-
isdir: boolean;
|
|
143
|
-
/** 转换为以 `/` 分割的路径,可能以 / 结尾 */
|
|
144
|
-
fp: string;
|
|
145
|
-
/** 转换为以 `/` 分割的文件夹路径,一定以 / 结尾 */
|
|
146
|
-
fpd: string;
|
|
147
|
-
/** 父文件夹路径,一定以 `/` 结尾,或为空
|
|
148
|
-
特殊情况:
|
|
149
|
-
- '/'.fdir === ''
|
|
150
|
-
- 'D:/'.fdir === '' */
|
|
151
|
-
fdir: string;
|
|
152
|
-
/** 文件或文件夹名, 保留结尾的 /
|
|
153
|
-
常规情况:
|
|
154
|
-
- D:/0/aaa.txt -> aaa.txt
|
|
155
|
-
- D:/aaa/ -> aaa/
|
|
156
|
-
特殊情况:
|
|
157
|
-
- '/'.fname === '/'
|
|
158
|
-
- 'D:/'.fname === 'D:/' */
|
|
159
|
-
fname: string;
|
|
160
|
-
/** 文件后缀名,不带点,如: txt, zip,没有后缀时返回空字符串
|
|
161
|
-
特殊情况: .aaa 的 fext 为 '' */
|
|
162
|
-
fext: string;
|
|
163
|
-
to_backslash(this: string): string;
|
|
164
|
-
}
|
|
165
|
-
interface Date {
|
|
166
|
-
/** - ms?: `false` 显示到 ms */
|
|
167
|
-
to_str(this: Date, ms?: boolean): string;
|
|
168
|
-
/** 格式化为 2024.01.01 这样的日期 */
|
|
169
|
-
to_date_str(this: Date): string;
|
|
170
|
-
/** 格式化为 早上 09:00:00 这样的十二小时制可读友好的时间
|
|
171
|
-
- ms?: `false` 显示到 ms */
|
|
172
|
-
to_time_str(this: Date, ms?: boolean): string;
|
|
173
|
-
/** 格式化为 17.00.00 这样的时间 */
|
|
174
|
-
to_dot_time_str(this: Date, ms?: boolean): string;
|
|
175
|
-
/** 格式化为 2024.01.01 17.00.00 这样的时间 */
|
|
176
|
-
to_dot_str(this: Date, ms?: boolean): string;
|
|
177
|
-
/** 格式化为 17:00:00 这样的时间 */
|
|
178
|
-
to_formal_time_str(this: Date, ms?: boolean): string;
|
|
179
|
-
/** 格式化为 2024.01.01 17:00:00 这样的时间 */
|
|
180
|
-
to_formal_str(this: Date, ms?: boolean): string;
|
|
181
|
-
}
|
|
182
|
-
interface Number {
|
|
183
|
-
/** 12.4 kb (1 kb = 1024 b) */
|
|
184
|
-
to_fsize_str(this: number): string;
|
|
185
|
-
to_bin_str(this: number): string;
|
|
186
|
-
/** 转换为 0x???? 这样的十六进制形式
|
|
187
|
-
- length?: 位数自动对齐到 4 的倍数 */
|
|
188
|
-
to_hex_str(this: number, length?: number): string;
|
|
189
|
-
to_oct_str(this: number): string;
|
|
190
27
|
}
|
|
191
28
|
interface Array<T> {
|
|
192
|
-
/** 等价于 .at(-1) */
|
|
193
|
-
last: T;
|
|
194
29
|
log(this: string[], limit?: number): void;
|
|
195
|
-
indent(this: string[], width?: number, c?: string): string[];
|
|
196
30
|
indent2to4(this: string[]): string[];
|
|
197
|
-
/** 对数组中所有元素求和 (+), 返回结果,可传入 mapper 计算出某个值,用作求和 */
|
|
198
|
-
sum<TKey extends keyof T>(this: T[], zero: T[TKey], mapper: TKey): T[TKey];
|
|
199
|
-
sum<TMapper extends Mapper<T>>(this: T[], zero: ReturnType<TMapper>, mapper: TMapper): ReturnType<TMapper>;
|
|
200
|
-
sum<TReturn = T>(this: T[], zero: TReturn, mapper?: keyof T | Mapper<T>): TReturn;
|
|
201
|
-
/** 查找数组中最大的元素,可传入 mapper 计算出某个值,用作大小比较 */
|
|
202
|
-
max(this: T[], mapper?: keyof T | Mapper<T>): T;
|
|
203
|
-
/** 查找数组中最小的元素,可传入 mapper 计算出某个值,用作大小比较 */
|
|
204
|
-
min(this: T[], mapper?: keyof T | Mapper<T>): T;
|
|
205
|
-
/** 去除重复元素(可按 mapper 选择或计算某个值来去重),重复值保留最后出现的那个
|
|
206
|
-
- mapper?: 可以是 key (string, number, symbol) 或 (obj: any) => any */
|
|
207
|
-
unique(this: T[], mapper?: keyof T | Mapper<T>): T[];
|
|
208
|
-
/**
|
|
209
|
-
- trim_line?: `true`
|
|
210
|
-
- rm_empty_lines?: `true`
|
|
211
|
-
- rm_last_empty_lines?: `false`
|
|
212
|
-
*/
|
|
213
|
-
trim_lines(this: string[], { trim_line, rm_empty_lines, rm_last_empty_lines }?: {
|
|
214
|
-
trim_line?: boolean;
|
|
215
|
-
rm_empty_lines?: boolean;
|
|
216
|
-
rm_last_empty_lines?: boolean;
|
|
217
|
-
}): string[];
|
|
218
31
|
trim_license(this: string[]): string[];
|
|
219
32
|
split_indents(this: string[]): {
|
|
220
33
|
indent: number;
|
|
221
34
|
text: string;
|
|
222
35
|
}[];
|
|
223
|
-
/** - append?: `this.length` 是否在 join 之后增加 \n */
|
|
224
|
-
join_lines(append?: boolean): string;
|
|
225
36
|
}
|
|
226
|
-
interface BigInt {
|
|
227
|
-
/** 12.4 kb (1 kb = 1024 b) */
|
|
228
|
-
to_fsize_str(this: bigint): string;
|
|
229
|
-
toJSON(this: bigint): string;
|
|
230
|
-
}
|
|
231
|
-
interface Error {
|
|
232
|
-
toJSON(this: Error): string;
|
|
233
|
-
}
|
|
234
|
-
interface Set<T> {
|
|
235
|
-
map<TResult>(mapper: (value: T, index: number) => TResult): TResult[];
|
|
236
|
-
}
|
|
237
|
-
interface Uint8Array<TArrayBuffer extends ArrayBufferLike> {
|
|
238
|
-
dataview: DataView<TArrayBuffer>;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
interface SliceOptions {
|
|
242
|
-
include?: boolean;
|
|
243
|
-
last?: boolean;
|
|
244
|
-
optional?: boolean;
|
|
245
37
|
}
|
|
246
|
-
|
|
247
|
-
export
|
|
248
|
-
export declare const ident: <T>(x: T) => T;
|
|
249
|
-
export declare const select: <TObj = any, TKey extends keyof TObj = keyof TObj>(key: TKey) => (obj: TObj) => TObj[TKey];
|
|
250
|
-
export type Mapper<TObj = any, TKey extends keyof TObj = keyof TObj> = (obj: TObj) => TObj[TKey];
|
|
251
|
-
/** value 不为 null 或 undefined */
|
|
252
|
-
export declare const not_empty: (value: any) => boolean;
|
|
253
|
-
export declare const empty: (value: any) => boolean;
|
|
254
|
-
export declare const is_key_type: IsKeyType;
|
|
255
|
-
type IsKeyType = (key: any) => key is string | number | symbol;
|
|
256
|
-
export declare function rethrow(error: Error): void;
|
|
257
|
-
export declare function to_snake_case(str: string): string;
|
|
258
|
-
export declare function to_method_property_descriptors(methods: {
|
|
259
|
-
[name: string]: Function;
|
|
260
|
-
}): PropertyDescriptorMap;
|
|
261
|
-
export declare function to_getter_property_descriptors(getters: {
|
|
262
|
-
[name: string]: Function;
|
|
263
|
-
}): PropertyDescriptorMap;
|
|
264
|
-
export declare const cjk = "([\u2E80-\u9FFF\uF900-\uFAFF])";
|
|
265
|
-
export declare const quotes: {
|
|
266
|
-
single: string;
|
|
267
|
-
double: string;
|
|
268
|
-
backtick: string;
|
|
269
|
-
};
|
|
270
|
-
export declare const brackets: {
|
|
271
|
-
readonly round: readonly ["(", ")"];
|
|
272
|
-
readonly square: readonly ["[", "]"];
|
|
273
|
-
readonly curly: readonly ["{", "}"];
|
|
274
|
-
readonly pointy: readonly ["<", ">"];
|
|
275
|
-
readonly corner: readonly ["「", "」"];
|
|
276
|
-
readonly fat: readonly ["【", "】"];
|
|
277
|
-
readonly tortoise_shell: readonly ["〔", "〕"];
|
|
278
|
-
};
|
|
279
|
-
export declare function to_json(obj: any, replacer?: any): string;
|
|
280
|
-
export declare function to_json_safely(obj: any, replacer?: any): string;
|
|
281
|
-
export declare function is_codepoint_fullwidth(codepoint: number): boolean;
|
|
282
|
-
export declare function byte_size(bytes: number | bigint): string;
|
|
283
|
-
export {};
|
|
38
|
+
import { quotes } from './prototype.common.ts';
|
|
39
|
+
export * from './prototype.common.ts';
|