@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
@@ -1,441 +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 unicode_exports = {};
20
- __export(unicode_exports, {
21
- XUnicode: () => XUnicode
22
- });
23
- module.exports = __toCommonJS(unicode_exports);
24
- var import_vtils = require("vtils");
25
- var import_puppeteer = require("../puppeteer.js");
26
- var import_text = require("../text.js");
27
- var import_lib_unicode = require("./lib_unicode.js");
28
- const ublockMap = {
29
- // @index('./lib_unicode.js', /BlockStart\[(\d+)\]\s*=\s*"(.+?)";\s*\/\/\s*([^\(\r\n]+)\b/g, m => `'${m[3]}': ${m[1]},`)
30
- "Basic Latin": 0,
31
- "Latin-1 Supplement": 1,
32
- "Latin Extended-A": 2,
33
- "Latin Extended-B": 3,
34
- "IPA Extensions": 4,
35
- "Spacing Modifier Letters": 5,
36
- "Combining Diacritical Marks": 6,
37
- "Greek and Coptic": 7,
38
- Cyrillic: 8,
39
- "Cyrillic Supplement": 9,
40
- Armenian: 10,
41
- Hebrew: 11,
42
- Arabic: 12,
43
- Syriac: 13,
44
- "Arabic Supplement": 14,
45
- Thaana: 15,
46
- NKo: 16,
47
- Samaritan: 17,
48
- Mandaic: 18,
49
- "Syriac Supplement": 19,
50
- "Arabic Extended-B": 20,
51
- "Arabic Extended-A": 21,
52
- Devanagari: 22,
53
- Bengali: 23,
54
- Gurmukhi: 24,
55
- Gujarati: 25,
56
- Oriya: 26,
57
- Tamil: 27,
58
- Telugu: 28,
59
- Kannada: 29,
60
- Malayalam: 30,
61
- Sinhala: 31,
62
- Thai: 32,
63
- Lao: 33,
64
- Tibetan: 34,
65
- Myanmar: 35,
66
- Georgian: 36,
67
- "Hangul Jamo": 37,
68
- Ethiopic: 38,
69
- "Ethiopic Supplement": 39,
70
- Cherokee: 40,
71
- "Unified Canadian Aboriginal Syllabics": 41,
72
- Ogham: 42,
73
- Runic: 43,
74
- Tagalog: 44,
75
- Hanunoo: 45,
76
- Buhid: 46,
77
- Tagbanwa: 47,
78
- Khmer: 48,
79
- Mongolian: 49,
80
- "Unified Canadian Aboriginal Syllabics Extended": 50,
81
- Limbu: 51,
82
- "Tai Le": 52,
83
- "New Tai Lue": 53,
84
- "Khmer Symbols": 54,
85
- Buginese: 55,
86
- "Tai Tham": 56,
87
- "Combining Diacritical Marks Extended": 57,
88
- Balinese: 58,
89
- Sundanese: 59,
90
- Batak: 60,
91
- Lepcha: 61,
92
- "Ol Chiki": 62,
93
- "Cyrillic Extended-C": 63,
94
- "Georgian Extended": 64,
95
- "Sundanese Supplement": 65,
96
- "Vedic Extensions": 66,
97
- "Phonetic Extensions": 67,
98
- "Phonetic Extensions Supplement": 68,
99
- "Combining Diacritical Marks Supplement": 69,
100
- "Latin Extended Additional": 70,
101
- "Greek Extended": 71,
102
- "General Punctuation": 72,
103
- "Superscripts and Subscripts": 73,
104
- "Currency Symbols": 74,
105
- "Combining Diacritical Marks for Symbols": 75,
106
- "Letterlike Symbols": 76,
107
- "Number Forms": 77,
108
- Arrows: 78,
109
- "Mathematical Operators": 79,
110
- "Miscellaneous Technical": 80,
111
- "Control Pictures": 81,
112
- "Optical Character Recognition": 82,
113
- "Enclosed Alphanumerics": 83,
114
- "Box Drawing": 84,
115
- "Block Elements": 85,
116
- "Geometric Shapes": 86,
117
- "Miscellaneous Symbols": 87,
118
- Dingbats: 88,
119
- "Miscellaneous Mathematical Symbols-A": 89,
120
- "Supplemental Arrows-A": 90,
121
- "Braille Patterns": 91,
122
- "Supplemental Arrows-B": 92,
123
- "Miscellaneous Mathematical Symbols-B": 93,
124
- "Supplemental Mathematical Operators": 94,
125
- "Miscellaneous Symbols and Arrows": 95,
126
- Glagolitic: 96,
127
- "Latin Extended-C": 97,
128
- Coptic: 98,
129
- "Georgian Supplement": 99,
130
- Tifinagh: 100,
131
- "Ethiopic Extended": 101,
132
- "Cyrillic Extended-A": 102,
133
- "Supplemental Punctuation": 103,
134
- "CJK Radicals Supplement": 104,
135
- "Kangxi Radicals": 105,
136
- "Ideographic Description Characters": 106,
137
- "CJK Symbols and Punctuation": 107,
138
- Hiragana: 108,
139
- Katakana: 109,
140
- Bopomofo: 110,
141
- "Hangul Compatibility Jamo": 111,
142
- Kanbun: 112,
143
- "Bopomofo Extended": 113,
144
- "CJK Strokes": 114,
145
- "Katakana Phonetic Extensions": 115,
146
- "Enclosed CJK Letters and Months": 116,
147
- "CJK Compatibility": 117,
148
- "CJK Unified Ideographs Extension A": 118,
149
- "Yijing Hexagram Symbols": 119,
150
- "CJK Unified Ideographs": 120,
151
- "Yi Syllables": 121,
152
- "Yi Radicals": 122,
153
- Lisu: 123,
154
- Vai: 124,
155
- "Cyrillic Extended-B": 125,
156
- Bamum: 126,
157
- "Modifier Tone Letters": 127,
158
- "Latin Extended-D": 128,
159
- "Syloti Nagri": 129,
160
- "Common Indic Number Forms": 130,
161
- "Phags-pa": 131,
162
- Saurashtra: 132,
163
- "Devanagari Extended": 133,
164
- "Kayah Li": 134,
165
- Rejang: 135,
166
- "Hangul Jamo Extended-A": 136,
167
- Javanese: 137,
168
- "Myanmar Extended-B": 138,
169
- Cham: 139,
170
- "Myanmar Extended-A": 140,
171
- "Tai Viet": 141,
172
- "Meetei Mayek Extensions": 142,
173
- "Ethiopic Extended-A": 143,
174
- "Latin Extended-E": 144,
175
- "Cherokee Supplement": 145,
176
- "Meetei Mayek": 146,
177
- "Hangul Syllables": 147,
178
- "Hangul Jamo Extended-B": 148,
179
- "Private Use Area": 149,
180
- "CJK Compatibility Ideographs": 150,
181
- "Alphabetic Presentation Forms": 151,
182
- "Arabic Presentation Forms-A": 152,
183
- "Variation Selectors": 153,
184
- "Vertical Forms": 154,
185
- "Combining Half Marks": 155,
186
- "CJK Compatibility Forms": 156,
187
- "Small Form Variants": 157,
188
- "Arabic Presentation Forms-B": 158,
189
- "Halfwidth and Fullwidth Forms": 159,
190
- Specials: 160,
191
- "Linear B Syllabary": 161,
192
- "Linear B Ideograms": 162,
193
- "Aegean Numbers": 163,
194
- "Ancient Greek Numbers": 164,
195
- "Ancient Symbols": 165,
196
- "Phaistos Disc": 166,
197
- Lycian: 167,
198
- Carian: 168,
199
- "Coptic Epact Numbers": 169,
200
- "Old Italic": 170,
201
- Gothic: 171,
202
- "Old Permic": 172,
203
- Ugaritic: 173,
204
- "Old Persian": 174,
205
- Deseret: 175,
206
- Shavian: 176,
207
- Osmanya: 177,
208
- Osage: 178,
209
- Elbasan: 179,
210
- "Caucasian Albanian": 180,
211
- Vithkuqi: 181,
212
- "Linear A": 182,
213
- "Latin Extended-F": 183,
214
- "Cypriot Syllabary": 184,
215
- "Imperial Aramaic": 185,
216
- Palmyrene: 186,
217
- Nabataean: 187,
218
- Hatran: 188,
219
- Phoenician: 189,
220
- Lydian: 190,
221
- "Meroitic Hieroglyphs": 191,
222
- "Meroitic Cursive": 192,
223
- Kharoshthi: 193,
224
- "Old South Arabian": 194,
225
- "Old North Arabian": 195,
226
- Manichaean: 196,
227
- Avestan: 197,
228
- "Inscriptional Parthian": 198,
229
- "Inscriptional Pahlavi": 199,
230
- "Psalter Pahlavi": 200,
231
- "Old Turkic": 201,
232
- "Old Hungarian": 202,
233
- "Hanifi Rohingya": 203,
234
- "Rumi Numeral Symbols": 204,
235
- Yezidi: 205,
236
- "Arabic Extended-C": 206,
237
- "Old Sogdian": 207,
238
- Sogdian: 208,
239
- "Old Uyghur": 209,
240
- Chorasmian: 210,
241
- Elymaic: 211,
242
- Brahmi: 212,
243
- Kaithi: 213,
244
- "Sora Sompeng": 214,
245
- Chakma: 215,
246
- Mahajani: 216,
247
- Sharada: 217,
248
- "Sinhala Archaic Numbers": 218,
249
- Khojki: 219,
250
- Multani: 220,
251
- Khudawadi: 221,
252
- Grantha: 222,
253
- Newa: 223,
254
- Tirhuta: 224,
255
- Siddham: 225,
256
- Modi: 226,
257
- "Mongolian Supplement": 227,
258
- Takri: 228,
259
- Ahom: 229,
260
- Dogra: 230,
261
- "Warang Citi": 231,
262
- "Dives Akuru": 232,
263
- Nandinagari: 233,
264
- "Zanabazar Square": 234,
265
- Soyombo: 235,
266
- "Unified Canadian Aboriginal Syllabics Extended-A": 236,
267
- "Pau Cin Hau": 237,
268
- "Devanagari Extended-A": 238,
269
- Bhaiksuki: 239,
270
- Marchen: 240,
271
- "Masaram Gondi": 241,
272
- "Gunjala Gondi": 242,
273
- Makasar: 243,
274
- Kawi: 244,
275
- "Lisu Supplement": 245,
276
- "Tamil Supplement": 246,
277
- Cuneiform: 247,
278
- "Cuneiform Numbers and Punctuation": 248,
279
- "Early Dynastic Cuneiform": 249,
280
- "Cypro-Minoan": 250,
281
- "Egyptian Hieroglyphs": 251,
282
- "Egyptian Hieroglyph Format Controls": 252,
283
- "Anatolian Hieroglyphs": 253,
284
- "Bamum Supplement": 254,
285
- Mro: 255,
286
- Tangsa: 256,
287
- "Bassa Vah": 257,
288
- "Pahawh Hmong": 258,
289
- Medefaidrin: 259,
290
- Miao: 260,
291
- "Ideographic Symbols and Punctuation": 261,
292
- Tangut: 262,
293
- "Tangut Components": 263,
294
- "Khitan Small Script": 264,
295
- "Tangut Supplement": 265,
296
- "Kana Extended-B": 266,
297
- "Kana Supplement": 267,
298
- "Kana Extended-A": 268,
299
- "Small Kana Extension": 269,
300
- Nushu: 270,
301
- Duployan: 271,
302
- "Shorthand Format Controls": 272,
303
- "Znamenny Musical Notation": 273,
304
- "Byzantine Musical Symbols": 274,
305
- "Musical Symbols": 275,
306
- "Ancient Greek Musical Notation": 276,
307
- "Kaktovik Numerals": 277,
308
- "Mayan Numerals": 278,
309
- "Tai Xuan Jing Symbols": 279,
310
- "Counting Rod Numerals": 280,
311
- "Mathematical Alphanumeric Symbols": 281,
312
- "Sutton SignWriting": 282,
313
- "Latin Extended-G": 283,
314
- "Glagolitic Supplement": 284,
315
- "Cyrillic Extended-D": 285,
316
- "Nyiakeng Puachue Hmong": 286,
317
- Toto: 287,
318
- Wancho: 288,
319
- "Nag Mundari": 289,
320
- "Ethiopic Extended-B": 290,
321
- "Mende Kikakui": 291,
322
- Adlam: 292,
323
- "Indic Siyaq Numbers": 293,
324
- "Ottoman Siyaq Numbers": 294,
325
- "Arabic Mathematical Alphabetic Symbols": 295,
326
- "Mahjong Tiles": 296,
327
- "Domino Tiles": 297,
328
- "Playing Cards": 298,
329
- "Enclosed Alphanumeric Supplement": 299,
330
- "Enclosed Ideographic Supplement": 300,
331
- "Miscellaneous Symbols and Pictographs": 301,
332
- Emoticons: 302,
333
- "Ornamental Dingbats": 303,
334
- "Transport and Map Symbols": 304,
335
- "Alchemical Symbols": 305,
336
- "Geometric Shapes Extended": 306,
337
- "Supplemental Arrows-C": 307,
338
- "Supplemental Symbols and Pictographs": 308,
339
- "Chess Symbols": 309,
340
- "Symbols and Pictographs Extended-A": 310,
341
- "Symbols for Legacy Computing": 311,
342
- "CJK Unified Ideographs Extension B": 312,
343
- "CJK Unified Ideographs Extension C": 313,
344
- "CJK Unified Ideographs Extension D": 314,
345
- "CJK Unified Ideographs Extension E": 315,
346
- "CJK Unified Ideographs Extension F": 316,
347
- "CJK Unified Ideographs Extension I": 317,
348
- "CJK Compatibility Ideographs Supplement": 318,
349
- "CJK Unified Ideographs Extension G": 319,
350
- "CJK Unified Ideographs Extension H": 320,
351
- Tags: 321,
352
- "Variation Selectors Supplement": 322,
353
- "Supplementary Private Use Area-A": 323,
354
- "Supplementary Private Use Area-B": 324
355
- // @endindex
356
- };
357
- class XUnicode {
358
- static getBlockNames() {
359
- return (0, import_vtils.keysStrict)(ublockMap).sort();
360
- }
361
- static getCharName(char) {
362
- return (0, import_lib_unicode.ToCharacterNames)(char, false, true).trim().replace(/[\r\n]+/g, ";");
363
- }
364
- static getBlockChars(blockName) {
365
- const ublock = ublockMap[blockName];
366
- const start = (0, import_lib_unicode.GetBlockStart)(ublock);
367
- const end = parseInt(import_lib_unicode.BlockEnd[ublock], 16);
368
- const chars = [];
369
- for (let char = start; char <= end; char++) {
370
- if ((0, import_lib_unicode.GetCharacterName)(ublock, char, true)) {
371
- chars.push(String.fromCodePoint(char));
372
- }
373
- }
374
- return chars;
375
- }
376
- static isCharVisibleId = 0;
377
- static isCharVisibleGetCharBuffer = async (char, page) => {
378
- const id = `_${XUnicode.isCharVisibleId++}`;
379
- await page.evaluate(
380
- (char2, id2) => {
381
- const el = document.createElement("span");
382
- el.innerText = char2;
383
- el.id = id2;
384
- document.body.appendChild(el);
385
- },
386
- char,
387
- id
388
- );
389
- const charEl = await page.$(`#${id}`);
390
- const charBuffer = await charEl.screenshot();
391
- await page.evaluate((id2) => {
392
- document.querySelector(`#${id2}`)?.remove();
393
- }, id);
394
- return charBuffer;
395
- };
396
- static isCharVisibleBrowsers = [];
397
- static isCharVisibleInit = (0, import_vtils.memoize)(
398
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
399
- async (flag) => {
400
- const { html } = import_text.XText;
401
- const browser = await import_puppeteer.XPuppeteer.openBrowser();
402
- XUnicode.isCharVisibleBrowsers.push(browser);
403
- const page = await browser.openPage(html`
404
- <html>
405
- <head>
406
- <style>
407
- span {
408
- display: inline-block;
409
- width: 100px;
410
- height: 100px;
411
- font-size: 40px;
412
- color: red;
413
- }
414
- </style>
415
- </head>
416
- <body></body>
417
- </html>
418
- `);
419
- const invisibleCharBuffer = await XUnicode.isCharVisibleGetCharBuffer(
420
- "\u{18BE8}",
421
- page
422
- );
423
- return {
424
- browser,
425
- page,
426
- invisibleCharBuffer
427
- };
428
- },
429
- (flag) => flag
430
- );
431
- static async isCharVisibleDispose() {
432
- await Promise.all(
433
- XUnicode.isCharVisibleBrowsers.map((browser) => browser.close())
434
- );
435
- }
436
- static async isCharVisible(char, flag = 0) {
437
- const { page, invisibleCharBuffer } = await XUnicode.isCharVisibleInit(flag);
438
- const charBuffer = await XUnicode.isCharVisibleGetCharBuffer(char, page);
439
- return !charBuffer.equals(invisibleCharBuffer);
440
- }
441
- }
package/_cjs/upload.js DELETED
@@ -1,101 +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 upload_exports = {};
30
- __export(upload_exports, {
31
- XUpload: () => XUpload
32
- });
33
- module.exports = __toCommonJS(upload_exports);
34
- var import_x_request = require("@jayfong/x-request");
35
- var import_file_type = require("file-type");
36
- var fs = __toESM(require("node:fs"), 1);
37
- var import_vtils = require("vtils");
38
- var import_env = require("./env.js");
39
- class XUpload {
40
- /**
41
- * 上传文件
42
- *
43
- * @param file 文件本地路径、文件 URL、文件 Buffer
44
- * @param options 选项
45
- * @param options.provider 默认 auto
46
- * @param options.source 默认 my-auto-tasks
47
- */
48
- static async upload(file, {
49
- fileExt: customFileExt,
50
- serverUrl,
51
- serverToken,
52
- provider = "auto",
53
- source = "my-auto-tasks",
54
- beforeUpload
55
- } = {}) {
56
- if (serverUrl == null) {
57
- serverUrl = await import_env.XEnv.getEnvVar("X_UPLOAD_SERVER_URL");
58
- }
59
- if (serverToken == null) {
60
- serverToken = await import_env.XEnv.getEnvVar("X_UPLOAD_SERVER_TOKEN");
61
- }
62
- const rawFile = file;
63
- if (typeof file === "string") {
64
- if ((0, import_vtils.isUrl)(file)) {
65
- const { data: data2 } = await import_x_request.xr.get({
66
- url: file,
67
- autoReferer: true
68
- });
69
- file = data2;
70
- } else {
71
- file = await fs.promises.readFile(file);
72
- }
73
- }
74
- const { ext: fileExt } = customFileExt ? { ext: customFileExt } : await (0, import_file_type.fileTypeFromBuffer)(file) || {
75
- ext: (typeof rawFile === "string" ? rawFile.split("?")[0].split(".").pop()?.toLowerCase() : "") || "unknown"
76
- };
77
- const imageExts = ["jpg", "png", "gif"];
78
- const isImage = imageExts.includes(fileExt);
79
- provider = provider === "auto" ? isImage ? "image" : "file" : provider;
80
- if (beforeUpload) {
81
- file = await beforeUpload({
82
- file,
83
- ext: fileExt,
84
- isImage
85
- });
86
- }
87
- const { data } = await import_x_request.xr.postJson({
88
- url: serverUrl,
89
- data: import_x_request.xr.formData({
90
- token: serverToken,
91
- provider,
92
- returnRawUrl: 1,
93
- source,
94
- file: import_x_request.xr.formFile(file, {
95
- name: `xxx.${fileExt}`
96
- })
97
- })
98
- });
99
- return data;
100
- }
101
- }
package/_cjs/yaml.js DELETED
@@ -1,52 +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 yaml_exports = {};
30
- __export(yaml_exports, {
31
- XYaml: () => XYaml
32
- });
33
- module.exports = __toCommonJS(yaml_exports);
34
- var fs = __toESM(require("node:fs"), 1);
35
- var import_yaml = __toESM(require("yaml"), 1);
36
- class XYaml {
37
- static parse(value) {
38
- return import_yaml.default.parse(value);
39
- }
40
- static stringify(value) {
41
- return import_yaml.default.stringify(value, {
42
- blockQuote: "literal"
43
- });
44
- }
45
- static async read(file) {
46
- const value = await fs.promises.readFile(file, "utf8");
47
- return XYaml.parse(value);
48
- }
49
- static async write(file, value) {
50
- await fs.promises.writeFile(file, XYaml.stringify(value));
51
- }
52
- }
package/ai.d.ts DELETED
@@ -1,26 +0,0 @@
1
- /// <reference types="lodash" />
2
- declare abstract class AiProvider {
3
- abstract prepare(): Promise<void>;
4
- abstract ask(question: string): Promise<string>;
5
- }
6
- export declare class CozeAiProvider extends AiProvider {
7
- private options;
8
- private xp;
9
- private page;
10
- constructor(options: {
11
- botUrl: string;
12
- });
13
- prepare(): Promise<void>;
14
- ask(question: string): Promise<string>;
15
- }
16
- export type XAiOptions = {
17
- provider: AiProvider;
18
- };
19
- export declare class XAi {
20
- private options;
21
- private provider;
22
- constructor(options: XAiOptions);
23
- prepare: (() => Promise<void>) & import("lodash").MemoizedFunction;
24
- ask(question: string): Promise<string>;
25
- }
26
- export {};
package/ai.js DELETED
@@ -1,60 +0,0 @@
1
- import { loopUntil, memoize, wait } from "vtils";
2
- import { XPuppeteer } from "./puppeteer.js";
3
- class AiProvider {
4
- }
5
- class CozeAiProvider extends AiProvider {
6
- constructor(options) {
7
- super();
8
- this.options = options;
9
- }
10
- xp;
11
- page;
12
- async prepare() {
13
- this.xp = new XPuppeteer();
14
- await this.xp.connectSystemBrowser();
15
- this.page = await this.xp.openPage(this.options.botUrl);
16
- }
17
- async ask(question) {
18
- const page = this.page;
19
- await page.evaluate(
20
- () => document.querySelector("textarea:not([placeholder])").parentElement.parentElement.previousElementSibling.firstElementChild.click()
21
- );
22
- await wait(300);
23
- await this.page.type("textarea:not([placeholder])", question);
24
- await wait(500);
25
- await this.page.keyboard.press("Enter");
26
- await wait(1e3);
27
- await loopUntil(
28
- () => page.$$eval(
29
- "button",
30
- (els) => !els.find((el) => el.textContent.includes("Stop Responding"))?.parentElement.getBoundingClientRect().height
31
- ),
32
- {
33
- retryDelay: 300
34
- }
35
- );
36
- await wait(300);
37
- const code = await page.$$eval(
38
- 'div[class^="code-area"]',
39
- (els) => els.pop().querySelector('[class^="content"]').textContent
40
- );
41
- return code;
42
- }
43
- }
44
- class XAi {
45
- constructor(options) {
46
- this.options = options;
47
- this.provider = options.provider;
48
- }
49
- provider;
50
- prepare = memoize(() => this.provider.prepare());
51
- async ask(question) {
52
- await this.prepare();
53
- const answer = await this.provider.ask(question);
54
- return answer;
55
- }
56
- }
57
- export {
58
- CozeAiProvider,
59
- XAi
60
- };