xshell 1.0.1 → 1.0.3
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/README.md +2 -2
- package/file.d.ts +10 -4
- package/file.js +19 -20
- package/file.js.map +1 -1
- package/i18n/dict.json +12 -0
- package/package.json +8 -8
- package/process.d.ts +13 -18
- package/process.js +22 -16
- package/process.js.map +1 -1
- package/prototype.d.ts +1 -2
- package/prototype.js +1 -1
- package/prototype.js.map +1 -1
- package/utils.browser.d.ts +1 -1
- package/utils.d.ts +1 -1
- package/utils.js +4 -4
- package/utils.js.map +1 -1
package/README.md
CHANGED
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
<img alt='npm downloads' src='https://img.shields.io/npm/dt/xshell?style=flat-square&color=brightgreen' />
|
|
17
17
|
</a>
|
|
18
18
|
<a href='https://marketplace.visualstudio.com/items?itemName=ShenHongFei.xshell' target='_blank'>
|
|
19
|
-
<img alt='vscode extension version' src='https://
|
|
19
|
+
<img alt='vscode extension version' src='https://vsmarketplacebadges.dev/version/ShenHongFei.xshell.svg?style=flat-square&color=4c98cf' />
|
|
20
20
|
</a>
|
|
21
21
|
<a href='https://marketplace.visualstudio.com/items?itemName=ShenHongFei.xshell' target='_blank'>
|
|
22
|
-
<img alt='vscode extension installs' src='https://
|
|
22
|
+
<img alt='vscode extension installs' src='https://vsmarketplacebadges.dev/installs/ShenHongFei.xshell.svg?style=flat-square&color=4c98cf' />
|
|
23
23
|
</a>
|
|
24
24
|
</p>
|
|
25
25
|
|
package/file.d.ts
CHANGED
|
@@ -89,9 +89,11 @@ export declare function flist(fpd: string, options?: {
|
|
|
89
89
|
absolute?: boolean;
|
|
90
90
|
print?: boolean;
|
|
91
91
|
}): Promise<string[]>;
|
|
92
|
-
export declare function fstat(fp: string): Promise<fs.BigIntStats
|
|
92
|
+
export declare function fstat(fp: string): Promise<fs.BigIntStats & {
|
|
93
|
+
fp: string;
|
|
94
|
+
}>;
|
|
93
95
|
/** 删除文件或文件夹 delete files or folders
|
|
94
|
-
- fp:
|
|
96
|
+
- fp: 文件或文件夹的完整路径 The full path to the file or folder
|
|
95
97
|
- options?:
|
|
96
98
|
- print?: `true`
|
|
97
99
|
|
|
@@ -101,8 +103,12 @@ export declare function fdelete(fp: string, { print }?: {
|
|
|
101
103
|
print?: boolean;
|
|
102
104
|
}): Promise<boolean>;
|
|
103
105
|
/** 复制文件或文件夹 copy file or direcotry
|
|
104
|
-
-
|
|
105
|
-
-
|
|
106
|
+
- fp_src: 源 文件/文件夹 完整路径 src file/directory absolute path
|
|
107
|
+
- fp_dst: 目标 文件/文件夹 完整路径 dst file/directory absolute path
|
|
108
|
+
- options?:
|
|
109
|
+
print?: `true`
|
|
110
|
+
overwrite?: `true`
|
|
111
|
+
|
|
106
112
|
@example
|
|
107
113
|
fcopy('d:/temp/camera/', 'd:/camera/') */
|
|
108
114
|
export declare function fcopy(fp_src: string, fp_dst: string, { print, overwrite, }?: {
|
package/file.js
CHANGED
|
@@ -6,6 +6,7 @@ import debounce from 'lodash/debounce.js';
|
|
|
6
6
|
import MFS from 'memfs';
|
|
7
7
|
import { t } from './i18n/instance.js';
|
|
8
8
|
import { to_json } from './prototype.js';
|
|
9
|
+
import { assert } from './utils.js';
|
|
9
10
|
export * from './ufs.js';
|
|
10
11
|
export { MFS };
|
|
11
12
|
/** fp 所指向的 文件/ 文件夹 是否存在
|
|
@@ -156,20 +157,20 @@ export async function flist(fpd, options = {}) {
|
|
|
156
157
|
export async function fstat(fp) {
|
|
157
158
|
if (!path.isAbsolute(fp))
|
|
158
159
|
throw new Error('fp: ' + fp + t(' 必须是绝对路径'));
|
|
159
|
-
|
|
160
|
+
let stat = await fsp.stat(fp, { bigint: true });
|
|
161
|
+
stat.fp = fp;
|
|
162
|
+
return stat;
|
|
160
163
|
}
|
|
161
164
|
/** 删除文件或文件夹 delete files or folders
|
|
162
|
-
- fp:
|
|
165
|
+
- fp: 文件或文件夹的完整路径 The full path to the file or folder
|
|
163
166
|
- options?:
|
|
164
167
|
- print?: `true`
|
|
165
168
|
|
|
166
169
|
返回是否实际进行了删除操作
|
|
167
170
|
Returns whether the delete operation actually took place */
|
|
168
171
|
export async function fdelete(fp, { print = true } = {}) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (!path.isAbsolute(fp))
|
|
172
|
-
throw new Error(t('fp 必须是绝对路径'));
|
|
172
|
+
assert(fp.length >= 6, `fp: ${fp} ${t('不能太短,防止误删文件')}`);
|
|
173
|
+
assert(path.isAbsolute(fp), t('fp 必须是绝对路径'));
|
|
173
174
|
try {
|
|
174
175
|
await fsp.rm(fp, { recursive: true });
|
|
175
176
|
if (print)
|
|
@@ -192,15 +193,17 @@ export async function fdelete(fp, { print = true } = {}) {
|
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
195
|
/** 复制文件或文件夹 copy file or direcotry
|
|
195
|
-
-
|
|
196
|
-
-
|
|
196
|
+
- fp_src: 源 文件/文件夹 完整路径 src file/directory absolute path
|
|
197
|
+
- fp_dst: 目标 文件/文件夹 完整路径 dst file/directory absolute path
|
|
198
|
+
- options?:
|
|
199
|
+
print?: `true`
|
|
200
|
+
overwrite?: `true`
|
|
201
|
+
|
|
197
202
|
@example
|
|
198
203
|
fcopy('d:/temp/camera/', 'd:/camera/') */
|
|
199
204
|
export async function fcopy(fp_src, fp_dst, { print = true, overwrite = true, } = {}) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (!path.isAbsolute(fp_src) || !path.isAbsolute(fp_dst))
|
|
203
|
-
throw new Error(t('fp_src 和 fp_dst 必须为完整路径'));
|
|
205
|
+
assert(fp_src.endsWith('/') === fp_dst.endsWith('/'), t('fp_src 和 fp_dst 必须同为文件路径或文件夹路径'));
|
|
206
|
+
assert(path.isAbsolute(fp_src) && path.isAbsolute(fp_dst), t('fp_src 和 fp_dst 必须为完整路径'));
|
|
204
207
|
if (print)
|
|
205
208
|
console.log(t('复制'), fp_src, '→', fp_dst);
|
|
206
209
|
await fse.copy(fp_src, fp_dst, { overwrite, errorOnExist: true });
|
|
@@ -248,10 +251,8 @@ export async function frename(fp, fp_, { fpd, print = true, overwrite = true } =
|
|
|
248
251
|
- print?: `true`
|
|
249
252
|
- mode?: `'0o777'` */
|
|
250
253
|
export async function fmkdir(fpd, { print = true, mode, } = {}) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (!fpd.endsWith('/'))
|
|
254
|
-
throw new Error(t('fpd 必须以 / 结尾: ') + fpd);
|
|
254
|
+
assert(path.isAbsolute(fpd), t('fpd 必须是绝对路径: ') + fpd);
|
|
255
|
+
assert(fpd.endsWith('/'), t('fpd 必须以 / 结尾: ') + fpd);
|
|
255
256
|
// CallingfsPromises.mkdir() when path is a directory that exists results in a rejection only when recursive is false.
|
|
256
257
|
const fpd_ = (await fsp.mkdir(fpd, { recursive: true, mode }))?.replaceAll('\\', '/');
|
|
257
258
|
if (fpd_) {
|
|
@@ -266,12 +267,10 @@ export async function fmkdir(fpd, { print = true, mode, } = {}) {
|
|
|
266
267
|
- fp_real: 现在真实文件/文件夹的路径 current real file/directory path
|
|
267
268
|
- fp_link: 目标链接文件/文件夹的路径 target file/directory path */
|
|
268
269
|
export async function flink(fp_real, fp_link, { junction = false, print = true } = {}) {
|
|
269
|
-
|
|
270
|
-
throw new Error(t('fp 必须是绝对路径'));
|
|
270
|
+
assert(path.isAbsolute(fp_real) && path.isAbsolute(fp_link), t('fp 必须是绝对路径'));
|
|
271
271
|
const is_fpd_real = fp_real.endsWith('/');
|
|
272
272
|
const is_fpd_link = fp_link.endsWith('/');
|
|
273
|
-
|
|
274
|
-
throw new Error(t('fp_real 和 fp_link 必须同为文件路径或文件夹路径'));
|
|
273
|
+
assert(is_fpd_real === is_fpd_link, t('fp_real 和 fp_link 必须同为文件路径或文件夹路径'));
|
|
275
274
|
if (fexists(fp_link))
|
|
276
275
|
throw new Error(t('存在同名') + (is_fpd_link ? t('文件夹') : t('文件')) + ': ' + fp_link + t(',无法创建链接'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AM,CAAC,CAAA;IAE3B,MAAM,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AAC1B,CAAC","sourcesContent":["import {\n promises as fsp,\n default as fs,\n} from 'fs'\ntype FileHandle = fsp.FileHandle & { fp: string }\n\nimport path from 'upath'\nimport iconv from 'iconv-lite'\nimport fse from 'fs-extra'\n\nimport debounce from 'lodash/debounce.js'\n\n\nimport MFS from 'memfs'\ndeclare module 'memfs' {\n interface IFs {\n join: typeof path.join\n is_mfs: true\n }\n}\n\n\nimport { t } from './i18n/instance.js'\nimport { to_json } from './prototype.js'\n\n\nexport * from './ufs.js'\n\nexport { MFS }\n\nexport type Encoding = 'utf-8' | 'gb18030' | 'shift-jis' | 'binary'\n\n\n/** fp 所指向的 文件/ 文件夹 是否存在 \n Does the file/folder pointed to by fp exist? */\nexport function fexists (fp: string, { print = true }: { print?: boolean } = { }) {\n const exists = fs.existsSync(fp)\n \n if (print)\n console.log(exists ? t('已存在') : t('不存在'), fp)\n \n return exists\n}\n\n\n/** 打开文件,返回 FileHandle \n open file, return FileHandle \n Some characters (`< > : \" / \\ | ? *`) are reserved under Windows as documented\n by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains\n a colon, Node.js will open a file system stream, as described by [this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams).\n \n - flags: `'r'`\n - options?:\n - mode?: `'0o666'` Sets the file mode (permission and sticky bits) if the file is created. */\nexport async function fopen (\n fp: string,\n flags: string | number,\n { mode, print }: { mode?: fs.Mode, print?: boolean } = { }\n) {\n if (print)\n console.log(t('打开文件'), fp)\n \n return Object.assign(\n await fsp.open(fp, flags, mode),\n { fp, flags, mode }\n )\n}\n\n\nexport function create_mfs () {\n let mfs = MFS.createFsFromVolume(\n new MFS.Volume()\n )\n \n mfs.join = path.join.bind(path)\n mfs.is_mfs = true\n \n return mfs\n}\n\n\nexport async function fread (fp: string): Promise<string>\nexport async function fread (fp: string, { dir, encoding, print }?: { dir?: string, encoding: 'binary', print?: boolean }): Promise<Buffer>\nexport async function fread (fp: string, { dir, encoding, print }?: { dir?: string, encoding?: Encoding | 'auto', print?: boolean }): Promise<string>\nexport async function fread (fp: string, {\n dir, \n encoding = 'utf-8', \n print = true\n}: {\n dir?: string\n encoding?: Encoding | 'auto'\n print?: boolean } = { }\n) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error(t('fp 必须是绝对路径,或传入 dir 参数: ') + fp)\n \n if (print)\n console.log(t('读取'), fp)\n \n switch (encoding) {\n case 'utf-8':\n return fsp.readFile(fp, { encoding: 'utf-8' })\n \n case 'binary':\n return fsp.readFile(fp)\n \n default: {\n const buffer = await fsp.readFile(fp)\n \n if (encoding === 'auto') {\n const { detect } = await import('chardet')\n encoding = detect(buffer) as any\n if (print)\n console.log(fp + t(' 的编码可能是 ') + encoding.toLowerCase())\n }\n \n return iconv.decode(buffer, encoding)\n }\n }\n}\n\nexport async function fread_lines (fp: string, options: { dir?: string, encoding?: Exclude<Encoding, 'binary'> | 'auto', print?: boolean } = { }) {\n return (await fread(fp, options))\n .split_lines()\n}\n\nexport async function fread_json <T = any> (fp: string, options: { dir?: string, encoding?: Encoding, print?: boolean } = { }): Promise<T> {\n return JSON.parse(await fread(fp, options))\n}\n\n\nexport async function fwrite (fp: string | FileHandle, data: Buffer, options?: { dir?: string, print?: boolean, mkdir?: boolean }): Promise<void>\nexport async function fwrite (fp: string | FileHandle, data: any, options?: { dir?: string, encoding?: Encoding, print?: boolean, mkdir?: boolean }): Promise<void>\nexport async function fwrite (\n fp: string | FileHandle,\n data: any,\n {\n dir,\n encoding = 'utf-8',\n print = true,\n mkdir = false,\n }: {\n dir?: string\n encoding?: Encoding\n print?: boolean\n mkdir?: boolean\n } = { }\n) {\n const is_handle = typeof fp === 'object' && fp && 'fd' in fp\n if (is_handle) {\n if (print)\n console.log(t('写入'), (fp as FileHandle).fp)\n } else {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp as string))\n throw new Error(t('fp 必须是绝对路径,或传入 dir 参数: ') + fp)\n \n if (print)\n console.log(t('写入'), fp)\n }\n \n if (encoding === 'gb18030')\n data = iconv.encode(data, encoding)\n \n if (!Buffer.isBuffer(data) && typeof data !== 'string')\n data = to_json(data)\n \n try {\n await fsp.writeFile(fp, data)\n } catch (error) {\n if (!mkdir || error.code !== 'ENOENT' || is_handle)\n throw error\n \n await fmkdir((fp as string).fdir)\n await fsp.writeFile(fp, data)\n }\n}\n\nexport async function fappend (fp: string, data: any, { dir, print = true }: { dir?: string, print?: boolean } = { }) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error(t('fp 必须是绝对路径,或传入 dir 参数: ') + fp)\n \n if (print)\n console.log(t('追加'), fp)\n \n if (!Buffer.isBuffer(data) && typeof data !== 'string')\n throw new Error(t('data 不是 Buffer 或 string'))\n \n await fsp.appendFile(fp, data)\n}\n\n\n/**\n - fpd: 文件夹完整路径 absolute path of directory\n - options?:\n - deep?: `false` 递归遍历 recursively\n - absolute?: `false` 返回、打印完整路径而不是相对路径 Return, print full path instead of relative path\n - print?: `true`\n - filter?: `true` RegExp | (fp: string) => any 注意当 deep = true 时被 filter 过滤掉的目录及目录中的文件不会包含在结果中 \n Note that when deep = true, directories and files in directories that are filtered out by the filter will not be included in the results */\nexport async function flist (\n fpd: string,\n options: {\n filter?: RegExp | ((fp: string) => any)\n deep?: boolean\n absolute?: boolean\n print?: boolean\n } = { }\n): Promise<string[]> {\n const {\n filter,\n deep = false,\n absolute = false,\n print = true,\n } = options\n \n if (!path.isAbsolute(fpd))\n throw new Error(t('参数 fpd: ') + fpd + t(' 必须是绝对路径'))\n \n if (!fpd.endsWith('/'))\n throw new Error(t('参数 fpd: ') + fpd + t(' 必须以 / 结尾'))\n \n // readdir withFileTypes 参数在底层有什么区别,速度上有什么差异\n // 都调用了 uv_fs_scandir, 且调用参数相同,仅仅是 Node.js 侧的回调不同 AfterScanDir / AfterScanDirWithTypes\n // 回调中通过 uv_fs_scandir_next 获取到每个条目的信息,而 uv_fs_scandir_next 中都会读取 type\n // 速度上:都在 0.2 ms 左右就可以完成\n \n const files = await fsp.readdir(fpd, {\n withFileTypes: true,\n encoding: 'utf-8',\n })\n \n const filter_regexp = filter instanceof RegExp\n const filter_fn = Boolean(filter && !filter_regexp)\n \n let fps: string[] = [ ]\n \n for (const file of files) {\n const fp = \n (absolute ? fpd : '') +\n file.name +\n (file.isDirectory() ? '/' : '')\n \n if (filter_regexp && !filter.test(fp))\n continue\n \n if (filter_fn && !(filter as Function)(fp))\n continue\n \n if (print)\n console.log(fp)\n \n fps.push(fp)\n }\n \n return deep ? (\n await Promise.all(\n fps.map(async fp => \n fp.endsWith('/') ?\n [\n fp,\n ... (await flist(\n absolute ? fp : fpd + fp,\n options\n )).map(fp_ => \n absolute ? fp_ : fp + fp_)\n ]\n :\n fp)\n )\n ).flat()\n :\n fps\n}\n\n\nexport async function fstat (fp: string) {\n if (!path.isAbsolute(fp))\n throw new Error('fp: ' + fp + t(' 必须是绝对路径'))\n \n return fsp.stat(fp, { bigint: true })\n}\n\n\n/** 删除文件或文件夹 delete files or folders \n - fp: 路径 file path\n - options?:\n - print?: `true`\n \n 返回是否实际进行了删除操作 \n Returns whether the delete operation actually took place */\nexport async function fdelete (fp: string, { print = true }: { print?: boolean } = { }) {\n if (fp.length < 6)\n throw new Error(fp + t(' 太短'))\n \n if (!path.isAbsolute(fp))\n throw new Error(t('fp 必须是绝对路径'))\n \n try {\n await fsp.rm(fp, { recursive: true })\n if (print)\n if (fp.endsWith('/'))\n console.log((t('删除了文件夹: ') + fp).red)\n else\n console.log((t('删除了文件: ') + fp).red)\n return true\n } catch (error) {\n if (error.code === 'ENOENT') {\n if (print)\n if (fp.endsWith('/'))\n console.log(t('文件夹已不存在: ') + fp)\n else\n console.log(t('文件已不存在: ') + fp)\n return false\n }\n \n throw error\n }\n}\n\n\n/** 复制文件或文件夹 copy file or direcotry\n - src: 源 文件/文件夹 完整路径 src file/directory absolute path\n - dst: 目标 文件/文件夹 完整路径 dst file/directory absolute path\n @example\n fcopy('d:/temp/camera/', 'd:/camera/') */\nexport async function fcopy (fp_src: string, fp_dst: string, {\n print = true,\n overwrite = true,\n}: {\n print?: boolean\n overwrite?: boolean\n} = { }) {\n if (fp_src.endsWith('/') !== fp_dst.endsWith('/'))\n throw new Error(t('fp_src 和 fp_dst 必须同为文件路径或文件夹路径'))\n \n if (!path.isAbsolute(fp_src) || !path.isAbsolute(fp_dst))\n throw new Error(t('fp_src 和 fp_dst 必须为完整路径'))\n \n if (print)\n console.log(t('复制'), fp_src, '→', fp_dst)\n \n await fse.copy(fp_src, fp_dst, { overwrite, errorOnExist: true })\n}\n\n\n/** 移动文件或文件夹 move file or direcotry\n - src: 源 文件/文件夹 完整路径 src file/directory absolute path\n - dst: 目标 文件/文件夹 完整路径 dst file/directory absolute path\n @example\n fmove('d:/temp/camera/', 'd:/camera/') */\nexport async function fmove (src: string, dst: string, {\n overwrite = false,\n print = true\n}: {\n overwrite?: boolean\n print?: boolean\n} = { }) {\n if (src.endsWith('/') !== dst.endsWith('/'))\n throw new Error(t('src 和 dst 必须同为文件路径或文件夹路径'))\n \n if (!path.isAbsolute(src) || !path.isAbsolute(dst))\n throw new Error(t('src 和 dst 必须为完整路径'))\n \n if (print)\n console.log(t('移动'), src, '→', dst)\n \n await fse.move(src, dst, { overwrite })\n}\n\n\n/** 重命名文件 rename file \n - fp: 当前文件名/路径 current filename/path\n - fp_: 新的文件名/路径 new filename/path\n - options?:\n - fpd?: fp 和 fp_ 在同一文件夹内 fp and fp_ is in same directory\n - print?: `true`\n - overwrite?: `true` 默认覆盖(不检查效率更高) better performance without check */\nexport async function frename (\n fp: string, \n fp_: string,\n {\n fpd,\n print = true,\n overwrite = true\n }: {\n fpd?: string\n print?: boolean\n overwrite?: boolean\n } = { }\n) {\n if (fpd) {\n fp = path.join(fpd, fp)\n fp_ = path.join(fpd, fp_)\n } else if (!path.isAbsolute(fp) || !path.isAbsolute(fp_))\n throw new Error(t('fp 和 fp_ 必须是绝对路径'))\n \n if (print)\n console.log(t('重命名'), fp, '→', fp_)\n \n if (!overwrite && fexists(fp_))\n throw new Error(t('文件已存在:') + fp_)\n \n await fsp.rename(fp, fp_)\n}\n\n\n/**\n 递归创建文件夹,确保 fpd 指向的文件夹存在 Create folders recursively, make sure the folder pointed to by fpd exists \n 返回首个创建的文件夹或 undefined Returns the first created folder or undefined\n \n - fpd: 文件夹完整路径 Folder full path\n - options?:\n - print?: `true`\n - mode?: `'0o777'` */\nexport async function fmkdir (\n fpd: string,\n {\n print = true,\n mode,\n }: {\n print?: boolean\n \n /** `0o777` A file mode. If a string is passed, it is parsed as an octal integer. */\n mode?: string | number\n } = { }\n) {\n if (!path.isAbsolute(fpd))\n throw new Error(t('fpd 必须是绝对路径: ') + fpd)\n \n if (!fpd.endsWith('/'))\n throw new Error(t('fpd 必须以 / 结尾: ') + fpd)\n \n // CallingfsPromises.mkdir() when path is a directory that exists results in a rejection only when recursive is false.\n const fpd_ = (\n await fsp.mkdir(fpd, { recursive: true, mode })\n )?.replaceAll('\\\\', '/')\n \n if (fpd_) {\n if (print)\n console.log(t('已创建文件夹'), fpd)\n } else\n if (print)\n console.log(t('已存在文件夹'), fpd)\n \n return fpd_\n}\n\n\n/** 创建软链接 Create soft links \n - fp_real: 现在真实文件/文件夹的路径 current real file/directory path\n - fp_link: 目标链接文件/文件夹的路径 target file/directory path */\nexport async function flink (\n fp_real: string, \n fp_link: string, \n {\n junction = false,\n print = true \n }: { \n junction?: boolean\n print?: boolean\n} = { }) {\n if (!path.isAbsolute(fp_real) || !path.isAbsolute(fp_link))\n throw new Error(t('fp 必须是绝对路径'))\n \n const is_fpd_real = fp_real.endsWith('/')\n const is_fpd_link = fp_link.endsWith('/')\n \n if (is_fpd_real !== is_fpd_link)\n throw new Error(t('fp_real 和 fp_link 必须同为文件路径或文件夹路径'))\n \n if (fexists(fp_link))\n throw new Error(t('存在同名') + (is_fpd_link ? t('文件夹') : t('文件')) + ': ' + fp_link + t(',无法创建链接'))\n \n if (print)\n console.log(t('已将源文件 ') + fp_real + t(' 链接到 ') + fp_link)\n \n if (junction)\n fsp.symlink(fp_real, fp_link, 'junction')\n else\n fsp.symlink(fp_real, fp_link, is_fpd_real ? 'dir' : 'file')\n}\n\n\nexport let fwatchers: Record<string, fs.FSWatcher> = { }\n\n/**\n - fp: 文件或文件夹路径 path of file or directory\n - callback: 文件修改时回调 called when modified\n - exec: `true` 首次 watch 时执行 onchange call callback when watch is executed\n \n 创建的 fs.FSWatcher 保存在 watchers 中, 再次调用相同的 fp 会自动关闭已有的 watcher \n save fs.FSWatcher in watchers, subsequent call will auto close existing watcher for the same fp\n \n https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_fs_watch_filename_options_listener \n The listener callback gets two arguments (event, fname). \n event is either 'rename' or 'change', and filename is the name of the file which triggered the event.\n On most platforms, 'rename' is emitted whenever a filename appears or disappears in the directory.\n \n The listener callback is attached to the 'change' event fired by fs.FSWatcher, but it is not the same thing as the 'change' value of event. */\nexport async function fwatch (\n fp: string,\n onchange: (event: string, fname: string) => any, \n { exec = true }: { exec?: boolean } = { }\n) {\n if (!path.isAbsolute(fp))\n throw new Error(t('fp 必须是完整路径'))\n \n const _watcher = fwatchers[fp]\n if (_watcher)\n _watcher.close()\n \n if (exec)\n await onchange('change', fp.fname)\n \n const start = new Date().getTime()\n \n const debounced_onchange = debounce(\n (event, fname) => {\n if (new Date().getTime() - start < 800)\n return\n console.log(t('文件修改 (') + event + '): ' + fname)\n onchange(event, path.normalize(fname))\n },\n 500,\n { leading: false, trailing: true }\n )\n \n let watcher = fs.watch(fp, debounced_onchange)\n watcher.on('error', error => {\n console.error(error)\n })\n return fwatchers[fp] = watcher\n}\n\n\n/** 打开一个文件并搜索替换某个 pattern open a file and replace certain pattern */\nexport async function freplace (fp: string, pattern: string | RegExp, replacement: string) {\n await fwrite(\n fp,\n (await fread(fp))\n .replaceAll(pattern, replacement)\n )\n}\n\n/** 将文件编码转为 UTF-8 convert file encoding to UTF-8\n - fp: 文件完整路径 file absolute path\n - options?:\n - dryrun?: `true`\n - encoding?: `'auto'` */\nexport async function f2utf8 (fp: string, {\n dryrun = true,\n encoding = 'auto',\n}: {\n dryrun?: boolean\n encoding?: Encoding | 'auto'\n} = { }) {\n const text = await fread(fp, { encoding })\n if (dryrun) {\n console.log(text.slice(0, 10000))\n return\n }\n \n const fp_bak = `${fp.fdir}${fp.fname.replace(/(.*?)(\\.[^.]+)?$/, '$1.bak$2')}`\n if (!fexists(fp_bak))\n await fcopy(fp, fp_bak)\n \n await fwrite(fp, text)\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["file.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,IAAI,GAAG,EACf,OAAO,IAAI,EAAE,GAChB,MAAM,IAAI,CAAA;AAGX,OAAO,IAAI,MAAM,OAAO,CAAA;AACxB,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,GAAG,MAAM,UAAU,CAAA;AAE1B,OAAO,QAAQ,MAAM,oBAAoB,CAAA;AAGzC,OAAO,GAAG,MAAM,OAAO,CAAA;AASvB,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAGnC,cAAc,UAAU,CAAA;AAExB,OAAO,EAAE,GAAG,EAAE,CAAA;AAKd;oDACoD;AACpD,MAAM,UAAU,OAAO,CAAE,EAAU,EAAE,EAAE,KAAK,GAAG,IAAI,KAA0B,EAAG;IAC5E,MAAM,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IAEhC,IAAI,KAAK;QACL,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,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AAQ,EAAE,CAAC,CAAA;IAC1C,IAAI,MAAM,EAAE;QACR,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;QACjC,OAAM;KACT;IAED,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,EAAE,UAAU,CAAC,EAAE,CAAA;IAC9E,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAChB,MAAM,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAE3B,MAAM,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AAC1B,CAAC","sourcesContent":["import {\n promises as fsp,\n default as fs,\n} from 'fs'\ntype FileHandle = fsp.FileHandle & { fp: string }\n\nimport path from 'upath'\nimport iconv from 'iconv-lite'\nimport fse from 'fs-extra'\n\nimport debounce from 'lodash/debounce.js'\n\n\nimport MFS from 'memfs'\ndeclare module 'memfs' {\n interface IFs {\n join: typeof path.join\n is_mfs: true\n }\n}\n\n\nimport { t } from './i18n/instance.js'\nimport { to_json } from './prototype.js'\nimport { assert } from './utils.js'\n\n\nexport * from './ufs.js'\n\nexport { MFS }\n\nexport type Encoding = 'utf-8' | 'gb18030' | 'shift-jis' | 'binary'\n\n\n/** fp 所指向的 文件/ 文件夹 是否存在 \n Does the file/folder pointed to by fp exist? */\nexport function fexists (fp: string, { print = true }: { print?: boolean } = { }) {\n const exists = fs.existsSync(fp)\n \n if (print)\n console.log(exists ? t('已存在') : t('不存在'), fp)\n \n return exists\n}\n\n\n/** 打开文件,返回 FileHandle \n open file, return FileHandle \n Some characters (`< > : \" / \\ | ? *`) are reserved under Windows as documented\n by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains\n a colon, Node.js will open a file system stream, as described by [this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams).\n \n - flags: `'r'`\n - options?:\n - mode?: `'0o666'` Sets the file mode (permission and sticky bits) if the file is created. */\nexport async function fopen (\n fp: string,\n flags: string | number,\n { mode, print }: { mode?: fs.Mode, print?: boolean } = { }\n) {\n if (print)\n console.log(t('打开文件'), fp)\n \n return Object.assign(\n await fsp.open(fp, flags, mode),\n { fp, flags, mode }\n )\n}\n\n\nexport function create_mfs () {\n let mfs = MFS.createFsFromVolume(\n new MFS.Volume()\n )\n \n mfs.join = path.join.bind(path)\n mfs.is_mfs = true\n \n return mfs\n}\n\n\nexport async function fread (fp: string): Promise<string>\nexport async function fread (fp: string, { dir, encoding, print }?: { dir?: string, encoding: 'binary', print?: boolean }): Promise<Buffer>\nexport async function fread (fp: string, { dir, encoding, print }?: { dir?: string, encoding?: Encoding | 'auto', print?: boolean }): Promise<string>\nexport async function fread (fp: string, {\n dir, \n encoding = 'utf-8', \n print = true\n}: {\n dir?: string\n encoding?: Encoding | 'auto'\n print?: boolean } = { }\n) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error(t('fp 必须是绝对路径,或传入 dir 参数: ') + fp)\n \n if (print)\n console.log(t('读取'), fp)\n \n switch (encoding) {\n case 'utf-8':\n return fsp.readFile(fp, { encoding: 'utf-8' })\n \n case 'binary':\n return fsp.readFile(fp)\n \n default: {\n const buffer = await fsp.readFile(fp)\n \n if (encoding === 'auto') {\n const { detect } = await import('chardet')\n encoding = detect(buffer) as any\n if (print)\n console.log(fp + t(' 的编码可能是 ') + encoding.toLowerCase())\n }\n \n return iconv.decode(buffer, encoding)\n }\n }\n}\n\nexport async function fread_lines (fp: string, options: { dir?: string, encoding?: Exclude<Encoding, 'binary'> | 'auto', print?: boolean } = { }) {\n return (await fread(fp, options))\n .split_lines()\n}\n\nexport async function fread_json <T = any> (fp: string, options: { dir?: string, encoding?: Encoding, print?: boolean } = { }): Promise<T> {\n return JSON.parse(await fread(fp, options))\n}\n\n\nexport async function fwrite (fp: string | FileHandle, data: Buffer, options?: { dir?: string, print?: boolean, mkdir?: boolean }): Promise<void>\nexport async function fwrite (fp: string | FileHandle, data: any, options?: { dir?: string, encoding?: Encoding, print?: boolean, mkdir?: boolean }): Promise<void>\nexport async function fwrite (\n fp: string | FileHandle,\n data: any,\n {\n dir,\n encoding = 'utf-8',\n print = true,\n mkdir = false,\n }: {\n dir?: string\n encoding?: Encoding\n print?: boolean\n mkdir?: boolean\n } = { }\n) {\n const is_handle = typeof fp === 'object' && fp && 'fd' in fp\n if (is_handle) {\n if (print)\n console.log(t('写入'), (fp as FileHandle).fp)\n } else {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp as string))\n throw new Error(t('fp 必须是绝对路径,或传入 dir 参数: ') + fp)\n \n if (print)\n console.log(t('写入'), fp)\n }\n \n if (encoding === 'gb18030')\n data = iconv.encode(data, encoding)\n \n if (!Buffer.isBuffer(data) && typeof data !== 'string')\n data = to_json(data)\n \n try {\n await fsp.writeFile(fp, data)\n } catch (error) {\n if (!mkdir || error.code !== 'ENOENT' || is_handle)\n throw error\n \n await fmkdir((fp as string).fdir)\n await fsp.writeFile(fp, data)\n }\n}\n\nexport async function fappend (fp: string, data: any, { dir, print = true }: { dir?: string, print?: boolean } = { }) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error(t('fp 必须是绝对路径,或传入 dir 参数: ') + fp)\n \n if (print)\n console.log(t('追加'), fp)\n \n if (!Buffer.isBuffer(data) && typeof data !== 'string')\n throw new Error(t('data 不是 Buffer 或 string'))\n \n await fsp.appendFile(fp, data)\n}\n\n\n/**\n - fpd: 文件夹完整路径 absolute path of directory\n - options?:\n - deep?: `false` 递归遍历 recursively\n - absolute?: `false` 返回、打印完整路径而不是相对路径 Return, print full path instead of relative path\n - print?: `true`\n - filter?: `true` RegExp | (fp: string) => any 注意当 deep = true 时被 filter 过滤掉的目录及目录中的文件不会包含在结果中 \n Note that when deep = true, directories and files in directories that are filtered out by the filter will not be included in the results */\nexport async function flist (\n fpd: string,\n options: {\n filter?: RegExp | ((fp: string) => any)\n deep?: boolean\n absolute?: boolean\n print?: boolean\n } = { }\n): Promise<string[]> {\n const {\n filter,\n deep = false,\n absolute = false,\n print = true,\n } = options\n \n if (!path.isAbsolute(fpd))\n throw new Error(t('参数 fpd: ') + fpd + t(' 必须是绝对路径'))\n \n if (!fpd.endsWith('/'))\n throw new Error(t('参数 fpd: ') + fpd + t(' 必须以 / 结尾'))\n \n // readdir withFileTypes 参数在底层有什么区别,速度上有什么差异\n // 都调用了 uv_fs_scandir, 且调用参数相同,仅仅是 Node.js 侧的回调不同 AfterScanDir / AfterScanDirWithTypes\n // 回调中通过 uv_fs_scandir_next 获取到每个条目的信息,而 uv_fs_scandir_next 中都会读取 type\n // 速度上:都在 0.2 ms 左右就可以完成\n \n const files = await fsp.readdir(fpd, {\n withFileTypes: true,\n encoding: 'utf-8',\n })\n \n const filter_regexp = filter instanceof RegExp\n const filter_fn = Boolean(filter && !filter_regexp)\n \n let fps: string[] = [ ]\n \n for (const file of files) {\n const fp = \n (absolute ? fpd : '') +\n file.name +\n (file.isDirectory() ? '/' : '')\n \n if (filter_regexp && !filter.test(fp))\n continue\n \n if (filter_fn && !(filter as Function)(fp))\n continue\n \n if (print)\n console.log(fp)\n \n fps.push(fp)\n }\n \n return deep ? (\n await Promise.all(\n fps.map(async fp => \n fp.endsWith('/') ?\n [\n fp,\n ... (await flist(\n absolute ? fp : fpd + fp,\n options\n )).map(fp_ => \n absolute ? fp_ : fp + fp_)\n ]\n :\n fp)\n )\n ).flat()\n :\n fps\n}\n\n\nexport async function fstat (fp: string): Promise<fs.BigIntStats & { fp: string }> {\n if (!path.isAbsolute(fp))\n throw new Error('fp: ' + fp + t(' 必须是绝对路径'))\n \n let stat = await fsp.stat(fp, { bigint: true })\n ;(stat as any).fp = fp\n \n return stat as any\n}\n\n\n/** 删除文件或文件夹 delete files or folders \n - fp: 文件或文件夹的完整路径 The full path to the file or folder\n - options?:\n - print?: `true`\n \n 返回是否实际进行了删除操作 \n Returns whether the delete operation actually took place */\nexport async function fdelete (fp: string, { print = true }: { print?: boolean } = { }) {\n assert(fp.length >= 6, `fp: ${fp} ${t('不能太短,防止误删文件')}`)\n assert(path.isAbsolute(fp), t('fp 必须是绝对路径'))\n \n try {\n await fsp.rm(fp, { recursive: true })\n if (print)\n if (fp.endsWith('/'))\n console.log((t('删除了文件夹: ') + fp).red)\n else\n console.log((t('删除了文件: ') + fp).red)\n return true\n } catch (error) {\n if (error.code === 'ENOENT') {\n if (print)\n if (fp.endsWith('/'))\n console.log(t('文件夹已不存在: ') + fp)\n else\n console.log(t('文件已不存在: ') + fp)\n return false\n }\n \n throw error\n }\n}\n\n\n/** 复制文件或文件夹 copy file or direcotry\n - fp_src: 源 文件/文件夹 完整路径 src file/directory absolute path\n - fp_dst: 目标 文件/文件夹 完整路径 dst file/directory absolute path\n - options?:\n print?: `true`\n overwrite?: `true`\n \n @example\n fcopy('d:/temp/camera/', 'd:/camera/') */\nexport async function fcopy (fp_src: string, fp_dst: string, {\n print = true,\n overwrite = true,\n}: {\n print?: boolean\n overwrite?: boolean\n} = { }) {\n assert(fp_src.endsWith('/') === fp_dst.endsWith('/'), t('fp_src 和 fp_dst 必须同为文件路径或文件夹路径'))\n assert(path.isAbsolute(fp_src) && path.isAbsolute(fp_dst), t('fp_src 和 fp_dst 必须为完整路径'))\n \n if (print)\n console.log(t('复制'), fp_src, '→', fp_dst)\n \n await fse.copy(fp_src, fp_dst, { overwrite, errorOnExist: true })\n}\n\n\n/** 移动文件或文件夹 move file or direcotry\n - src: 源 文件/文件夹 完整路径 src file/directory absolute path\n - dst: 目标 文件/文件夹 完整路径 dst file/directory absolute path\n @example\n fmove('d:/temp/camera/', 'd:/camera/') */\nexport async function fmove (src: string, dst: string, {\n overwrite = false,\n print = true\n}: {\n overwrite?: boolean\n print?: boolean\n} = { }) {\n if (src.endsWith('/') !== dst.endsWith('/'))\n throw new Error(t('src 和 dst 必须同为文件路径或文件夹路径'))\n \n if (!path.isAbsolute(src) || !path.isAbsolute(dst))\n throw new Error(t('src 和 dst 必须为完整路径'))\n \n if (print)\n console.log(t('移动'), src, '→', dst)\n \n await fse.move(src, dst, { overwrite })\n}\n\n\n/** 重命名文件 rename file \n - fp: 当前文件名/路径 current filename/path\n - fp_: 新的文件名/路径 new filename/path\n - options?:\n - fpd?: fp 和 fp_ 在同一文件夹内 fp and fp_ is in same directory\n - print?: `true`\n - overwrite?: `true` 默认覆盖(不检查效率更高) better performance without check */\nexport async function frename (\n fp: string, \n fp_: string,\n {\n fpd,\n print = true,\n overwrite = true\n }: {\n fpd?: string\n print?: boolean\n overwrite?: boolean\n } = { }\n) {\n if (fpd) {\n fp = path.join(fpd, fp)\n fp_ = path.join(fpd, fp_)\n } else if (!path.isAbsolute(fp) || !path.isAbsolute(fp_))\n throw new Error(t('fp 和 fp_ 必须是绝对路径'))\n \n if (print)\n console.log(t('重命名'), fp, '→', fp_)\n \n if (!overwrite && fexists(fp_))\n throw new Error(t('文件已存在:') + fp_)\n \n await fsp.rename(fp, fp_)\n}\n\n\n/**\n 递归创建文件夹,确保 fpd 指向的文件夹存在 Create folders recursively, make sure the folder pointed to by fpd exists \n 返回首个创建的文件夹或 undefined Returns the first created folder or undefined\n \n - fpd: 文件夹完整路径 Folder full path\n - options?:\n - print?: `true`\n - mode?: `'0o777'` */\nexport async function fmkdir (\n fpd: string,\n {\n print = true,\n mode,\n }: {\n print?: boolean\n \n /** `0o777` A file mode. If a string is passed, it is parsed as an octal integer. */\n mode?: string | number\n } = { }\n) {\n assert(path.isAbsolute(fpd), t('fpd 必须是绝对路径: ') + fpd)\n assert(fpd.endsWith('/'), t('fpd 必须以 / 结尾: ') + fpd)\n \n // CallingfsPromises.mkdir() when path is a directory that exists results in a rejection only when recursive is false.\n const fpd_ = (\n await fsp.mkdir(fpd, { recursive: true, mode })\n )?.replaceAll('\\\\', '/')\n \n if (fpd_) {\n if (print)\n console.log(t('已创建文件夹'), fpd)\n } else\n if (print)\n console.log(t('已存在文件夹'), fpd)\n \n return fpd_\n}\n\n\n/** 创建软链接 Create soft links \n - fp_real: 现在真实文件/文件夹的路径 current real file/directory path\n - fp_link: 目标链接文件/文件夹的路径 target file/directory path */\nexport async function flink (\n fp_real: string, \n fp_link: string, \n {\n junction = false,\n print = true \n }: { \n junction?: boolean\n print?: boolean\n} = { }) {\n assert(path.isAbsolute(fp_real) && path.isAbsolute(fp_link), t('fp 必须是绝对路径'))\n \n const is_fpd_real = fp_real.endsWith('/')\n const is_fpd_link = fp_link.endsWith('/')\n \n assert(is_fpd_real === is_fpd_link, t('fp_real 和 fp_link 必须同为文件路径或文件夹路径'))\n \n if (fexists(fp_link))\n throw new Error(t('存在同名') + (is_fpd_link ? t('文件夹') : t('文件')) + ': ' + fp_link + t(',无法创建链接'))\n \n if (print)\n console.log(t('已将源文件 ') + fp_real + t(' 链接到 ') + fp_link)\n \n if (junction)\n fsp.symlink(fp_real, fp_link, 'junction')\n else\n fsp.symlink(fp_real, fp_link, is_fpd_real ? 'dir' : 'file')\n}\n\n\nexport let fwatchers: Record<string, fs.FSWatcher> = { }\n\n/**\n - fp: 文件或文件夹路径 path of file or directory\n - callback: 文件修改时回调 called when modified\n - exec: `true` 首次 watch 时执行 onchange call callback when watch is executed\n \n 创建的 fs.FSWatcher 保存在 watchers 中, 再次调用相同的 fp 会自动关闭已有的 watcher \n save fs.FSWatcher in watchers, subsequent call will auto close existing watcher for the same fp\n \n https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_fs_watch_filename_options_listener \n The listener callback gets two arguments (event, fname). \n event is either 'rename' or 'change', and filename is the name of the file which triggered the event.\n On most platforms, 'rename' is emitted whenever a filename appears or disappears in the directory.\n \n The listener callback is attached to the 'change' event fired by fs.FSWatcher, but it is not the same thing as the 'change' value of event. */\nexport async function fwatch (\n fp: string,\n onchange: (event: string, fname: string) => any, \n { exec = true }: { exec?: boolean } = { }\n) {\n if (!path.isAbsolute(fp))\n throw new Error(t('fp 必须是完整路径'))\n \n const _watcher = fwatchers[fp]\n if (_watcher)\n _watcher.close()\n \n if (exec)\n await onchange('change', fp.fname)\n \n const start = new Date().getTime()\n \n const debounced_onchange = debounce(\n (event, fname) => {\n if (new Date().getTime() - start < 800)\n return\n console.log(t('文件修改 (') + event + '): ' + fname)\n onchange(event, path.normalize(fname))\n },\n 500,\n { leading: false, trailing: true }\n )\n \n let watcher = fs.watch(fp, debounced_onchange)\n watcher.on('error', error => {\n console.error(error)\n })\n return fwatchers[fp] = watcher\n}\n\n\n/** 打开一个文件并搜索替换某个 pattern open a file and replace certain pattern */\nexport async function freplace (fp: string, pattern: string | RegExp, replacement: string) {\n await fwrite(\n fp,\n (await fread(fp))\n .replaceAll(pattern, replacement)\n )\n}\n\n/** 将文件编码转为 UTF-8 convert file encoding to UTF-8\n - fp: 文件完整路径 file absolute path\n - options?:\n - dryrun?: `true`\n - encoding?: `'auto'` */\nexport async function f2utf8 (fp: string, {\n dryrun = true,\n encoding = 'auto',\n}: {\n dryrun?: boolean\n encoding?: Encoding | 'auto'\n} = { }) {\n const text = await fread(fp, { encoding })\n if (dryrun) {\n console.log(text.slice(0, 10000))\n return\n }\n \n const fp_bak = `${fp.fdir}${fp.fname.replace(/(.*?)(\\.[^.]+)?$/, '$1.bak$2')}`\n if (!fexists(fp_bak))\n await fcopy(fp, fp_bak)\n \n await fwrite(fp, text)\n}\n\n"]}
|
package/i18n/dict.json
CHANGED
|
@@ -247,5 +247,17 @@
|
|
|
247
247
|
},
|
|
248
248
|
"已存在文件夹": {
|
|
249
249
|
"en": "folder already exists:"
|
|
250
|
+
},
|
|
251
|
+
" 太短,防止误删文件": {
|
|
252
|
+
"en": " is too short (prevent accidental deletion of files)"
|
|
253
|
+
},
|
|
254
|
+
"异常结束": {
|
|
255
|
+
"en": "exited abnormally"
|
|
256
|
+
},
|
|
257
|
+
"结束": {
|
|
258
|
+
"en": "exited"
|
|
259
|
+
},
|
|
260
|
+
"不能太短,防止误删文件": {
|
|
261
|
+
"en": "can not be too short to prevent accidental deletion of files"
|
|
250
262
|
}
|
|
251
263
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xshell",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"interactive programming"
|
|
17
17
|
],
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=19.
|
|
19
|
+
"node": ">=19.5.0",
|
|
20
20
|
"vscode": ">=1.74.0"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@babel/core": "^7.20.12",
|
|
69
|
-
"@babel/parser": "^7.20.
|
|
70
|
-
"@babel/traverse": "^7.20.
|
|
69
|
+
"@babel/parser": "^7.20.13",
|
|
70
|
+
"@babel/traverse": "^7.20.13",
|
|
71
71
|
"@koa/cors": "^4.0.0",
|
|
72
72
|
"byte-size": "^8.1.0",
|
|
73
73
|
"chalk": "^5.2.0",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"stream-buffers": "^3.0.2",
|
|
104
104
|
"strip-ansi": "^7.0.1",
|
|
105
105
|
"tough-cookie": "^4.1.2",
|
|
106
|
-
"tslib": "^2.
|
|
106
|
+
"tslib": "^2.5.0",
|
|
107
107
|
"typescript": "^4.9.4",
|
|
108
108
|
"upath": "^2.0.1",
|
|
109
109
|
"vinyl": "^3.0.0",
|
|
@@ -125,12 +125,12 @@
|
|
|
125
125
|
"@types/node": "^18.11.18",
|
|
126
126
|
"@types/promise-retry": "^1.1.3",
|
|
127
127
|
"@types/qs": "^6.9.7",
|
|
128
|
-
"@types/react": "^18.0.
|
|
128
|
+
"@types/react": "^18.0.27",
|
|
129
129
|
"@types/request": "^2.48.8",
|
|
130
130
|
"@types/request-promise-native": "^1.0.18",
|
|
131
131
|
"@types/stream-buffers": "^3.0.4",
|
|
132
|
-
"@types/tampermonkey": "^4.0.
|
|
133
|
-
"@types/vinyl-fs": "^
|
|
132
|
+
"@types/tampermonkey": "^4.0.10",
|
|
133
|
+
"@types/vinyl-fs": "^3.0.0",
|
|
134
134
|
"@types/vscode": "^1.74.0",
|
|
135
135
|
"@types/ws": "^8.5.4",
|
|
136
136
|
"source-map-loader": "^4.0.1",
|
package/process.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { type ChildProcess } from 'child_process';
|
|
|
5
5
|
import './prototype.js';
|
|
6
6
|
import { Encoding } from './file.js';
|
|
7
7
|
import { inspect } from './utils.js';
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const exe_nodejs: string;
|
|
9
9
|
interface StartOptions {
|
|
10
10
|
/** `继承当前工作目录 process.cwd()` 子进程的工作目录 `inherit the cwd` cwd of the child process. */
|
|
11
11
|
cwd?: string;
|
|
@@ -53,10 +53,10 @@ export interface CallOptions extends StartOptions {
|
|
|
53
53
|
throw_code?: boolean;
|
|
54
54
|
input?: string;
|
|
55
55
|
}
|
|
56
|
-
export interface CallResult<
|
|
56
|
+
export interface CallResult<TOutput extends string | Buffer = string> {
|
|
57
57
|
pid: number;
|
|
58
|
-
stdout:
|
|
59
|
-
stderr:
|
|
58
|
+
stdout: TOutput;
|
|
59
|
+
stderr: TOutput;
|
|
60
60
|
code: number | null;
|
|
61
61
|
signal: NodeJS.Signals | null;
|
|
62
62
|
child: ChildProcess;
|
|
@@ -68,20 +68,18 @@ export interface CallResult<T = string> {
|
|
|
68
68
|
- options?:
|
|
69
69
|
- cwd?: `'d:/'`
|
|
70
70
|
- env?: `process.env` 覆盖/添加到 process.env 的环境变量 overwrite/add to process.env
|
|
71
|
-
- encoding?: `'utf-8'`
|
|
71
|
+
- encoding?: `'utf-8'` 子进程输出编码, 设置为 binary 时返回 stdout, stderr 类型为 Buffer; 否则是 string
|
|
72
|
+
child output encoding. When set to binary, return stdout, stderr is of type Buffer; otherwise it is string
|
|
72
73
|
- print?: `true` print 选项,支持设置细项 print option (with details)
|
|
73
74
|
- stdio?: `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing
|
|
74
75
|
- input?: string, start 子进程之后写入到子进程 stdin 中的内容 After starting the sub-process, write to the content of the sub-process STDIN
|
|
75
76
|
- detached?: `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref)
|
|
76
|
-
- throw_code?: `true` code 不为 0 时是否抛出异常 whether to throw Error when code is not 0
|
|
77
|
-
*/
|
|
77
|
+
- throw_code?: `true` code 不为 0 时是否抛出异常 whether to throw Error when code is not 0 */
|
|
78
78
|
export declare function call(exe: string, args?: string[]): Promise<CallResult<string>>;
|
|
79
|
-
export declare function call(exe: string, args?: string[], options?: CallOptions & {
|
|
80
|
-
encoding?: 'utf-8' | 'gb18030';
|
|
81
|
-
}): Promise<CallResult<string>>;
|
|
82
79
|
export declare function call(exe: string, args?: string[], options?: CallOptions & {
|
|
83
80
|
encoding: 'binary';
|
|
84
81
|
}): Promise<CallResult<Buffer>>;
|
|
82
|
+
export declare function call(exe: string, args?: string[], options?: CallOptions): Promise<CallResult<string>>;
|
|
85
83
|
/** call node <js> for result
|
|
86
84
|
- js: .js 路径 (相对路径根据 cwd 解析) path (relative path will resolve based on cwd)
|
|
87
85
|
- args: `[]` 参数列表 arguments list
|
|
@@ -92,15 +90,12 @@ export declare function call(exe: string, args?: string[], options?: CallOptions
|
|
|
92
90
|
- print?: `true` print 选项,支持设置细项 print option (with details)
|
|
93
91
|
- stdio?: `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing
|
|
94
92
|
- detached?: `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref)
|
|
95
|
-
- throw_code?: `true` code 不为 0 时是否抛出异常 whether to throw Error when code is not 0
|
|
96
|
-
|
|
97
|
-
export
|
|
98
|
-
encoding?: 'utf-8' | 'gb18030';
|
|
99
|
-
}): Promise<CallResult<string>>;
|
|
100
|
-
interface TermOptions {
|
|
93
|
+
- throw_code?: `true` code 不为 0 时是否抛出异常 whether to throw Error when code is not 0 */
|
|
94
|
+
export declare function call_nodejs(js: string, args?: string[], options?: CallOptions): Promise<CallResult<string>>;
|
|
95
|
+
export interface TermOptions {
|
|
101
96
|
/** `d:/t/` */
|
|
102
97
|
cwd?: string;
|
|
103
|
-
/** `
|
|
98
|
+
/** `true` 打印参数 */
|
|
104
99
|
print?: boolean;
|
|
105
100
|
title?: string;
|
|
106
101
|
}
|
|
@@ -124,5 +119,5 @@ export interface TermNodeOptions extends TermOptions {
|
|
|
124
119
|
trace_warnings?: boolean;
|
|
125
120
|
}
|
|
126
121
|
/** 在 term tab 中创建 node.exe 进程 create the node.exe process in term tab */
|
|
127
|
-
export declare function
|
|
122
|
+
export declare function term_nodejs(fp_js: string, args?: string[], { title, inspect, tsnode, break: _break, resolve, trace_warnings, ..._options }?: TermNodeOptions): Promise<ChildProcess>;
|
|
128
123
|
export {};
|
package/process.js
CHANGED
|
@@ -4,7 +4,7 @@ import iconv from 'iconv-lite';
|
|
|
4
4
|
import { t } from './i18n/instance.js';
|
|
5
5
|
import './prototype.js';
|
|
6
6
|
import { inspect } from './utils.js';
|
|
7
|
-
export const
|
|
7
|
+
export const exe_nodejs = process.execPath.to_slash();
|
|
8
8
|
/** start process
|
|
9
9
|
- exe: .exe 路径或文件名 (建议使用完整路径,跳过 path 搜索,性能更高) path or filename (full path is recommanded to skip path searching for better perf)
|
|
10
10
|
- args: `[]` 参数列表 arguments list
|
|
@@ -36,11 +36,13 @@ export async function start(exe, args = [], { cwd, encoding = 'utf-8', print = t
|
|
|
36
36
|
if (typeof stdio === 'string')
|
|
37
37
|
stdio = [stdio, stdio, stdio];
|
|
38
38
|
if (print.command)
|
|
39
|
-
console.log(((exe
|
|
40
|
-
(args.
|
|
41
|
-
|
|
39
|
+
console.log(((short_exe_names[exe] || (exe.includes(' ') ? exe.quote() : exe)) +
|
|
40
|
+
(args.length ?
|
|
41
|
+
' ' + args.filter(arg => arg !== '--suppressApplicationTitle')
|
|
42
|
+
.map(arg => arg.includes(' ') ? arg.quote() : arg)
|
|
43
|
+
.join(' ')
|
|
42
44
|
:
|
|
43
|
-
|
|
45
|
+
'')).blue);
|
|
44
46
|
if (detached) {
|
|
45
47
|
let child = spawn(exe, args, {
|
|
46
48
|
...options,
|
|
@@ -91,8 +93,9 @@ export async function call(exe, args = [], options = {}) {
|
|
|
91
93
|
};
|
|
92
94
|
if (typeof stdio === 'string')
|
|
93
95
|
stdio = [stdio, stdio, stdio];
|
|
94
|
-
const cmd = (exe.includes(' ') ? exe.quote() : exe) +
|
|
95
|
-
(args.length ? (' ' + args.map(arg => arg.includes(' ') ? arg.quote() : arg)
|
|
96
|
+
const cmd = (short_exe_names[exe] || (exe.includes(' ') ? exe.quote() : exe)) +
|
|
97
|
+
(args.length ? (' ' + args.map(arg => arg.includes(' ') ? arg.quote() : arg)
|
|
98
|
+
.join(' '))
|
|
96
99
|
:
|
|
97
100
|
'');
|
|
98
101
|
if (print.command)
|
|
@@ -133,11 +136,11 @@ export async function call(exe, args = [], options = {}) {
|
|
|
133
136
|
})()
|
|
134
137
|
]);
|
|
135
138
|
const message = `${t('进程')} ${cmd} ` + (code ?
|
|
136
|
-
`(pid: ${child.pid}) ${t('
|
|
139
|
+
`(pid: ${child.pid}) ${throw_code ? t('异常结束') : t('结束')}, code: ${code}${signal ? `, signal: ${signal}` : ''}`
|
|
137
140
|
:
|
|
138
141
|
t('正常结束'));
|
|
139
|
-
if (print.code || code || signal)
|
|
140
|
-
console.log(message[code || signal ? 'red' : 'blue']);
|
|
142
|
+
if (print.code || (throw_code && (code || signal)))
|
|
143
|
+
console.log(message[(throw_code && (code || signal)) ? 'red' : 'blue']);
|
|
141
144
|
const result = {
|
|
142
145
|
pid: child.pid,
|
|
143
146
|
stdout: encoding === 'binary' ?
|
|
@@ -169,10 +172,9 @@ export async function call(exe, args = [], options = {}) {
|
|
|
169
172
|
- print?: `true` print 选项,支持设置细项 print option (with details)
|
|
170
173
|
- stdio?: `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing
|
|
171
174
|
- detached?: `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref)
|
|
172
|
-
- throw_code?: `true` code 不为 0 时是否抛出异常 whether to throw Error when code is not 0
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return call(exe_node, [js, ...args], options);
|
|
175
|
+
- throw_code?: `true` code 不为 0 时是否抛出异常 whether to throw Error when code is not 0 */
|
|
176
|
+
export async function call_nodejs(js, args = [], options) {
|
|
177
|
+
return call(exe_nodejs, [js, ...args], options);
|
|
176
178
|
}
|
|
177
179
|
export const exe_winterm = `C:/Users/${userInfo().username}/AppData/Local/Microsoft/WindowsApps/wt.exe`;
|
|
178
180
|
/** 新建 terminal 窗口执行进程 New Terminal window execution process
|
|
@@ -197,8 +199,8 @@ export function term(exe, args = [], { cwd = 'd:/t/', print = true, title,
|
|
|
197
199
|
});
|
|
198
200
|
}
|
|
199
201
|
/** 在 term tab 中创建 node.exe 进程 create the node.exe process in term tab */
|
|
200
|
-
export async function
|
|
201
|
-
return term(
|
|
202
|
+
export async function term_nodejs(fp_js, args = [], { title, inspect, tsnode = false, break: _break, resolve = false, trace_warnings = false, ..._options } = {}) {
|
|
203
|
+
return term(exe_nodejs, [
|
|
202
204
|
...trace_warnings ? ['--trace-warnings'] : [],
|
|
203
205
|
...resolve ? ['--experimental-specifier-resolution=node'] : [],
|
|
204
206
|
...title ? [`--title=${title}`] : [],
|
|
@@ -216,4 +218,8 @@ export async function term_node(fp_js, args = [], { title, inspect, tsnode = fal
|
|
|
216
218
|
..._options,
|
|
217
219
|
});
|
|
218
220
|
}
|
|
221
|
+
const short_exe_names = {
|
|
222
|
+
[exe_winterm]: 'term',
|
|
223
|
+
[exe_nodejs]: 'node',
|
|
224
|
+
};
|
|
219
225
|
//# sourceMappingURL=process.js.map
|
package/process.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process.js","sourceRoot":"","sources":["process.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EAGR,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAA;AAE7B,OAAO,KAAK,MAAM,YAAY,CAAA;AAE9B,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAEtC,OAAO,gBAAgB,CAAA;AAEvB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAGpC,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAA;AA0CnD;;;;;;;;;;EAUE;AACF,MAAM,CAAC,KAAK,UAAU,KAAK,CAAE,GAAW,EAAE,OAAiB,EAAG,EAAE,EAC5D,GAAG,EAEH,QAAQ,GAAG,OAAO,EAElB,KAAK,GAAG,IAAI,EAEZ,KAAK,GAAG,MAAM,EAEd,QAAQ,GAAG,KAAK,EAEhB,GAAG,EAEH,MAAM,EAAE,OAAO,GAAG,IAAI,MACR,EAAG;IACjB,MAAM,OAAO,GAAiB;QAC1B,GAAG;QACH,KAAK,EAAE,KAAK;QACZ,WAAW,EAAE,CAAC,OAAO;QACrB,KAAK;QACL,GAAI,GAAG,CAAC,CAAC,CAAC;YACN,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE;SAClC,CAAC,CAAC,CAAC,EAAG;KACV,CAAA;IAED,IAAI,OAAO,KAAK,KAAK,SAAS;QAC1B,KAAK,GAAG;YACJ,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,KAAK;SACd,CAA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EAAE;QACC,KAAK;QACL,GAAG,QAAQ;KACd,CAAC,CAAA;AACN,CAAC","sourcesContent":["import {\n spawn,\n type SpawnOptions,\n type ChildProcess\n} from 'child_process'\nimport { Readable } from 'stream'\nimport { userInfo } from 'os'\n\nimport iconv from 'iconv-lite'\n\nimport { t } from './i18n/instance.js'\n\nimport './prototype.js'\nimport { Encoding } from './file.js'\nimport { inspect } from './utils.js'\n\n\nexport const exe_node = process.execPath.to_slash()\n\n\n// ------------------------------------ start & call\ninterface StartOptions {\n /** `继承当前工作目录 process.cwd()` 子进程的工作目录 `inherit the cwd` cwd of the child process. */\n cwd?: string\n \n /** `process.env` 覆盖/添加到 process.env 的环境变量 overwrite/add to process.env */\n env?: Record<string, string>\n \n /** `'utf-8'` 子进程输出编码 child output encoding */\n encoding?: Encoding\n \n /** `true` print 选项,支持设置细项 print option (with details) */\n print?: boolean | {\n stdout: boolean\n stderr: boolean\n command: boolean\n code: boolean\n }\n \n /** `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing */\n stdio?: 'pipe' | 'ignore' | ['pipe' | 'ignore' | 'inherit', 'pipe' | 'ignore' | 'inherit', 'pipe' | 'ignore' | 'inherit']\n \n /** `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref) */\n detached?: boolean\n \n /** 为 true 时会设置 UV_PROCESS_WINDOWS_HIDE \n 然后设置启动进程的参数 CREATE_NO_WINDOW, 和 SW_HIDE \n d:/0/libuv/src/win/process.c \n CREATE_NO_WINDOW:\n The process is a console application that is being run without a console window. \n Therefore, the console handle for the application is not set.\n This flag is ignored if the application is not a console application, or \n if it is used with either CREATE_NEW_CONSOLE or DETACHED_PROCESS.\n \n 具体有什么用还不清楚\n */\n window?: boolean\n}\n\n/** start process \n - exe: .exe 路径或文件名 (建议使用完整路径,跳过 path 搜索,性能更高) path or filename (full path is recommanded to skip path searching for better perf)\n - args: `[]` 参数列表 arguments list\n - options\n - cwd?: `fp_root`\n - env?: `process.env` 覆盖/添加到 process.env 的环境变量 overwrite/add to process.env\n - encoding?: `'utf-8'` 子进程输出编码 child output encoding\n - print?: `true` print 选项,支持设置细项 print option (with details)\n - stdio?: `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing\n - detached?: `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref)\n*/\nexport async function start (exe: string, args: string[] = [ ], {\n cwd,\n \n encoding = 'utf-8',\n \n print = true,\n \n stdio = 'pipe',\n \n detached = false,\n \n env,\n \n window: _window = true,\n}: StartOptions = { }): Promise<ChildProcess> {\n const options: SpawnOptions = {\n cwd,\n shell: false,\n windowsHide: !_window,\n stdio,\n ... env ? {\n env: { ...process.env, ...env }\n } : { },\n }\n \n if (typeof print === 'boolean')\n print = {\n stdout: print,\n stderr: print,\n command: print,\n code: print,\n }\n \n if (typeof stdio === 'string')\n stdio = [stdio, stdio, stdio]\n \n if (print.command)\n console.log((\n (exe === exe_winterm ? 'term.exe' : exe) + ' ' +\n (args.filter(arg => \n arg !== '--suppressApplicationTitle'\n ).map(arg =>\n arg.includes(' ') ? \n arg.quote()\n :\n arg\n ).join(' ')\n )\n ).blue)\n \n if (detached) {\n let child = spawn(exe, args, {\n ...options,\n stdio: 'ignore',\n detached: true,\n })\n \n child.unref()\n return child\n }\n \n let child = spawn(exe, args, options)\n \n // 防止 child spawn 失败时 crash nodejs 进程\n child.on('error', error => {\n console.error(error)\n })\n \n if (stdio[0] === 'pipe')\n child.stdin.setDefaultEncoding('utf8')\n \n if (\n stdio.every(s => \n s === 'ignore')\n )\n return child\n \n if (encoding !== 'binary') {\n if (stdio[1] === 'pipe') {\n if (encoding === 'utf-8')\n child.stdout.setEncoding('utf-8')\n else\n child.stdout = child.stdout.pipe(\n iconv.decodeStream(encoding)\n ) as any as Readable\n \n if (print.stdout)\n child.stdout.pipe(process.stdout, { end: false })\n }\n \n if (stdio[2] === 'pipe') {\n if (encoding === 'utf-8')\n child.stderr.setEncoding('utf-8')\n else\n child.stderr = child.stderr.pipe(\n iconv.decodeStream(encoding)\n ) as any as Readable\n \n if (print.stderr)\n child.stderr.pipe(process.stderr, { end: false })\n }\n }\n \n return child\n}\n\n\nexport interface CallOptions extends StartOptions {\n throw_code?: boolean\n input?: string\n}\n\nexport interface CallResult <T = string> {\n pid: number\n stdout: T\n stderr: T\n code: number | null\n signal: NodeJS.Signals | null\n child: ChildProcess\n [inspect.custom] (): string\n}\n\n\n/** call process for result\n - exe: .exe 路径或文件名 (建议使用路径,跳过 path 搜索,性能更高) path or filename (full path is recommanded to skip path searching for better perf)\n - args: `[]` 参数列表 arguments list\n - options?:\n - cwd?: `'d:/'`\n - env?: `process.env` 覆盖/添加到 process.env 的环境变量 overwrite/add to process.env\n - encoding?: `'utf-8'` 子进程输出编码 child output encoding\n - print?: `true` print 选项,支持设置细项 print option (with details)\n - stdio?: `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing\n - input?: string, start 子进程之后写入到子进程 stdin 中的内容 After starting the sub-process, write to the content of the sub-process STDIN\n - detached?: `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref)\n - throw_code?: `true` code 不为 0 时是否抛出异常 whether to throw Error when code is not 0\n*/\nexport async function call (exe: string, args?: string[]): Promise<CallResult<string>>\nexport async function call (exe: string, args?: string[], options?: CallOptions & { encoding?: 'utf-8' | 'gb18030' }): Promise<CallResult<string>>\nexport async function call (exe: string, args?: string[], options?: CallOptions & { encoding: 'binary' }): Promise<CallResult<Buffer>>\nexport async function call (exe: string, args: string[] = [ ], options: CallOptions = { }): Promise<CallResult<string | Buffer>> {\n const {\n encoding = 'utf-8', \n throw_code = true,\n input,\n } = options\n \n let {\n stdio = 'pipe',\n print = true\n } = options\n \n if (typeof print === 'boolean')\n print = {\n command: print,\n stdout: print,\n stderr: print,\n code: print,\n }\n \n if (typeof stdio === 'string')\n stdio = [stdio, stdio, stdio]\n \n const cmd = \n (exe.includes(' ') ? exe.quote() : exe) + \n (args.length ? (\n ' ' + args.map(arg => \n arg.includes(' ') ? arg.quote() : arg\n ).join(' '))\n :\n '')\n \n if (print.command)\n console.log(cmd.blue)\n \n let child = await start(exe, args, {\n ...options,\n print: false,\n })\n \n if (input)\n child.stdin.write(input)\n \n // --- collect output\n let stdouts: (string | Buffer)[] = [ ]\n let stderrs: (string | Buffer)[] = [ ]\n \n let code: number | null, \n signal: NodeJS.Signals\n \n await Promise.all([\n new Promise<void>(resolve => {\n child.once('exit', (_code, _signal) => {\n code = _code\n signal = _signal\n resolve()\n })\n }),\n (async () => {\n if (stdio[1] === 'pipe')\n for await (const chunk of child.stdout as AsyncIterable<string | Buffer>) {\n if (encoding !== 'binary' && print.stdout)\n process.stdout.write(chunk)\n stdouts.push(chunk)\n }\n })(),\n (async () => {\n if (stdio[2] === 'pipe')\n for await (const chunk of child.stderr as AsyncIterable<string | Buffer>) {\n if (encoding !== 'binary' && print.stderr)\n process.stderr.write(chunk)\n stderrs.push(chunk)\n }\n })()\n ])\n \n const message = `${t('进程')} ${cmd} ` + (\n code ? \n `(pid: ${child.pid}) ${t('异常结束, 错误码:')} ${code}${ signal ? `, ${t('信号:')} ${ signal }` : '' }`\n :\n t('正常结束'))\n \n if (print.code || code || signal)\n console.log(message[code || signal ? 'red' : 'blue'])\n \n const result = {\n pid: child.pid,\n \n stdout: encoding === 'binary' ?\n Buffer.concat(stdouts as Buffer[])\n :\n (stdouts as string[]).join(''),\n \n stderr: encoding === 'binary' ?\n Buffer.concat(stderrs as Buffer[])\n :\n (stderrs as string[]).join(''),\n \n code,\n \n signal,\n \n child,\n \n [inspect.custom] () {\n return inspect(this, { omit: ['child'] })\n }\n }\n \n if (code && throw_code)\n throw Object.assign(\n new Error(message), \n result\n )\n \n return result\n}\n\n\n/** call node <js> for result\n - js: .js 路径 (相对路径根据 cwd 解析) path (relative path will resolve based on cwd)\n - args: `[]` 参数列表 arguments list\n - options\n - cwd?: `'d:/'`\n - env?: `process.env` 覆盖/添加到 process.env 的环境变量 overwrite/add to process.env\n - encoding?: `'utf-8'` 子进程输出编码 child process output encoding\n - print?: `true` print 选项,支持设置细项 print option (with details)\n - stdio?: `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing\n - detached?: `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref)\n - throw_code?: `true` code 不为 0 时是否抛出异常 whether to throw Error when code is not 0\n*/\nexport async function call_node (js: string, args: string[] = [], options?: CallOptions & { encoding?: 'utf-8' | 'gb18030' }) {\n return call(exe_node, [js, ...args], options)\n}\n\n\n// ------------------------------------ term\ninterface TermOptions {\n /** `d:/t/` */\n cwd?: string\n \n /** `false` 打印参数 */\n print?: boolean\n \n title?: string\n \n // 不支持 background, 在 WinTerm 中后台创建标签页,而非创建并切换到该标签页\n // 不支持 icon\n // 不支持 env, WindowsTerminal 在调用 CreateProcess API 时没有传入 env\n}\n\nexport const exe_winterm = `C:/Users/${userInfo().username}/AppData/Local/Microsoft/WindowsApps/wt.exe`\n\n/** 新建 terminal 窗口执行进程 New Terminal window execution process\n - exe: exe 文件路径 exe file path\n - args: 调用参数 call parameter\n - options?: WinTermOptions\n*/\nexport function term (exe: string, args: string[] = [], {\n cwd = 'd:/t/',\n \n print = true,\n \n title,\n \n // env\n}: TermOptions = { }) {\n \n \n return start(\n exe_winterm,\n [\n 'new-tab',\n \n '-d', cwd,\n \n ... title ? ['--suppressApplicationTitle', '--title', title] : [ ],\n \n exe,\n \n ...args.map(arg => \n arg.replaceAll(';', '\\\\;')), \n ],\n {\n print,\n detached: true,\n cwd,\n // env\n }\n )\n}\n\n\nexport interface TermNodeOptions extends TermOptions {\n /** nodejs debugger port */\n inspect?: number\n \n /** break at first line */\n break?: boolean\n \n /** 使用 ts-node 直接运行 use ts-node to run directly */\n tsnode?: boolean\n \n /** `false` --experimental-specifier-resolution=node */\n resolve?: boolean\n \n /** `false` --trace-warnings */\n trace_warnings?: boolean\n}\n\n\n/** 在 term tab 中创建 node.exe 进程 create the node.exe process in term tab */\nexport async function term_node (\n fp_js: string, \n args: string[] = [ ],\n {\n title, \n inspect, \n tsnode = false,\n break: _break,\n resolve = false,\n trace_warnings = false,\n ..._options\n }: TermNodeOptions = { }\n) {\n return term(exe_node, [\n ... trace_warnings ? ['--trace-warnings'] : [ ],\n ... resolve ? ['--experimental-specifier-resolution=node'] : [ ],\n ... title ? [`--title=${title}`] : [ ],\n ... inspect ? [\n _break ? `--inspect-brk=0.0.0.0:${inspect}` : `--inspect=0.0.0.0:${inspect}`\n ] : [ ],\n ... tsnode ? [\n '--loader=ts-node/esm',\n '--experimental-specifier-resolution=node'\n ] : [ ],\n fp_js,\n ... args\n ], {\n title,\n ..._options,\n })\n}\n\n\n\n"]}
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["process.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EAGR,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAA;AAE7B,OAAO,KAAK,MAAM,YAAY,CAAA;AAE9B,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAEtC,OAAO,gBAAgB,CAAA;AAEvB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAGpC,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAA;AA0CrD;;;;;;;;;;EAUE;AACF,MAAM,CAAC,KAAK,UAAU,KAAK,CAAE,GAAW,EAAE,OAAiB,EAAG,EAAE,EAC5D,GAAG,EAEH,QAAQ,GAAG,OAAO,EAElB,KAAK,GAAG,IAAI,EAEZ,KAAK,GAAG,MAAM,EAEd,QAAQ,GAAG,KAAK,EAEhB,GAAG,EAEH,MAAM,EAAE,OAAO,GAAG,IAAI,MACR,EAAG;IACjB,MAAM,OAAO,GAAiB;QAC1B,GAAG;QAC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K,EAAE,MAAM,EACb,OAAO,GAAG,KAAK,EACf,cAAc,GAAG,KAAK,EACtB,GAAG,QAAQ,KACM,EAAG;IAExB,OAAO,IAAI,CAAC,UAAU,EAAE;QACpB,GAAI,cAAc,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAAG;QAC/C,GAAI,OAAO,CAAC,CAAC,CAAC,CAAC,0CAA0C,CAAC,CAAC,CAAC,CAAC,EAAG;QAChE,GAAI,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAG;QACtC,GAAI,OAAO,CAAC,CAAC,CAAC;YACV,MAAM,CAAC,CAAC,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAC,CAAC,qBAAqB,OAAO,EAAE;SAC/E,CAAC,CAAC,CAAC,EAAG;QACP,GAAI,MAAM,CAAC,CAAC,CAAC;YACT,sBAAsB;YACtB,0CAA0C;SAC7C,CAAC,CAAC,CAAC,EAAG;QACP,KAAK;QACL,GAAI,IAAI;KACX,EAAE;QACC,KAAK;QACL,GAAG,QAAQ;KACd,CAAC,CAAA;AACN,CAAC;AAGD,MAAM,eAAe,GAAG;IACpB,CAAC,WAAW,CAAC,EAAE,MAAM;IACrB,CAAC,UAAU,CAAC,EAAE,MAAM;CACd,CAAA","sourcesContent":["import {\n spawn,\n type SpawnOptions,\n type ChildProcess\n} from 'child_process'\nimport { Readable } from 'stream'\nimport { userInfo } from 'os'\n\nimport iconv from 'iconv-lite'\n\nimport { t } from './i18n/instance.js'\n\nimport './prototype.js'\nimport { Encoding } from './file.js'\nimport { inspect } from './utils.js'\n\n\nexport const exe_nodejs = process.execPath.to_slash()\n\n\n// ------------------------------------ start & call\ninterface StartOptions {\n /** `继承当前工作目录 process.cwd()` 子进程的工作目录 `inherit the cwd` cwd of the child process. */\n cwd?: string\n \n /** `process.env` 覆盖/添加到 process.env 的环境变量 overwrite/add to process.env */\n env?: Record<string, string>\n \n /** `'utf-8'` 子进程输出编码 child output encoding */\n encoding?: Encoding\n \n /** `true` print 选项,支持设置细项 print option (with details) */\n print?: boolean | {\n stdout: boolean\n stderr: boolean\n command: boolean\n code: boolean\n }\n \n /** `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing */\n stdio?: 'pipe' | 'ignore' | ['pipe' | 'ignore' | 'inherit', 'pipe' | 'ignore' | 'inherit', 'pipe' | 'ignore' | 'inherit']\n \n /** `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref) */\n detached?: boolean\n \n /** 为 true 时会设置 UV_PROCESS_WINDOWS_HIDE \n 然后设置启动进程的参数 CREATE_NO_WINDOW, 和 SW_HIDE \n d:/0/libuv/src/win/process.c \n CREATE_NO_WINDOW:\n The process is a console application that is being run without a console window. \n Therefore, the console handle for the application is not set.\n This flag is ignored if the application is not a console application, or \n if it is used with either CREATE_NEW_CONSOLE or DETACHED_PROCESS.\n \n 具体有什么用还不清楚\n */\n window?: boolean\n}\n\n/** start process \n - exe: .exe 路径或文件名 (建议使用完整路径,跳过 path 搜索,性能更高) path or filename (full path is recommanded to skip path searching for better perf)\n - args: `[]` 参数列表 arguments list\n - options\n - cwd?: `fp_root`\n - env?: `process.env` 覆盖/添加到 process.env 的环境变量 overwrite/add to process.env\n - encoding?: `'utf-8'` 子进程输出编码 child output encoding\n - print?: `true` print 选项,支持设置细项 print option (with details)\n - stdio?: `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing\n - detached?: `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref)\n*/\nexport async function start (exe: string, args: string[] = [ ], {\n cwd,\n \n encoding = 'utf-8',\n \n print = true,\n \n stdio = 'pipe',\n \n detached = false,\n \n env,\n \n window: _window = true,\n}: StartOptions = { }): Promise<ChildProcess> {\n const options: SpawnOptions = {\n cwd,\n shell: false,\n windowsHide: !_window,\n stdio,\n ... env ? {\n env: { ...process.env, ...env }\n } : { },\n }\n \n if (typeof print === 'boolean')\n print = {\n stdout: print,\n stderr: print,\n command: print,\n code: print,\n }\n \n if (typeof stdio === 'string')\n stdio = [stdio, stdio, stdio]\n \n if (print.command)\n console.log((\n (short_exe_names[exe] || (exe.includes(' ') ? exe.quote() : exe)) +\n (args.length ? \n ' ' + args.filter(arg => arg !== '--suppressApplicationTitle')\n .map(arg => arg.includes(' ') ? arg.quote() : arg)\n .join(' ')\n :\n '')\n ).blue)\n \n if (detached) {\n let child = spawn(exe, args, {\n ...options,\n stdio: 'ignore',\n detached: true,\n })\n \n child.unref()\n return child\n }\n \n let child = spawn(exe, args, options)\n \n // 防止 child spawn 失败时 crash nodejs 进程\n child.on('error', error => {\n console.error(error)\n })\n \n if (stdio[0] === 'pipe')\n child.stdin.setDefaultEncoding('utf8')\n \n if (\n stdio.every(s => \n s === 'ignore')\n )\n return child\n \n if (encoding !== 'binary') {\n if (stdio[1] === 'pipe') {\n if (encoding === 'utf-8')\n child.stdout.setEncoding('utf-8')\n else\n child.stdout = child.stdout.pipe(\n iconv.decodeStream(encoding)\n ) as any as Readable\n \n if (print.stdout)\n child.stdout.pipe(process.stdout, { end: false })\n }\n \n if (stdio[2] === 'pipe') {\n if (encoding === 'utf-8')\n child.stderr.setEncoding('utf-8')\n else\n child.stderr = child.stderr.pipe(\n iconv.decodeStream(encoding)\n ) as any as Readable\n \n if (print.stderr)\n child.stderr.pipe(process.stderr, { end: false })\n }\n }\n \n return child\n}\n\n\nexport interface CallOptions extends StartOptions {\n throw_code?: boolean\n input?: string\n}\n\nexport interface CallResult <TOutput extends string | Buffer = string> {\n pid: number\n stdout: TOutput\n stderr: TOutput\n code: number | null\n signal: NodeJS.Signals | null\n child: ChildProcess\n [inspect.custom] (): string\n}\n\n\n/** call process for result\n - exe: .exe 路径或文件名 (建议使用路径,跳过 path 搜索,性能更高) path or filename (full path is recommanded to skip path searching for better perf)\n - args: `[]` 参数列表 arguments list\n - options?:\n - cwd?: `'d:/'`\n - env?: `process.env` 覆盖/添加到 process.env 的环境变量 overwrite/add to process.env\n - encoding?: `'utf-8'` 子进程输出编码, 设置为 binary 时返回 stdout, stderr 类型为 Buffer; 否则是 string \n child output encoding. When set to binary, return stdout, stderr is of type Buffer; otherwise it is string\n - print?: `true` print 选项,支持设置细项 print option (with details)\n - stdio?: `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing\n - input?: string, start 子进程之后写入到子进程 stdin 中的内容 After starting the sub-process, write to the content of the sub-process STDIN\n - detached?: `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref)\n - throw_code?: `true` code 不为 0 时是否抛出异常 whether to throw Error when code is not 0 */\nexport async function call (exe: string, args?: string[]): Promise<CallResult<string>>\nexport async function call (exe: string, args?: string[], options?: CallOptions & { encoding: 'binary' }): Promise<CallResult<Buffer>>\nexport async function call (exe: string, args?: string[], options?: CallOptions): Promise<CallResult<string>>\nexport async function call (exe: string, args: string[] = [ ], options: CallOptions = { }): Promise<CallResult<string | Buffer>> {\n const {\n encoding = 'utf-8', \n throw_code = true,\n input,\n } = options\n \n let {\n stdio = 'pipe',\n print = true\n } = options\n \n if (typeof print === 'boolean')\n print = {\n command: print,\n stdout: print,\n stderr: print,\n code: print,\n }\n \n if (typeof stdio === 'string')\n stdio = [stdio, stdio, stdio]\n \n const cmd = \n (short_exe_names[exe] || (exe.includes(' ') ? exe.quote() : exe)) + \n (args.length ? (\n ' ' + args.map(arg => arg.includes(' ') ? arg.quote() : arg)\n .join(' '))\n :\n '')\n \n if (print.command)\n console.log(cmd.blue)\n \n let child = await start(exe, args, {\n ...options,\n print: false,\n })\n \n if (input)\n child.stdin.write(input)\n \n // --- collect output\n let stdouts: (string | Buffer)[] = [ ]\n let stderrs: (string | Buffer)[] = [ ]\n \n let code: number | null, \n signal: NodeJS.Signals\n \n await Promise.all([\n new Promise<void>(resolve => {\n child.once('exit', (_code, _signal) => {\n code = _code\n signal = _signal\n resolve()\n })\n }),\n (async () => {\n if (stdio[1] === 'pipe')\n for await (const chunk of child.stdout as AsyncIterable<string | Buffer>) {\n if (encoding !== 'binary' && print.stdout)\n process.stdout.write(chunk)\n stdouts.push(chunk)\n }\n })(),\n (async () => {\n if (stdio[2] === 'pipe')\n for await (const chunk of child.stderr as AsyncIterable<string | Buffer>) {\n if (encoding !== 'binary' && print.stderr)\n process.stderr.write(chunk)\n stderrs.push(chunk)\n }\n })()\n ])\n \n const message = `${t('进程')} ${cmd} ` + (\n code ? \n `(pid: ${child.pid}) ${ throw_code ? t('异常结束') : t('结束') }, code: ${code}${ signal ? `, signal: ${ signal }` : '' }`\n :\n t('正常结束'))\n \n if (print.code || (throw_code && (code || signal)))\n console.log(message[(throw_code && (code || signal)) ? 'red' : 'blue'])\n \n const result = {\n pid: child.pid,\n \n stdout: encoding === 'binary' ?\n Buffer.concat(stdouts as Buffer[])\n :\n (stdouts as string[]).join(''),\n \n stderr: encoding === 'binary' ?\n Buffer.concat(stderrs as Buffer[])\n :\n (stderrs as string[]).join(''),\n \n code,\n \n signal,\n \n child,\n \n [inspect.custom] () {\n return inspect(this, { omit: ['child'] })\n }\n }\n \n if (code && throw_code)\n throw Object.assign(\n new Error(message), \n result\n )\n \n return result\n}\n\n\n/** call node <js> for result\n - js: .js 路径 (相对路径根据 cwd 解析) path (relative path will resolve based on cwd)\n - args: `[]` 参数列表 arguments list\n - options\n - cwd?: `'d:/'`\n - env?: `process.env` 覆盖/添加到 process.env 的环境变量 overwrite/add to process.env\n - encoding?: `'utf-8'` 子进程输出编码 child process output encoding\n - print?: `true` print 选项,支持设置细项 print option (with details)\n - stdio?: `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing\n - detached?: `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref)\n - throw_code?: `true` code 不为 0 时是否抛出异常 whether to throw Error when code is not 0 */\nexport async function call_nodejs (js: string, args: string[] = [], options?: CallOptions) {\n return call(exe_nodejs, [js, ...args], options)\n}\n\n\n// ------------------------------------ term\nexport interface TermOptions {\n /** `d:/t/` */\n cwd?: string\n \n /** `true` 打印参数 */\n print?: boolean\n \n title?: string\n \n // 不支持 background, 在 WinTerm 中后台创建标签页,而非创建并切换到该标签页\n // 不支持 icon\n // 不支持 env, WindowsTerminal 在调用 CreateProcess API 时没有传入 env\n}\n\nexport const exe_winterm = `C:/Users/${userInfo().username}/AppData/Local/Microsoft/WindowsApps/wt.exe`\n\n/** 新建 terminal 窗口执行进程 New Terminal window execution process\n - exe: exe 文件路径 exe file path\n - args: 调用参数 call parameter\n - options?: WinTermOptions\n*/\nexport function term (exe: string, args: string[] = [], {\n cwd = 'd:/t/',\n \n print = true,\n \n title,\n \n // env\n}: TermOptions = { }) {\n \n \n return start(\n exe_winterm,\n [\n 'new-tab',\n \n '-d', cwd,\n \n ... title ? ['--suppressApplicationTitle', '--title', title] : [ ],\n \n exe,\n \n ...args.map(arg => \n arg.replaceAll(';', '\\\\;')), \n ],\n {\n print,\n detached: true,\n cwd,\n // env\n }\n )\n}\n\n\nexport interface TermNodeOptions extends TermOptions {\n /** nodejs debugger port */\n inspect?: number\n \n /** break at first line */\n break?: boolean\n \n /** 使用 ts-node 直接运行 use ts-node to run directly */\n tsnode?: boolean\n \n /** `false` --experimental-specifier-resolution=node */\n resolve?: boolean\n \n /** `false` --trace-warnings */\n trace_warnings?: boolean\n}\n\n\n/** 在 term tab 中创建 node.exe 进程 create the node.exe process in term tab */\nexport async function term_nodejs (\n fp_js: string, \n args: string[] = [ ],\n {\n title, \n inspect, \n tsnode = false,\n break: _break,\n resolve = false,\n trace_warnings = false,\n ..._options\n }: TermNodeOptions = { }\n) {\n return term(exe_nodejs, [\n ... trace_warnings ? ['--trace-warnings'] : [ ],\n ... resolve ? ['--experimental-specifier-resolution=node'] : [ ],\n ... title ? [`--title=${title}`] : [ ],\n ... inspect ? [\n _break ? `--inspect-brk=0.0.0.0:${inspect}` : `--inspect=0.0.0.0:${inspect}`\n ] : [ ],\n ... tsnode ? [\n '--loader=ts-node/esm',\n '--experimental-specifier-resolution=node'\n ] : [ ],\n fp_js,\n ... args\n ], {\n title,\n ..._options,\n })\n}\n\n\nconst short_exe_names = {\n [exe_winterm]: 'term',\n [exe_nodejs]: 'node',\n} as const\n\n"]}
|
package/prototype.d.ts
CHANGED
package/prototype.js
CHANGED
|
@@ -318,7 +318,7 @@ if (!global.my_prototype_defined) {
|
|
|
318
318
|
return dir.endsWith('/') ? dir : `${dir}/`;
|
|
319
319
|
},
|
|
320
320
|
fname() {
|
|
321
|
-
return path.basename(this)
|
|
321
|
+
return `${path.basename(this)}${this.endsWith('/') ? '/' : ''}`;
|
|
322
322
|
},
|
|
323
323
|
fext() {
|
|
324
324
|
return path.extname(this);
|
package/prototype.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prototype.js","sourceRoot":"","sources":["prototype.ts"],"names":[],"mappings":"AA4OA,OAAO,IAAI,MAAM,OAAO,CAAA;AACxB,OAAO,SAAS,MAAM,WAAW,CAAA;AAEjC,OAAO,UAAU,MAAM,aAAa,CAAA;AAEpC,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,KAAK,CAAC,KAAK,GAAG,CAAC,CAAA;AAEf,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAGtC,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,EAAE,CAAA;AAEvC,OAAO,EAAE,KAAK,EAAE,CAAA;AAEhB,MAAM,UAAU,8BAA8B,CAAE,OAAqC;IACjF,OAAO,MAAM,CAAC,WAAW,CACrB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SAClB,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;YAC5B,YAAY,EAAE,IAAI;YAClB,QAAQ,E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AAM,CAAC;YAC5C,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,MAAM,CAAC;YAE5C,kBAAkB;YAClB,CAAC,OAAO,IAAI,SAAS,IAAI,SAAS,IAAI,OAAO,CAAC;YAE9C,kCAAkC;YAClC,CAAC,OAAO,IAAI,SAAS,IAAI,SAAS,IAAI,OAAO,CAAC;YAE9C,mEAAmE;YACnE,CAAC,OAAO,IAAI,SAAS,IAAI,SAAS,IAAI,OAAO,CAAC,CACjD,CACJ,CAAA;AACL,CAAC","sourcesContent":["declare global {\n var my_prototype_defined: boolean\n \n interface String {\n readonly width: number\n \n // --- 工具方法\n /** 截取字符串不超过 width 显示宽度的部分,并保留颜色 \n 找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted \n 若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + … \n 否则 返回 this \n */\n truncate (this: string, width: number): string\n \n /** pad string to `<width>` \n - character?: `' '`\n - position?: `'right'`\n */\n pad (this: string, width: number, { character, position }?: { character?: string, position?: 'left' | 'right'}): string\n \n limit (this: string, width: number, { character, position }?: { character?: string, position?: 'left' | 'right'}): string\n \n to_regexp (this: string, preservations?: string, flags?: string): RegExp\n \n to_bool (this: string): boolean\n \n /** 字符串模式替换 \n - pattern: 匹配部分的格式\n - pattern_: 替换后的格式\n - preservations?: `''` 保留的正则表达式字符\n - flags?: `''` 正则匹配选项\n - transformer?: `(name, matched) => matched || ''` placeholder transformer\n - pattern_placeholder?: `/\\{.*?\\}/g`\n \n ```ts\n 'g:/acgn/海贼王/[Skytree][海贼王][One_Piece][893][GB_BIG5_JP][X264_AAC][1080P][CRRIP][天空树双语字幕组].mkv'.refmt( \n '{dirp}/[Skytree][海贼王][{ en_name: \\\\w+ }][{ episode: \\\\d+ }][GB_BIG5_JP][{encoding}_AAC][1080P][CRRIP][天空树双语字幕组].{format}', \n 'g:/acgn/海贼王/{episode} {encoding}.{format}', \n '\\\\+', \n 'i', \n (name, value) => name === 'episode' ? String(+value + 1) : value.toLowerCase() \n )\n ```\n */\n refmt ( this: string,\n pattern: string,\n \n pattern_: string,\n \n preservations?: string,\n \n flags?: string,\n \n transformer?: (name: string, value: string, placeholders: { [name: string]: string }) => string,\n \n pattern_placeholder?: RegExp\n \n ): string\n \n \n /** 字符串模式搜索\n ```ts\n 'git+https://github.com/tamino-martinius/node-ts-dedent-123.git'.find(\n '^{protocol:[\\\\w+]+}://{hostname:[\\\\w\\\\.]+}/{username}/{project}-{index:\\\\d+}.{suffix}', '^', 'i'\n )\n {\n protocol: 'git+https',\n hostname: 'github.com',\n ...\n }\n ```\n \n - preservations?: `''` 保留的正则表达式字符\n - flags?: `''` 正则匹配选项\n - pattern_placeholder?: `/\\{.*?\\}/g`\n */\n find (this: string,\n \n pattern: string, \n \n preservations?: string, \n \n flags?: string, \n \n pattern_placeholder?: RegExp\n \n ): Record<string, string>\n \n \n /** - type?: `'single'` */\n quote (this: string, type?: keyof typeof quotes | 'psh'): string\n \n /** - shape?: `'parenthesis'` */\n bracket (this: string, shape?: keyof typeof brackets): string\n \n surround (this: string, left: string, right?: string): string\n \n surround_tag (this: string, tag_name: string): string\n \n to_lf (this: string): string\n \n to_crlf (this: string): string\n \n /** 'xxx'.replace(/pattern/g, '') \n 如果 pattern 是 string 则在创建 RegExp 时自动加上 flags (默认 'g'), 否则忽略 flags\n */\n rm (this: string, pattern: string | RegExp, flags?: string): string\n \n \n // --- chalk colors\n readonly red: string\n readonly red_: string\n \n readonly green: string\n readonly green_: string\n \n readonly yellow: string\n readonly yellow_: string\n \n readonly blue: string\n readonly blue_: string\n \n readonly magenta: string\n readonly magenta_: string\n \n readonly cyan: string\n readonly cyan_: string\n \n readonly grey: string\n \n readonly underline: string\n \n strip_ansi (this: string): string\n \n \n // --- 文本处理\n /** 将 string 划分为行,并去掉最后一个 \\n 之后的 '' */\n split_lines (this: string): string[]\n \n trim_doc_comment (this: string): string\n \n split_indent (this: string): { indent: number, text: string }\n \n \n to_base64 (this: string): string\n \n \n /** - buffer: `false` 直接返回 Buffer */\n decode_base64 (this: string): string\n decode_base64 (this: string, buffer: true): Buffer\n decode_base64 (this: string, buffer?: boolean): string | Buffer\n \n \n space (this: string): string\n \n \n // --- 文件路径操作\n fdir: string\n \n /** path.basename, 如: \n - d:/0/aaa.txt -> aaa.txt\n - d:/aaa/ -> aaa\n */\n fname: string\n \n /** .txt */\n fext: string\n \n to_slash (this: string): string\n \n to_backslash (this: string): string\n }\n \n \n interface Date {\n /** - ms?: `false` 显示到 ms */\n to_str (this: Date, ms?: boolean): string\n \n to_date_str (this: Date): string\n \n /** - ms?: `false` 显示到 ms */\n to_time_str (this: Date, ms?: boolean): string\n }\n \n \n interface Number {\n /** 12.4 KB (1 KB = 1024 B) */\n to_fsize_str (this: number, units?: 'iec' | 'metric'): string\n \n \n to_bin_str (this: number): string\n \n to_hex_str (this: number, length?: number): string\n \n to_oct_str (this: number): string\n }\n \n \n interface Array<T> {\n last: T\n \n log (this: string[], limit?: number): void\n \n indent (this: string[], width: number, c?: string): string[]\n \n indent2to4 (this: string[]): string[]\n \n \n // --- 文本处理\n /**\n - trim_line?: `true`\n - rm_empty_lines?: `true`\n - rm_last_empty_lines?: `false`\n */\n trim_lines (this: string[], { trim_line, rm_empty_lines, rm_last_empty_lines }?: { trim_line?: boolean, rm_empty_lines?: boolean, rm_last_empty_lines?: boolean }): string[]\n \n trim_license (this: string[]): string[]\n \n split_indents (this: string[]): { indent: number, text: string }[]\n \n /** - append?: `true` 是否在 join 之后增加 \\n */\n join_lines (append?: boolean): string\n }\n \n \n interface BigInt {\n toJSON (this: bigint): string\n }\n \n \n interface Error {\n toJSON (this: Error): string\n }\n}\n\n\nimport path from 'upath'\nimport byte_size from 'byte-size'\n\nimport EmojiRegex from 'emoji-regex'\n\nimport strip_ansi from 'strip-ansi'\nimport chalk from 'chalk'\nchalk.level = 2\n\nimport { t } from './i18n/instance.js'\n\n\nexport const emoji_regex = EmojiRegex()\n\nexport { chalk }\n\nexport function to_method_property_descriptors (methods: { [name: string]: Function }): PropertyDescriptorMap {\n return Object.fromEntries(\n Object.entries(methods)\n .map(([name, value]) => ([name, {\n configurable: true,\n writable: true,\n enumerable: false,\n value,\n } as PropertyDescriptor])\n ))\n}\n\n\nexport function to_getter_property_descriptors (getters: { [name: string]: Function }): PropertyDescriptorMap {\n return Object.fromEntries(\n Object.entries(getters)\n .map(([name, get]) => ([name, {\n configurable: true,\n enumerable: false,\n get,\n } as PropertyDescriptor])\n ))\n}\n\n\nexport const cjk = '([\\u2e80-\\u9fff\\uf900-\\ufaff])'\n\nexport const quotes = {\n single: \"'\",\n double: '\"',\n backtick: '`',\n}\n\nexport const brackets = {\n round: ['(', ')'],\n square: ['[', ']'],\n curly: ['{', '}'],\n pointy: ['<', '>'],\n corner: ['「', '」'],\n fat: ['【', '】'],\n tortoise_shell: ['〔', '〕'],\n} as const\n\nconst color_map = Object.fromEntries(\n ['red_', 'green_', 'yellow_', 'blue_', 'magenta_', 'cyan_'].map(color =>\n [color, `${color.slice(0, -1)}Bright`])\n)\n\n\nif (!global.my_prototype_defined) {\n // ------------------------------------ String.prototype\n Object.defineProperties(String.prototype, {\n ... to_getter_property_descriptors({\n width (this: string) {\n const s = strip_ansi(\n this.replace(emoji_regex, ' ')\n )\n let width = 0\n for (let i = 0; i < s.length; i++) {\n const code = s.codePointAt(i)\n \n if (\n (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) || // ignore control characters\n code >= 0x300 && code <= 0x36f // ignore combining characters\n ) continue\n \n // surrogates\n if (code > 0xffff)\n i++\n \n width += is_codepoint_fullwidth(code) ? 2 : 1\n }\n return width\n }\n }),\n \n \n // ------------ 文本处理工具方法\n ... to_method_property_descriptors({\n /** 截取字符串不超过 width 显示宽度的部分,并保留颜色 \n 找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted \n - 若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + … \n - 否则 返回 this \n */\n truncate (this: string, width: number) {\n const color_bak = this.startsWith('\\u001b') ? this.slice(0, 5) : ''\n const s = strip_ansi(this)\n if (width <= 2) return this.slice(0, width)\n let i_fitted = 0\n let fitted_width = 0\n let cur_width = 0\n for (let i = 0; i < s.length; i++) {\n const code = s.codePointAt(i)\n \n if (\n (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) || // Ignore control characters\n code >= 0x300 && code <= 0x36F // Ignore combining characters\n ) continue\n \n // surrogates (codepoint 需要用两个 utf-16 编码单位表示,因此这里跳过第二个编码单位,防止重复计算显示宽度)\n if (code > 0xFFFF)\n i++\n \n const w = is_codepoint_fullwidth(code) ? 2 : 1\n \n if (cur_width + w + 2 <= width) {\n i_fitted = i\n fitted_width += w\n }\n \n cur_width += w\n \n if (cur_width > width) {\n const i_fitted_next = i_fitted + 1\n const t = s.slice(0, i_fitted_next) + ' '.repeat(width - 2 - fitted_width) + '…' \n return color_bak ? color_bak + t + '\\u001b[39m' : t\n }\n }\n return this\n },\n \n \n pad (this: string, width: number, { character = ' ', position = 'right' }: { character?: string, position?: 'left' | 'right'} = { }) {\n const _width = this.width\n if (_width >= width) return this\n if (position === 'right') return this + character.repeat( (width - _width) / character.width )\n return character.repeat(width - _width) + this\n },\n \n \n limit (this: string, width: number, { character = ' ', position = 'right' }: { character?: string, position?: 'left' | 'right'} = { }) {\n return this.pad(width, { character, position }).truncate(width)\n },\n \n \n to_regexp (this: string, preservations: string, flags = ''): RegExp {\n const preserved_chars = new Set(preservations)\n const replace_chars: string = Array.prototype.filter.call('|\\\\{}()[]^$+*?.-', (c: string) => !preserved_chars.has(c))\n .map((c: string) =>\n c === ']' ? '\\\\]' : c\n ).join('')\n \n return new RegExp(\n this.replace(\n new RegExp(`[${replace_chars}]`, 'g'),\n '\\\\$&'\n ), \n flags\n )\n },\n \n \n to_bool (this: string) {\n return this.length && this !== '0' && this.toLowerCase() !== 'false'\n },\n \n refmt (this: string, \n pattern : string,\n pattern_: string,\n preservations: string = '',\n flags = '',\n transformer: (name: string, value: string, placeholders: { [name: string]: string }) => string = (name, value) => value || '',\n pattern_placeholder = /\\{.*?\\}/g,\n ): string {\n // --- 转换 pattern 为 pattern_regx\n let last_end = 0\n \n // placeholder matched group indexes\n let $placeholders: Record<string, number> = { }\n \n let regx_parts = [ ]\n \n function add_part (left: number, right?: number) {\n const part = pattern.slice(left, right)\n if (part)\n regx_parts.push(\n part.to_regexp(preservations).source.bracket()\n )\n }\n \n pattern.replace(pattern_placeholder, ($0, offset) => {\n add_part(last_end, offset)\n last_end = offset + $0.length\n \n const placeholder = $0.slice(1, -1)\n let [placeholder_name, placeholder_pattern] = placeholder.split(':').map(s => s.trim())\n let optional = false\n if (placeholder_name.endsWith('?')) {\n placeholder_name = placeholder_name.slice(0, -1)\n optional = true\n }\n $placeholders[placeholder_name] = regx_parts.push(\n placeholder_pattern ? \n `${placeholder_pattern.bracket()}${optional ? '?' : ''}`\n :\n '(.*?)'\n )\n return ''\n })\n \n add_part(last_end)\n \n // 最后一个 (.*?) 改为贪心匹配,满足 .{suffix} 的需要\n regx_parts = regx_parts.filter(part => part)\n if (regx_parts.last === '(.*?)')\n regx_parts[regx_parts.length - 1] = '(.*)'\n \n const pattern_regx = new RegExp(regx_parts.join(''), flags)\n \n \n // --- 根据 pattern_regx 去匹配原有字符串,获取匹配结果,生成 placeholders 词典\n const matches = pattern_regx.exec(this)\n \n if (!matches) return this\n \n const placeholders = Object.fromEntries(\n Object.entries($placeholders)\n .map(([name, $i]) => [\n [name, matches[$i]],\n [`${name}.before`, matches[$i - 1] || ''],\n [`${name}.after`, matches[$i + 1] || ''],\n ])\n .flat()\n )\n \n \n // --- 转换 pattern_ 为 replacement_str,如果有 transformer 则在遇到 placeholder 时应用\n last_end = 0\n let replacement_parts = [ ]\n \n pattern_.replace(pattern_placeholder, ($0, offset) => {\n replacement_parts.push(\n pattern_.slice(last_end, offset)\n )\n last_end = offset + $0.length\n \n const placeholder_name = $0.slice(1, -1)\n \n replacement_parts.push(\n transformer(placeholder_name, placeholders[placeholder_name], placeholders)\n )\n \n return ''\n })\n replacement_parts.push(\n pattern_.slice(last_end)\n )\n \n return this.replace(pattern_regx, replacement_parts.join(''))\n },\n \n \n find (this: string,\n pattern: string, \n preservations: string = '', \n flags = '', \n pattern_placeholder = /\\{.*?\\}/g\n ): Record<string, string> {\n // --- 转换 pattern 为 pattern_regx\n let last_end = 0\n \n // placeholder matched group index\n let $placeholders: Record<string, number> = { }\n \n let regx_parts = [ ]\n \n function add_part (left: number, right?: number) {\n const part = pattern.slice(left, right)\n if (part)\n regx_parts.push(\n part.to_regexp(preservations).source.bracket()\n )\n }\n \n pattern.replace(pattern_placeholder, ($0, offset) => {\n add_part(last_end, offset)\n last_end = offset + $0.length\n \n const placeholder = $0.slice(1, -1)\n let [placeholder_name, placeholder_pattern] = placeholder.split(':').map(s => s.trim())\n let optional = false\n if (placeholder_name.endsWith('?')) {\n placeholder_name = placeholder_name.slice(0, -1)\n optional = true\n }\n \n $placeholders[placeholder_name] = regx_parts.push(\n placeholder_pattern ? \n `${placeholder_pattern.bracket()}${optional ? '?' : ''}`\n :\n '(.*?)'\n )\n return ''\n })\n \n add_part(last_end)\n \n // 最后一个 (.*?) 改为贪心匹配,满足 .{suffix} 的需要\n regx_parts = regx_parts.filter(part => part)\n if (regx_parts[regx_parts.length - 1] === '(.*?)')\n regx_parts[regx_parts.length - 1] = '(.*)'\n \n const pattern_regx = new RegExp(regx_parts.join(''), flags)\n \n \n // --- 根据 pattern_regx 去匹配原有字符串,获取匹配结果,生成 placeholders 词典\n const matches = pattern_regx.exec(this)\n \n if (!matches) return { }\n \n return Object.fromEntries(\n Object.entries($placeholders)\n .map(([name, $i]) => \n [name, matches[$i] || '']\n )\n )\n },\n \n quote (this: string, type: keyof typeof quotes | 'psh' = 'single') {\n if (type === 'psh')\n return `& ${this.quote()}`\n return this.surround(quotes[type])\n },\n \n \n bracket (this: string, shape: keyof typeof brackets = 'round') {\n return this.surround(...brackets[shape] as [string, string])\n },\n \n \n surround (this: string, left: string, right?: string) {\n return left + this + (right || left)\n },\n \n surround_tag (this: string, tag_name: string): string {\n return '<' + tag_name + '>' + this + '</' + tag_name + '>'\n },\n \n \n to_lf (this: string) {\n return this.replace(/\\r\\n/g, '\\n')\n },\n \n \n to_crlf (this: string) {\n return this.replace(/\\n/g, '\\r\\n')\n },\n \n \n rm (this: string, pattern: string | RegExp, flags: string = 'g') {\n if (typeof pattern === 'string')\n pattern = new RegExp(pattern, flags)\n \n return this.replace(pattern, '')\n },\n \n \n split_lines (this: string, delimiter: string | RegExp = /\\r?\\n/) {\n let lines = this.split(delimiter)\n if (lines.last === '')\n lines.pop()\n return lines\n },\n \n \n split_indent (this: string): { indent: number, text: string } {\n let i = 0\n let indent = 0\n for (; i < this.length; i++)\n if (this[i] === ' ')\n indent += 1\n else if (this[i] === '\\t')\n indent += 4\n else\n break\n \n return {\n indent,\n text: this.slice(i)\n }\n },\n \n \n trim_doc_comment (this: string) {\n return `/** ${this.slice(3, -2).replace(/\\s*\\*\\s*/g, ' ').replace(/@(param|params|return) \\{.*?\\}\\s*/g, '').trim()} */`\n },\n \n \n to_base64 (this: string) {\n return Buffer.from(this).toString('base64')\n },\n \n \n decode_base64 (this: string, buffer = false) {\n const buf = Buffer.from(this, 'base64')\n if (buffer)\n return buf\n return buf.toString()\n },\n \n \n strip_ansi (this: string) {\n return strip_ansi(this)\n },\n \n \n space (this: string) {\n if (!this) return this\n let text_: string\n text_ = this\n .replace(new RegExp(cjk + `(['\"])`, 'g'), '$1 $2')\n .replace(new RegExp(`(['\"])` + cjk, 'g'), '$1 $2')\n \n .replace(/([\"']+)\\s*(.+?)\\s*([\"']+)/g, '$1$2$3')\n \n .replace(new RegExp(cjk + '([\\\\+\\\\-\\\\*\\\\/=&\\\\\\\\\\\\|<>])([A-Za-z0-9])', 'g'), '$1 $2 $3')\n .replace(new RegExp('([A-Za-z0-9])([\\\\+\\\\-\\\\*\\\\/=&\\\\\\\\\\\\|<>])' + cjk, 'g'), '$1 $2 $3')\n \n const text_bak = text_\n \n text_ = text_.replace(new RegExp(cjk + '([\\\\(\\\\[\\\\{<\\u201c]+(.*?)[\\\\)\\\\]\\\\}>\\u201d]+)' + cjk, 'g'), '$1 $2 $4')\n \n if (text_ === text_bak)\n text_ = text_\n .replace(new RegExp(cjk + '([\\\\(\\\\[\\\\{<\\u201c>])', 'g'), '$1 $2')\n .replace(new RegExp('([\\\\)\\\\]\\\\}>\\u201d<])' + cjk, 'g'), '$1 $2')\n \n return text_\n .replace(/([\\(\\[\\{<\\u201c]+)(\\s*)(.+?)(\\s*)([\\)\\]\\}>\\u201d]+)/g, '$1$3$5')\n .replace(new RegExp(cjk + '([~!;:,\\\\.\\\\?\\u2026])([A-Za-z0-9])', 'g'), '$1$2 $3')\n .replace(new RegExp(cjk + '([A-Za-z0-9`\\\\$%\\\\^&\\\\*\\\\-=\\\\+\\\\\\\\\\\\|\\\\/@\\u00a1-\\u00ff\\u2022\\u2027\\u2150-\\u218f])', 'g'), '$1 $2')\n .replace(new RegExp('([A-Za-z0-9`\\\\$%\\\\^&\\\\*\\\\-=\\\\+\\\\\\\\\\\\|\\\\/@\\u00a1-\\u00ff\\u2022\\u2027\\u2150-\\u218f])' + cjk, 'g'), '$1 $2')\n }\n }),\n \n \n // ------------ chalk colors\n ... Object.fromEntries(\n [\n 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'grey', \n 'red_', 'green_', 'yellow_', 'blue_', 'magenta_', 'cyan_',\n 'underline',\n ].map(color =>\n ([color, {\n configurable: true,\n get (this: string) {\n return chalk[color_map[color] || color](this)\n }\n }]))\n ),\n \n \n // ------------ 文件路径操作\n ... to_getter_property_descriptors({\n fdir (this: string) {\n const dir = path.dirname(this)\n return dir.endsWith('/') ? dir : `${dir}/`\n },\n \n fname (this: string) {\n return path.basename(this)\n },\n \n fext (this: string) {\n return path.extname(this)\n },\n }),\n \n ... to_method_property_descriptors({\n to_slash (this: string) {\n if (!this)\n return this\n return path.normalizeSafe(this)\n },\n \n to_backslash (this: string) {\n return this.replaceAll('/', '\\\\')\n },\n })\n })\n \n \n // ------------------------------------ Date.prototype\n Object.defineProperties(Date.prototype, to_method_property_descriptors({\n to_str (this: Date, ms?: boolean) {\n const [ampm, hour] = (() => {\n let hour = this.getHours()\n if (hour <= 6)\n return [t('凌晨'), hour]\n \n if (hour <= 8)\n return [t('清晨'), hour]\n \n if (hour <= 9)\n return [t('早上'), hour]\n \n if (hour <= 10)\n return [t('上午'), hour]\n \n if (hour <= 12)\n return [t('中午'), hour]\n \n hour -= 12\n \n if (hour <= 5)\n return [t('下午'), hour]\n \n if (hour <= 10)\n return [t('晚上'), hour]\n \n return [t('深夜'), hour]\n })()\n \n const zero_padding = { character: '0', position: 'left' } as const\n \n return '' +\n // year.month.date\n this.getFullYear() + '.' + \n String(this.getMonth() + 1).pad(2, zero_padding) + '.' + \n String(this.getDate()).pad(2, zero_padding) + ' ' +\n \n // 上午\n ampm + ' ' +\n \n // 10:03:02\n String(hour).pad(2, zero_padding) + ':' +\n String(this.getMinutes()).pad(2, zero_padding) + ':' +\n String(this.getSeconds()).pad(2, zero_padding) + \n \n (ms ?\n '.' + String(this.getMilliseconds()).pad(3, zero_padding)\n :\n ''\n )\n },\n \n to_date_str (this: Date) {\n return this.to_str().split(' ')[0]\n },\n \n to_time_str (this: Date, ms?: boolean) {\n const [, ampm, time] = this.to_str(ms).split(' ')\n return `${ampm} ${time}`\n },\n }))\n \n \n \n // ------------------------------------ Number.prototype\n Object.defineProperties(Number.prototype, to_method_property_descriptors({\n to_fsize_str (this: number, units: 'iec' | 'metric' = 'iec') {\n const { value, unit } = byte_size(this, { units })\n return `${value} ${unit.replace('i', '')}`\n },\n \n to_bin_str (this: number) {\n return `0b${this.toString(2)}`\n },\n \n to_hex_str (this: number, length?: number) {\n const s = this.toString(16)\n // 长度自动对齐到 4 的倍数\n if (!length)\n length = Math.ceil(s.length / 4) * 4\n return `0x${'0'.repeat(length - s.length)}${s}`\n },\n \n to_oct_str (this: number) {\n return `0o${this.toString(8)}`\n },\n }))\n \n \n \n // ------------------------------------ Array.prototype\n Object.defineProperties(Array.prototype, {\n ... to_getter_property_descriptors({\n last (this: any[]) {\n return this[this.length - 1]\n }\n }),\n \n \n // --- 文本处理工具方法\n ... to_method_property_descriptors({\n log (this: string[], limit: number = 10000) {\n const text = this.join('\\n') + '\\n'\n if (limit === -1 || this.length <= limit)\n console.log(text)\n else if (limit > 0)\n console.log(text.slice(0, limit) + '\\n...'.blue)\n else \n console.log('...\\n'.blue + text.slice(limit))\n },\n \n trim_lines (this: string[], { trim_line = true, rm_empty_lines = true, rm_last_empty_lines = false }: { trim_line?: boolean, rm_empty_lines?: boolean, rm_last_empty_lines?: boolean } = { }) {\n if (!this.length)\n return this\n let lines = this\n \n if (trim_line)\n lines = lines.map(line => line.trim())\n \n if (rm_empty_lines)\n return lines.filter( line => line )\n \n if (rm_last_empty_lines) {\n lines.reverse()\n const i_not_empty = lines.findIndex( line => line )\n if (i_not_empty !== -1)\n lines = lines.slice(i_not_empty)\n lines.reverse()\n return lines\n }\n \n return lines\n },\n \n \n trim_license (this: string[]) {\n const i = this.indexOf('/*')\n const j = this.indexOf('*/')\n if (i === 0 && this[i+1].includes('License'))\n return this.slice(j+1)\n else\n return this\n },\n \n split_indents (this: string[]): { indent: number, text: string }[] {\n return this.map(line => \n line.split_indent()\n )\n },\n \n indent (this: string[], width?: number, character: string = ' ') {\n return this.map(line => \n character.repeat(width) + line\n )\n },\n \n indent2to4 (this: string[]) {\n return this.split_indents()\n .map(line => \n ' '.repeat(\n Math.floor(line.indent / 2) * 4\n ) + line.text\n )\n },\n \n join_lines (this: string[], append = true) {\n return `${this.join('\\n')}${append ? '\\n' : ''}`\n }\n })\n })\n \n \n Object.defineProperties(BigInt.prototype, to_method_property_descriptors({\n toJSON (this: bigint) {\n return this.toString()\n }\n }))\n \n Object.defineProperties(Error.prototype, to_method_property_descriptors({\n toJSON (this: Error) {\n return Object.fromEntries(\n Object.getOwnPropertyNames(this)\n .map(name => \n [name, this[name]])\n )\n }\n }))\n}\n\n\nexport function to_json (obj: any, replacer?: any) {\n return JSON.stringify(obj, replacer, 4) + '\\n'\n}\n\nexport function to_json_safely (obj: any, replacer?: any) {\n return to_json(obj, replacer)\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029')\n .replace(/<\\/script>/g, '<\\\\/script>')\n}\n\n\nexport function is_codepoint_fullwidth (codepoint: number) {\n // code points are derived from:\n // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt\n return (\n !Number.isNaN(codepoint) &&\n codepoint >= 0x1100 &&\n (\n codepoint <= 0x115f || // hangul jamo\n \n codepoint === 0x201c || codepoint === 0x201d || // \n codepoint === 0x2026 || // …\n codepoint === 0x203b || // ※\n \n // arrows\n (0x2190 <= codepoint && codepoint <= 0x21FF) ||\n \n codepoint === 0x2329 || // left-pointing angle bracket\n codepoint === 0x232a || // right-pointing angle bracket\n \n // ①\n (0x2460 <= codepoint && codepoint <= 0x24ff) ||\n \n // box drawing\n (0x2500 <= codepoint && codepoint <= 0x257f) ||\n \n // shapes, symbols, …\n (0x2580 <= codepoint && codepoint <= 0x2bef) ||\n \n // cjk radicals supplement .. enclosed cjk letters and months\n (0x2e80 <= codepoint && codepoint <= 0x3247 && codepoint !== 0x303f) ||\n \n // enclosed cjk letters and months .. cjk unified ideographs extension a\n (0x3250 <= codepoint && codepoint <= 0x4dbf) ||\n \n // cjk unified ideographs .. yi radicals\n (0x4E00 <= codepoint && codepoint <= 0xA4C6) ||\n \n // hangul jamo extended-a\n (0xa960 <= codepoint && codepoint <= 0xa97c) ||\n \n // hangul syllables\n (0xac00 <= codepoint && codepoint <= 0xd7a3) ||\n \n // cjk compatibility ideographs\n (0xf900 <= codepoint && codepoint <= 0xfaff) ||\n \n // vertical forms\n (0xfe10 <= codepoint && codepoint <= 0xfe19) ||\n \n // cjk compatibility forms .. small form variants\n (0xfe30 <= codepoint && codepoint <= 0xfe6b) ||\n \n // halfwidth and fullwidth forms\n (0xff01 <= codepoint && codepoint <= 0xff60) ||\n (0xffe0 <= codepoint && codepoint <= 0xffe6) ||\n \n // kana supplement\n (0x1b000 <= codepoint && codepoint <= 0x1b001) ||\n \n // enclosed ideographic supplement\n (0x1f200 <= codepoint && codepoint <= 0x1f251) ||\n \n // cjk unified ideographs extension b .. tertiary ideographic plane\n (0x20000 <= codepoint && codepoint <= 0x3fffd)\n )\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"prototype.js","sourceRoot":"","sources":["prototype.ts"],"names":[],"mappings":"AA2OA,OAAO,IAAI,MAAM,OAAO,CAAA;AACxB,OAAO,SAAS,MAAM,WAAW,CAAA;AAEjC,OAAO,UAAU,MAAM,aAAa,CAAA;AAEpC,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,KAAK,CAAC,KAAK,GAAG,CAAC,CAAA;AAEf,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAGtC,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,EAAE,CAAA;AAEvC,OAAO,EAAE,KAAK,EAAE,CAAA;AAEhB,MAAM,UAAU,8BAA8B,CAAE,OAAqC;IACjF,OAAO,MAAM,CAAC,WAAW,CACrB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SAClB,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;YAC5B,YAAY,EAAE,IAAI;YAClB,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,KAAK;YACjB,KAAK;SACc,CAAC,CAAC,CAC5B,CAAC,CAAA;AACV,CAAC;AAGD,MAAM,UAAU,8BAA8B,CAAE,OAAqC;IACjF,OAAO,MAAM,CAAC,WAAW,CACrB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SAClB,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,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,IAAI,SAAS,IAAI,OAAO,CAAC;YAE9C,mEAAmE;YACnE,CAAC,OAAO,IAAI,SAAS,IAAI,SAAS,IAAI,OAAO,CAAC,CACjD,CACJ,CAAA;AACL,CAAC","sourcesContent":["declare global {\n var my_prototype_defined: boolean\n \n interface String {\n readonly width: number\n \n // --- 工具方法\n /** 截取字符串不超过 width 显示宽度的部分,并保留颜色 \n 找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted \n 若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + … \n 否则 返回 this \n */\n truncate (this: string, width: number): string\n \n /** pad string to `<width>` \n - character?: `' '`\n - position?: `'right'`\n */\n pad (this: string, width: number, { character, position }?: { character?: string, position?: 'left' | 'right'}): string\n \n limit (this: string, width: number, { character, position }?: { character?: string, position?: 'left' | 'right'}): string\n \n to_regexp (this: string, preservations?: string, flags?: string): RegExp\n \n to_bool (this: string): boolean\n \n /** 字符串模式替换 \n - pattern: 匹配部分的格式\n - pattern_: 替换后的格式\n - preservations?: `''` 保留的正则表达式字符\n - flags?: `''` 正则匹配选项\n - transformer?: `(name, matched) => matched || ''` placeholder transformer\n - pattern_placeholder?: `/\\{.*?\\}/g`\n \n ```ts\n 'g:/acgn/海贼王/[Skytree][海贼王][One_Piece][893][GB_BIG5_JP][X264_AAC][1080P][CRRIP][天空树双语字幕组].mkv'.refmt( \n '{dirp}/[Skytree][海贼王][{ en_name: \\\\w+ }][{ episode: \\\\d+ }][GB_BIG5_JP][{encoding}_AAC][1080P][CRRIP][天空树双语字幕组].{format}', \n 'g:/acgn/海贼王/{episode} {encoding}.{format}', \n '\\\\+', \n 'i', \n (name, value) => name === 'episode' ? String(+value + 1) : value.toLowerCase() \n )\n ```\n */\n refmt ( this: string,\n pattern: string,\n \n pattern_: string,\n \n preservations?: string,\n \n flags?: string,\n \n transformer?: (name: string, value: string, placeholders: { [name: string]: string }) => string,\n \n pattern_placeholder?: RegExp\n \n ): string\n \n \n /** 字符串模式搜索\n ```ts\n 'git+https://github.com/tamino-martinius/node-ts-dedent-123.git'.find(\n '^{protocol:[\\\\w+]+}://{hostname:[\\\\w\\\\.]+}/{username}/{project}-{index:\\\\d+}.{suffix}', '^', 'i'\n )\n {\n protocol: 'git+https',\n hostname: 'github.com',\n ...\n }\n ```\n \n - preservations?: `''` 保留的正则表达式字符\n - flags?: `''` 正则匹配选项\n - pattern_placeholder?: `/\\{.*?\\}/g`\n */\n find (this: string,\n \n pattern: string, \n \n preservations?: string, \n \n flags?: string, \n \n pattern_placeholder?: RegExp\n \n ): Record<string, string>\n \n \n /** - type?: `'single'` */\n quote (this: string, type?: keyof typeof quotes | 'psh'): string\n \n /** - shape?: `'parenthesis'` */\n bracket (this: string, shape?: keyof typeof brackets): string\n \n surround (this: string, left: string, right?: string): string\n \n surround_tag (this: string, tag_name: string): string\n \n to_lf (this: string): string\n \n to_crlf (this: string): string\n \n /** 'xxx'.replace(/pattern/g, '') \n 如果 pattern 是 string 则在创建 RegExp 时自动加上 flags (默认 'g'), 否则忽略 flags\n */\n rm (this: string, pattern: string | RegExp, flags?: string): string\n \n \n // --- chalk colors\n readonly red: string\n readonly red_: string\n \n readonly green: string\n readonly green_: string\n \n readonly yellow: string\n readonly yellow_: string\n \n readonly blue: string\n readonly blue_: string\n \n readonly magenta: string\n readonly magenta_: string\n \n readonly cyan: string\n readonly cyan_: string\n \n readonly grey: string\n \n readonly underline: string\n \n strip_ansi (this: string): string\n \n \n // --- 文本处理\n /** 将 string 划分为行,并去掉最后一个 \\n 之后的 '' */\n split_lines (this: string): string[]\n \n trim_doc_comment (this: string): string\n \n split_indent (this: string): { indent: number, text: string }\n \n \n to_base64 (this: string): string\n \n \n /** - buffer: `false` 直接返回 Buffer */\n decode_base64 (this: string): string\n decode_base64 (this: string, buffer: true): Buffer\n decode_base64 (this: string, buffer?: boolean): string | Buffer\n \n \n space (this: string): string\n \n \n // --- 文件路径操作\n fdir: string\n \n /** path.basename, 如: \n - d:/0/aaa.txt -> aaa.txt\n - d:/aaa/ -> aaa/ */\n fname: string\n \n /** .txt */\n fext: string\n \n to_slash (this: string): string\n \n to_backslash (this: string): string\n }\n \n \n interface Date {\n /** - ms?: `false` 显示到 ms */\n to_str (this: Date, ms?: boolean): string\n \n to_date_str (this: Date): string\n \n /** - ms?: `false` 显示到 ms */\n to_time_str (this: Date, ms?: boolean): string\n }\n \n \n interface Number {\n /** 12.4 KB (1 KB = 1024 B) */\n to_fsize_str (this: number, units?: 'iec' | 'metric'): string\n \n \n to_bin_str (this: number): string\n \n to_hex_str (this: number, length?: number): string\n \n to_oct_str (this: number): string\n }\n \n \n interface Array<T> {\n last: T\n \n log (this: string[], limit?: number): void\n \n indent (this: string[], width: number, c?: string): string[]\n \n indent2to4 (this: string[]): string[]\n \n \n // --- 文本处理\n /**\n - trim_line?: `true`\n - rm_empty_lines?: `true`\n - rm_last_empty_lines?: `false`\n */\n trim_lines (this: string[], { trim_line, rm_empty_lines, rm_last_empty_lines }?: { trim_line?: boolean, rm_empty_lines?: boolean, rm_last_empty_lines?: boolean }): string[]\n \n trim_license (this: string[]): string[]\n \n split_indents (this: string[]): { indent: number, text: string }[]\n \n /** - append?: `true` 是否在 join 之后增加 \\n */\n join_lines (append?: boolean): string\n }\n \n \n interface BigInt {\n toJSON (this: bigint): string\n }\n \n \n interface Error {\n toJSON (this: Error): string\n }\n}\n\n\nimport path from 'upath'\nimport byte_size from 'byte-size'\n\nimport EmojiRegex from 'emoji-regex'\n\nimport strip_ansi from 'strip-ansi'\nimport chalk from 'chalk'\nchalk.level = 2\n\nimport { t } from './i18n/instance.js'\n\n\nexport const emoji_regex = EmojiRegex()\n\nexport { chalk }\n\nexport function to_method_property_descriptors (methods: { [name: string]: Function }): PropertyDescriptorMap {\n return Object.fromEntries(\n Object.entries(methods)\n .map(([name, value]) => ([name, {\n configurable: true,\n writable: true,\n enumerable: false,\n value,\n } as PropertyDescriptor])\n ))\n}\n\n\nexport function to_getter_property_descriptors (getters: { [name: string]: Function }): PropertyDescriptorMap {\n return Object.fromEntries(\n Object.entries(getters)\n .map(([name, get]) => ([name, {\n configurable: true,\n enumerable: false,\n get,\n } as PropertyDescriptor])\n ))\n}\n\n\nexport const cjk = '([\\u2e80-\\u9fff\\uf900-\\ufaff])'\n\nexport const quotes = {\n single: \"'\",\n double: '\"',\n backtick: '`',\n}\n\nexport const brackets = {\n round: ['(', ')'],\n square: ['[', ']'],\n curly: ['{', '}'],\n pointy: ['<', '>'],\n corner: ['「', '」'],\n fat: ['【', '】'],\n tortoise_shell: ['〔', '〕'],\n} as const\n\nconst color_map = Object.fromEntries(\n ['red_', 'green_', 'yellow_', 'blue_', 'magenta_', 'cyan_'].map(color =>\n [color, `${color.slice(0, -1)}Bright`])\n)\n\n\nif (!global.my_prototype_defined) {\n // ------------------------------------ String.prototype\n Object.defineProperties(String.prototype, {\n ... to_getter_property_descriptors({\n width (this: string) {\n const s = strip_ansi(\n this.replace(emoji_regex, ' ')\n )\n let width = 0\n for (let i = 0; i < s.length; i++) {\n const code = s.codePointAt(i)\n \n if (\n (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) || // ignore control characters\n code >= 0x300 && code <= 0x36f // ignore combining characters\n ) continue\n \n // surrogates\n if (code > 0xffff)\n i++\n \n width += is_codepoint_fullwidth(code) ? 2 : 1\n }\n return width\n }\n }),\n \n \n // ------------ 文本处理工具方法\n ... to_method_property_descriptors({\n /** 截取字符串不超过 width 显示宽度的部分,并保留颜色 \n 找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted \n - 若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + … \n - 否则 返回 this \n */\n truncate (this: string, width: number) {\n const color_bak = this.startsWith('\\u001b') ? this.slice(0, 5) : ''\n const s = strip_ansi(this)\n if (width <= 2) return this.slice(0, width)\n let i_fitted = 0\n let fitted_width = 0\n let cur_width = 0\n for (let i = 0; i < s.length; i++) {\n const code = s.codePointAt(i)\n \n if (\n (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) || // Ignore control characters\n code >= 0x300 && code <= 0x36F // Ignore combining characters\n ) continue\n \n // surrogates (codepoint 需要用两个 utf-16 编码单位表示,因此这里跳过第二个编码单位,防止重复计算显示宽度)\n if (code > 0xFFFF)\n i++\n \n const w = is_codepoint_fullwidth(code) ? 2 : 1\n \n if (cur_width + w + 2 <= width) {\n i_fitted = i\n fitted_width += w\n }\n \n cur_width += w\n \n if (cur_width > width) {\n const i_fitted_next = i_fitted + 1\n const t = s.slice(0, i_fitted_next) + ' '.repeat(width - 2 - fitted_width) + '…' \n return color_bak ? color_bak + t + '\\u001b[39m' : t\n }\n }\n return this\n },\n \n \n pad (this: string, width: number, { character = ' ', position = 'right' }: { character?: string, position?: 'left' | 'right'} = { }) {\n const _width = this.width\n if (_width >= width) return this\n if (position === 'right') return this + character.repeat( (width - _width) / character.width )\n return character.repeat(width - _width) + this\n },\n \n \n limit (this: string, width: number, { character = ' ', position = 'right' }: { character?: string, position?: 'left' | 'right'} = { }) {\n return this.pad(width, { character, position }).truncate(width)\n },\n \n \n to_regexp (this: string, preservations: string, flags = ''): RegExp {\n const preserved_chars = new Set(preservations)\n const replace_chars: string = Array.prototype.filter.call('|\\\\{}()[]^$+*?.-', (c: string) => !preserved_chars.has(c))\n .map((c: string) =>\n c === ']' ? '\\\\]' : c\n ).join('')\n \n return new RegExp(\n this.replace(\n new RegExp(`[${replace_chars}]`, 'g'),\n '\\\\$&'\n ), \n flags\n )\n },\n \n \n to_bool (this: string) {\n return this.length && this !== '0' && this.toLowerCase() !== 'false'\n },\n \n refmt (this: string, \n pattern : string,\n pattern_: string,\n preservations: string = '',\n flags = '',\n transformer: (name: string, value: string, placeholders: { [name: string]: string }) => string = (name, value) => value || '',\n pattern_placeholder = /\\{.*?\\}/g,\n ): string {\n // --- 转换 pattern 为 pattern_regx\n let last_end = 0\n \n // placeholder matched group indexes\n let $placeholders: Record<string, number> = { }\n \n let regx_parts = [ ]\n \n function add_part (left: number, right?: number) {\n const part = pattern.slice(left, right)\n if (part)\n regx_parts.push(\n part.to_regexp(preservations).source.bracket()\n )\n }\n \n pattern.replace(pattern_placeholder, ($0, offset) => {\n add_part(last_end, offset)\n last_end = offset + $0.length\n \n const placeholder = $0.slice(1, -1)\n let [placeholder_name, placeholder_pattern] = placeholder.split(':').map(s => s.trim())\n let optional = false\n if (placeholder_name.endsWith('?')) {\n placeholder_name = placeholder_name.slice(0, -1)\n optional = true\n }\n $placeholders[placeholder_name] = regx_parts.push(\n placeholder_pattern ? \n `${placeholder_pattern.bracket()}${optional ? '?' : ''}`\n :\n '(.*?)'\n )\n return ''\n })\n \n add_part(last_end)\n \n // 最后一个 (.*?) 改为贪心匹配,满足 .{suffix} 的需要\n regx_parts = regx_parts.filter(part => part)\n if (regx_parts.last === '(.*?)')\n regx_parts[regx_parts.length - 1] = '(.*)'\n \n const pattern_regx = new RegExp(regx_parts.join(''), flags)\n \n \n // --- 根据 pattern_regx 去匹配原有字符串,获取匹配结果,生成 placeholders 词典\n const matches = pattern_regx.exec(this)\n \n if (!matches) return this\n \n const placeholders = Object.fromEntries(\n Object.entries($placeholders)\n .map(([name, $i]) => [\n [name, matches[$i]],\n [`${name}.before`, matches[$i - 1] || ''],\n [`${name}.after`, matches[$i + 1] || ''],\n ])\n .flat()\n )\n \n \n // --- 转换 pattern_ 为 replacement_str,如果有 transformer 则在遇到 placeholder 时应用\n last_end = 0\n let replacement_parts = [ ]\n \n pattern_.replace(pattern_placeholder, ($0, offset) => {\n replacement_parts.push(\n pattern_.slice(last_end, offset)\n )\n last_end = offset + $0.length\n \n const placeholder_name = $0.slice(1, -1)\n \n replacement_parts.push(\n transformer(placeholder_name, placeholders[placeholder_name], placeholders)\n )\n \n return ''\n })\n replacement_parts.push(\n pattern_.slice(last_end)\n )\n \n return this.replace(pattern_regx, replacement_parts.join(''))\n },\n \n \n find (this: string,\n pattern: string, \n preservations: string = '', \n flags = '', \n pattern_placeholder = /\\{.*?\\}/g\n ): Record<string, string> {\n // --- 转换 pattern 为 pattern_regx\n let last_end = 0\n \n // placeholder matched group index\n let $placeholders: Record<string, number> = { }\n \n let regx_parts = [ ]\n \n function add_part (left: number, right?: number) {\n const part = pattern.slice(left, right)\n if (part)\n regx_parts.push(\n part.to_regexp(preservations).source.bracket()\n )\n }\n \n pattern.replace(pattern_placeholder, ($0, offset) => {\n add_part(last_end, offset)\n last_end = offset + $0.length\n \n const placeholder = $0.slice(1, -1)\n let [placeholder_name, placeholder_pattern] = placeholder.split(':').map(s => s.trim())\n let optional = false\n if (placeholder_name.endsWith('?')) {\n placeholder_name = placeholder_name.slice(0, -1)\n optional = true\n }\n \n $placeholders[placeholder_name] = regx_parts.push(\n placeholder_pattern ? \n `${placeholder_pattern.bracket()}${optional ? '?' : ''}`\n :\n '(.*?)'\n )\n return ''\n })\n \n add_part(last_end)\n \n // 最后一个 (.*?) 改为贪心匹配,满足 .{suffix} 的需要\n regx_parts = regx_parts.filter(part => part)\n if (regx_parts[regx_parts.length - 1] === '(.*?)')\n regx_parts[regx_parts.length - 1] = '(.*)'\n \n const pattern_regx = new RegExp(regx_parts.join(''), flags)\n \n \n // --- 根据 pattern_regx 去匹配原有字符串,获取匹配结果,生成 placeholders 词典\n const matches = pattern_regx.exec(this)\n \n if (!matches) return { }\n \n return Object.fromEntries(\n Object.entries($placeholders)\n .map(([name, $i]) => \n [name, matches[$i] || '']\n )\n )\n },\n \n quote (this: string, type: keyof typeof quotes | 'psh' = 'single') {\n if (type === 'psh')\n return `& ${this.quote()}`\n return this.surround(quotes[type])\n },\n \n \n bracket (this: string, shape: keyof typeof brackets = 'round') {\n return this.surround(...brackets[shape] as [string, string])\n },\n \n \n surround (this: string, left: string, right?: string) {\n return left + this + (right || left)\n },\n \n surround_tag (this: string, tag_name: string): string {\n return '<' + tag_name + '>' + this + '</' + tag_name + '>'\n },\n \n \n to_lf (this: string) {\n return this.replace(/\\r\\n/g, '\\n')\n },\n \n \n to_crlf (this: string) {\n return this.replace(/\\n/g, '\\r\\n')\n },\n \n \n rm (this: string, pattern: string | RegExp, flags: string = 'g') {\n if (typeof pattern === 'string')\n pattern = new RegExp(pattern, flags)\n \n return this.replace(pattern, '')\n },\n \n \n split_lines (this: string, delimiter: string | RegExp = /\\r?\\n/) {\n let lines = this.split(delimiter)\n if (lines.last === '')\n lines.pop()\n return lines\n },\n \n \n split_indent (this: string): { indent: number, text: string } {\n let i = 0\n let indent = 0\n for (; i < this.length; i++)\n if (this[i] === ' ')\n indent += 1\n else if (this[i] === '\\t')\n indent += 4\n else\n break\n \n return {\n indent,\n text: this.slice(i)\n }\n },\n \n \n trim_doc_comment (this: string) {\n return `/** ${this.slice(3, -2).replace(/\\s*\\*\\s*/g, ' ').replace(/@(param|params|return) \\{.*?\\}\\s*/g, '').trim()} */`\n },\n \n \n to_base64 (this: string) {\n return Buffer.from(this).toString('base64')\n },\n \n \n decode_base64 (this: string, buffer = false) {\n const buf = Buffer.from(this, 'base64')\n if (buffer)\n return buf\n return buf.toString()\n },\n \n \n strip_ansi (this: string) {\n return strip_ansi(this)\n },\n \n \n space (this: string) {\n if (!this) return this\n let text_: string\n text_ = this\n .replace(new RegExp(cjk + `(['\"])`, 'g'), '$1 $2')\n .replace(new RegExp(`(['\"])` + cjk, 'g'), '$1 $2')\n \n .replace(/([\"']+)\\s*(.+?)\\s*([\"']+)/g, '$1$2$3')\n \n .replace(new RegExp(cjk + '([\\\\+\\\\-\\\\*\\\\/=&\\\\\\\\\\\\|<>])([A-Za-z0-9])', 'g'), '$1 $2 $3')\n .replace(new RegExp('([A-Za-z0-9])([\\\\+\\\\-\\\\*\\\\/=&\\\\\\\\\\\\|<>])' + cjk, 'g'), '$1 $2 $3')\n \n const text_bak = text_\n \n text_ = text_.replace(new RegExp(cjk + '([\\\\(\\\\[\\\\{<\\u201c]+(.*?)[\\\\)\\\\]\\\\}>\\u201d]+)' + cjk, 'g'), '$1 $2 $4')\n \n if (text_ === text_bak)\n text_ = text_\n .replace(new RegExp(cjk + '([\\\\(\\\\[\\\\{<\\u201c>])', 'g'), '$1 $2')\n .replace(new RegExp('([\\\\)\\\\]\\\\}>\\u201d<])' + cjk, 'g'), '$1 $2')\n \n return text_\n .replace(/([\\(\\[\\{<\\u201c]+)(\\s*)(.+?)(\\s*)([\\)\\]\\}>\\u201d]+)/g, '$1$3$5')\n .replace(new RegExp(cjk + '([~!;:,\\\\.\\\\?\\u2026])([A-Za-z0-9])', 'g'), '$1$2 $3')\n .replace(new RegExp(cjk + '([A-Za-z0-9`\\\\$%\\\\^&\\\\*\\\\-=\\\\+\\\\\\\\\\\\|\\\\/@\\u00a1-\\u00ff\\u2022\\u2027\\u2150-\\u218f])', 'g'), '$1 $2')\n .replace(new RegExp('([A-Za-z0-9`\\\\$%\\\\^&\\\\*\\\\-=\\\\+\\\\\\\\\\\\|\\\\/@\\u00a1-\\u00ff\\u2022\\u2027\\u2150-\\u218f])' + cjk, 'g'), '$1 $2')\n }\n }),\n \n \n // ------------ chalk colors\n ... Object.fromEntries(\n [\n 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'grey', \n 'red_', 'green_', 'yellow_', 'blue_', 'magenta_', 'cyan_',\n 'underline',\n ].map(color =>\n ([color, {\n configurable: true,\n get (this: string) {\n return chalk[color_map[color] || color](this)\n }\n }]))\n ),\n \n \n // ------------ 文件路径操作\n ... to_getter_property_descriptors({\n fdir (this: string) {\n const dir = path.dirname(this)\n return dir.endsWith('/') ? dir : `${dir}/`\n },\n \n fname (this: string) {\n return `${path.basename(this)}${this.endsWith('/') ? '/' : ''}`\n },\n \n fext (this: string) {\n return path.extname(this)\n },\n }),\n \n ... to_method_property_descriptors({\n to_slash (this: string) {\n if (!this)\n return this\n return path.normalizeSafe(this)\n },\n \n to_backslash (this: string) {\n return this.replaceAll('/', '\\\\')\n },\n })\n })\n \n \n // ------------------------------------ Date.prototype\n Object.defineProperties(Date.prototype, to_method_property_descriptors({\n to_str (this: Date, ms?: boolean) {\n const [ampm, hour] = (() => {\n let hour = this.getHours()\n if (hour <= 6)\n return [t('凌晨'), hour]\n \n if (hour <= 8)\n return [t('清晨'), hour]\n \n if (hour <= 9)\n return [t('早上'), hour]\n \n if (hour <= 10)\n return [t('上午'), hour]\n \n if (hour <= 12)\n return [t('中午'), hour]\n \n hour -= 12\n \n if (hour <= 5)\n return [t('下午'), hour]\n \n if (hour <= 10)\n return [t('晚上'), hour]\n \n return [t('深夜'), hour]\n })()\n \n const zero_padding = { character: '0', position: 'left' } as const\n \n return '' +\n // year.month.date\n this.getFullYear() + '.' + \n String(this.getMonth() + 1).pad(2, zero_padding) + '.' + \n String(this.getDate()).pad(2, zero_padding) + ' ' +\n \n // 上午\n ampm + ' ' +\n \n // 10:03:02\n String(hour).pad(2, zero_padding) + ':' +\n String(this.getMinutes()).pad(2, zero_padding) + ':' +\n String(this.getSeconds()).pad(2, zero_padding) + \n \n (ms ?\n '.' + String(this.getMilliseconds()).pad(3, zero_padding)\n :\n ''\n )\n },\n \n to_date_str (this: Date) {\n return this.to_str().split(' ')[0]\n },\n \n to_time_str (this: Date, ms?: boolean) {\n const [, ampm, time] = this.to_str(ms).split(' ')\n return `${ampm} ${time}`\n },\n }))\n \n \n \n // ------------------------------------ Number.prototype\n Object.defineProperties(Number.prototype, to_method_property_descriptors({\n to_fsize_str (this: number, units: 'iec' | 'metric' = 'iec') {\n const { value, unit } = byte_size(this, { units })\n return `${value} ${unit.replace('i', '')}`\n },\n \n to_bin_str (this: number) {\n return `0b${this.toString(2)}`\n },\n \n to_hex_str (this: number, length?: number) {\n const s = this.toString(16)\n // 长度自动对齐到 4 的倍数\n if (!length)\n length = Math.ceil(s.length / 4) * 4\n return `0x${'0'.repeat(length - s.length)}${s}`\n },\n \n to_oct_str (this: number) {\n return `0o${this.toString(8)}`\n },\n }))\n \n \n \n // ------------------------------------ Array.prototype\n Object.defineProperties(Array.prototype, {\n ... to_getter_property_descriptors({\n last (this: any[]) {\n return this[this.length - 1]\n }\n }),\n \n \n // --- 文本处理工具方法\n ... to_method_property_descriptors({\n log (this: string[], limit: number = 10000) {\n const text = this.join('\\n') + '\\n'\n if (limit === -1 || this.length <= limit)\n console.log(text)\n else if (limit > 0)\n console.log(text.slice(0, limit) + '\\n...'.blue)\n else \n console.log('...\\n'.blue + text.slice(limit))\n },\n \n trim_lines (this: string[], { trim_line = true, rm_empty_lines = true, rm_last_empty_lines = false }: { trim_line?: boolean, rm_empty_lines?: boolean, rm_last_empty_lines?: boolean } = { }) {\n if (!this.length)\n return this\n let lines = this\n \n if (trim_line)\n lines = lines.map(line => line.trim())\n \n if (rm_empty_lines)\n return lines.filter( line => line )\n \n if (rm_last_empty_lines) {\n lines.reverse()\n const i_not_empty = lines.findIndex( line => line )\n if (i_not_empty !== -1)\n lines = lines.slice(i_not_empty)\n lines.reverse()\n return lines\n }\n \n return lines\n },\n \n \n trim_license (this: string[]) {\n const i = this.indexOf('/*')\n const j = this.indexOf('*/')\n if (i === 0 && this[i+1].includes('License'))\n return this.slice(j+1)\n else\n return this\n },\n \n split_indents (this: string[]): { indent: number, text: string }[] {\n return this.map(line => \n line.split_indent()\n )\n },\n \n indent (this: string[], width?: number, character: string = ' ') {\n return this.map(line => \n character.repeat(width) + line\n )\n },\n \n indent2to4 (this: string[]) {\n return this.split_indents()\n .map(line => \n ' '.repeat(\n Math.floor(line.indent / 2) * 4\n ) + line.text\n )\n },\n \n join_lines (this: string[], append = true) {\n return `${this.join('\\n')}${append ? '\\n' : ''}`\n }\n })\n })\n \n \n Object.defineProperties(BigInt.prototype, to_method_property_descriptors({\n toJSON (this: bigint) {\n return this.toString()\n }\n }))\n \n Object.defineProperties(Error.prototype, to_method_property_descriptors({\n toJSON (this: Error) {\n return Object.fromEntries(\n Object.getOwnPropertyNames(this)\n .map(name => \n [name, this[name]])\n )\n }\n }))\n}\n\n\nexport function to_json (obj: any, replacer?: any) {\n return JSON.stringify(obj, replacer, 4) + '\\n'\n}\n\nexport function to_json_safely (obj: any, replacer?: any) {\n return to_json(obj, replacer)\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029')\n .replace(/<\\/script>/g, '<\\\\/script>')\n}\n\n\nexport function is_codepoint_fullwidth (codepoint: number) {\n // code points are derived from:\n // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt\n return (\n !Number.isNaN(codepoint) &&\n codepoint >= 0x1100 &&\n (\n codepoint <= 0x115f || // hangul jamo\n \n codepoint === 0x201c || codepoint === 0x201d || // \n codepoint === 0x2026 || // …\n codepoint === 0x203b || // ※\n \n // arrows\n (0x2190 <= codepoint && codepoint <= 0x21FF) ||\n \n codepoint === 0x2329 || // left-pointing angle bracket\n codepoint === 0x232a || // right-pointing angle bracket\n \n // ①\n (0x2460 <= codepoint && codepoint <= 0x24ff) ||\n \n // box drawing\n (0x2500 <= codepoint && codepoint <= 0x257f) ||\n \n // shapes, symbols, …\n (0x2580 <= codepoint && codepoint <= 0x2bef) ||\n \n // cjk radicals supplement .. enclosed cjk letters and months\n (0x2e80 <= codepoint && codepoint <= 0x3247 && codepoint !== 0x303f) ||\n \n // enclosed cjk letters and months .. cjk unified ideographs extension a\n (0x3250 <= codepoint && codepoint <= 0x4dbf) ||\n \n // cjk unified ideographs .. yi radicals\n (0x4E00 <= codepoint && codepoint <= 0xA4C6) ||\n \n // hangul jamo extended-a\n (0xa960 <= codepoint && codepoint <= 0xa97c) ||\n \n // hangul syllables\n (0xac00 <= codepoint && codepoint <= 0xd7a3) ||\n \n // cjk compatibility ideographs\n (0xf900 <= codepoint && codepoint <= 0xfaff) ||\n \n // vertical forms\n (0xfe10 <= codepoint && codepoint <= 0xfe19) ||\n \n // cjk compatibility forms .. small form variants\n (0xfe30 <= codepoint && codepoint <= 0xfe6b) ||\n \n // halfwidth and fullwidth forms\n (0xff01 <= codepoint && codepoint <= 0xff60) ||\n (0xffe0 <= codepoint && codepoint <= 0xffe6) ||\n \n // kana supplement\n (0x1b000 <= codepoint && codepoint <= 0x1b001) ||\n \n // enclosed ideographic supplement\n (0x1f200 <= codepoint && codepoint <= 0x1f251) ||\n \n // cjk unified ideographs extension b .. tertiary ideographic plane\n (0x20000 <= codepoint && codepoint <= 0x3fffd)\n )\n )\n}\n"]}
|
package/utils.browser.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export declare function assert(assertion: any, message?: string): never | void;
|
|
|
2
2
|
export declare function delay(milliseconds: number): Promise<void>;
|
|
3
3
|
export declare function debug(milliseconds?: number): Promise<void>;
|
|
4
4
|
/** 字符串字典序比较 */
|
|
5
|
-
export declare function strcmp(l: string, r: string):
|
|
5
|
+
export declare function strcmp(l: string, r: string): 0 | 1 | -1;
|
|
6
6
|
/** 拼接 TypedArrays 生成一个完整的 Uint8Array */
|
|
7
7
|
export declare function concat(arrays: ArrayBufferView[]): Uint8Array;
|
|
8
8
|
/** 时间间隔 (milliseconds) 格式化 */
|
package/utils.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare function unique<T>(iterable: T[] | Iterable<T>, selector?: string
|
|
|
17
17
|
/** 排序对象中 key 的顺序,返回新的对象 */
|
|
18
18
|
export declare function sort_keys<T>(obj: T): T;
|
|
19
19
|
/** 字符串字典序比较 */
|
|
20
|
-
export declare function strcmp(l: string, r: string):
|
|
20
|
+
export declare function strcmp(l: string, r: string): 0 | 1 | -1;
|
|
21
21
|
/** 拼接 TypedArrays 生成一个完整的 Uint8Array */
|
|
22
22
|
export declare function concat(arrays: ArrayBufferView[]): Uint8Array;
|
|
23
23
|
export declare function typed_array_to_buffer(view: ArrayBufferView): Buffer;
|
package/utils.js
CHANGED
|
@@ -22,10 +22,10 @@ export function set_inspect_options() {
|
|
|
22
22
|
util.inspect.styles.special = 'white';
|
|
23
23
|
}
|
|
24
24
|
export function assert(assertion, message) {
|
|
25
|
-
if (assertion)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
if (!assertion) {
|
|
26
|
+
debugger;
|
|
27
|
+
throw new Error(`${t('断言失败')}: ${message ? `${message}: ` : ''}${inspect(assertion)}`);
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
30
|
export function dedent(templ, ...values) {
|
|
31
31
|
let strings = Array.from(typeof templ === 'string' ? [templ] : templ.raw);
|
package/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA8B,MAAM,QAAQ,CAAA;AAC3D,OAAO,IAAI,MAAM,MAAM,CAAA;AAGvB,OAAO,IAAI,MAAM,gBAAgB,CAAA;AAEjC,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACtC,OAAO,gBAAgB,CAAA;AAGvB,iCAAiC;AACjC,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAA;AAG/B,MAAM,UAAU,mBAAmB;IAC/B,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,cAAc,GAAI,EAAE,CAAA;IAChD,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,eAAe,GAAG,KAAK,CAAA;IACnD,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,WAAW,GAAO,YAAY,CAAA;IAC1D,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,GAAY,IAAI,CAAA;IAClD,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,GAAW,KAAK,CAAA;IACnD,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,GAAW,IAAI,CAAA;IAClD,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,GAAa,CAAC,CAAA;IAC/C,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,GAAY,KAAK,CAAA;IACnD,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,GAAS,IAAI,CAAA;IAElD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,GAAI,OAAO,CAAA;IACrC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,GAAI,MAAM,CAAA;IACpC,IAAI,CAA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,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;QAChB,OAAQ,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAK;YAC1C,IAAI,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;YAC5B,IAAI,GAAG,EAAE;gBACL,IAAI,GAAG,GAAG,GAAG,IAAI,CAAA;gBACjB,GAAG,GAAG,EAAE,CAAA;aACX;YACD,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACT,MAAM,IAAI,CAAA;SACb;QACD,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KACvB;AACL,CAAC","sourcesContent":["import { Stream, type Readable, type Duplex } from 'stream'\nimport util from 'util'\n\nimport type Vinyl from 'vinyl'\nimport omit from 'lodash/omit.js'\n\nimport { t } from './i18n/instance.js'\nimport './prototype.js'\n\n\n/** `230` term 字符宽度 (实际上有 240) */\nexport const output_width = 230\n\n\nexport function set_inspect_options () {\n util.inspect.defaultOptions.maxArrayLength = 40\n util.inspect.defaultOptions.maxStringLength = 10000\n util.inspect.defaultOptions.breakLength = output_width\n util.inspect.defaultOptions.colors = true\n util.inspect.defaultOptions.compact = false\n util.inspect.defaultOptions.getters = true\n util.inspect.defaultOptions.depth = 2\n util.inspect.defaultOptions.sorted = false\n util.inspect.defaultOptions.showProxy = true\n \n util.inspect.styles.number = 'green'\n util.inspect.styles.string = 'cyan'\n util.inspect.styles.boolean = 'blue'\n util.inspect.styles.date = 'magenta'\n util.inspect.styles.special = 'white'\n}\n\n\nexport function assert (assertion: any, message?: string): never | void {\n if (assertion)\n return\n \n debugger\n \n throw new Error(`${t('断言失败')}: ${ message ? `${message}: ` : '' }${inspect(assertion)}`)\n}\n\n\nexport function dedent (\n templ: TemplateStringsArray | string,\n ...values: any[]\n): string {\n let strings = Array.from(typeof templ === 'string' ? [templ] : templ.raw)\n \n // 1. remove trailing whitespace\n strings[strings.length - 1] = strings[strings.length - 1].replace(\n /\\r?\\n([\\t ]*)$/,\n '',\n )\n \n // 2. find all line breaks to determine the highest common indentation level\n const indent_lengths = strings.reduce<number[]>(\n (arr, str) => {\n const matches = str.match(/\\n[\\t ]+/g)\n if (matches) \n return arr.concat(\n matches.map(match => \n match.length - 1)\n )\n \n return arr\n },\n [],\n )\n \n // 3. remove the common indentation from all strings\n if (indent_lengths.length) {\n const pattern = new RegExp(`\\n[\\t ]{${Math.min(...indent_lengths)}}`, 'g')\n \n strings = strings.map(str => str.replace(pattern, '\\n'))\n }\n \n // 4. remove leading whitespace\n strings[0] = strings[0].replace(/^\\r?\\n/, '')\n \n // 5. perform interpolation\n let string = strings[0]\n \n values.forEach((value, i) => {\n string += value + strings[i + 1]\n })\n \n string += '\\n'\n \n return string\n}\n\n\n/** 数组或 iterable 去重(可按 selector 去重) \n - selector?: 可以是 key (string) 或 (obj: any) => any\n*/\nexport function unique <T> (iterable: T[] | Iterable<T>, selector?: string | ((obj: T) => any)) {\n if (!selector)\n return [...new Set(iterable)]\n \n let map = new Map()\n const is_str_selector = typeof selector === 'string'\n for (const x of iterable)\n map.set(\n is_str_selector ? x[selector] : selector(x),\n x\n )\n \n return [...map.values()]\n}\n\n/** 排序对象中 key 的顺序,返回新的对象 */\nexport function sort_keys <T> (obj: T) {\n return Object.fromEntries(\n Object.entries(obj)\n .sort(([key_l], [key_r]) => \n strcmp(key_l, key_r))\n ) as T\n}\n\n\n/** 字符串字典序比较 */\nexport function strcmp (l: string, r: string) {\n if (l === r) return 0\n if (l < r) return -1\n return 1\n}\n\n\n/** 拼接 TypedArrays 生成一个完整的 Uint8Array */\nexport function concat (arrays: ArrayBufferView[]) {\n let length = 0\n for (const a of arrays)\n length += a.byteLength\n \n let buf = new Uint8Array(length)\n let offset = 0\n for (const a of arrays) {\n const uint8view = new Uint8Array(a.buffer, a.byteOffset, a.byteLength)\n buf.set(uint8view, offset)\n offset += uint8view.byteLength\n }\n \n return buf\n}\n\n\nexport function typed_array_to_buffer (view: ArrayBufferView) {\n return Buffer.from(\n view.buffer,\n view.byteOffset,\n view.byteLength\n )\n}\n\n\n/** 时间间隔 (milliseconds) 格式化 */\nexport function delta2str (delta: number) {\n // [0, 1000) ms\n if (delta < 1000)\n return `${delta} ms`\n \n // 1.123 s\n if (1000 <= delta && delta < 1000 * 60)\n return `${(delta / 1000).toFixed(1)} s`\n \n // 1 min 12 s [1 min 0s, 60 min)\n const seconds = Math.trunc(delta / 1000)\n \n if (seconds < 60 * 60)\n return `${Math.trunc(seconds / 60)} min ${seconds % 60} s`\n \n const hour = Math.trunc(seconds / 3600)\n \n return `${hour} h ${Math.trunc((seconds - 3600 * hour) / 60)} min ${seconds % 60} s`\n}\n\n\n/** generate random id */\nexport function genid () {\n return Math.random() * 2**53\n}\n\n\nexport class Timer {\n started = new Date().getTime()\n \n ended: number\n \n stop () {\n this.ended = new Date().getTime()\n }\n \n get () {\n if (!this.ended)\n this.stop()\n \n return this.ended - this.started\n }\n \n getstr () {\n return `(${delta2str(this.get())})`\n }\n \n print () {\n console.log(this.getstr())\n }\n}\n\n\n// ------------------------------------ log: module loaded, section, line\nexport function log_section (\n message: string, \n {\n time = false,\n timestamp = false,\n color = undefined,\n }: {\n time?: boolean\n timestamp?: boolean | Date\n color?: 'green' | 'red' | 'yellow'\n } = { }\n) {\n const stime = (() => {\n if (time)\n return delta2str(\n new Date().getTime() - global.started_at.getTime()\n ).pad(4, { position: 'left' })\n if (timestamp)\n if (typeof timestamp === 'object')\n return `${timestamp.to_str()}`\n else\n return `${new Date().to_str()}`\n return ''\n })()\n \n message = `${`${message} `.pad(39)} ${stime}`\n \n if (color)\n message = message[color]\n \n console.log(message)\n}\n\n\nexport function log_line () {\n console.log('---')\n}\n\n\nexport async function delay (milliseconds: number) {\n return new Promise( resolve => {\n setTimeout(resolve, milliseconds)\n })\n}\n\n\n// ------------ text\nexport function has_chinese (str: string) {\n return /[\\u4E00-\\u9FA5]/.test(str)\n}\n\n\nexport function escape_line_feed (str: string) {\n return str.replace(/\\n/g, '\\\\n')\n}\n\n/** util.inspect(obj) \n - options\n - limit?: `10000`\n - omit?: string[]\n*/\nexport function inspect (\n obj: any, \n options: util.InspectOptions & {\n limit?: number\n omit?: string[]\n } = { }\n) {\n if (options.omit)\n obj = omit(obj, [inspect.custom, ...(options.omit || [])])\n \n let text = util.inspect(obj, options)\n \n if (!('limit' in options))\n options.limit = 10000\n if (options.limit && text.length > options.limit)\n return `${text.slice(0, options.limit)}……'\\u001b[39m\\n`\n else\n return text\n}\n\nexport namespace inspect {\n export const custom: typeof util.inspect.custom = util.inspect.custom\n}\n\n\n// ------------------------------------ Steam\n/** npm map-stream \n filter will reemit the data if cb(err,pass) pass is truthy \n \n reduce is more tricky \n maybe we want to group the reductions or emit progress updates occasionally \n the most basic reduce just emits one 'data' event after it has recieved 'end'\n \n create an event stream and apply function to each .write, \n emitting each response as data unless it's an empty callback\n */\nexport function map_stream <Out, In = Vinyl> (\n mapper: (obj: In, cb: Function) => any, \n options?: { failures?: boolean }\n) {\n options = options || { }\n \n let inputs = 0,\n outputs = 0,\n ended = false,\n paused = false,\n destroyed = false,\n last_written = 0,\n in_next = false\n \n \n let stream = Object.assign(new Stream(), {\n readable: true, \n writable: true,\n \n write (data?: any) {\n if (ended) throw new Error('map stream is not writable')\n in_next = false\n inputs++\n \n try {\n // catch sync errors and handle them like async errors\n const written = wrapped_mapper(data, inputs, next)\n paused = (written === false)\n return !paused\n } catch (err) {\n // if the callback has been called syncronously, and the error has occured in an listener, throw it again.\n if (in_next)\n throw err\n next(err)\n return !paused\n }\n },\n \n end (data?: any) {\n if (ended) return\n _end(data)\n },\n \n destroy () {\n ended = destroyed = true\n stream.writable = stream.readable = paused = false\n process.nextTick(function () {\n stream.emit('close')\n })\n },\n \n pause () {\n paused = true\n },\n \n resume () {\n paused = false\n }\n })\n \n \n let error_event_name = options.failures ? 'failure' : 'error'\n \n // Items that are not ready to be written yet (because they would come out of order) get stuck in a queue for later.\n let write_queue = { }\n \n \n function queue_data (data, number) {\n let next_to_write = last_written + 1\n \n if (number === next_to_write) {\n // If it's next, and its not undefined write it\n if (data !== undefined) \n stream.emit('data', data)\n \n last_written++\n next_to_write++\n } else \n // Otherwise queue it for later.\n write_queue[number] = data\n \n \n // If the next value is in the queue, write it\n if (Object.prototype.hasOwnProperty.call(write_queue, next_to_write)) {\n let data_to_write = write_queue[next_to_write]\n delete write_queue[next_to_write]\n return queue_data(data_to_write, next_to_write)\n }\n \n outputs++\n if (inputs === outputs) {\n if (paused) {\n paused = false\n stream.emit('drain') // written all the incoming events\n }\n if (ended) _end()\n }\n }\n \n function next (err?: Error, data?: any, number?: number) {\n if (destroyed) return\n in_next = true\n \n if (!err || options.failures)\n queue_data(data, number)\n \n if (err)\n stream.emit(error_event_name, err)\n \n in_next = false\n }\n \n /** Wrap the mapper function by calling its callback with the order number of the item in the stream. */ \n function wrapped_mapper (input, number, callback) {\n return mapper.call(null, input, function (err, data) {\n callback(err, data, number)\n })\n }\n \n function _end (data?: any) {\n // if end was called with args, write it, \n ended = true // write will emit 'end' if ended is true\n stream.writable = false\n if (data !== undefined) \n return queue_data(data, inputs)\n else if (inputs === outputs) { // wait for processing \n stream.readable = false\n stream.emit('end')\n stream.destroy() \n }\n }\n \n return stream as Duplex\n}\n\n\nexport async function stream_to_buffer (stream: Readable) {\n let chunks = [ ]\n for await (const chunk of stream as AsyncIterable<Buffer>)\n chunks.push(chunk)\n return Buffer.concat(chunks)\n}\n\n\nexport async function * stream_to_lines (stream: Readable) {\n let buf = ''\n for await (const chunk of stream as AsyncIterable<string>) {\n let i = 0, j = 0\n for (; (i = chunk.indexOf('\\n', j)) >= 0; ) {\n let line = chunk.slice(j, i)\n if (buf) {\n line = buf + line\n buf = ''\n }\n j = i + 1\n yield line\n }\n buf = chunk.slice(j)\n }\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources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;YAC1C,IAAI,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;YAC5B,IAAI,GAAG,EAAE;gBACL,IAAI,GAAG,GAAG,GAAG,IAAI,CAAA;gBACjB,GAAG,GAAG,EAAE,CAAA;aACX;YACD,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACT,MAAM,IAAI,CAAA;SACb;QACD,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KACvB;AACL,CAAC","sourcesContent":["import { Stream, type Readable, type Duplex } from 'stream'\nimport util from 'util'\n\nimport type Vinyl from 'vinyl'\nimport omit from 'lodash/omit.js'\n\nimport { t } from './i18n/instance.js'\nimport './prototype.js'\n\n\n/** `230` term 字符宽度 (实际上有 240) */\nexport const output_width = 230\n\n\nexport function set_inspect_options () {\n util.inspect.defaultOptions.maxArrayLength = 40\n util.inspect.defaultOptions.maxStringLength = 10000\n util.inspect.defaultOptions.breakLength = output_width\n util.inspect.defaultOptions.colors = true\n util.inspect.defaultOptions.compact = false\n util.inspect.defaultOptions.getters = true\n util.inspect.defaultOptions.depth = 2\n util.inspect.defaultOptions.sorted = false\n util.inspect.defaultOptions.showProxy = true\n \n util.inspect.styles.number = 'green'\n util.inspect.styles.string = 'cyan'\n util.inspect.styles.boolean = 'blue'\n util.inspect.styles.date = 'magenta'\n util.inspect.styles.special = 'white'\n}\n\n\nexport function assert (assertion: any, message?: string): never | void {\n if (!assertion) {\n debugger\n throw new Error(`${t('断言失败')}: ${ message ? `${message}: ` : '' }${inspect(assertion)}`)\n }\n}\n\n\nexport function dedent (\n templ: TemplateStringsArray | string,\n ...values: any[]\n): string {\n let strings = Array.from(typeof templ === 'string' ? [templ] : templ.raw)\n \n // 1. remove trailing whitespace\n strings[strings.length - 1] = strings[strings.length - 1].replace(\n /\\r?\\n([\\t ]*)$/,\n '',\n )\n \n // 2. find all line breaks to determine the highest common indentation level\n const indent_lengths = strings.reduce<number[]>(\n (arr, str) => {\n const matches = str.match(/\\n[\\t ]+/g)\n if (matches) \n return arr.concat(\n matches.map(match => \n match.length - 1)\n )\n \n return arr\n },\n [],\n )\n \n // 3. remove the common indentation from all strings\n if (indent_lengths.length) {\n const pattern = new RegExp(`\\n[\\t ]{${Math.min(...indent_lengths)}}`, 'g')\n \n strings = strings.map(str => str.replace(pattern, '\\n'))\n }\n \n // 4. remove leading whitespace\n strings[0] = strings[0].replace(/^\\r?\\n/, '')\n \n // 5. perform interpolation\n let string = strings[0]\n \n values.forEach((value, i) => {\n string += value + strings[i + 1]\n })\n \n string += '\\n'\n \n return string\n}\n\n\n/** 数组或 iterable 去重(可按 selector 去重) \n - selector?: 可以是 key (string) 或 (obj: any) => any\n*/\nexport function unique <T> (iterable: T[] | Iterable<T>, selector?: string | ((obj: T) => any)) {\n if (!selector)\n return [...new Set(iterable)]\n \n let map = new Map()\n const is_str_selector = typeof selector === 'string'\n for (const x of iterable)\n map.set(\n is_str_selector ? x[selector] : selector(x),\n x\n )\n \n return [...map.values()]\n}\n\n/** 排序对象中 key 的顺序,返回新的对象 */\nexport function sort_keys <T> (obj: T) {\n return Object.fromEntries(\n Object.entries(obj)\n .sort(([key_l], [key_r]) => \n strcmp(key_l, key_r))\n ) as T\n}\n\n\n/** 字符串字典序比较 */\nexport function strcmp (l: string, r: string) {\n if (l === r) return 0\n if (l < r) return -1\n return 1\n}\n\n\n/** 拼接 TypedArrays 生成一个完整的 Uint8Array */\nexport function concat (arrays: ArrayBufferView[]) {\n let length = 0\n for (const a of arrays)\n length += a.byteLength\n \n let buf = new Uint8Array(length)\n let offset = 0\n for (const a of arrays) {\n const uint8view = new Uint8Array(a.buffer, a.byteOffset, a.byteLength)\n buf.set(uint8view, offset)\n offset += uint8view.byteLength\n }\n \n return buf\n}\n\n\nexport function typed_array_to_buffer (view: ArrayBufferView) {\n return Buffer.from(\n view.buffer,\n view.byteOffset,\n view.byteLength\n )\n}\n\n\n/** 时间间隔 (milliseconds) 格式化 */\nexport function delta2str (delta: number) {\n // [0, 1000) ms\n if (delta < 1000)\n return `${delta} ms`\n \n // 1.123 s\n if (1000 <= delta && delta < 1000 * 60)\n return `${(delta / 1000).toFixed(1)} s`\n \n // 1 min 12 s [1 min 0s, 60 min)\n const seconds = Math.trunc(delta / 1000)\n \n if (seconds < 60 * 60)\n return `${Math.trunc(seconds / 60)} min ${seconds % 60} s`\n \n const hour = Math.trunc(seconds / 3600)\n \n return `${hour} h ${Math.trunc((seconds - 3600 * hour) / 60)} min ${seconds % 60} s`\n}\n\n\n/** generate random id */\nexport function genid () {\n return Math.random() * 2**53\n}\n\n\nexport class Timer {\n started = new Date().getTime()\n \n ended: number\n \n stop () {\n this.ended = new Date().getTime()\n }\n \n get () {\n if (!this.ended)\n this.stop()\n \n return this.ended - this.started\n }\n \n getstr () {\n return `(${delta2str(this.get())})`\n }\n \n print () {\n console.log(this.getstr())\n }\n}\n\n\n// ------------------------------------ log: module loaded, section, line\nexport function log_section (\n message: string, \n {\n time = false,\n timestamp = false,\n color = undefined,\n }: {\n time?: boolean\n timestamp?: boolean | Date\n color?: 'green' | 'red' | 'yellow'\n } = { }\n) {\n const stime = (() => {\n if (time)\n return delta2str(\n new Date().getTime() - global.started_at.getTime()\n ).pad(4, { position: 'left' })\n if (timestamp)\n if (typeof timestamp === 'object')\n return `${timestamp.to_str()}`\n else\n return `${new Date().to_str()}`\n return ''\n })()\n \n message = `${`${message} `.pad(39)} ${stime}`\n \n if (color)\n message = message[color]\n \n console.log(message)\n}\n\n\nexport function log_line () {\n console.log('---')\n}\n\n\nexport async function delay (milliseconds: number) {\n return new Promise( resolve => {\n setTimeout(resolve, milliseconds)\n })\n}\n\n\n// ------------ text\nexport function has_chinese (str: string) {\n return /[\\u4E00-\\u9FA5]/.test(str)\n}\n\n\nexport function escape_line_feed (str: string) {\n return str.replace(/\\n/g, '\\\\n')\n}\n\n/** util.inspect(obj) \n - options\n - limit?: `10000`\n - omit?: string[]\n*/\nexport function inspect (\n obj: any, \n options: util.InspectOptions & {\n limit?: number\n omit?: string[]\n } = { }\n) {\n if (options.omit)\n obj = omit(obj, [inspect.custom, ...(options.omit || [])])\n \n let text = util.inspect(obj, options)\n \n if (!('limit' in options))\n options.limit = 10000\n if (options.limit && text.length > options.limit)\n return `${text.slice(0, options.limit)}……'\\u001b[39m\\n`\n else\n return text\n}\n\nexport namespace inspect {\n export const custom: typeof util.inspect.custom = util.inspect.custom\n}\n\n\n// ------------------------------------ Steam\n/** npm map-stream \n filter will reemit the data if cb(err,pass) pass is truthy \n \n reduce is more tricky \n maybe we want to group the reductions or emit progress updates occasionally \n the most basic reduce just emits one 'data' event after it has recieved 'end'\n \n create an event stream and apply function to each .write, \n emitting each response as data unless it's an empty callback\n */\nexport function map_stream <Out, In = Vinyl> (\n mapper: (obj: In, cb: Function) => any, \n options?: { failures?: boolean }\n) {\n options = options || { }\n \n let inputs = 0,\n outputs = 0,\n ended = false,\n paused = false,\n destroyed = false,\n last_written = 0,\n in_next = false\n \n \n let stream = Object.assign(new Stream(), {\n readable: true, \n writable: true,\n \n write (data?: any) {\n if (ended) throw new Error('map stream is not writable')\n in_next = false\n inputs++\n \n try {\n // catch sync errors and handle them like async errors\n const written = wrapped_mapper(data, inputs, next)\n paused = (written === false)\n return !paused\n } catch (err) {\n // if the callback has been called syncronously, and the error has occured in an listener, throw it again.\n if (in_next)\n throw err\n next(err)\n return !paused\n }\n },\n \n end (data?: any) {\n if (ended) return\n _end(data)\n },\n \n destroy () {\n ended = destroyed = true\n stream.writable = stream.readable = paused = false\n process.nextTick(function () {\n stream.emit('close')\n })\n },\n \n pause () {\n paused = true\n },\n \n resume () {\n paused = false\n }\n })\n \n \n let error_event_name = options.failures ? 'failure' : 'error'\n \n // Items that are not ready to be written yet (because they would come out of order) get stuck in a queue for later.\n let write_queue = { }\n \n \n function queue_data (data, number) {\n let next_to_write = last_written + 1\n \n if (number === next_to_write) {\n // If it's next, and its not undefined write it\n if (data !== undefined) \n stream.emit('data', data)\n \n last_written++\n next_to_write++\n } else \n // Otherwise queue it for later.\n write_queue[number] = data\n \n \n // If the next value is in the queue, write it\n if (Object.prototype.hasOwnProperty.call(write_queue, next_to_write)) {\n let data_to_write = write_queue[next_to_write]\n delete write_queue[next_to_write]\n return queue_data(data_to_write, next_to_write)\n }\n \n outputs++\n if (inputs === outputs) {\n if (paused) {\n paused = false\n stream.emit('drain') // written all the incoming events\n }\n if (ended) _end()\n }\n }\n \n function next (err?: Error, data?: any, number?: number) {\n if (destroyed) return\n in_next = true\n \n if (!err || options.failures)\n queue_data(data, number)\n \n if (err)\n stream.emit(error_event_name, err)\n \n in_next = false\n }\n \n /** Wrap the mapper function by calling its callback with the order number of the item in the stream. */ \n function wrapped_mapper (input, number, callback) {\n return mapper.call(null, input, function (err, data) {\n callback(err, data, number)\n })\n }\n \n function _end (data?: any) {\n // if end was called with args, write it, \n ended = true // write will emit 'end' if ended is true\n stream.writable = false\n if (data !== undefined) \n return queue_data(data, inputs)\n else if (inputs === outputs) { // wait for processing \n stream.readable = false\n stream.emit('end')\n stream.destroy() \n }\n }\n \n return stream as Duplex\n}\n\n\nexport async function stream_to_buffer (stream: Readable) {\n let chunks = [ ]\n for await (const chunk of stream as AsyncIterable<Buffer>)\n chunks.push(chunk)\n return Buffer.concat(chunks)\n}\n\n\nexport async function * stream_to_lines (stream: Readable) {\n let buf = ''\n for await (const chunk of stream as AsyncIterable<string>) {\n let i = 0, j = 0\n for (; (i = chunk.indexOf('\\n', j)) >= 0; ) {\n let line = chunk.slice(j, i)\n if (buf) {\n line = buf + line\n buf = ''\n }\n j = i + 1\n yield line\n }\n buf = chunk.slice(j)\n }\n}\n\n"]}
|