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