@jayfong/x-utils 1.0.0-202510061015 → 3.3.0
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/lib/case.d.mts +184 -0
- package/lib/case.mjs +120 -0
- package/lib/chinese.d.mts +39 -0
- package/lib/chinese.mjs +52 -0
- package/lib/cli.d.mts +64 -0
- package/lib/cli.mjs +59 -0
- package/lib/clipboard.d.mts +50 -0
- package/lib/clipboard.mjs +122 -0
- package/lib/cmd.d.mts +38 -0
- package/lib/cmd.mjs +52 -0
- package/lib/crawler.d.mts +330 -0
- package/lib/crawler.mjs +313 -0
- package/lib/csv.d.mts +67 -0
- package/lib/csv.mjs +76 -0
- package/lib/data_set.d.mts +76 -0
- package/lib/data_set.mjs +104 -0
- package/lib/fs.d.mts +49 -0
- package/lib/fs.mjs +65 -0
- package/lib/json.d.mts +50 -0
- package/lib/json.mjs +74 -0
- package/lib/puppeteer.d.mts +88 -0
- package/lib/puppeteer.mjs +219 -0
- package/lib/runner.d.mts +52 -0
- package/lib/runner.mjs +50 -0
- package/lib/task.d.mts +37 -0
- package/lib/task.mjs +43 -0
- package/lib/text.d.mts +84 -0
- package/lib/text.mjs +141 -0
- package/lib/yaml.d.mts +51 -0
- package/lib/yaml.mjs +64 -0
- package/package.json +50 -164
- package/_cjs/ai.js +0 -80
- package/_cjs/alipan.js +0 -173
- package/_cjs/cli.js +0 -51
- package/_cjs/clipboard.js +0 -65
- package/_cjs/cmd.js +0 -42
- package/_cjs/compressor.js +0 -47
- package/_cjs/crawler.js +0 -341
- package/_cjs/csv.js +0 -97
- package/_cjs/data_set.js +0 -115
- package/_cjs/env.js +0 -82
- package/_cjs/fs.js +0 -86
- package/_cjs/html.js +0 -62
- package/_cjs/http_server.js +0 -79
- package/_cjs/json.js +0 -49
- package/_cjs/ksb.js +0 -218
- package/_cjs/number.js +0 -39
- package/_cjs/ocr.js +0 -74
- package/_cjs/package.json +0 -3
- package/_cjs/path.js +0 -35
- package/_cjs/pinyin.js +0 -37
- package/_cjs/puppeteer.js +0 -271
- package/_cjs/runner.js +0 -88
- package/_cjs/task.js +0 -41
- package/_cjs/text.js +0 -136
- package/_cjs/unicode/lib_unicode.js +0 -58643
- package/_cjs/unicode/unicode.js +0 -441
- package/_cjs/upload.js +0 -101
- package/_cjs/yaml.js +0 -52
- package/ai.d.ts +0 -26
- package/ai.js +0 -60
- package/alipan.d.ts +0 -209
- package/alipan.js +0 -153
- package/cli.d.ts +0 -14
- package/cli.js +0 -21
- package/clipboard.d.ts +0 -6
- package/clipboard.js +0 -35
- package/cmd.d.ts +0 -5
- package/cmd.js +0 -22
- package/compressor.d.ts +0 -5
- package/compressor.js +0 -17
- package/crawler.d.ts +0 -162
- package/crawler.js +0 -332
- package/csv.d.ts +0 -14
- package/csv.js +0 -67
- package/data_set.d.ts +0 -22
- package/data_set.js +0 -85
- package/env.d.ts +0 -6
- package/env.js +0 -52
- package/fs.d.ts +0 -23
- package/fs.js +0 -56
- package/html.d.ts +0 -7
- package/html.js +0 -45
- package/http_server.d.ts +0 -13
- package/http_server.js +0 -49
- package/json.d.ts +0 -6
- package/json.js +0 -19
- package/ksb.d.ts +0 -37
- package/ksb.js +0 -198
- package/number.d.ts +0 -3
- package/number.js +0 -9
- package/ocr.d.ts +0 -17
- package/ocr.js +0 -54
- package/path.d.ts +0 -2
- package/path.js +0 -5
- package/pinyin.d.ts +0 -8
- package/pinyin.js +0 -17
- package/puppeteer.d.ts +0 -38
- package/puppeteer.js +0 -241
- package/runner.d.ts +0 -13
- package/runner.js +0 -58
- package/task.d.ts +0 -6
- package/task.js +0 -21
- package/text.d.ts +0 -63
- package/text.js +0 -119
- package/unicode/lib_unicode.d.ts +0 -4
- package/unicode/lib_unicode.js +0 -58623
- package/unicode/unicode.d.ts +0 -347
- package/unicode/unicode.js +0 -426
- package/upload.d.ts +0 -34
- package/upload.js +0 -71
- package/yaml.d.ts +0 -6
- package/yaml.js +0 -22
package/lib/text.d.mts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export declare class XText {
|
|
2
|
+
private text;
|
|
3
|
+
/**
|
|
4
|
+
* 将字符串按“用户可见字符(grapheme)”分割为数组。
|
|
5
|
+
*
|
|
6
|
+
* 与 `text.split('')` 不同,这里会正确处理 Emoji、组合字符等场景,
|
|
7
|
+
* 例如 `👍🏽` 会被视为一个字符而不是多个 code unit。
|
|
8
|
+
*
|
|
9
|
+
* @see https://stackoverflow.com/a/71619350
|
|
10
|
+
*/
|
|
11
|
+
static split(text: string): string[];
|
|
12
|
+
/**
|
|
13
|
+
* HTML 模板字符串辅助函数。
|
|
14
|
+
*
|
|
15
|
+
* 该方法不做任何转义,仅用于让书写 HTML 片段时有模板字符串提示。
|
|
16
|
+
* 若插值来自不可信输入,应在调用前自行做转义/清洗。
|
|
17
|
+
*/
|
|
18
|
+
static html(literals: TemplateStringsArray, ...interpolations: unknown[]): string;
|
|
19
|
+
/**
|
|
20
|
+
* 提取 `start` 与 `end` 之间的内容。
|
|
21
|
+
*
|
|
22
|
+
* 规则:
|
|
23
|
+
* - 若 `start` 或 `end` 任一边界不存在,返回空字符串;
|
|
24
|
+
* - 仅提取从第一个 `start` 开始、到其后第一个 `end` 之前的内容;
|
|
25
|
+
* - 不包含边界本身。
|
|
26
|
+
*/
|
|
27
|
+
static cut(text: string, start: string, end: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* 移除全部空白字符(含空格、换行、制表符等)。
|
|
30
|
+
*/
|
|
31
|
+
static stripWhitespace(text: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* 移除首尾空白字符,保留中间内容。
|
|
34
|
+
*/
|
|
35
|
+
static stripMarginWhitespace(text: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* HTML 实体编码。
|
|
38
|
+
*/
|
|
39
|
+
static encodeHtmlEntity(text: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* HTML 实体解码。
|
|
42
|
+
*/
|
|
43
|
+
static decodeHtmlEntity(text: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* 移除 HTML 标签内容,包含 `script/style` 标签块。
|
|
46
|
+
*
|
|
47
|
+
* 注意:
|
|
48
|
+
* - 该方法面向轻量文本清洗,不是完整的 HTML 解析器;
|
|
49
|
+
* - 对复杂畸形 HTML 不能保证 100% 精确。
|
|
50
|
+
*/
|
|
51
|
+
static stripHtml(text: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* 创建一个可链式处理的文本实例。
|
|
54
|
+
*/
|
|
55
|
+
constructor(text: string);
|
|
56
|
+
/**
|
|
57
|
+
* 链式版本:提取 `start` 与 `end` 之间的内容。
|
|
58
|
+
*/
|
|
59
|
+
cut(start: string, end: string): this;
|
|
60
|
+
/**
|
|
61
|
+
* 链式版本:移除全部空白字符。
|
|
62
|
+
*/
|
|
63
|
+
stripWhitespace(): this;
|
|
64
|
+
/**
|
|
65
|
+
* 链式版本:移除首尾空白字符。
|
|
66
|
+
*/
|
|
67
|
+
stripMarginWhitespace(): this;
|
|
68
|
+
/**
|
|
69
|
+
* 链式版本:HTML 实体编码。
|
|
70
|
+
*/
|
|
71
|
+
encodeHtmlEntity(): this;
|
|
72
|
+
/**
|
|
73
|
+
* 链式版本:HTML 实体解码。
|
|
74
|
+
*/
|
|
75
|
+
decodeHtmlEntity(): this;
|
|
76
|
+
/**
|
|
77
|
+
* 链式版本:移除 HTML 代码。
|
|
78
|
+
*/
|
|
79
|
+
stripHtml(): this;
|
|
80
|
+
/**
|
|
81
|
+
* 返回当前链式处理后的文本。
|
|
82
|
+
*/
|
|
83
|
+
toString(): string;
|
|
84
|
+
}
|
package/lib/text.mjs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { decode, encode } from "html-entities";
|
|
2
|
+
// src/text.ts
|
|
3
|
+
var XText = class XText {
|
|
4
|
+
text;
|
|
5
|
+
/**
|
|
6
|
+
* 将字符串按“用户可见字符(grapheme)”分割为数组。
|
|
7
|
+
*
|
|
8
|
+
* 与 `text.split('')` 不同,这里会正确处理 Emoji、组合字符等场景,
|
|
9
|
+
* 例如 `👍🏽` 会被视为一个字符而不是多个 code unit。
|
|
10
|
+
*
|
|
11
|
+
* @see https://stackoverflow.com/a/71619350
|
|
12
|
+
*/
|
|
13
|
+
static split(text) {
|
|
14
|
+
return [...new Intl.Segmenter().segment(text)].map((x) => x.segment);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* HTML 模板字符串辅助函数。
|
|
18
|
+
*
|
|
19
|
+
* 该方法不做任何转义,仅用于让书写 HTML 片段时有模板字符串提示。
|
|
20
|
+
* 若插值来自不可信输入,应在调用前自行做转义/清洗。
|
|
21
|
+
*/
|
|
22
|
+
static html(literals, ...interpolations) {
|
|
23
|
+
let result = "";
|
|
24
|
+
for (let i = 0; i < interpolations.length; i++) {
|
|
25
|
+
result += literals[i];
|
|
26
|
+
result += interpolations[i];
|
|
27
|
+
}
|
|
28
|
+
result += literals[literals.length - 1];
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 提取 `start` 与 `end` 之间的内容。
|
|
33
|
+
*
|
|
34
|
+
* 规则:
|
|
35
|
+
* - 若 `start` 或 `end` 任一边界不存在,返回空字符串;
|
|
36
|
+
* - 仅提取从第一个 `start` 开始、到其后第一个 `end` 之前的内容;
|
|
37
|
+
* - 不包含边界本身。
|
|
38
|
+
*/
|
|
39
|
+
static cut(text, start, end) {
|
|
40
|
+
const startIndex = text.indexOf(start);
|
|
41
|
+
if (startIndex < 0) return "";
|
|
42
|
+
const contentStartIndex = startIndex + start.length;
|
|
43
|
+
const endIndex = text.indexOf(end, contentStartIndex);
|
|
44
|
+
if (endIndex < 0) return "";
|
|
45
|
+
return text.slice(contentStartIndex, endIndex);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 移除全部空白字符(含空格、换行、制表符等)。
|
|
49
|
+
*/
|
|
50
|
+
static stripWhitespace(text) {
|
|
51
|
+
text = text.replace(/\s+/g, "");
|
|
52
|
+
return text;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 移除首尾空白字符,保留中间内容。
|
|
56
|
+
*/
|
|
57
|
+
static stripMarginWhitespace(text) {
|
|
58
|
+
text = text.trim();
|
|
59
|
+
return text;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* HTML 实体编码。
|
|
63
|
+
*/
|
|
64
|
+
static encodeHtmlEntity(text) {
|
|
65
|
+
text = encode(text);
|
|
66
|
+
return text;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* HTML 实体解码。
|
|
70
|
+
*/
|
|
71
|
+
static decodeHtmlEntity(text) {
|
|
72
|
+
text = decode(text);
|
|
73
|
+
return text;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 移除 HTML 标签内容,包含 `script/style` 标签块。
|
|
77
|
+
*
|
|
78
|
+
* 注意:
|
|
79
|
+
* - 该方法面向轻量文本清洗,不是完整的 HTML 解析器;
|
|
80
|
+
* - 对复杂畸形 HTML 不能保证 100% 精确。
|
|
81
|
+
*/
|
|
82
|
+
static stripHtml(text) {
|
|
83
|
+
text = text.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, "").replace(/<\/?[^>]+>/g, "");
|
|
84
|
+
return text;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 创建一个可链式处理的文本实例。
|
|
88
|
+
*/
|
|
89
|
+
constructor(text) {
|
|
90
|
+
this.text = text;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 链式版本:提取 `start` 与 `end` 之间的内容。
|
|
94
|
+
*/
|
|
95
|
+
cut(start, end) {
|
|
96
|
+
this.text = XText.cut(this.text, start, end);
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 链式版本:移除全部空白字符。
|
|
101
|
+
*/
|
|
102
|
+
stripWhitespace() {
|
|
103
|
+
this.text = XText.stripWhitespace(this.text);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 链式版本:移除首尾空白字符。
|
|
108
|
+
*/
|
|
109
|
+
stripMarginWhitespace() {
|
|
110
|
+
this.text = XText.stripMarginWhitespace(this.text);
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 链式版本:HTML 实体编码。
|
|
115
|
+
*/
|
|
116
|
+
encodeHtmlEntity() {
|
|
117
|
+
this.text = XText.encodeHtmlEntity(this.text);
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 链式版本:HTML 实体解码。
|
|
122
|
+
*/
|
|
123
|
+
decodeHtmlEntity() {
|
|
124
|
+
this.text = XText.decodeHtmlEntity(this.text);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 链式版本:移除 HTML 代码。
|
|
129
|
+
*/
|
|
130
|
+
stripHtml() {
|
|
131
|
+
this.text = XText.stripHtml(this.text);
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 返回当前链式处理后的文本。
|
|
136
|
+
*/
|
|
137
|
+
toString() {
|
|
138
|
+
return this.text;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
export { XText };
|
package/lib/yaml.d.mts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 封装常用 YAML 文本处理逻辑,统一提供解析、序列化、文件读写入口。
|
|
3
|
+
*
|
|
4
|
+
* 设计目标:
|
|
5
|
+
* - 让调用方无需直接接触 `yaml` 依赖细节;
|
|
6
|
+
* - 统一使用 UTF-8 文本读取/写入;
|
|
7
|
+
* - 通过 `blockQuote: 'literal'` 保持多行文本块更稳定的输出格式,避免
|
|
8
|
+
* 长文本在 YAML 中被错误地折叠或渲染为普通单行字符串。
|
|
9
|
+
*
|
|
10
|
+
* 典型用法:
|
|
11
|
+
* - `const cfg = XYaml.parse<{ name: string }>(content)`
|
|
12
|
+
* - `await XYaml.write('/tmp/app.yaml', { name: 'demo' })`
|
|
13
|
+
*/
|
|
14
|
+
export declare class XYaml {
|
|
15
|
+
/**
|
|
16
|
+
* 解析 YAML 文本为目标类型。
|
|
17
|
+
*
|
|
18
|
+
* 适用场景包括配置文件、表单内容、轻量结构化描述等。由于 YAML 语法
|
|
19
|
+
* 允许解析为对象、数组、布尔值、数字、字符串等原始值,因此这里使用
|
|
20
|
+
* 泛型让调用方在类型层面明确期望值。
|
|
21
|
+
*
|
|
22
|
+
* 例子:
|
|
23
|
+
* ```ts
|
|
24
|
+
* const config = XYaml.parse<{ name: string; port: number }>(`\nname: demo\nport: 3000\n`);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
static parse<T>(value: string): T;
|
|
28
|
+
/**
|
|
29
|
+
* 将任意值转换成 YAML 文本。
|
|
30
|
+
*
|
|
31
|
+
* 这里固定使用 `blockQuote: 'literal'`,这样当值中包含多行字符串时,
|
|
32
|
+
* 输出会优先采用 `|` 形式的 literal block,与普通单行折叠输出相比更
|
|
33
|
+
* 稳定,也更符合配置文件/说明文档场景的阅读习惯。
|
|
34
|
+
*/
|
|
35
|
+
static stringify(value: unknown): string;
|
|
36
|
+
/**
|
|
37
|
+
* 读取 YAML 文件并立即解析为指定类型。
|
|
38
|
+
*
|
|
39
|
+
* 读取时使用 UTF-8 编码,适合配置文件、模板文件或脚本状态容器。若
|
|
40
|
+
* 文件为空,`yaml.parse` 可能返回 `null`,调用方需要按业务规则处理。
|
|
41
|
+
*/
|
|
42
|
+
static read<T>(file: string): Promise<T>;
|
|
43
|
+
/**
|
|
44
|
+
* 将对象写入 YAML 文件。
|
|
45
|
+
*
|
|
46
|
+
* 这里不额外指定缩进或换行策略,使用 `stringify` 的统一默认行为;
|
|
47
|
+
* 一旦调用方传入 `undefined`,`yaml.stringify` 会输出空文档,调用方应在
|
|
48
|
+
* 业务层避免该情况,或在必要时进行显式校验。
|
|
49
|
+
*/
|
|
50
|
+
static write(file: string, value: unknown): Promise<void>;
|
|
51
|
+
}
|
package/lib/yaml.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import yaml from "yaml";
|
|
3
|
+
// src/yaml.ts
|
|
4
|
+
/**
|
|
5
|
+
* 封装常用 YAML 文本处理逻辑,统一提供解析、序列化、文件读写入口。
|
|
6
|
+
*
|
|
7
|
+
* 设计目标:
|
|
8
|
+
* - 让调用方无需直接接触 `yaml` 依赖细节;
|
|
9
|
+
* - 统一使用 UTF-8 文本读取/写入;
|
|
10
|
+
* - 通过 `blockQuote: 'literal'` 保持多行文本块更稳定的输出格式,避免
|
|
11
|
+
* 长文本在 YAML 中被错误地折叠或渲染为普通单行字符串。
|
|
12
|
+
*
|
|
13
|
+
* 典型用法:
|
|
14
|
+
* - `const cfg = XYaml.parse<{ name: string }>(content)`
|
|
15
|
+
* - `await XYaml.write('/tmp/app.yaml', { name: 'demo' })`
|
|
16
|
+
*/
|
|
17
|
+
var XYaml = class XYaml {
|
|
18
|
+
/**
|
|
19
|
+
* 解析 YAML 文本为目标类型。
|
|
20
|
+
*
|
|
21
|
+
* 适用场景包括配置文件、表单内容、轻量结构化描述等。由于 YAML 语法
|
|
22
|
+
* 允许解析为对象、数组、布尔值、数字、字符串等原始值,因此这里使用
|
|
23
|
+
* 泛型让调用方在类型层面明确期望值。
|
|
24
|
+
*
|
|
25
|
+
* 例子:
|
|
26
|
+
* ```ts
|
|
27
|
+
* const config = XYaml.parse<{ name: string; port: number }>(`\nname: demo\nport: 3000\n`);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
static parse(value) {
|
|
31
|
+
return yaml.parse(value);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 将任意值转换成 YAML 文本。
|
|
35
|
+
*
|
|
36
|
+
* 这里固定使用 `blockQuote: 'literal'`,这样当值中包含多行字符串时,
|
|
37
|
+
* 输出会优先采用 `|` 形式的 literal block,与普通单行折叠输出相比更
|
|
38
|
+
* 稳定,也更符合配置文件/说明文档场景的阅读习惯。
|
|
39
|
+
*/
|
|
40
|
+
static stringify(value) {
|
|
41
|
+
return yaml.stringify(value, { blockQuote: "literal" });
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 读取 YAML 文件并立即解析为指定类型。
|
|
45
|
+
*
|
|
46
|
+
* 读取时使用 UTF-8 编码,适合配置文件、模板文件或脚本状态容器。若
|
|
47
|
+
* 文件为空,`yaml.parse` 可能返回 `null`,调用方需要按业务规则处理。
|
|
48
|
+
*/
|
|
49
|
+
static async read(file) {
|
|
50
|
+
const value = await fs.promises.readFile(file, "utf8");
|
|
51
|
+
return XYaml.parse(value);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 将对象写入 YAML 文件。
|
|
55
|
+
*
|
|
56
|
+
* 这里不额外指定缩进或换行策略,使用 `stringify` 的统一默认行为;
|
|
57
|
+
* 一旦调用方传入 `undefined`,`yaml.stringify` 会输出空文档,调用方应在
|
|
58
|
+
* 业务层避免该情况,或在必要时进行显式校验。
|
|
59
|
+
*/
|
|
60
|
+
static async write(file, value) {
|
|
61
|
+
await fs.promises.writeFile(file, XYaml.stringify(value));
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
export { XYaml };
|
package/package.json
CHANGED
|
@@ -1,177 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-utils",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"version": "3.3.0",
|
|
4
|
+
"license": "ISC",
|
|
5
|
+
"sideEffects": false,
|
|
5
6
|
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
6
10
|
"dependencies": {
|
|
7
|
-
"
|
|
8
|
-
"@jayfong/x-request": "^2.35.2",
|
|
9
|
-
"cli-table3": "^0.6.3",
|
|
10
|
-
"inquirer": "^9.2.13",
|
|
11
|
-
"@types/inquirer": "^9.0.7",
|
|
12
|
-
"clipboardy": "^4.0.0",
|
|
13
|
-
"execa": "^8.0.1",
|
|
14
|
-
"sharp": "^0.32.5",
|
|
15
|
-
"node-html-parser": "^6.1.12",
|
|
16
|
-
"csv": "^6.3.6",
|
|
17
|
-
"exit-hook": "^4.0.0",
|
|
18
|
-
"fs-extra": "^11.2.0",
|
|
11
|
+
"@jayfong/x-request": "^3.3.0",
|
|
19
12
|
"@types/fs-extra": "^11.0.4",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
13
|
+
"change-case": "^5.4.4",
|
|
14
|
+
"cli-table3": "^0.6.5",
|
|
15
|
+
"clipboardy": "^5.3.2",
|
|
16
|
+
"consola": "^3.4.2",
|
|
17
|
+
"csv": "^6.6.4",
|
|
18
|
+
"exit-hook": "^5.1.0",
|
|
19
|
+
"fs-extra": "^11.4.1",
|
|
20
|
+
"html-entities": "^2.6.0",
|
|
21
|
+
"inquirer": "^14.3.0",
|
|
22
|
+
"mime": "^4.1.2",
|
|
23
|
+
"node-html-parser": "^9.0.7",
|
|
24
|
+
"pinyin-pro": "^3.26.0",
|
|
25
|
+
"vtils": "^4.138.0",
|
|
26
|
+
"yaml": "^2.9.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"puppeteer": "^25.17.0"
|
|
37
30
|
},
|
|
38
31
|
"peerDependencies": {
|
|
39
|
-
"puppeteer": "^
|
|
32
|
+
"puppeteer": "^25.17.0"
|
|
40
33
|
},
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
"require": "./_cjs/ai.js",
|
|
45
|
-
"import": "./ai.js",
|
|
46
|
-
"types": "./ai.d.ts"
|
|
47
|
-
},
|
|
48
|
-
"./alipan": {
|
|
49
|
-
"require": "./_cjs/alipan.js",
|
|
50
|
-
"import": "./alipan.js",
|
|
51
|
-
"types": "./alipan.d.ts"
|
|
52
|
-
},
|
|
53
|
-
"./cli": {
|
|
54
|
-
"require": "./_cjs/cli.js",
|
|
55
|
-
"import": "./cli.js",
|
|
56
|
-
"types": "./cli.d.ts"
|
|
57
|
-
},
|
|
58
|
-
"./clipboard": {
|
|
59
|
-
"require": "./_cjs/clipboard.js",
|
|
60
|
-
"import": "./clipboard.js",
|
|
61
|
-
"types": "./clipboard.d.ts"
|
|
62
|
-
},
|
|
63
|
-
"./cmd": {
|
|
64
|
-
"require": "./_cjs/cmd.js",
|
|
65
|
-
"import": "./cmd.js",
|
|
66
|
-
"types": "./cmd.d.ts"
|
|
67
|
-
},
|
|
68
|
-
"./compressor": {
|
|
69
|
-
"require": "./_cjs/compressor.js",
|
|
70
|
-
"import": "./compressor.js",
|
|
71
|
-
"types": "./compressor.d.ts"
|
|
72
|
-
},
|
|
73
|
-
"./crawler": {
|
|
74
|
-
"require": "./_cjs/crawler.js",
|
|
75
|
-
"import": "./crawler.js",
|
|
76
|
-
"types": "./crawler.d.ts"
|
|
77
|
-
},
|
|
78
|
-
"./csv": {
|
|
79
|
-
"require": "./_cjs/csv.js",
|
|
80
|
-
"import": "./csv.js",
|
|
81
|
-
"types": "./csv.d.ts"
|
|
82
|
-
},
|
|
83
|
-
"./data_set": {
|
|
84
|
-
"require": "./_cjs/data_set.js",
|
|
85
|
-
"import": "./data_set.js",
|
|
86
|
-
"types": "./data_set.d.ts"
|
|
87
|
-
},
|
|
88
|
-
"./env": {
|
|
89
|
-
"require": "./_cjs/env.js",
|
|
90
|
-
"import": "./env.js",
|
|
91
|
-
"types": "./env.d.ts"
|
|
92
|
-
},
|
|
93
|
-
"./fs": {
|
|
94
|
-
"require": "./_cjs/fs.js",
|
|
95
|
-
"import": "./fs.js",
|
|
96
|
-
"types": "./fs.d.ts"
|
|
97
|
-
},
|
|
98
|
-
"./html": {
|
|
99
|
-
"require": "./_cjs/html.js",
|
|
100
|
-
"import": "./html.js",
|
|
101
|
-
"types": "./html.d.ts"
|
|
102
|
-
},
|
|
103
|
-
"./http_server": {
|
|
104
|
-
"require": "./_cjs/http_server.js",
|
|
105
|
-
"import": "./http_server.js",
|
|
106
|
-
"types": "./http_server.d.ts"
|
|
107
|
-
},
|
|
108
|
-
"./json": {
|
|
109
|
-
"require": "./_cjs/json.js",
|
|
110
|
-
"import": "./json.js",
|
|
111
|
-
"types": "./json.d.ts"
|
|
112
|
-
},
|
|
113
|
-
"./ksb": {
|
|
114
|
-
"require": "./_cjs/ksb.js",
|
|
115
|
-
"import": "./ksb.js",
|
|
116
|
-
"types": "./ksb.d.ts"
|
|
117
|
-
},
|
|
118
|
-
"./number": {
|
|
119
|
-
"require": "./_cjs/number.js",
|
|
120
|
-
"import": "./number.js",
|
|
121
|
-
"types": "./number.d.ts"
|
|
122
|
-
},
|
|
123
|
-
"./ocr": {
|
|
124
|
-
"require": "./_cjs/ocr.js",
|
|
125
|
-
"import": "./ocr.js",
|
|
126
|
-
"types": "./ocr.d.ts"
|
|
127
|
-
},
|
|
128
|
-
"./path": {
|
|
129
|
-
"require": "./_cjs/path.js",
|
|
130
|
-
"import": "./path.js",
|
|
131
|
-
"types": "./path.d.ts"
|
|
132
|
-
},
|
|
133
|
-
"./pinyin": {
|
|
134
|
-
"require": "./_cjs/pinyin.js",
|
|
135
|
-
"import": "./pinyin.js",
|
|
136
|
-
"types": "./pinyin.d.ts"
|
|
137
|
-
},
|
|
138
|
-
"./puppeteer": {
|
|
139
|
-
"require": "./_cjs/puppeteer.js",
|
|
140
|
-
"import": "./puppeteer.js",
|
|
141
|
-
"types": "./puppeteer.d.ts"
|
|
142
|
-
},
|
|
143
|
-
"./runner": {
|
|
144
|
-
"require": "./_cjs/runner.js",
|
|
145
|
-
"import": "./runner.js",
|
|
146
|
-
"types": "./runner.d.ts"
|
|
147
|
-
},
|
|
148
|
-
"./task": {
|
|
149
|
-
"require": "./_cjs/task.js",
|
|
150
|
-
"import": "./task.js",
|
|
151
|
-
"types": "./task.d.ts"
|
|
152
|
-
},
|
|
153
|
-
"./text": {
|
|
154
|
-
"require": "./_cjs/text.js",
|
|
155
|
-
"import": "./text.js",
|
|
156
|
-
"types": "./text.d.ts"
|
|
157
|
-
},
|
|
158
|
-
"./upload": {
|
|
159
|
-
"require": "./_cjs/upload.js",
|
|
160
|
-
"import": "./upload.js",
|
|
161
|
-
"types": "./upload.d.ts"
|
|
162
|
-
},
|
|
163
|
-
"./yaml": {
|
|
164
|
-
"require": "./_cjs/yaml.js",
|
|
165
|
-
"import": "./yaml.js",
|
|
166
|
-
"types": "./yaml.d.ts"
|
|
167
|
-
},
|
|
168
|
-
"./unicode": {
|
|
169
|
-
"require": "./_cjs/unicode/unicode.js",
|
|
170
|
-
"import": "./unicode/unicode.js",
|
|
171
|
-
"types": "./unicode/unicode.d.ts"
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"puppeteer": {
|
|
36
|
+
"optional": true
|
|
172
37
|
}
|
|
173
38
|
},
|
|
174
39
|
"publishConfig": {
|
|
175
40
|
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"exports": {
|
|
43
|
+
"./case": "./lib/case.mjs",
|
|
44
|
+
"./chinese": "./lib/chinese.mjs",
|
|
45
|
+
"./cli": "./lib/cli.mjs",
|
|
46
|
+
"./clipboard": "./lib/clipboard.mjs",
|
|
47
|
+
"./cmd": "./lib/cmd.mjs",
|
|
48
|
+
"./crawler": "./lib/crawler.mjs",
|
|
49
|
+
"./csv": "./lib/csv.mjs",
|
|
50
|
+
"./data_set": "./lib/data_set.mjs",
|
|
51
|
+
"./fs": "./lib/fs.mjs",
|
|
52
|
+
"./json": "./lib/json.mjs",
|
|
53
|
+
"./puppeteer": "./lib/puppeteer.mjs",
|
|
54
|
+
"./runner": "./lib/runner.mjs",
|
|
55
|
+
"./task": "./lib/task.mjs",
|
|
56
|
+
"./text": "./lib/text.mjs",
|
|
57
|
+
"./yaml": "./lib/yaml.mjs",
|
|
58
|
+
"./package.json": "./package.json"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsdown"
|
|
176
62
|
}
|
|
177
|
-
}
|
|
63
|
+
}
|
package/_cjs/ai.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var ai_exports = {};
|
|
20
|
-
__export(ai_exports, {
|
|
21
|
-
CozeAiProvider: () => CozeAiProvider,
|
|
22
|
-
XAi: () => XAi
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(ai_exports);
|
|
25
|
-
var import_vtils = require("vtils");
|
|
26
|
-
var import_puppeteer = require("./puppeteer.js");
|
|
27
|
-
class AiProvider {
|
|
28
|
-
}
|
|
29
|
-
class CozeAiProvider extends AiProvider {
|
|
30
|
-
constructor(options) {
|
|
31
|
-
super();
|
|
32
|
-
this.options = options;
|
|
33
|
-
}
|
|
34
|
-
xp;
|
|
35
|
-
page;
|
|
36
|
-
async prepare() {
|
|
37
|
-
this.xp = new import_puppeteer.XPuppeteer();
|
|
38
|
-
await this.xp.connectSystemBrowser();
|
|
39
|
-
this.page = await this.xp.openPage(this.options.botUrl);
|
|
40
|
-
}
|
|
41
|
-
async ask(question) {
|
|
42
|
-
const page = this.page;
|
|
43
|
-
await page.evaluate(
|
|
44
|
-
() => document.querySelector("textarea:not([placeholder])").parentElement.parentElement.previousElementSibling.firstElementChild.click()
|
|
45
|
-
);
|
|
46
|
-
await (0, import_vtils.wait)(300);
|
|
47
|
-
await this.page.type("textarea:not([placeholder])", question);
|
|
48
|
-
await (0, import_vtils.wait)(500);
|
|
49
|
-
await this.page.keyboard.press("Enter");
|
|
50
|
-
await (0, import_vtils.wait)(1e3);
|
|
51
|
-
await (0, import_vtils.loopUntil)(
|
|
52
|
-
() => page.$$eval(
|
|
53
|
-
"button",
|
|
54
|
-
(els) => !els.find((el) => el.textContent.includes("Stop Responding"))?.parentElement.getBoundingClientRect().height
|
|
55
|
-
),
|
|
56
|
-
{
|
|
57
|
-
retryDelay: 300
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
await (0, import_vtils.wait)(300);
|
|
61
|
-
const code = await page.$$eval(
|
|
62
|
-
'div[class^="code-area"]',
|
|
63
|
-
(els) => els.pop().querySelector('[class^="content"]').textContent
|
|
64
|
-
);
|
|
65
|
-
return code;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
class XAi {
|
|
69
|
-
constructor(options) {
|
|
70
|
-
this.options = options;
|
|
71
|
-
this.provider = options.provider;
|
|
72
|
-
}
|
|
73
|
-
provider;
|
|
74
|
-
prepare = (0, import_vtils.memoize)(() => this.provider.prepare());
|
|
75
|
-
async ask(question) {
|
|
76
|
-
await this.prepare();
|
|
77
|
-
const answer = await this.provider.ask(question);
|
|
78
|
-
return answer;
|
|
79
|
-
}
|
|
80
|
-
}
|