@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/_cjs/fs.js DELETED
@@ -1,86 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var fs_exports = {};
30
- __export(fs_exports, {
31
- XFs: () => XFs
32
- });
33
- module.exports = __toCommonJS(fs_exports);
34
- var import_fs_extra = __toESM(require("fs-extra"), 1);
35
- var import_mime = __toESM(require("mime"), 1);
36
- var import_probe_image_size = __toESM(require("probe-image-size"), 1);
37
- const XFsExtra = {
38
- getMimeType(extOrName) {
39
- return import_mime.default.getType(extOrName) || "application/octet-stream";
40
- },
41
- getExtension(typeOrName) {
42
- if (typeOrName.includes(".")) {
43
- return typeOrName.split(".").pop();
44
- }
45
- return import_mime.default.getExtension(typeOrName) || "";
46
- },
47
- async toBuffer(file) {
48
- if (Buffer.isBuffer(file)) {
49
- return file;
50
- }
51
- const chunks = [];
52
- for await (const chunk of file) {
53
- chunks.push(chunk);
54
- }
55
- const buffer = Buffer.concat(chunks);
56
- return buffer;
57
- },
58
- async toText(file) {
59
- const buffer = Buffer.isBuffer(file) ? file : await XFsExtra.toBuffer(file);
60
- return buffer.toString("utf-8");
61
- },
62
- async toMaskImage(file) {
63
- const buffers = [
64
- // PNG 文件头
65
- // https://zh.wikipedia.org/wiki/PNG
66
- Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
67
- await XFsExtra.toBuffer(file)
68
- ];
69
- return Buffer.concat(buffers);
70
- },
71
- async getImageInfo(urlOrStreamOrBuffer, options) {
72
- return typeof urlOrStreamOrBuffer === "string" ? (0, import_probe_image_size.default)(urlOrStreamOrBuffer, {
73
- rejectUnauthorized: false,
74
- ...options,
75
- headers: {
76
- "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.17(0x17001126) NetType/WIFI Language/zh_CN",
77
- Referer: urlOrStreamOrBuffer,
78
- ...options?.headers
79
- }
80
- }) : Buffer.isBuffer(urlOrStreamOrBuffer) ? import_probe_image_size.default.sync(urlOrStreamOrBuffer) : (0, import_probe_image_size.default)(urlOrStreamOrBuffer, true);
81
- }
82
- };
83
- const XFs = {
84
- ...import_fs_extra.default,
85
- ...XFsExtra
86
- };
package/_cjs/html.js DELETED
@@ -1,62 +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 html_exports = {};
20
- __export(html_exports, {
21
- XHtml: () => XHtml,
22
- XHtmlElement: () => import_node_html_parser2.HTMLElement,
23
- XHtmlNodeType: () => import_node_html_parser2.NodeType
24
- });
25
- module.exports = __toCommonJS(html_exports);
26
- var import_docx = require("docx");
27
- var import_image_dimensions = require("image-dimensions");
28
- var import_node_html_parser = require("node-html-parser");
29
- var import_posthtml_parser = require("posthtml-parser");
30
- var import_vtils = require("vtils");
31
- var import_node_html_parser2 = require("node-html-parser");
32
- class XHtml {
33
- static parse(html) {
34
- return (0, import_node_html_parser.parse)(html);
35
- }
36
- static async toDocxParagraphChildren(html, fetchImage) {
37
- const nodes = (0, import_posthtml_parser.parser)(html, {
38
- decodeEntities: true
39
- }).map(function process(node) {
40
- return typeof node === "object" && node.content && Array.isArray(node.content) ? (0, import_vtils.flattenDeep)(node.content).map(process).flat() : [node];
41
- }).flat();
42
- return await Promise.all(
43
- nodes.map(async (node) => {
44
- return typeof node === "string" || typeof node === "number" ? new import_docx.TextRun({
45
- text: String(node)
46
- }) : node.tag === "img" && typeof node.attrs?.src === "string" ? await (0, import_vtils.ii)(async () => {
47
- const imageBuffer = await fetchImage(node.attrs.src);
48
- const size = (0, import_image_dimensions.imageDimensionsFromData)(imageBuffer);
49
- return new import_docx.ImageRun({
50
- data: imageBuffer,
51
- transformation: {
52
- width: size?.width || 0,
53
- height: size?.height || 0
54
- }
55
- });
56
- }) : new import_docx.TextRun({
57
- text: ""
58
- });
59
- })
60
- );
61
- }
62
- }
@@ -1,79 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var http_server_exports = {};
30
- __export(http_server_exports, {
31
- XHttpServer: () => XHttpServer
32
- });
33
- module.exports = __toCommonJS(http_server_exports);
34
- var import_cookie = __toESM(require("@fastify/cookie"), 1);
35
- var import_cors = __toESM(require("@fastify/cors"), 1);
36
- var import_fastify = __toESM(require("fastify"), 1);
37
- class XHttpServer {
38
- constructor(options) {
39
- this.options = options;
40
- }
41
- async start() {
42
- const fastify = (0, import_fastify.default)({
43
- logger: true
44
- });
45
- await fastify.register(import_cors.default);
46
- await fastify.register(import_cookie.default, {
47
- secret: "cm0elm25o000094rlctgk6a7w"
48
- });
49
- Object.keys(this.options.handlers).forEach((name) => {
50
- let _method;
51
- let _name;
52
- if (name.includes("#")) {
53
- [_method, _name] = name.split("#");
54
- } else {
55
- _method = "post";
56
- _name = name;
57
- }
58
- fastify[_method](
59
- `/${_name}`,
60
- (req, rep) => this.options.handlers[name](
61
- {
62
- ...req.params,
63
- ...req.query,
64
- ...req.body
65
- },
66
- req,
67
- rep
68
- )
69
- );
70
- });
71
- await fastify.listen({
72
- host: "0.0.0.0",
73
- port: this.options.port
74
- });
75
- }
76
- static async start(options) {
77
- await new XHttpServer(options).start();
78
- }
79
- }
package/_cjs/json.js DELETED
@@ -1,49 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var json_exports = {};
30
- __export(json_exports, {
31
- XJson: () => XJson
32
- });
33
- module.exports = __toCommonJS(json_exports);
34
- var fs = __toESM(require("node:fs"), 1);
35
- class XJson {
36
- static parse(value) {
37
- return JSON.parse(value);
38
- }
39
- static stringify(value, compact = false) {
40
- return JSON.stringify(value, null, compact ? void 0 : 2);
41
- }
42
- static async read(file) {
43
- const value = await fs.promises.readFile(file, "utf8");
44
- return XJson.parse(value);
45
- }
46
- static async write(file, value, compact = false) {
47
- await fs.promises.writeFile(file, XJson.stringify(value, compact));
48
- }
49
- }
package/_cjs/ksb.js DELETED
@@ -1,218 +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 ksb_exports = {};
20
- __export(ksb_exports, {
21
- XKsb: () => XKsb
22
- });
23
- module.exports = __toCommonJS(ksb_exports);
24
- var import_x_request = require("@jayfong/x-request");
25
- var import_vtils = require("vtils");
26
- var import_env = require("./env.js");
27
- class XKsb {
28
- static async request(url, data) {
29
- const token = await import_env.XEnv.getEnvVar("X_KSB_USER_TOKEN");
30
- const key = "12b6bb84e093532fb72b4d65fec3f00b";
31
- const clientId = "ca37dd67-f885-4678-91a7-6531bb153ef2";
32
- const ts = (/* @__PURE__ */ new Date()).getTime();
33
- const sign = (0, import_vtils.md5)(`${key}${clientId}${url}${ts}${key}`);
34
- return import_x_request.xr.postJson({
35
- url: `https://www.kaoshibao.com/api${url}`,
36
- data,
37
- autoReferer: true,
38
- // proxyUrl: 'http://127.0.0.1:8888',
39
- headers: {
40
- Timestamp: ts,
41
- Version: "2.2.2",
42
- Platform: "web",
43
- Authorization: token,
44
- "Client-Identifier": clientId,
45
- Sign: sign
46
- }
47
- }).then((res) => res.data);
48
- }
49
- static desensitize(text) {
50
- return text.replace(/台湾|澳门|香港|西藏|新疆|习近平/g, (word) => {
51
- return word.split("").join(String.fromCharCode(8290));
52
- });
53
- }
54
- static async getPaperId(payload) {
55
- const res = await XKsb.request("/user/paper/list", {
56
- keyword: payload.paperName,
57
- page: 1,
58
- size: 10,
59
- parentid: "",
60
- column: "0",
61
- direction: ""
62
- });
63
- return res.data.rows?.[0]?.paperid;
64
- }
65
- static getPaperIdMemo = (0, import_vtils.memoize)(
66
- (payload) => XKsb.getPaperId(payload),
67
- (payload) => payload.paperName
68
- );
69
- static async deletePaper(payload) {
70
- const paperId = await XKsb.getPaperId(payload);
71
- if (paperId) {
72
- await XKsb.request("/user/paper/delete", {
73
- id: paperId
74
- });
75
- XKsb.getPaperIdMemo.cache.delete(payload.paperName);
76
- }
77
- }
78
- static async addPaper(payload) {
79
- await XKsb.request("/user/paper/add", {
80
- name: payload.paperName,
81
- type: "4"
82
- });
83
- XKsb.getPaperIdMemo.cache.delete(payload.paperName);
84
- }
85
- static async ensurePaperExistsAndEmpty(payload) {
86
- await XKsb.deletePaper(payload);
87
- await XKsb.addPaper(payload);
88
- }
89
- static async addQuestion(payload) {
90
- payload.question.question = XKsb.desensitize(payload.question.question);
91
- payload.question.options.forEach((opt) => {
92
- opt.value = XKsb.desensitize(opt.value);
93
- });
94
- if (typeof payload.question.answer === "string") {
95
- payload.question.answer = XKsb.desensitize(payload.question.answer);
96
- } else if (Array.isArray(payload.question.answer)) {
97
- payload.question.answer.forEach((v, i) => {
98
- if (typeof v === "string") {
99
- payload.question.answer[i] = XKsb.desensitize(v);
100
- }
101
- });
102
- }
103
- const paperId = await XKsb.getPaperIdMemo(payload);
104
- await XKsb.request(
105
- "/user/question/add",
106
- // 单选
107
- payload.question.type === "\u5355\u9009" ? {
108
- id: "",
109
- qtype: "1",
110
- paperid: paperId,
111
- options: JSON.stringify(
112
- payload.question.options.map((opt) => ({
113
- Key: opt.key,
114
- Value: opt.value,
115
- checked: false,
116
- extend: ""
117
- }))
118
- ),
119
- judgeOptions: [
120
- { Key: "A", Value: "\u6B63\u786E" },
121
- { Key: "B", Value: "\u9519\u8BEF" }
122
- ],
123
- question: payload.question.question,
124
- answer: payload.question.answer,
125
- extra: '{"ordered":"0","case_sensitive":"0"}',
126
- paixuAnswer: "",
127
- analysis: "",
128
- parentid: 0,
129
- chapter: "",
130
- difficulty: "",
131
- blanks: [{ Value: "" }],
132
- optionData: [],
133
- optionTipic: [],
134
- optionDataTipic: {
135
- options: [
136
- { Key: "A", Value: "", checked: false },
137
- { Key: "B", Value: "", checked: false },
138
- { Key: "C", Value: "", checked: false },
139
- { Key: "D", Value: "", checked: false }
140
- ],
141
- answer: ""
142
- },
143
- fileList: []
144
- } : payload.question.type === "\u5224\u65AD" ? {
145
- id: "",
146
- qtype: "3",
147
- paperid: paperId,
148
- options: '[{"Key":"A","Value":"","checked":false},{"Key":"B","Value":"","checked":false},{"Key":"C","Value":"","checked":false},{"Key":"D","Value":"","checked":false}]',
149
- judgeOptions: [
150
- { Key: "A", Value: "\u6B63\u786E" },
151
- { Key: "B", Value: "\u9519\u8BEF" }
152
- ],
153
- question: payload.question.question,
154
- answer: payload.question.answer ? "A" : "B",
155
- parentid: 0,
156
- chapter: "",
157
- difficulty: "",
158
- extra: '{"ordered":"0","case_sensitive":"0"}',
159
- analysis: "",
160
- paixuAnswer: "",
161
- blanks: [{ Value: "" }],
162
- optionData: [],
163
- optionTipic: [],
164
- optionDataTipic: ""
165
- } : payload.question.type === "\u586B\u7A7A" ? {
166
- id: "",
167
- qtype: "4",
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: (0, import_vtils.castArray)(payload.question.answer).join("|"),
176
- parentid: 0,
177
- chapter: "",
178
- difficulty: "",
179
- extra: '{"ordered":"0","case_sensitive":"0"}',
180
- analysis: "",
181
- paixuAnswer: "",
182
- blanks: (0, import_vtils.castArray)(payload.question.answer).map((v) => ({
183
- Value: v
184
- })),
185
- optionData: [],
186
- optionTipic: [],
187
- optionDataTipic: ""
188
- } : payload.question.type === "\u95EE\u7B54" ? {
189
- id: "",
190
- qtype: "11",
191
- paperid: paperId,
192
- options: '[{"Key":"A","Value":"","checked":false},{"Key":"B","Value":"","checked":false},{"Key":"C","Value":"","checked":false},{"Key":"D","Value":"","checked":false}]',
193
- judgeOptions: [
194
- { Key: "A", Value: "\u6B63\u786E" },
195
- { Key: "B", Value: "\u9519\u8BEF" }
196
- ],
197
- question: payload.question.question,
198
- answer: payload.question.answer,
199
- parentid: 0,
200
- chapter: "",
201
- difficulty: "",
202
- extra: '{"ordered":"0","case_sensitive":"0"}',
203
- analysis: "",
204
- paixuAnswer: "",
205
- blanks: [{ Value: "" }],
206
- optionData: [],
207
- optionTipic: [],
208
- optionDataTipic: ""
209
- } : {}
210
- // 判断
211
- // {"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":""}
212
- // 填空
213
- // {"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":""}
214
- // 问答
215
- // {"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":""}
216
- );
217
- }
218
- }
package/_cjs/number.js DELETED
@@ -1,39 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var number_exports = {};
30
- __export(number_exports, {
31
- XNumber: () => XNumber
32
- });
33
- module.exports = __toCommonJS(number_exports);
34
- var import_nzh = __toESM(require("nzh"), 1);
35
- class XNumber {
36
- static toChinese(value) {
37
- return import_nzh.default.cn.encodeS(value);
38
- }
39
- }
package/_cjs/ocr.js DELETED
@@ -1,74 +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 ocr_exports = {};
20
- __export(ocr_exports, {
21
- XOcr: () => XOcr
22
- });
23
- module.exports = __toCommonJS(ocr_exports);
24
- var import_x_request = require("@jayfong/x-request");
25
- var import_env = require("./env.js");
26
- class XOcr {
27
- static async recognize(url, {
28
- serverUrl
29
- } = {}) {
30
- if (serverUrl == null) {
31
- serverUrl = await import_env.XEnv.getEnvVar("X_OCR_RECOGNIZE_SERVER_URL");
32
- }
33
- const { data: buffer } = await import_x_request.xr.get({
34
- url,
35
- autoReferer: true
36
- });
37
- const base64 = buffer.toString("base64");
38
- const { data: res } = await import_x_request.xr.postJson({
39
- url: serverUrl,
40
- data: {
41
- base64,
42
- options: {}
43
- }
44
- });
45
- if (res.code !== 100) {
46
- if (res.data.includes("No text found in image")) {
47
- return "";
48
- }
49
- throw new Error(res.data);
50
- }
51
- return res.data.map((item) => item.text).join(" ");
52
- }
53
- static async recognizeCaptcha(buffer, {
54
- serverUrl,
55
- serverToken
56
- } = {}) {
57
- if (serverUrl == null) {
58
- serverUrl = await import_env.XEnv.getEnvVar("X_OCR_RECOGNIZE_CAPTCHA_SERVER_URL");
59
- }
60
- if (serverToken == null) {
61
- serverToken = await import_env.XEnv.getEnvVar(
62
- "X_OCR_RECOGNIZE_CAPTCHA_SERVER_TOKEN"
63
- );
64
- }
65
- const res = await import_x_request.xr.postJson({
66
- url: serverUrl,
67
- data: import_x_request.xr.formData({
68
- token: serverToken,
69
- file: import_x_request.xr.formFile(buffer, { name: "xx.png" })
70
- })
71
- });
72
- return res.data.text;
73
- }
74
- }
package/_cjs/path.js DELETED
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var path_exports = {};
30
- __export(path_exports, {
31
- XPath: () => XPath
32
- });
33
- module.exports = __toCommonJS(path_exports);
34
- var import_pathe = __toESM(require("pathe"), 1);
35
- const XPath = import_pathe.default;