xshell 1.1.8 → 1.1.10

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 ADDED
@@ -0,0 +1,43 @@
1
+ .ant-modal-root
2
+ // 增加 modal 标题下方空白
3
+ .ant-modal-header
4
+ margin-bottom: 18px
5
+
6
+ .ant-modal-mask
7
+ background-color: unset
8
+
9
+ .ant-modal
10
+ .ant-modal-content
11
+ padding: 20px
12
+
13
+
14
+ @mixin height()
15
+ .ant-table-wrapper
16
+ height: 100%
17
+
18
+ .ant-spin-nested-loading
19
+ height: 100%
20
+
21
+ .ant-spin-container
22
+ height: 100%
23
+ display: flex
24
+ flex-direction: column
25
+
26
+ .ant-table-container
27
+ height: 100%
28
+ display: flex
29
+ flex-direction: column
30
+
31
+ .ant-table-body
32
+ position: relative
33
+ flex: 1
34
+
35
+ table
36
+ position: absolute
37
+ left: 0
38
+ top: 0
39
+ right: 0
40
+ bottom: 0
41
+
42
+ .ant-table
43
+ flex: 1
package/file.js CHANGED
@@ -154,7 +154,10 @@ export async function flist(fpd, options = {}) {
154
154
  return _stats;
155
155
  }
156
156
  if (deep)
157
- return (await Promise.all(fps.map(async (fp) => {
157
+ return (await Promise.all(
158
+ // 顶层文件/文件夹
159
+ fps.map(async (fp) => {
160
+ /** 顶层文件夹的大小 */
158
161
  let fpd_stats;
159
162
  return fp.isdir ?
160
163
  [
@@ -163,7 +166,9 @@ export async function flist(fpd, options = {}) {
163
166
  if (stats) {
164
167
  if (!absolute)
165
168
  fp_or_stats.fp = fp + fp_or_stats.fp;
166
- fpd_stats.size += fp_or_stats.size;
169
+ // 所有顶层文件夹中的文件(不包括文件夹)大小总和加起来作为文件夹大小
170
+ if (!fp_or_stats.fp.isdir)
171
+ fpd_stats.size += fp_or_stats.size;
167
172
  return fp_or_stats;
168
173
  }
169
174
  else
package/i18n/dict.json CHANGED
@@ -382,5 +382,8 @@
382
382
  },
383
383
  "等待 {{duration}} 秒后重试 request (已尝试 {{_count}} 次) …": {
384
384
  "en": "Wait {{duration}} seconds before retrying request (tried {{_count}} times) …"
385
+ },
386
+ "fsend 必须传 absolute 选项, sea 选项, 或 fpd_root 文件夹": {
387
+ "en": "fsend must be passed the absolute option, the sea option, or the fpd_root folder"
385
388
  }
386
389
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -57,17 +57,16 @@
57
57
  "@svgr/webpack": "^8.1.0",
58
58
  "@types/sass-loader": "^8.0.9",
59
59
  "@types/ws": "^8.5.13",
60
- "@typescript-eslint/eslint-plugin": "^8.18.1",
61
- "@typescript-eslint/parser": "^8.18.1",
62
- "@typescript-eslint/utils": "^8.18.1",
60
+ "@typescript-eslint/eslint-plugin": "^8.18.2",
61
+ "@typescript-eslint/parser": "^8.18.2",
62
+ "@typescript-eslint/utils": "^8.18.2",
63
63
  "@xterm/addon-fit": "^0.10.0",
64
64
  "@xterm/addon-web-links": "^0.11.0",
65
65
  "@xterm/addon-webgl": "^0.18.0",
66
66
  "@xterm/xterm": "^5.5.0",
67
67
  "ali-oss": "^6.22.0",
68
68
  "archiver": "^7.0.1",
69
- "byte-size": "^9.0.1",
70
- "chalk": "^5.4.0",
69
+ "chalk": "^5.4.1",
71
70
  "chardet": "^2.0.0",
72
71
  "cli-table3": "^0.6.5",
73
72
  "cli-truncate": "^4.0.0",
@@ -77,11 +76,11 @@
77
76
  "emoji-regex": "^10.4.0",
78
77
  "eslint": "^9.17.0",
79
78
  "eslint-plugin-import": "^2.31.0",
80
- "eslint-plugin-react": "^7.37.2",
79
+ "eslint-plugin-react": "^7.37.3",
81
80
  "gulp-sort": "^2.0.0",
82
81
  "hash-string": "^1.0.0",
83
82
  "https-proxy-agent": "^7.0.6",
84
- "i18next": "^24.1.2",
83
+ "i18next": "^24.2.0",
85
84
  "i18next-scanner": "^4.6.0",
86
85
  "koa": "^2.15.3",
87
86
  "koa-compress": "^5.1.1",
@@ -92,7 +91,7 @@
92
91
  "ora": "^8.1.1",
93
92
  "react": "^19.0.0",
94
93
  "react-i18next": "^15.2.0",
95
- "react-object-model": "^1.2.20",
94
+ "react-object-model": "^1.2.21",
96
95
  "resolve-path": "^1.4.0",
97
96
  "sass": "^1.83.0",
98
97
  "sass-loader": "^16.0.4",
@@ -117,7 +116,6 @@
117
116
  "@types/ali-oss": "^6.16.11",
118
117
  "@types/archiver": "^6.0.3",
119
118
  "@types/babel__traverse": "^7.20.6",
120
- "@types/byte-size": "^8.1.2",
121
119
  "@types/chardet": "^0.8.3",
122
120
  "@types/eslint": "^9.6.1",
123
121
  "@types/estree": "^1.0.6",
@@ -137,7 +135,6 @@
137
135
  },
138
136
  "pnpm": {
139
137
  "patchedDependencies": {
140
- "@types/byte-size@8.1.2": "patches/@types__byte-size@8.1.2.patch",
141
138
  "koa@2.15.3": "patches/koa@2.15.3.patch"
142
139
  }
143
140
  }
package/path.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { default as npath, type FormatInputPathObject } from 'path';
2
- export declare function to_fp(str: string): string;
3
2
  /** Normalize a string path, reducing '..' and '.' parts.
4
3
  When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved.
5
4
  @param path string path to normalize.
@@ -55,7 +54,7 @@ export declare function extname(path: string): string;
55
54
  /** `/` */
56
55
  export declare const sep = "/";
57
56
  /** The platform-specific file delimiter. ';' or ':'. */
58
- export declare const delimiter: ":" | ";";
57
+ export declare const delimiter: ";" | ":";
59
58
  /** Returns an object from a path string - the opposite of format().
60
59
  @param path path to evaluate.
61
60
  @throws {TypeError} if `path` is not a string. */
@@ -67,12 +66,11 @@ export declare function format(pathObject: FormatInputPathObject): string;
67
66
  If path is not a string, path will be returned without modifications.
68
67
  This method is meaningful only on Windows system.
69
68
  On POSIX systems, the method is non-operational and always returns path without modifications. */
70
- export declare function toNamespacedPath(path: string): any;
69
+ export declare function toNamespacedPath(path: string): string;
71
70
  export declare const posix: npath.PlatformPath;
72
71
  export declare const win32: npath.PlatformPath;
73
72
  /** 统一使用 / 作为分隔符的 path 模块 */
74
73
  export declare let path: {
75
- to_fp: typeof to_fp;
76
74
  normalize: typeof normalize;
77
75
  join: typeof join;
78
76
  resolve: typeof resolve;
@@ -83,7 +81,7 @@ export declare let path: {
83
81
  basename: typeof basename;
84
82
  extname: typeof extname;
85
83
  sep: string;
86
- delimiter: ":" | ";";
84
+ delimiter: ";" | ":";
87
85
  parse: typeof parse;
88
86
  format: typeof format;
89
87
  toNamespacedPath: typeof toNamespacedPath;
package/path.js CHANGED
@@ -1,25 +1,16 @@
1
1
  import { default as npath } from 'path';
2
- export function to_fp(str) {
3
- if (!str)
4
- return str;
5
- const fp = str.replaceAll('\\', '/');
6
- // 转换小写盘符开头的路径
7
- return fp[1] === ':' && 'a' <= fp[0] && fp[0] <= 'z'
8
- ? fp[0].toUpperCase() + fp.slice(1)
9
- : fp;
10
- }
11
2
  /** Normalize a string path, reducing '..' and '.' parts.
12
3
  When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved.
13
4
  @param path string path to normalize.
14
5
  @throws {TypeError} if `path` is not a string. */
15
6
  export function normalize(path) {
16
- return to_fp(npath.normalize(to_fp(path)));
7
+ return npath.normalize(path).fp;
17
8
  }
18
9
  /** Join all arguments together and normalize the resulting path.
19
10
  @param paths paths to join.
20
11
  @throws {TypeError} if any of the path segments is not a string. */
21
12
  export function join(...paths) {
22
- return to_fp(npath.join(...paths.map(p => to_fp(p))));
13
+ return npath.join(...paths.map(p => p.fp)).fp;
23
14
  }
24
15
  /** The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
25
16
 
@@ -33,7 +24,7 @@ export function join(...paths) {
33
24
  @param paths A sequence of paths or path segments.
34
25
  @throws {TypeError} if any of the arguments is not a string. */
35
26
  export function resolve(...paths) {
36
- return to_fp(npath.resolve(...paths.map(p => to_fp(p))));
27
+ return npath.resolve(...paths.map(p => p.fp)).fp;
37
28
  }
38
29
  /** 和 resolve 一样,但是保留最后一个 path 结尾的 / */
39
30
  export function resolve_with_slash(...paths) {
@@ -50,20 +41,20 @@ export function resolve_with_slash(...paths) {
50
41
  @param path path to test.
51
42
  @throws {TypeError} if `path` is not a string. */
52
43
  export function isAbsolute(path) {
53
- return npath.isAbsolute(to_fp(path));
44
+ return npath.isAbsolute(path.fp);
54
45
  }
55
46
  /** Solve the relative path from {from} to {to} based on the current working directory.
56
47
  At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve.
57
48
 
58
49
  @throws {TypeError} if either `from` or `to` is not a string. */
59
50
  export function relative(from, to) {
60
- return to_fp(npath.relative(to_fp(from), to_fp(to)));
51
+ return npath.relative(from.fp, to.fp).fp;
61
52
  }
62
53
  /** Return the directory name of a path. Similar to the Unix dirname command.
63
54
  @param path the path to evaluate.
64
55
  @throws {TypeError} if `path` is not a string. */
65
56
  export function dirname(path) {
66
- return to_fp(npath.dirname(path));
57
+ return npath.dirname(path.fp).fp;
67
58
  }
68
59
  /** Return the last portion of a path. Similar to the Unix basename command.
69
60
  Often used to extract the file name from a fully qualified path.
@@ -71,7 +62,7 @@ export function dirname(path) {
71
62
  @param suffix optionally, an extension to remove from the result.
72
63
  @throws {TypeError} if `path` is not a string or if `ext` is given and is not a string. */
73
64
  export function basename(path, suffix) {
74
- return npath.basename(to_fp(path), suffix);
65
+ return npath.basename(path.fp, suffix);
75
66
  }
76
67
  /** Return the extension of the path, from the last '.' to end of string in the last portion of the path.
77
68
  If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string.
@@ -79,7 +70,7 @@ export function basename(path, suffix) {
79
70
  @param path the path to evaluate.
80
71
  @throws {TypeError} if `path` is not a string. */
81
72
  export function extname(path) {
82
- return npath.extname(to_fp(path));
73
+ return npath.extname(path.fp);
83
74
  }
84
75
  /** `/` */
85
76
  export const sep = '/';
@@ -89,25 +80,24 @@ export const delimiter = npath.delimiter;
89
80
  @param path path to evaluate.
90
81
  @throws {TypeError} if `path` is not a string. */
91
82
  export function parse(path) {
92
- return npath.parse(to_fp(path));
83
+ return npath.parse(path.fp);
93
84
  }
94
85
  /** Returns a path string from an object - the opposite of parse().
95
86
  @param pathObject path to evaluate. */
96
87
  export function format(pathObject) {
97
- return to_fp(npath.format(pathObject));
88
+ return npath.format(pathObject).fp;
98
89
  }
99
90
  /** On Windows systems only, returns an equivalent namespace-prefixed path for the given path.
100
91
  If path is not a string, path will be returned without modifications.
101
92
  This method is meaningful only on Windows system.
102
93
  On POSIX systems, the method is non-operational and always returns path without modifications. */
103
94
  export function toNamespacedPath(path) {
104
- return to_fp(toNamespacedPath(to_fp(path)));
95
+ return npath.toNamespacedPath(path.fp).fp;
105
96
  }
106
97
  export const posix = npath.posix;
107
98
  export const win32 = npath.win32;
108
99
  /** 统一使用 / 作为分隔符的 path 模块 */
109
100
  export let path = {
110
- to_fp,
111
101
  normalize,
112
102
  join,
113
103
  resolve,
package/process.d.ts CHANGED
@@ -2,6 +2,7 @@ import { type ChildProcess } from 'child_process';
2
2
  import './prototype.ts';
3
3
  import type { Encoding } from './file.ts';
4
4
  import type { MyProxy } from './net.ts';
5
+ import { inspect } from './utils.ts';
5
6
  export declare const sea: boolean;
6
7
  export declare const exe_nodejs: string;
7
8
  export declare const platform: NodeJS.Platform;
@@ -97,19 +98,25 @@ export interface CallResult<TOutput extends string | Buffer = string> {
97
98
  stderr: TOutput;
98
99
  code: number | null;
99
100
  signal: NodeJS.Signals | null;
101
+ command: string;
102
+ message: string;
100
103
  child: ChildProcess;
104
+ print: FullPrintOptions;
101
105
  }
102
- export interface CallError<TOutput extends string | Buffer = string> {
103
- result: {
104
- pid: number;
105
- stdout: TOutput;
106
- stderr: TOutput;
107
- code: number;
108
- signal: NodeJS.Signals;
109
- child: ChildProcess;
110
- };
106
+ export declare class CallError<TOutput extends string | Buffer = string> extends Error {
107
+ name: string;
108
+ pid: number;
109
+ stdout: TOutput;
110
+ stderr: TOutput;
111
+ code: number;
112
+ signal: NodeJS.Signals;
113
+ command: string;
114
+ child: ChildProcess;
115
+ print: FullPrintOptions;
116
+ constructor({ message, pid, stdout, stderr, code, signal, command, child, print }: CallResult<TOutput>);
117
+ [inspect.custom](): string;
111
118
  }
112
- /** 调用可执行文件,获取返回结果
119
+ /** 调用可执行文件,获取返回结果,错误时抛出 CallError
113
120
  - exe: .exe 路径或文件名 (建议使用路径,跳过 path 搜索,性能更高)
114
121
  - args: `[ ]` 参数列表
115
122
  - options?:
@@ -122,6 +129,9 @@ export interface CallError<TOutput extends string | Buffer = string> {
122
129
  - stdio?: `'pipe'` 设置为 'ignore' 时忽略 stdio 处理
123
130
  - input?: string, 启动子进程之后写入到子进程 stdin 中的内容,写完后关闭子进程 stdin
124
131
  - on_child?: 可以传入回调函数及时获取通过 start 创建的子进程,便于执行 kill、获得 pid 等操作 */
132
+ export declare function call(exe: string, args: string[], options: CallOptions & {
133
+ encoding: 'binary';
134
+ }): Promise<CallResult<Buffer>>;
125
135
  export declare function call(exe: string, args?: string[], options?: CallOptions): Promise<CallResult<string>>;
126
136
  export interface CallNodeJsOptions extends CallOptions {
127
137
  inspect?: number | true;
package/process.js CHANGED
@@ -9,12 +9,6 @@ export const platform = os.platform();
9
9
  export const username = os.userInfo().username;
10
10
  export const noprint = { print: false };
11
11
  export const print_no_command = { print: { command: false, code: false, stdout: true, stderr: true } };
12
- function get_command(exe, args) {
13
- return (short_exe_names[exe] || exe.quote_if_space()) +
14
- (args.length
15
- ? ' ' + args.map(arg => arg.quote_if_space()).join(' ')
16
- : '');
17
- }
18
12
  async function prepare_spawn(detached, exe, args, { cwd, window: _window = true, envs,
19
13
  // @ts-ignore
20
14
  input, fp_stdin, fp_stdout, fp_stderr, print = true, proxy,
@@ -84,9 +78,15 @@ stdio }) {
84
78
  stdout: print,
85
79
  stderr: print
86
80
  };
87
- let command;
81
+ const command = (short_exe_names[exe] || exe.quote_if_space()) +
82
+ (args.length
83
+ ? ' ' +
84
+ args
85
+ .map(arg => arg.quote_if_space())
86
+ .join(' ')
87
+ : '');
88
88
  if (print.command)
89
- console.log((command = get_command(exe, args)).blue);
89
+ console.log(command.blue);
90
90
  return {
91
91
  print,
92
92
  command,
@@ -126,8 +126,35 @@ export async function start(exe, args = [], options = {}) {
126
126
  await close_all_handles();
127
127
  }
128
128
  }
129
+ export class CallError extends Error {
130
+ name = 'CallError';
131
+ pid;
132
+ stdout;
133
+ stderr;
134
+ code;
135
+ signal;
136
+ command;
137
+ child;
138
+ print;
139
+ constructor({ message, pid, stdout, stderr, code, signal, command, child, print }) {
140
+ super(message);
141
+ this.pid = pid;
142
+ this.stdout = stdout;
143
+ this.stderr = stderr;
144
+ this.code = code;
145
+ this.signal = signal;
146
+ this.command = command;
147
+ this.child = child;
148
+ this.print = print;
149
+ }
150
+ [inspect.custom]() {
151
+ return (!this.print.stdout && this.stdout ? `标准输出:\n${this.stdout}\n` : '') +
152
+ (!this.print.stderr && this.stderr ? `标准错误:\n${this.stderr}\n` : '') +
153
+ this.stack;
154
+ }
155
+ }
129
156
  export async function call(exe, args = [], options = {}) {
130
- const { print, command, spawn_options, close_all_handles } = await prepare_spawn(false, exe, args, options);
157
+ const { print, spawn_options, close_all_handles, command } = await prepare_spawn(false, exe, args, options);
131
158
  let child;
132
159
  try {
133
160
  child = spawn(exe, args, spawn_options);
@@ -191,14 +218,11 @@ export async function call(exe, args = [], options = {}) {
191
218
  resolve();
192
219
  });
193
220
  });
194
- let message;
195
- const code_error = throw_code && (code || signal);
196
- if (print.code || code_error) {
197
- message = `进程 ${command || get_command(exe, args)} ` + (code
198
- ? `${throw_code ? '异常' : ''}结束,退出码: ${code}${signal ? `,信号: ${signal}` : ''}`
199
- : '正常结束');
200
- console.log(message[code_error ? 'red' : 'blue']);
201
- }
221
+ const message = `进程 ${command} ` + (code
222
+ ? `${throw_code ? '异常' : ''}结束,退出码: ${code}${signal ? `,信号: ${signal}` : ''}`
223
+ : '正常结束');
224
+ if (print.code && !code)
225
+ console.log(message.blue);
202
226
  const result = {
203
227
  pid: child.pid,
204
228
  stdout: encoding === 'binary'
@@ -209,16 +233,28 @@ export async function call(exe, args = [], options = {}) {
209
233
  : stderrs.join(''),
210
234
  code,
211
235
  signal,
236
+ command,
237
+ message,
212
238
  child,
239
+ print,
213
240
  [inspect.custom]() {
214
- return inspect(this, { omit: ['child'] });
241
+ return inspect(this, {
242
+ omit: [
243
+ 'child',
244
+ 'message',
245
+ 'command',
246
+ 'code',
247
+ 'signal',
248
+ 'pid',
249
+ 'print',
250
+ ...print.stdout ? ['stdout'] : [],
251
+ ...print.stderr ? ['stderr'] : [],
252
+ ]
253
+ });
215
254
  }
216
255
  };
217
- if (code_error) {
218
- let error = new Error(message);
219
- error.result = result;
220
- throw error;
221
- }
256
+ if (throw_code && (code || signal))
257
+ throw new CallError(result);
222
258
  return result;
223
259
  }
224
260
  /** 调用 node <js> 并等待结果
@@ -57,10 +57,11 @@ declare global {
57
57
 
58
58
  - preservations?: `''` 保留的正则表达式字符
59
59
  - flags?: `''` 正则匹配选项
60
- - pattern_placeholder?: `/\{.*?\}/g`
61
- */
60
+ - pattern_placeholder?: `/\{.*?\}/g` */
62
61
  find(this: string, pattern: string, preservations?: string, flags?: string, pattern_placeholder?: RegExp): Record<string, string>;
63
- /** - type?: `'single'` */
62
+ /** 查找子串或字符出现的次数 */
63
+ count(this: string, search: string): number;
64
+ /** - type?: `'single'` 引号类型 */
64
65
  quote(this: string, type?: keyof typeof quotes | 'psh'): string;
65
66
  /** - shape?: `'parenthesis'` */
66
67
  bracket(this: string, shape?: keyof typeof brackets): string;
@@ -103,17 +104,25 @@ declare global {
103
104
  slice_to(this: string, search: string, options?: SliceOptions): string;
104
105
  /** 等价于 .endsWith('/') */
105
106
  isdir: boolean;
106
- /** `/` 分割的路径,可能以 / 结尾 */
107
+ /** 转换为以 `/` 分割的路径,可能以 / 结尾 */
107
108
  fp: string;
108
- /** `/` 分割的文件夹路径,一定以 / 结尾 */
109
+ /** 转换为以 `/` 分割的文件夹路径,一定以 / 结尾 */
109
110
  fpd: string;
110
- /** 父文件夹路径 (path.dirname),一定以 `/` 结尾 */
111
+ /** 父文件夹路径,一定以 `/` 结尾,或为空
112
+ 特殊情况:
113
+ - '/'.fdir === ''
114
+ - 'D:/'.fdir === '' */
111
115
  fdir: string;
112
- /** 文件名 (path.basename 的结果), 保留结尾的 /,如:
116
+ /** 文件或文件夹名, 保留结尾的 /
117
+ 常规情况:
113
118
  - D:/0/aaa.txt -> aaa.txt
114
- - D:/aaa/ -> aaa/ */
119
+ - D:/aaa/ -> aaa/
120
+ 特殊情况:
121
+ - '/'.fname === '/'
122
+ - 'D:/'.fname === 'D:/' */
115
123
  fname: string;
116
- /** .txt */
124
+ /** 文件后缀名,不带点,如: txt, zip,没有后缀时返回空字符串
125
+ 特殊情况: .aaa 的 fext 为 '' */
117
126
  fext: string;
118
127
  }
119
128
  interface Date {
@@ -134,8 +143,8 @@ declare global {
134
143
  to_formal_str(this: Date, ms?: boolean): string;
135
144
  }
136
145
  interface Number {
137
- /** 12.4 KB (1 KB = 1024 B) */
138
- to_fsize_str(this: number, units?: 'iec' | 'metric'): string;
146
+ /** 12.4 kb (1 kb = 1024 b) */
147
+ to_fsize_str(this: number): string;
139
148
  to_bin_str(this: number): string;
140
149
  /** 转换为 0x???? 这样的十六进制形式
141
150
  - length?: 位数自动对齐到 4 的倍数 */
@@ -146,15 +155,15 @@ declare global {
146
155
  /** 等价于 .at(-1) */
147
156
  last: T;
148
157
  indent(this: string[], width?: number, c?: string): string[];
149
- /** 对数组中所有元素求和 (+), 返回结果 */
150
- sum(this: T[]): T;
151
- /** 查找数组中最大的元素,可传入 selector 选择某个属性,或者计算出某个值,用作大小比较 */
152
- max(this: T[], selector?: keyof T | KeySelector<T>): T;
153
- /** 查找数组中最小的元素,可传入 selector 选择某个属性,或者计算出某个值,用作大小比较 */
154
- min(this: T[], selector?: keyof T | KeySelector<T>): T;
155
- /** 去除重复元素(可按 selector 去重),重复值保留最后出现的那个
156
- - selector?: 可以是 key (string, number, symbol) 或 (obj: any) => any */
157
- unique(this: T[], selector?: keyof T | KeySelector<T>): T[];
158
+ /** 对数组中所有元素求和 (+), 返回结果,可传入 mapper 计算出某个值,用作求和 */
159
+ sum<TReturn = T>(this: T[], mapper?: keyof T | Mapper<T>): TReturn;
160
+ /** 查找数组中最大的元素,可传入 mapper 计算出某个值,用作大小比较 */
161
+ max(this: T[], mapper?: keyof T | Mapper<T>): T;
162
+ /** 查找数组中最小的元素,可传入 mapper 计算出某个值,用作大小比较 */
163
+ min(this: T[], mapper?: keyof T | Mapper<T>): T;
164
+ /** 去除重复元素(可按 mapper 选择或计算某个值来去重),重复值保留最后出现的那个
165
+ - mapper?: 可以是 key (string, number, symbol) 或 (obj: any) => any */
166
+ unique(this: T[], mapper?: keyof T | Mapper<T>): T[];
158
167
  /**
159
168
  - trim_line?: `true`
160
169
  - rm_empty_lines?: `true`
@@ -169,13 +178,15 @@ declare global {
169
178
  join_lines(append?: boolean): string;
170
179
  }
171
180
  interface BigInt {
181
+ /** 12.4 kb (1 kb = 1024 b) */
182
+ to_fsize_str(this: bigint): string;
172
183
  toJSON(this: bigint): string;
173
184
  }
174
185
  interface Error {
175
186
  toJSON(this: Error): string;
176
187
  }
177
188
  interface Set<T> {
178
- map<TResult>(mapfn: (value: T, index: number) => TResult): TResult[];
189
+ map<TResult>(mapper: (value: T, index: number) => TResult): TResult[];
179
190
  }
180
191
  }
181
192
  interface SliceOptions {
@@ -185,8 +196,8 @@ interface SliceOptions {
185
196
  export declare const emoji_regex: RegExp;
186
197
  export declare const noop: () => void;
187
198
  export declare const ident: <T>(x: T) => T;
188
- export declare const build_selector: <TObj>(key: keyof TObj) => (obj: TObj) => TObj[keyof TObj];
189
- export type KeySelector<TObj = any, TKey extends keyof TObj = keyof TObj> = (key: TObj) => TObj[TKey];
199
+ export declare const build_mapper: <TObj>(key: keyof TObj) => (obj: TObj) => TObj[keyof TObj];
200
+ export type Mapper<TObj = any, TKey extends keyof TObj = keyof TObj> = (obj: TObj) => TObj[TKey];
190
201
  /** value 不为 null 或 undefined */
191
202
  export declare const not_empty: (value: any) => boolean;
192
203
  export declare const empty: (value: any) => boolean;
@@ -215,4 +226,5 @@ export declare const brackets: {
215
226
  };
216
227
  export declare function to_json(obj: any, replacer?: any): string;
217
228
  export declare function is_codepoint_fullwidth(codepoint: number): boolean;
229
+ export declare function byte_size(bytes: number | bigint): string;
218
230
  export {};