@jayfong/x-utils 1.0.0-202407012223

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 (77) hide show
  1. package/_cjs/ai.js +80 -0
  2. package/_cjs/cli.js +51 -0
  3. package/_cjs/clipboard.js +65 -0
  4. package/_cjs/cmd.js +42 -0
  5. package/_cjs/crawler.js +341 -0
  6. package/_cjs/csv.js +97 -0
  7. package/_cjs/data_set.js +115 -0
  8. package/_cjs/env.js +63 -0
  9. package/_cjs/fs.js +35 -0
  10. package/_cjs/html.js +62 -0
  11. package/_cjs/http_server.js +56 -0
  12. package/_cjs/json.js +49 -0
  13. package/_cjs/ksb.js +217 -0
  14. package/_cjs/number.js +39 -0
  15. package/_cjs/ocr.js +74 -0
  16. package/_cjs/path.js +35 -0
  17. package/_cjs/pinyin.js +32 -0
  18. package/_cjs/puppeteer.js +271 -0
  19. package/_cjs/runner.js +88 -0
  20. package/_cjs/task.js +41 -0
  21. package/_cjs/text.js +136 -0
  22. package/_cjs/unicode/lib_unicode.js +58643 -0
  23. package/_cjs/unicode/unicode.js +441 -0
  24. package/_cjs/upload.js +100 -0
  25. package/_cjs/yaml.js +52 -0
  26. package/ai.d.ts +26 -0
  27. package/ai.js +60 -0
  28. package/cli.d.ts +14 -0
  29. package/cli.js +21 -0
  30. package/clipboard.d.ts +6 -0
  31. package/clipboard.js +35 -0
  32. package/cmd.d.ts +5 -0
  33. package/cmd.js +22 -0
  34. package/crawler.d.ts +162 -0
  35. package/crawler.js +332 -0
  36. package/csv.d.ts +14 -0
  37. package/csv.js +67 -0
  38. package/data_set.d.ts +22 -0
  39. package/data_set.js +85 -0
  40. package/env.d.ts +4 -0
  41. package/env.js +32 -0
  42. package/fs.d.ts +2 -0
  43. package/fs.js +5 -0
  44. package/html.d.ts +7 -0
  45. package/html.js +45 -0
  46. package/http_server.d.ts +10 -0
  47. package/http_server.js +26 -0
  48. package/json.d.ts +6 -0
  49. package/json.js +19 -0
  50. package/ksb.d.ts +32 -0
  51. package/ksb.js +197 -0
  52. package/number.d.ts +3 -0
  53. package/number.js +9 -0
  54. package/ocr.d.ts +10 -0
  55. package/ocr.js +54 -0
  56. package/ofd.d.ts +1 -0
  57. package/package.json +158 -0
  58. package/path.d.ts +2 -0
  59. package/path.js +5 -0
  60. package/pinyin.d.ts +3 -0
  61. package/pinyin.js +12 -0
  62. package/puppeteer.d.ts +38 -0
  63. package/puppeteer.js +241 -0
  64. package/runner.d.ts +13 -0
  65. package/runner.js +58 -0
  66. package/task.d.ts +6 -0
  67. package/task.js +21 -0
  68. package/text.d.ts +63 -0
  69. package/text.js +119 -0
  70. package/unicode/lib_unicode.d.ts +4 -0
  71. package/unicode/lib_unicode.js +58623 -0
  72. package/unicode/unicode.d.ts +347 -0
  73. package/unicode/unicode.js +426 -0
  74. package/upload.d.ts +22 -0
  75. package/upload.js +70 -0
  76. package/yaml.d.ts +6 -0
  77. package/yaml.js +22 -0
@@ -0,0 +1,115 @@
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 data_set_exports = {};
30
+ __export(data_set_exports, {
31
+ XDataSet: () => XDataSet
32
+ });
33
+ module.exports = __toCommonJS(data_set_exports);
34
+ var import_exit_hook = require("exit-hook");
35
+ var import_fs_extra = __toESM(require("fs-extra"), 1);
36
+ var path = __toESM(require("node:path"), 1);
37
+ var import_vtils = require("vtils");
38
+ var import_vae = require("vtils/vae");
39
+ var import_csv = require("./csv.js");
40
+ var import_json = require("./json.js");
41
+ var import_yaml = require("./yaml.js");
42
+ class XDataSet {
43
+ constructor(options) {
44
+ this.options = options;
45
+ this.storeType = options.storeFile.endsWith(".csv") ? "csv" : options.storeFile.endsWith(".yaml") || options.storeFile.endsWith(".yml") ? "yaml" : "json";
46
+ this.dataShapeSchema = options.dataSchema(import_vae.v);
47
+ this.dataSchema = import_vae.v.object(this.dataShapeSchema);
48
+ this.csvOptions = {
49
+ arrayDelimiter: options.csvArrayDelimiter,
50
+ arrayFieldNames: (0, import_vtils.keysStrict)(this.dataShapeSchema).filter(
51
+ (key) => this.dataShapeSchema[key].options.type === "array"
52
+ ),
53
+ objectFieldNames: (0, import_vtils.keysStrict)(this.dataShapeSchema).filter(
54
+ (key) => this.dataShapeSchema[key].options.type === "object"
55
+ ),
56
+ booleanFieldNames: (0, import_vtils.keysStrict)(this.dataShapeSchema).filter(
57
+ (key) => this.dataShapeSchema[key].options.type === "boolean"
58
+ ),
59
+ dateFieldNames: (0, import_vtils.keysStrict)(this.dataShapeSchema).filter(
60
+ (key) => this.dataShapeSchema[key].options.type === "date"
61
+ )
62
+ };
63
+ if (!options.noAutoWrite) {
64
+ const timer = setInterval(() => {
65
+ this.write();
66
+ }, options.autoWriteInterval || 5e3);
67
+ (0, import_exit_hook.asyncExitHook)(
68
+ async () => {
69
+ clearInterval(timer);
70
+ await this.write();
71
+ },
72
+ {
73
+ wait: 1e4
74
+ }
75
+ );
76
+ }
77
+ }
78
+ storeType;
79
+ dataShapeSchema;
80
+ dataSchema;
81
+ csvOptions;
82
+ currentMap;
83
+ get current() {
84
+ const orderedDataFieldNames = (0, import_vtils.keysStrict)(this.dataShapeSchema);
85
+ const dataSet = (0, import_vtils.keysStrict)(this.currentMap).map((dataKeyValue) => {
86
+ const data = {
87
+ ...this.currentMap[dataKeyValue],
88
+ [this.options.dataKey]: dataKeyValue
89
+ };
90
+ return this.dataSchema.cast(
91
+ (0, import_vtils.pickStrict)(data, orderedDataFieldNames)
92
+ );
93
+ });
94
+ return dataSet;
95
+ }
96
+ async read() {
97
+ let dataSet = [];
98
+ try {
99
+ dataSet = await (this.storeType === "csv" ? import_csv.XCsv.read(this.options.storeFile, this.csvOptions) : this.storeType === "yaml" ? import_yaml.XYaml.read(this.options.storeFile) : import_json.XJson.read(this.options.storeFile));
100
+ } catch {
101
+ }
102
+ dataSet = dataSet.map((data) => this.dataSchema.cast(data));
103
+ this.currentMap = (0, import_vtils.keyBy)(
104
+ dataSet,
105
+ (data) => data[this.options.dataKey]
106
+ );
107
+ return dataSet;
108
+ }
109
+ async write(dataSet = this.current) {
110
+ console.log(`\u{1F4A5} \u5199\u5165 ${this.options.storeFile}`);
111
+ await import_fs_extra.default.ensureDir(path.dirname(this.options.storeFile));
112
+ await (this.storeType === "csv" ? import_csv.XCsv.write(this.options.storeFile, dataSet, this.csvOptions) : this.storeType === "yaml" ? import_yaml.XYaml.write(this.options.storeFile, dataSet) : import_json.XJson.write(this.options.storeFile, dataSet));
113
+ console.log(`\u2705 \u5199\u5165 ${this.options.storeFile}`);
114
+ }
115
+ }
package/_cjs/env.js ADDED
@@ -0,0 +1,63 @@
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 env_exports = {};
30
+ __export(env_exports, {
31
+ XEnv: () => XEnv
32
+ });
33
+ module.exports = __toCommonJS(env_exports);
34
+ var import_dotenv = __toESM(require("dotenv"), 1);
35
+ var import_vtils = require("vtils");
36
+ var import_fs = require("./fs.js");
37
+ var import_path = require("./path.js");
38
+ var import_yaml = require("./yaml.js");
39
+ const import_meta = {};
40
+ class XEnv {
41
+ static getEnvVarsFromFile = (0, import_vtils.memoize)(async () => {
42
+ const envYmlFile = import_path.XPath.join(import_meta.dirname, ".env.yml");
43
+ if (await import_fs.XFs.pathExists(envYmlFile)) {
44
+ return import_yaml.XYaml.read(envYmlFile);
45
+ }
46
+ const envYamlFile = import_path.XPath.join(import_meta.dirname, ".env.yaml");
47
+ if (await import_fs.XFs.pathExists(envYamlFile)) {
48
+ return import_yaml.XYaml.read(envYamlFile);
49
+ }
50
+ const dotenvFile = import_path.XPath.join(import_meta.dirname, ".env");
51
+ if (await import_fs.XFs.pathExists(dotenvFile)) {
52
+ const dotenvContent = await import_fs.XFs.readFile(dotenvFile, "utf-8");
53
+ return import_dotenv.default.parse(dotenvContent);
54
+ }
55
+ });
56
+ static async getEnvVar(name) {
57
+ if (process.env[name] != null) {
58
+ return process.env[name];
59
+ }
60
+ const envVars = await XEnv.getEnvVarsFromFile();
61
+ return (0, import_vtils.isPlainObject)(envVars) ? envVars[name] ?? void 0 : void 0;
62
+ }
63
+ }
package/_cjs/fs.js ADDED
@@ -0,0 +1,35 @@
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
+ const XFs = import_fs_extra.default;
package/_cjs/html.js ADDED
@@ -0,0 +1,62 @@
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
+ }
@@ -0,0 +1,56 @@
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_cors = __toESM(require("@fastify/cors"), 1);
35
+ var import_fastify = __toESM(require("fastify"), 1);
36
+ class XHttpServer {
37
+ constructor(options) {
38
+ this.options = options;
39
+ }
40
+ async start() {
41
+ const fastify = (0, import_fastify.default)({
42
+ logger: true
43
+ });
44
+ await fastify.register(import_cors.default);
45
+ Object.keys(this.options.handlers).forEach((name) => {
46
+ fastify.post(`/${name}`, (req) => this.options.handlers[name](req.body));
47
+ });
48
+ await fastify.listen({
49
+ host: "0.0.0.0",
50
+ port: this.options.port
51
+ });
52
+ }
53
+ static async start(options) {
54
+ await new XHttpServer(options).start();
55
+ }
56
+ }
package/_cjs/json.js ADDED
@@ -0,0 +1,49 @@
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 ADDED
@@ -0,0 +1,217 @@
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
+ class XKsb {
27
+ static request(url, data) {
28
+ const token = "%22ZpWKMcjeUIsZMwZIMUdkhEfAq93e3dPsQyWxAtkRNbc=%22";
29
+ const key = "12b6bb84e093532fb72b4d65fec3f00b";
30
+ const clientId = "ca37dd67-f885-4678-91a7-6531bb153ef2";
31
+ const ts = (/* @__PURE__ */ new Date()).getTime();
32
+ const sign = (0, import_vtils.md5)(`${key}${clientId}${url}${ts}${key}`);
33
+ return import_x_request.xr.postJson({
34
+ url: `https://www.kaoshibao.com/api${url}`,
35
+ data,
36
+ autoReferer: true,
37
+ // proxyUrl: 'http://127.0.0.1:8888',
38
+ headers: {
39
+ Timestamp: ts,
40
+ Version: "2.2.2",
41
+ Platform: "web",
42
+ Authorization: token,
43
+ "Client-Identifier": clientId,
44
+ Sign: sign
45
+ }
46
+ }).then((res) => res.data);
47
+ }
48
+ static desensitize(text) {
49
+ return text.replace(/台湾|澳门|香港|西藏|新疆|习近平/g, (word) => {
50
+ return word.split("").join(String.fromCharCode(8290));
51
+ });
52
+ }
53
+ static async getPaperId(payload) {
54
+ const res = await XKsb.request("/user/paper/list", {
55
+ keyword: payload.paperName,
56
+ page: 1,
57
+ size: 10,
58
+ parentid: "",
59
+ column: "0",
60
+ direction: ""
61
+ });
62
+ return res.data.rows?.[0]?.paperid;
63
+ }
64
+ static getPaperIdMemo = (0, import_vtils.memoize)(
65
+ (payload) => XKsb.getPaperId(payload),
66
+ (payload) => payload.paperName
67
+ );
68
+ static async deletePaper(payload) {
69
+ const paperId = await XKsb.getPaperId(payload);
70
+ if (paperId) {
71
+ await XKsb.request("/user/paper/delete", {
72
+ id: paperId
73
+ });
74
+ XKsb.getPaperIdMemo.cache.delete(payload.paperName);
75
+ }
76
+ }
77
+ static async addPaper(payload) {
78
+ await XKsb.request("/user/paper/add", {
79
+ name: payload.paperName,
80
+ type: "4"
81
+ });
82
+ XKsb.getPaperIdMemo.cache.delete(payload.paperName);
83
+ }
84
+ static async ensurePaperExistsAndEmpty(payload) {
85
+ await XKsb.deletePaper(payload);
86
+ await XKsb.addPaper(payload);
87
+ }
88
+ static async addQuestion(payload) {
89
+ payload.question.question = XKsb.desensitize(payload.question.question);
90
+ payload.question.options.forEach((opt) => {
91
+ opt.value = XKsb.desensitize(opt.value);
92
+ });
93
+ if (typeof payload.question.answer === "string") {
94
+ payload.question.answer = XKsb.desensitize(payload.question.answer);
95
+ } else if (Array.isArray(payload.question.answer)) {
96
+ payload.question.answer.forEach((v, i) => {
97
+ if (typeof v === "string") {
98
+ payload.question.answer[i] = XKsb.desensitize(v);
99
+ }
100
+ });
101
+ }
102
+ const paperId = await XKsb.getPaperIdMemo(payload);
103
+ await XKsb.request(
104
+ "/user/question/add",
105
+ // 单选
106
+ payload.question.type === "\u5355\u9009" ? {
107
+ id: "",
108
+ qtype: "1",
109
+ paperid: paperId,
110
+ options: JSON.stringify(
111
+ payload.question.options.map((opt) => ({
112
+ Key: opt.key,
113
+ Value: opt.value,
114
+ checked: false,
115
+ extend: ""
116
+ }))
117
+ ),
118
+ judgeOptions: [
119
+ { Key: "A", Value: "\u6B63\u786E" },
120
+ { Key: "B", Value: "\u9519\u8BEF" }
121
+ ],
122
+ question: payload.question.question,
123
+ answer: payload.question.answer,
124
+ extra: '{"ordered":"0","case_sensitive":"0"}',
125
+ paixuAnswer: "",
126
+ analysis: "",
127
+ parentid: 0,
128
+ chapter: "",
129
+ difficulty: "",
130
+ blanks: [{ Value: "" }],
131
+ optionData: [],
132
+ optionTipic: [],
133
+ optionDataTipic: {
134
+ options: [
135
+ { Key: "A", Value: "", checked: false },
136
+ { Key: "B", Value: "", checked: false },
137
+ { Key: "C", Value: "", checked: false },
138
+ { Key: "D", Value: "", checked: false }
139
+ ],
140
+ answer: ""
141
+ },
142
+ fileList: []
143
+ } : payload.question.type === "\u5224\u65AD" ? {
144
+ id: "",
145
+ qtype: "3",
146
+ paperid: paperId,
147
+ options: '[{"Key":"A","Value":"","checked":false},{"Key":"B","Value":"","checked":false},{"Key":"C","Value":"","checked":false},{"Key":"D","Value":"","checked":false}]',
148
+ judgeOptions: [
149
+ { Key: "A", Value: "\u6B63\u786E" },
150
+ { Key: "B", Value: "\u9519\u8BEF" }
151
+ ],
152
+ question: payload.question.question,
153
+ answer: payload.question.answer ? "A" : "B",
154
+ parentid: 0,
155
+ chapter: "",
156
+ difficulty: "",
157
+ extra: '{"ordered":"0","case_sensitive":"0"}',
158
+ analysis: "",
159
+ paixuAnswer: "",
160
+ blanks: [{ Value: "" }],
161
+ optionData: [],
162
+ optionTipic: [],
163
+ optionDataTipic: ""
164
+ } : payload.question.type === "\u586B\u7A7A" ? {
165
+ id: "",
166
+ qtype: "4",
167
+ paperid: paperId,
168
+ options: '[{"Key":"A","Value":"","checked":false},{"Key":"B","Value":"","checked":false},{"Key":"C","Value":"","checked":false},{"Key":"D","Value":"","checked":false}]',
169
+ judgeOptions: [
170
+ { Key: "A", Value: "\u6B63\u786E" },
171
+ { Key: "B", Value: "\u9519\u8BEF" }
172
+ ],
173
+ question: payload.question.question,
174
+ answer: (0, import_vtils.castArray)(payload.question.answer).join("|"),
175
+ parentid: 0,
176
+ chapter: "",
177
+ difficulty: "",
178
+ extra: '{"ordered":"0","case_sensitive":"0"}',
179
+ analysis: "",
180
+ paixuAnswer: "",
181
+ blanks: (0, import_vtils.castArray)(payload.question.answer).map((v) => ({
182
+ Value: v
183
+ })),
184
+ optionData: [],
185
+ optionTipic: [],
186
+ optionDataTipic: ""
187
+ } : payload.question.type === "\u95EE\u7B54" ? {
188
+ id: "",
189
+ qtype: "11",
190
+ paperid: paperId,
191
+ options: '[{"Key":"A","Value":"","checked":false},{"Key":"B","Value":"","checked":false},{"Key":"C","Value":"","checked":false},{"Key":"D","Value":"","checked":false}]',
192
+ judgeOptions: [
193
+ { Key: "A", Value: "\u6B63\u786E" },
194
+ { Key: "B", Value: "\u9519\u8BEF" }
195
+ ],
196
+ question: payload.question.question,
197
+ answer: payload.question.answer,
198
+ parentid: 0,
199
+ chapter: "",
200
+ difficulty: "",
201
+ extra: '{"ordered":"0","case_sensitive":"0"}',
202
+ analysis: "",
203
+ paixuAnswer: "",
204
+ blanks: [{ Value: "" }],
205
+ optionData: [],
206
+ optionTipic: [],
207
+ optionDataTipic: ""
208
+ } : {}
209
+ // 判断
210
+ // {"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":""}
211
+ // 填空
212
+ // {"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":""}
213
+ // 问答
214
+ // {"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":""}
215
+ );
216
+ }
217
+ }
package/_cjs/number.js ADDED
@@ -0,0 +1,39 @@
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
+ }