@jayfong/x-utils 1.0.0-202410181400 → 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.
Files changed (112) hide show
  1. package/lib/case.d.mts +184 -0
  2. package/lib/case.mjs +120 -0
  3. package/lib/chinese.d.mts +39 -0
  4. package/lib/chinese.mjs +52 -0
  5. package/lib/cli.d.mts +64 -0
  6. package/lib/cli.mjs +59 -0
  7. package/lib/clipboard.d.mts +50 -0
  8. package/lib/clipboard.mjs +122 -0
  9. package/lib/cmd.d.mts +38 -0
  10. package/lib/cmd.mjs +52 -0
  11. package/lib/crawler.d.mts +330 -0
  12. package/lib/crawler.mjs +313 -0
  13. package/lib/csv.d.mts +67 -0
  14. package/lib/csv.mjs +76 -0
  15. package/lib/data_set.d.mts +76 -0
  16. package/lib/data_set.mjs +104 -0
  17. package/lib/fs.d.mts +49 -0
  18. package/lib/fs.mjs +65 -0
  19. package/lib/json.d.mts +50 -0
  20. package/lib/json.mjs +74 -0
  21. package/lib/puppeteer.d.mts +88 -0
  22. package/lib/puppeteer.mjs +219 -0
  23. package/lib/runner.d.mts +52 -0
  24. package/lib/runner.mjs +50 -0
  25. package/lib/task.d.mts +37 -0
  26. package/lib/task.mjs +43 -0
  27. package/lib/text.d.mts +84 -0
  28. package/lib/text.mjs +141 -0
  29. package/lib/yaml.d.mts +51 -0
  30. package/lib/yaml.mjs +64 -0
  31. package/package.json +50 -164
  32. package/_cjs/ai.js +0 -80
  33. package/_cjs/alipan.js +0 -173
  34. package/_cjs/cli.js +0 -51
  35. package/_cjs/clipboard.js +0 -65
  36. package/_cjs/cmd.js +0 -42
  37. package/_cjs/compressor.js +0 -47
  38. package/_cjs/crawler.js +0 -341
  39. package/_cjs/csv.js +0 -97
  40. package/_cjs/data_set.js +0 -115
  41. package/_cjs/env.js +0 -82
  42. package/_cjs/fs.js +0 -86
  43. package/_cjs/html.js +0 -62
  44. package/_cjs/http_server.js +0 -79
  45. package/_cjs/json.js +0 -49
  46. package/_cjs/ksb.js +0 -218
  47. package/_cjs/number.js +0 -39
  48. package/_cjs/ocr.js +0 -74
  49. package/_cjs/path.js +0 -35
  50. package/_cjs/pinyin.js +0 -37
  51. package/_cjs/puppeteer.js +0 -271
  52. package/_cjs/runner.js +0 -88
  53. package/_cjs/task.js +0 -41
  54. package/_cjs/text.js +0 -136
  55. package/_cjs/unicode/lib_unicode.js +0 -58643
  56. package/_cjs/unicode/unicode.js +0 -441
  57. package/_cjs/upload.js +0 -101
  58. package/_cjs/yaml.js +0 -52
  59. package/ai.d.ts +0 -26
  60. package/ai.js +0 -60
  61. package/alipan.d.ts +0 -209
  62. package/alipan.js +0 -153
  63. package/cli.d.ts +0 -14
  64. package/cli.js +0 -21
  65. package/clipboard.d.ts +0 -6
  66. package/clipboard.js +0 -35
  67. package/cmd.d.ts +0 -5
  68. package/cmd.js +0 -22
  69. package/compressor.d.ts +0 -5
  70. package/compressor.js +0 -17
  71. package/crawler.d.ts +0 -162
  72. package/crawler.js +0 -332
  73. package/csv.d.ts +0 -14
  74. package/csv.js +0 -67
  75. package/data_set.d.ts +0 -22
  76. package/data_set.js +0 -85
  77. package/env.d.ts +0 -6
  78. package/env.js +0 -52
  79. package/fs.d.ts +0 -23
  80. package/fs.js +0 -56
  81. package/html.d.ts +0 -7
  82. package/html.js +0 -45
  83. package/http_server.d.ts +0 -13
  84. package/http_server.js +0 -49
  85. package/json.d.ts +0 -6
  86. package/json.js +0 -19
  87. package/ksb.d.ts +0 -37
  88. package/ksb.js +0 -198
  89. package/number.d.ts +0 -3
  90. package/number.js +0 -9
  91. package/ocr.d.ts +0 -17
  92. package/ocr.js +0 -54
  93. package/path.d.ts +0 -2
  94. package/path.js +0 -5
  95. package/pinyin.d.ts +0 -8
  96. package/pinyin.js +0 -17
  97. package/puppeteer.d.ts +0 -38
  98. package/puppeteer.js +0 -241
  99. package/runner.d.ts +0 -13
  100. package/runner.js +0 -58
  101. package/task.d.ts +0 -6
  102. package/task.js +0 -21
  103. package/text.d.ts +0 -63
  104. package/text.js +0 -119
  105. package/unicode/lib_unicode.d.ts +0 -4
  106. package/unicode/lib_unicode.js +0 -58623
  107. package/unicode/unicode.d.ts +0 -347
  108. package/unicode/unicode.js +0 -426
  109. package/upload.d.ts +0 -34
  110. package/upload.js +0 -71
  111. package/yaml.d.ts +0 -6
  112. package/yaml.js +0 -22
package/html.js DELETED
@@ -1,45 +0,0 @@
1
- import { ImageRun, TextRun } from "docx";
2
- import { imageDimensionsFromData } from "image-dimensions";
3
- import { parse } from "node-html-parser";
4
- import { parser } from "posthtml-parser";
5
- import { flattenDeep, ii } from "vtils";
6
- import {
7
- HTMLElement,
8
- NodeType
9
- } from "node-html-parser";
10
- class XHtml {
11
- static parse(html) {
12
- return parse(html);
13
- }
14
- static async toDocxParagraphChildren(html, fetchImage) {
15
- const nodes = parser(html, {
16
- decodeEntities: true
17
- }).map(function process(node) {
18
- return typeof node === "object" && node.content && Array.isArray(node.content) ? flattenDeep(node.content).map(process).flat() : [node];
19
- }).flat();
20
- return await Promise.all(
21
- nodes.map(async (node) => {
22
- return typeof node === "string" || typeof node === "number" ? new TextRun({
23
- text: String(node)
24
- }) : node.tag === "img" && typeof node.attrs?.src === "string" ? await ii(async () => {
25
- const imageBuffer = await fetchImage(node.attrs.src);
26
- const size = imageDimensionsFromData(imageBuffer);
27
- return new ImageRun({
28
- data: imageBuffer,
29
- transformation: {
30
- width: size?.width || 0,
31
- height: size?.height || 0
32
- }
33
- });
34
- }) : new TextRun({
35
- text: ""
36
- });
37
- })
38
- );
39
- }
40
- }
41
- export {
42
- XHtml,
43
- HTMLElement as XHtmlElement,
44
- NodeType as XHtmlNodeType
45
- };
package/http_server.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import { FastifyReply, FastifyRequest } from 'fastify';
2
- export type XHttpServerOptions = {
3
- /** 监听端口 */
4
- port: number;
5
- /** key 为处理器名称,可以加请求方法前缀,如 get#, put# 等,不加则默认 post */
6
- handlers: Record<string, (data: any, req: FastifyRequest, rep: FastifyReply) => any>;
7
- };
8
- export declare class XHttpServer {
9
- private options;
10
- constructor(options: XHttpServerOptions);
11
- start(): Promise<void>;
12
- static start(options: XHttpServerOptions): Promise<void>;
13
- }
package/http_server.js DELETED
@@ -1,49 +0,0 @@
1
- import cookie from "@fastify/cookie";
2
- import cors from "@fastify/cors";
3
- import Fastify from "fastify";
4
- class XHttpServer {
5
- constructor(options) {
6
- this.options = options;
7
- }
8
- async start() {
9
- const fastify = Fastify({
10
- logger: true
11
- });
12
- await fastify.register(cors);
13
- await fastify.register(cookie, {
14
- secret: "cm0elm25o000094rlctgk6a7w"
15
- });
16
- Object.keys(this.options.handlers).forEach((name) => {
17
- let _method;
18
- let _name;
19
- if (name.includes("#")) {
20
- [_method, _name] = name.split("#");
21
- } else {
22
- _method = "post";
23
- _name = name;
24
- }
25
- fastify[_method](
26
- `/${_name}`,
27
- (req, rep) => this.options.handlers[name](
28
- {
29
- ...req.params,
30
- ...req.query,
31
- ...req.body
32
- },
33
- req,
34
- rep
35
- )
36
- );
37
- });
38
- await fastify.listen({
39
- host: "0.0.0.0",
40
- port: this.options.port
41
- });
42
- }
43
- static async start(options) {
44
- await new XHttpServer(options).start();
45
- }
46
- }
47
- export {
48
- XHttpServer
49
- };
package/json.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export declare class XJson {
2
- static parse<T>(value: string): T;
3
- static stringify(value: any, compact?: boolean): string;
4
- static read<T>(file: string): Promise<T>;
5
- static write(file: string, value: any, compact?: boolean): Promise<void>;
6
- }
package/json.js DELETED
@@ -1,19 +0,0 @@
1
- import * as fs from "node:fs";
2
- class XJson {
3
- static parse(value) {
4
- return JSON.parse(value);
5
- }
6
- static stringify(value, compact = false) {
7
- return JSON.stringify(value, null, compact ? void 0 : 2);
8
- }
9
- static async read(file) {
10
- const value = await fs.promises.readFile(file, "utf8");
11
- return XJson.parse(value);
12
- }
13
- static async write(file, value, compact = false) {
14
- await fs.promises.writeFile(file, XJson.stringify(value, compact));
15
- }
16
- }
17
- export {
18
- XJson
19
- };
package/ksb.d.ts DELETED
@@ -1,37 +0,0 @@
1
- /// <reference types="lodash" />
2
- /**
3
- * 环境变量:
4
- *
5
- * `X_KSB_USER_TOKEN`: 用户令牌
6
- */
7
- export declare class XKsb {
8
- static request<T>(url: string, data?: any): Promise<T>;
9
- static desensitize(text: string): string;
10
- static getPaperId(payload: {
11
- paperName: string;
12
- }): Promise<string | undefined>;
13
- static getPaperIdMemo: ((payload: {
14
- paperName: string;
15
- }) => Promise<string | undefined>) & import("lodash").MemoizedFunction;
16
- static deletePaper(payload: {
17
- paperName: string;
18
- }): Promise<void>;
19
- static addPaper(payload: {
20
- paperName: string;
21
- }): Promise<void>;
22
- static ensurePaperExistsAndEmpty(payload: {
23
- paperName: string;
24
- }): Promise<void>;
25
- static addQuestion(payload: {
26
- paperName: string;
27
- question: {
28
- type: '单选' | '判断' | '填空' | '问答';
29
- question: string;
30
- options: Array<{
31
- key: string;
32
- value: string;
33
- }>;
34
- answer: string | boolean | string[];
35
- };
36
- }): Promise<void>;
37
- }
package/ksb.js DELETED
@@ -1,198 +0,0 @@
1
- import { xr } from "@jayfong/x-request";
2
- import { castArray, md5, memoize } from "vtils";
3
- import { XEnv } from "./env.js";
4
- class XKsb {
5
- static async request(url, data) {
6
- const token = await XEnv.getEnvVar("X_KSB_USER_TOKEN");
7
- const key = "12b6bb84e093532fb72b4d65fec3f00b";
8
- const clientId = "ca37dd67-f885-4678-91a7-6531bb153ef2";
9
- const ts = (/* @__PURE__ */ new Date()).getTime();
10
- const sign = md5(`${key}${clientId}${url}${ts}${key}`);
11
- return xr.postJson({
12
- url: `https://www.kaoshibao.com/api${url}`,
13
- data,
14
- autoReferer: true,
15
- // proxyUrl: 'http://127.0.0.1:8888',
16
- headers: {
17
- Timestamp: ts,
18
- Version: "2.2.2",
19
- Platform: "web",
20
- Authorization: token,
21
- "Client-Identifier": clientId,
22
- Sign: sign
23
- }
24
- }).then((res) => res.data);
25
- }
26
- static desensitize(text) {
27
- return text.replace(/台湾|澳门|香港|西藏|新疆|习近平/g, (word) => {
28
- return word.split("").join(String.fromCharCode(8290));
29
- });
30
- }
31
- static async getPaperId(payload) {
32
- const res = await XKsb.request("/user/paper/list", {
33
- keyword: payload.paperName,
34
- page: 1,
35
- size: 10,
36
- parentid: "",
37
- column: "0",
38
- direction: ""
39
- });
40
- return res.data.rows?.[0]?.paperid;
41
- }
42
- static getPaperIdMemo = memoize(
43
- (payload) => XKsb.getPaperId(payload),
44
- (payload) => payload.paperName
45
- );
46
- static async deletePaper(payload) {
47
- const paperId = await XKsb.getPaperId(payload);
48
- if (paperId) {
49
- await XKsb.request("/user/paper/delete", {
50
- id: paperId
51
- });
52
- XKsb.getPaperIdMemo.cache.delete(payload.paperName);
53
- }
54
- }
55
- static async addPaper(payload) {
56
- await XKsb.request("/user/paper/add", {
57
- name: payload.paperName,
58
- type: "4"
59
- });
60
- XKsb.getPaperIdMemo.cache.delete(payload.paperName);
61
- }
62
- static async ensurePaperExistsAndEmpty(payload) {
63
- await XKsb.deletePaper(payload);
64
- await XKsb.addPaper(payload);
65
- }
66
- static async addQuestion(payload) {
67
- payload.question.question = XKsb.desensitize(payload.question.question);
68
- payload.question.options.forEach((opt) => {
69
- opt.value = XKsb.desensitize(opt.value);
70
- });
71
- if (typeof payload.question.answer === "string") {
72
- payload.question.answer = XKsb.desensitize(payload.question.answer);
73
- } else if (Array.isArray(payload.question.answer)) {
74
- payload.question.answer.forEach((v, i) => {
75
- if (typeof v === "string") {
76
- payload.question.answer[i] = XKsb.desensitize(v);
77
- }
78
- });
79
- }
80
- const paperId = await XKsb.getPaperIdMemo(payload);
81
- await XKsb.request(
82
- "/user/question/add",
83
- // 单选
84
- payload.question.type === "\u5355\u9009" ? {
85
- id: "",
86
- qtype: "1",
87
- paperid: paperId,
88
- options: JSON.stringify(
89
- payload.question.options.map((opt) => ({
90
- Key: opt.key,
91
- Value: opt.value,
92
- checked: false,
93
- extend: ""
94
- }))
95
- ),
96
- judgeOptions: [
97
- { Key: "A", Value: "\u6B63\u786E" },
98
- { Key: "B", Value: "\u9519\u8BEF" }
99
- ],
100
- question: payload.question.question,
101
- answer: payload.question.answer,
102
- extra: '{"ordered":"0","case_sensitive":"0"}',
103
- paixuAnswer: "",
104
- analysis: "",
105
- parentid: 0,
106
- chapter: "",
107
- difficulty: "",
108
- blanks: [{ Value: "" }],
109
- optionData: [],
110
- optionTipic: [],
111
- optionDataTipic: {
112
- options: [
113
- { Key: "A", Value: "", checked: false },
114
- { Key: "B", Value: "", checked: false },
115
- { Key: "C", Value: "", checked: false },
116
- { Key: "D", Value: "", checked: false }
117
- ],
118
- answer: ""
119
- },
120
- fileList: []
121
- } : payload.question.type === "\u5224\u65AD" ? {
122
- id: "",
123
- qtype: "3",
124
- paperid: paperId,
125
- options: '[{"Key":"A","Value":"","checked":false},{"Key":"B","Value":"","checked":false},{"Key":"C","Value":"","checked":false},{"Key":"D","Value":"","checked":false}]',
126
- judgeOptions: [
127
- { Key: "A", Value: "\u6B63\u786E" },
128
- { Key: "B", Value: "\u9519\u8BEF" }
129
- ],
130
- question: payload.question.question,
131
- answer: payload.question.answer ? "A" : "B",
132
- parentid: 0,
133
- chapter: "",
134
- difficulty: "",
135
- extra: '{"ordered":"0","case_sensitive":"0"}',
136
- analysis: "",
137
- paixuAnswer: "",
138
- blanks: [{ Value: "" }],
139
- optionData: [],
140
- optionTipic: [],
141
- optionDataTipic: ""
142
- } : payload.question.type === "\u586B\u7A7A" ? {
143
- id: "",
144
- qtype: "4",
145
- paperid: paperId,
146
- options: '[{"Key":"A","Value":"","checked":false},{"Key":"B","Value":"","checked":false},{"Key":"C","Value":"","checked":false},{"Key":"D","Value":"","checked":false}]',
147
- judgeOptions: [
148
- { Key: "A", Value: "\u6B63\u786E" },
149
- { Key: "B", Value: "\u9519\u8BEF" }
150
- ],
151
- question: payload.question.question,
152
- answer: castArray(payload.question.answer).join("|"),
153
- parentid: 0,
154
- chapter: "",
155
- difficulty: "",
156
- extra: '{"ordered":"0","case_sensitive":"0"}',
157
- analysis: "",
158
- paixuAnswer: "",
159
- blanks: castArray(payload.question.answer).map((v) => ({
160
- Value: v
161
- })),
162
- optionData: [],
163
- optionTipic: [],
164
- optionDataTipic: ""
165
- } : payload.question.type === "\u95EE\u7B54" ? {
166
- id: "",
167
- qtype: "11",
168
- paperid: paperId,
169
- options: '[{"Key":"A","Value":"","checked":false},{"Key":"B","Value":"","checked":false},{"Key":"C","Value":"","checked":false},{"Key":"D","Value":"","checked":false}]',
170
- judgeOptions: [
171
- { Key: "A", Value: "\u6B63\u786E" },
172
- { Key: "B", Value: "\u9519\u8BEF" }
173
- ],
174
- question: payload.question.question,
175
- answer: payload.question.answer,
176
- parentid: 0,
177
- chapter: "",
178
- difficulty: "",
179
- extra: '{"ordered":"0","case_sensitive":"0"}',
180
- analysis: "",
181
- paixuAnswer: "",
182
- blanks: [{ Value: "" }],
183
- optionData: [],
184
- optionTipic: [],
185
- optionDataTipic: ""
186
- } : {}
187
- // 判断
188
- // {"id":"","qtype":"3","paperid":"15844653","options":"[{\"Key\":\"A\",\"Value\":\"\",\"checked\":false},{\"Key\":\"B\",\"Value\":\"\",\"checked\":false},{\"Key\":\"C\",\"Value\":\"\",\"checked\":false},{\"Key\":\"D\",\"Value\":\"\",\"checked\":false}]","judgeOptions":[{"Key":"A","Value":"正确"},{"Key":"B","Value":"错误"}],"question":"<p>顶顶顶顶</p>","answer":"A","parentid":0,"chapter":"","difficulty":"","extra":"{\"ordered\":\"0\",\"case_sensitive\":\"0\"}","analysis":"","paixuAnswer":"","blanks":[{"Value":""}],"optionData":[],"optionTipic":[],"optionDataTipic":""}
189
- // 填空
190
- // {"id":"","qtype":"4","paperid":"15844653","options":"[{\"Key\":\"A\",\"Value\":\"\",\"checked\":false},{\"Key\":\"B\",\"Value\":\"\",\"checked\":false},{\"Key\":\"C\",\"Value\":\"\",\"checked\":false},{\"Key\":\"D\",\"Value\":\"\",\"checked\":false}]","judgeOptions":[{"Key":"A","Value":"正确"},{"Key":"B","Value":"错误"}],"question":"<p>99999999</p>","answer":"999|888","parentid":0,"chapter":"","difficulty":"","extra":"{\"ordered\":\"0\",\"case_sensitive\":\"0\"}","analysis":"","paixuAnswer":"","blanks":[{"Value":"999"},{"Value":"888"}],"optionData":[],"optionTipic":[],"optionDataTipic":""}
191
- // 问答
192
- // {"id":"","qtype":"11","paperid":"15844653","options":"[{\"Key\":\"A\",\"Value\":\"\",\"checked\":false},{\"Key\":\"B\",\"Value\":\"\",\"checked\":false},{\"Key\":\"C\",\"Value\":\"\",\"checked\":false},{\"Key\":\"D\",\"Value\":\"\",\"checked\":false}]","judgeOptions":[{"Key":"A","Value":"正确"},{"Key":"B","Value":"错误"}],"question":"<p>666666</p>","answer":"<p>67777777</p>","parentid":0,"chapter":"","difficulty":"","extra":"{\"ordered\":\"0\",\"case_sensitive\":\"0\"}","analysis":"","paixuAnswer":"","blanks":[{"Value":""}],"optionData":[],"optionTipic":[],"optionDataTipic":""}
193
- );
194
- }
195
- }
196
- export {
197
- XKsb
198
- };
package/number.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare class XNumber {
2
- static toChinese(value: number): string;
3
- }
package/number.js DELETED
@@ -1,9 +0,0 @@
1
- import nzh from "nzh";
2
- class XNumber {
3
- static toChinese(value) {
4
- return nzh.cn.encodeS(value);
5
- }
6
- }
7
- export {
8
- XNumber
9
- };
package/ocr.d.ts DELETED
@@ -1,17 +0,0 @@
1
- /// <reference types="node" />
2
- /**
3
- * 环境变量:
4
- *
5
- * - `X_OCR_RECOGNIZE_SERVER_URL`: 文字识别服务地址
6
- * - `X_OCR_RECOGNIZE_CAPTCHA_SERVER_URL`: 验证码识别服务地址
7
- * - `X_OCR_RECOGNIZE_CAPTCHA_SERVER_TOKEN`: 验证码识别服务令牌
8
- */
9
- export declare class XOcr {
10
- static recognize(url: string, { serverUrl, }?: {
11
- serverUrl?: string;
12
- }): Promise<string>;
13
- static recognizeCaptcha(buffer: Buffer, { serverUrl, serverToken, }?: {
14
- serverUrl?: string;
15
- serverToken?: string;
16
- }): Promise<string>;
17
- }
package/ocr.js DELETED
@@ -1,54 +0,0 @@
1
- import { xr } from "@jayfong/x-request";
2
- import { XEnv } from "./env.js";
3
- class XOcr {
4
- static async recognize(url, {
5
- serverUrl
6
- } = {}) {
7
- if (serverUrl == null) {
8
- serverUrl = await XEnv.getEnvVar("X_OCR_RECOGNIZE_SERVER_URL");
9
- }
10
- const { data: buffer } = await xr.get({
11
- url,
12
- autoReferer: true
13
- });
14
- const base64 = buffer.toString("base64");
15
- const { data: res } = await xr.postJson({
16
- url: serverUrl,
17
- data: {
18
- base64,
19
- options: {}
20
- }
21
- });
22
- if (res.code !== 100) {
23
- if (res.data.includes("No text found in image")) {
24
- return "";
25
- }
26
- throw new Error(res.data);
27
- }
28
- return res.data.map((item) => item.text).join(" ");
29
- }
30
- static async recognizeCaptcha(buffer, {
31
- serverUrl,
32
- serverToken
33
- } = {}) {
34
- if (serverUrl == null) {
35
- serverUrl = await XEnv.getEnvVar("X_OCR_RECOGNIZE_CAPTCHA_SERVER_URL");
36
- }
37
- if (serverToken == null) {
38
- serverToken = await XEnv.getEnvVar(
39
- "X_OCR_RECOGNIZE_CAPTCHA_SERVER_TOKEN"
40
- );
41
- }
42
- const res = await xr.postJson({
43
- url: serverUrl,
44
- data: xr.formData({
45
- token: serverToken,
46
- file: xr.formFile(buffer, { name: "xx.png" })
47
- })
48
- });
49
- return res.data.text;
50
- }
51
- }
52
- export {
53
- XOcr
54
- };
package/path.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import path from 'pathe';
2
- export declare const XPath: typeof path;
package/path.js DELETED
@@ -1,5 +0,0 @@
1
- import path from "pathe";
2
- const XPath = path;
3
- export {
4
- XPath
5
- };
package/pinyin.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export declare class XPinyin {
2
- /**
3
- * - `我们` => `['wo', 'men']`
4
- *
5
- * - `2` => `['2']`
6
- */
7
- static getTonelessPinyin(text: string): string[];
8
- }
package/pinyin.js DELETED
@@ -1,17 +0,0 @@
1
- import { pinyin } from "pinyin-pro";
2
- class XPinyin {
3
- /**
4
- * - `我们` => `['wo', 'men']`
5
- *
6
- * - `2` => `['2']`
7
- */
8
- static getTonelessPinyin(text) {
9
- return pinyin(text, {
10
- type: "array",
11
- toneType: "none"
12
- });
13
- }
14
- }
15
- export {
16
- XPinyin
17
- };
package/puppeteer.d.ts DELETED
@@ -1,38 +0,0 @@
1
- /// <reference types="lodash" />
2
- import { Browser, ElementHandle, Page } from 'puppeteer';
3
- export type XPuppeteerBrowser = Browser;
4
- export type XPuppeteerPage = Page;
5
- export type XPuppeteerOpenBrowserOptions = {
6
- headful?: boolean;
7
- proxy?: string;
8
- dataDir?: string;
9
- };
10
- export type XPuppeteerOpenPageOptions = {
11
- match?: string | RegExp;
12
- blockAssets?: boolean;
13
- referer?: string;
14
- };
15
- export type XPuppeteerGetPageHtmlOptions = XPuppeteerOpenBrowserOptions & XPuppeteerOpenPageOptions & {
16
- instanceId?: string | number;
17
- useSystemBrowser?: boolean;
18
- afterOpenPage?: (payload: {
19
- browser: XPuppeteer;
20
- page: XPuppeteerPage;
21
- }) => any;
22
- };
23
- export declare class XPuppeteer {
24
- browser: Browser;
25
- connectSystemBrowser(): Promise<Browser>;
26
- openBrowser(options?: XPuppeteerOpenBrowserOptions): Promise<Browser>;
27
- openPage(urlOrHtml: string, options?: XPuppeteerOpenPageOptions): Promise<Page>;
28
- input(page: Page, selector: string, textOrHtml: string, frameIndex?: number): Promise<void>;
29
- selectAll(page: Page): Promise<void>;
30
- paste(page: Page): Promise<void>;
31
- queryByText<T extends Node = HTMLDivElement>(page: Page, text: string | RegExp | ((el: T) => boolean)): Promise<ElementHandle<T>>;
32
- disconnect(): Promise<void>;
33
- close(): Promise<void>;
34
- static openBrowser(options?: XPuppeteerOpenBrowserOptions): Promise<XPuppeteer>;
35
- static openPage(urlOrHtml: string, options?: XPuppeteerGetPageHtmlOptions): Promise<Page>;
36
- static getPageHtmlXp: ((options: XPuppeteerGetPageHtmlOptions) => Promise<XPuppeteer>) & import("lodash").MemoizedFunction;
37
- static getPageHtml(url: string, options?: XPuppeteerGetPageHtmlOptions): Promise<string>;
38
- }