@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.
Files changed (113) 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/package.json +0 -3
  50. package/_cjs/path.js +0 -35
  51. package/_cjs/pinyin.js +0 -37
  52. package/_cjs/puppeteer.js +0 -271
  53. package/_cjs/runner.js +0 -88
  54. package/_cjs/task.js +0 -41
  55. package/_cjs/text.js +0 -136
  56. package/_cjs/unicode/lib_unicode.js +0 -58643
  57. package/_cjs/unicode/unicode.js +0 -441
  58. package/_cjs/upload.js +0 -101
  59. package/_cjs/yaml.js +0 -52
  60. package/ai.d.ts +0 -26
  61. package/ai.js +0 -60
  62. package/alipan.d.ts +0 -209
  63. package/alipan.js +0 -153
  64. package/cli.d.ts +0 -14
  65. package/cli.js +0 -21
  66. package/clipboard.d.ts +0 -6
  67. package/clipboard.js +0 -35
  68. package/cmd.d.ts +0 -5
  69. package/cmd.js +0 -22
  70. package/compressor.d.ts +0 -5
  71. package/compressor.js +0 -17
  72. package/crawler.d.ts +0 -162
  73. package/crawler.js +0 -332
  74. package/csv.d.ts +0 -14
  75. package/csv.js +0 -67
  76. package/data_set.d.ts +0 -22
  77. package/data_set.js +0 -85
  78. package/env.d.ts +0 -6
  79. package/env.js +0 -52
  80. package/fs.d.ts +0 -23
  81. package/fs.js +0 -56
  82. package/html.d.ts +0 -7
  83. package/html.js +0 -45
  84. package/http_server.d.ts +0 -13
  85. package/http_server.js +0 -49
  86. package/json.d.ts +0 -6
  87. package/json.js +0 -19
  88. package/ksb.d.ts +0 -37
  89. package/ksb.js +0 -198
  90. package/number.d.ts +0 -3
  91. package/number.js +0 -9
  92. package/ocr.d.ts +0 -17
  93. package/ocr.js +0 -54
  94. package/path.d.ts +0 -2
  95. package/path.js +0 -5
  96. package/pinyin.d.ts +0 -8
  97. package/pinyin.js +0 -17
  98. package/puppeteer.d.ts +0 -38
  99. package/puppeteer.js +0 -241
  100. package/runner.d.ts +0 -13
  101. package/runner.js +0 -58
  102. package/task.d.ts +0 -6
  103. package/task.js +0 -21
  104. package/text.d.ts +0 -63
  105. package/text.js +0 -119
  106. package/unicode/lib_unicode.d.ts +0 -4
  107. package/unicode/lib_unicode.js +0 -58623
  108. package/unicode/unicode.d.ts +0 -347
  109. package/unicode/unicode.js +0 -426
  110. package/upload.d.ts +0 -34
  111. package/upload.js +0 -71
  112. package/yaml.d.ts +0 -6
  113. package/yaml.js +0 -22
package/_cjs/alipan.js DELETED
@@ -1,173 +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 alipan_exports = {};
20
- __export(alipan_exports, {
21
- XAlipan: () => XAlipan
22
- });
23
- module.exports = __toCommonJS(alipan_exports);
24
- var import_x_request = require("@jayfong/x-request");
25
- var import_vtils = require("vtils");
26
- var import_path = require("./path.js");
27
- class XAlipan {
28
- constructor(options) {
29
- this.options = options;
30
- this.xr = import_x_request.xr.extend({
31
- baseUrl: "https://open.aliyundrive.com",
32
- headers: {
33
- Authorization: `Bearer ${options.accessToken}`
34
- },
35
- timeoutMs: (0, import_vtils.ms)("30s")
36
- });
37
- }
38
- xr;
39
- getUserInfo = (0, import_vtils.memoize)(async () => {
40
- const res = await this.xr.postJson({
41
- url: "/adrive/v1.0/user/getDriveInfo"
42
- });
43
- return res.data;
44
- });
45
- async createFile(payload) {
46
- const res = await this.xr.postJson({
47
- url: "/adrive/v1.0/openFile/create",
48
- data: payload
49
- });
50
- return res.data;
51
- }
52
- async uploadFile(payload) {
53
- await this.xr.post({
54
- method: "PUT",
55
- url: payload.useIntranet ? payload.uploadUrl.replace(
56
- "https://cn-beijing-data.aliyundrive.net/",
57
- "http://ccp-bj29-bj-1592982087.oss-cn-beijing-internal.aliyuncs.com/"
58
- ) : payload.uploadUrl,
59
- data: payload.file,
60
- headers: {
61
- "Content-Type": ""
62
- }
63
- });
64
- }
65
- async completeFile(payload) {
66
- await this.xr.post({
67
- url: "/adrive/v1.0/openFile/complete",
68
- data: payload
69
- });
70
- }
71
- async getFileInfoByPath(payload) {
72
- const res = await this.xr.postJson({
73
- url: "/adrive/v1.0/openFile/get_by_path",
74
- data: payload
75
- });
76
- return res.data;
77
- }
78
- async getFileDownloadUrl(payload) {
79
- const res = await this.xr.postJson({
80
- url: "/adrive/v1.0/openFile/getDownloadUrl",
81
- data: payload
82
- });
83
- return res.data;
84
- }
85
- getDriveId = (0, import_vtils.memoize)(
86
- async (payload) => {
87
- {
88
- const userInfo = await this.getUserInfo();
89
- return payload.drive === "backup" ? userInfo.backup_drive_id : payload.drive === "resource" ? userInfo.resource_drive_id : payload.drive === "album" ? userInfo.album_drive_id : "";
90
- }
91
- },
92
- (payload) => payload.drive
93
- );
94
- async existsFileHuman(payload) {
95
- try {
96
- const driveId = await this.getDriveId(payload);
97
- const res = await this.getFileInfoByPath({
98
- drive_id: driveId,
99
- file_path: payload.path
100
- });
101
- return res.file_id;
102
- } catch {
103
- return false;
104
- }
105
- }
106
- ensurePathHuman = (0, import_vtils.memoize)(
107
- async (payload) => {
108
- const driveId = await this.getDriveId(payload);
109
- const pathParts = payload.path.split("/");
110
- let prevFileId = "root";
111
- for (let i = 1; i < pathParts.length; i++) {
112
- const path = pathParts.slice(0, i + 1).join("/");
113
- const fileId = await this.existsFileHuman({
114
- drive: payload.drive,
115
- path
116
- });
117
- if (!fileId) {
118
- const createRes = await this.createFile({
119
- drive_id: driveId,
120
- parent_file_id: prevFileId,
121
- type: "folder",
122
- check_name_mode: "refuse",
123
- name: pathParts[i]
124
- });
125
- prevFileId = createRes.file_id;
126
- } else {
127
- prevFileId = fileId;
128
- }
129
- }
130
- return prevFileId;
131
- },
132
- (payload) => `${payload.drive}:${payload.path}`
133
- );
134
- async uploadFileHuman(payload) {
135
- const driveId = await this.getDriveId(payload);
136
- const fileId = await this.ensurePathHuman({
137
- drive: payload.drive,
138
- path: import_path.XPath.dirname(payload.path)
139
- });
140
- const createRes = await this.createFile({
141
- drive_id: driveId,
142
- parent_file_id: fileId,
143
- type: "file",
144
- check_name_mode: "refuse",
145
- name: import_path.XPath.basename(payload.path)
146
- });
147
- if (!createRes.exist && createRes.part_info_list?.length === 1) {
148
- await this.uploadFile({
149
- uploadUrl: createRes.part_info_list[0].upload_url,
150
- file: payload.file,
151
- useIntranet: payload.useIntranet
152
- });
153
- await this.completeFile({
154
- drive_id: createRes.drive_id,
155
- file_id: createRes.file_id,
156
- upload_id: createRes.upload_id
157
- });
158
- }
159
- }
160
- async getFileDownloadUrlHuman(payload) {
161
- const driveId = await this.getDriveId(payload);
162
- const fileInfo = await this.getFileInfoByPath({
163
- drive_id: driveId,
164
- file_path: payload.path
165
- });
166
- const downloadInfo = await this.getFileDownloadUrl({
167
- drive_id: driveId,
168
- file_id: fileInfo.file_id,
169
- expire_sec: 900
170
- });
171
- return downloadInfo.url;
172
- }
173
- }
package/_cjs/cli.js DELETED
@@ -1,51 +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 cli_exports = {};
30
- __export(cli_exports, {
31
- XCli: () => XCli
32
- });
33
- module.exports = __toCommonJS(cli_exports);
34
- var import_cli_table3 = __toESM(require("cli-table3"), 1);
35
- var import_inquirer = __toESM(require("inquirer"), 1);
36
- class XCli {
37
- static async prompt(options) {
38
- const { x } = await import_inquirer.default.prompt({
39
- name: "x",
40
- message: options.message,
41
- type: options.type,
42
- default: options.default
43
- });
44
- return x;
45
- }
46
- static table(data) {
47
- const table = new import_cli_table3.default();
48
- table.push(...data);
49
- return table.toString();
50
- }
51
- }
package/_cjs/clipboard.js DELETED
@@ -1,65 +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 clipboard_exports = {};
30
- __export(clipboard_exports, {
31
- XClipboard: () => XClipboard
32
- });
33
- module.exports = __toCommonJS(clipboard_exports);
34
- var import_clipboardy = __toESM(require("clipboardy"), 1);
35
- var import_cmd = require("./cmd.js");
36
- class XClipboard {
37
- static async readText() {
38
- return import_clipboardy.default.read();
39
- }
40
- static async readHtml() {
41
- const hex = await import_cmd.XCmd.exec(
42
- // 读取剪切板为 HTML
43
- // https://stackoverflow.com/questions/2545289/getting-rtf-data-out-of-mac-os-x-pasteboard-clipboard
44
- // https://stackoverflow.com/a/17217886
45
- `osascript -e "the clipboard as \xABclass HTML\xBB"`
46
- );
47
- const html = Buffer.from(
48
- hex.substring(10, hex.length - 1),
49
- "hex"
50
- ).toString();
51
- return html;
52
- }
53
- static async writeText(text) {
54
- await import_clipboardy.default.write(text);
55
- }
56
- static async writeHtml(html) {
57
- const hex = Buffer.from(html).toString("hex");
58
- await import_cmd.XCmd.exec(
59
- // 设置剪切板为 HTML
60
- // https://stackoverflow.com/questions/11085654/apple-script-how-can-i-copy-html-content-to-the-clipboard
61
- // https://stackoverflow.com/a/11089226
62
- `osascript -e "set the clipboard to \xABdata HTML${hex}\xBB"`
63
- );
64
- }
65
- }
package/_cjs/cmd.js DELETED
@@ -1,42 +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 cmd_exports = {};
20
- __export(cmd_exports, {
21
- XCmd: () => XCmd
22
- });
23
- module.exports = __toCommonJS(cmd_exports);
24
- var import_execa = require("execa");
25
- class XCmd {
26
- static execDivider = "clrue91c60000e6rl7w03b40p";
27
- static async exec(command, options) {
28
- const { stdout } = await (0, import_execa.execa)(
29
- "zsh",
30
- [
31
- "-c",
32
- `
33
- echo ${XCmd.execDivider}
34
- ${command}
35
- echo ${XCmd.execDivider}
36
- `
37
- ],
38
- options
39
- );
40
- return stdout.split(XCmd.execDivider)[1].trim();
41
- }
42
- }
@@ -1,47 +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 compressor_exports = {};
30
- __export(compressor_exports, {
31
- XCompressor: () => XCompressor
32
- });
33
- module.exports = __toCommonJS(compressor_exports);
34
- var import_sharp = __toESM(require("sharp"), 1);
35
- class XCompressor {
36
- static png(content) {
37
- return (0, import_sharp.default)(content).png({
38
- quality: 80,
39
- compressionLevel: 6
40
- }).toBuffer();
41
- }
42
- static jpg(content) {
43
- return (0, import_sharp.default)(content).jpeg({
44
- quality: 80
45
- }).toBuffer();
46
- }
47
- }