melperjs 17.1.1 → 17.2.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.
@@ -1,651 +0,0 @@
1
- //#region \0rolldown/runtime.js
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 __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
- //#endregion
23
- let xss = require("xss");
24
- xss = __toESM(xss, 1);
25
- let set_cookie_parser = require("set-cookie-parser");
26
- set_cookie_parser = __toESM(set_cookie_parser, 1);
27
- let es_toolkit_string = require("es-toolkit/string");
28
- let es_toolkit_array = require("es-toolkit/array");
29
- let es_toolkit_compat_isEmpty = require("es-toolkit/compat/isEmpty");
30
- es_toolkit_compat_isEmpty = __toESM(es_toolkit_compat_isEmpty, 1);
31
- //#region src/general.js
32
- const CONSTANTS = {
33
- LOWER_CASE: "abcdefghijklmnopqrstuvwxyz",
34
- UPPER_CASE: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
35
- HEXADECIMAL: "0123456789abcdef",
36
- NUMBERS: "0123456789",
37
- INT32_MIN: -2147483648,
38
- INT32_MAX: 2147483647
39
- };
40
- const NUMBER_PATTERN = /^-?\d+(\.\d+)?(e[+-]?\d+)?$/i;
41
- const INTEGER_PATTERN = /^-?\d+$/;
42
- function Exception(message, response = {}, name = null) {
43
- const error = new Error(message);
44
- error.name = name || "Exception";
45
- error.response = response;
46
- if (checkEmpty(response)) error.response = {};
47
- return error;
48
- }
49
- function time() {
50
- return Math.floor(Date.now() / 1e3);
51
- }
52
- function sleepMs(milliseconds) {
53
- return new Promise((resolve) => setTimeout(resolve, milliseconds));
54
- }
55
- function sleep(seconds) {
56
- return sleepMs(seconds * 1e3);
57
- }
58
- function promiseTimeout(milliseconds, promise) {
59
- let timer;
60
- const timeout = new Promise((_, reject) => {
61
- timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Promise timed out after ${milliseconds}ms`)), milliseconds);
62
- });
63
- return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
64
- }
65
- function promiseSilent(promise) {
66
- return promise?.then(() => {})?.catch(() => {});
67
- }
68
- async function forever(delayMs, task, onError = null, onFinally = null) {
69
- if (!isPositiveNumber(delayMs)) throw new Error("delayMs must be a positive number");
70
- const update = (value) => {
71
- if (isPositiveNumber(value)) delayMs = value;
72
- };
73
- while (true) try {
74
- update(await task());
75
- } catch (error) {
76
- if (onError) update(await onError(error));
77
- } finally {
78
- if (onFinally) try {
79
- update(await onFinally());
80
- } catch {}
81
- await sleepMs(delayMs);
82
- }
83
- }
84
- async function retry(task, maxAttempts = 1, onError = null, { delayMs = 0, backoffFactor = 1 } = {}) {
85
- for (let attempt = 1; attempt <= maxAttempts; attempt++) try {
86
- return await task();
87
- } catch (error) {
88
- if (onError) await onError(error, attempt);
89
- if (attempt >= maxAttempts) throw error;
90
- if (delayMs > 0) await sleepMs(delayMs * backoffFactor ** (attempt - 1));
91
- }
92
- }
93
- function isValidURL(url) {
94
- try {
95
- new URL(url);
96
- return true;
97
- } catch {
98
- return false;
99
- }
100
- }
101
- function splitTrim(string, separator = null) {
102
- return string.split(separator ?? /\r?\n/).map((item) => item.trim()).filter(Boolean);
103
- }
104
- function checkEmpty(value) {
105
- if (typeof value === "number") return value === 0;
106
- return (0, es_toolkit_compat_isEmpty.default)(value);
107
- }
108
- function pascalCase(string) {
109
- return (0, es_toolkit_string.upperFirst)((0, es_toolkit_string.camelCase)(string));
110
- }
111
- function titleCase(string, separator = " ") {
112
- return (string || "").split(separator).map(es_toolkit_string.upperFirst).join(separator);
113
- }
114
- function isInt32(value) {
115
- return Number.isInteger(value) && value >= CONSTANTS.INT32_MIN && value <= CONSTANTS.INT32_MAX;
116
- }
117
- function isPositiveNumber(value) {
118
- return Number.isFinite(value) && value > 0;
119
- }
120
- function coerceObjectNumbers(object) {
121
- for (const key of Object.keys(object)) {
122
- const value = object[key];
123
- if (typeof value === "string" && NUMBER_PATTERN.test(value)) object[key] = parseFloat(value);
124
- }
125
- return object;
126
- }
127
- function coerceObjectIntegers(object) {
128
- for (const key of Object.keys(object)) {
129
- const value = object[key];
130
- if (typeof value === "string" && INTEGER_PATTERN.test(value)) object[key] = parseInt(value);
131
- }
132
- return object;
133
- }
134
- function findNodeByKey(key, node, pair = null) {
135
- if (node && typeof node === "object") {
136
- if (Object.hasOwn(node, key) && (pair === null || node[key] === pair)) return node;
137
- for (const childKey of Object.keys(node)) {
138
- const result = findNodeByKey(key, node[childKey], pair);
139
- if (result) return result;
140
- }
141
- }
142
- return null;
143
- }
144
- function waitForProperty(object, property, timeoutMs, interval = 100) {
145
- return new Promise((resolve, reject) => {
146
- if (Object.hasOwn(object, property)) {
147
- resolve(object[property]);
148
- return;
149
- }
150
- const startTime = Date.now();
151
- const checkProperty = setInterval(() => {
152
- if (Object.hasOwn(object, property)) {
153
- clearInterval(checkProperty);
154
- resolve(object[property]);
155
- } else if (Date.now() - startTime >= timeoutMs) {
156
- clearInterval(checkProperty);
157
- reject(/* @__PURE__ */ new Error(`Property "${property}" did not appear within ${timeoutMs}ms`));
158
- }
159
- }, interval);
160
- });
161
- }
162
- function shuffleObject(object) {
163
- return Object.fromEntries((0, es_toolkit_array.shuffle)(Object.entries(object)));
164
- }
165
- function objectStringify(object) {
166
- for (const key of Object.keys(object)) {
167
- const value = object[key];
168
- if (value !== null && typeof value === "object") objectStringify(value);
169
- else object[key] = String(value);
170
- }
171
- return object;
172
- }
173
- function limitString(string, limit = 35, omission = "...") {
174
- string = string || "";
175
- if (string.length <= limit) return string;
176
- return string.slice(0, limit - omission.length) + omission;
177
- }
178
- function safeString(string) {
179
- return (0, xss.default)(string || "", {
180
- whiteList: {},
181
- stripIgnoreTag: true,
182
- stripIgnoreTagBody: [
183
- "script",
184
- "style",
185
- "iframe",
186
- "object",
187
- "embed",
188
- "form"
189
- ],
190
- css: false
191
- });
192
- }
193
- function shuffleString(string) {
194
- return (0, es_toolkit_array.shuffle)(string.split("")).join("");
195
- }
196
- function randomBoolean() {
197
- return Math.random() < .5;
198
- }
199
- function randomString(length, useNumbers = true, useUppercase = false) {
200
- let characters = CONSTANTS.LOWER_CASE;
201
- if (useUppercase) characters += CONSTANTS.UPPER_CASE;
202
- if (useNumbers) characters += CONSTANTS.NUMBERS;
203
- let result = "";
204
- for (let i = 0; i < length; i++) result += characters[Math.random() * characters.length | 0];
205
- return result;
206
- }
207
- function randomHex(length) {
208
- let result = "";
209
- for (let i = 0; i < length; i++) result += CONSTANTS.HEXADECIMAL[Math.random() * 16 | 0];
210
- return result;
211
- }
212
- function randomInteger(min, max = void 0) {
213
- if (typeof max === "undefined") {
214
- max = min;
215
- min = 0;
216
- }
217
- if (typeof min !== "number" || typeof max !== "number") throw new Error("min and max must be numerical values");
218
- if (max <= min) throw new Error("max must be greater than min");
219
- return Math.floor(Math.random() * (max - min)) + min;
220
- }
221
- function randomUuid(useDashes = true) {
222
- const uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
223
- const r = Math.random() * 16 | 0;
224
- return (c === "x" ? r : r & 3 | 8).toString(16);
225
- });
226
- return useDashes ? uuid : uuid.replaceAll("-", "");
227
- }
228
- function randomWeighted(object) {
229
- if (checkEmpty(object)) return void 0;
230
- const elements = Object.keys(object);
231
- const weights = Object.values(object);
232
- const totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
233
- const randomNum = Math.random() * totalWeight;
234
- let weightSum = 0;
235
- for (let i = 0; i < elements.length; i++) {
236
- weightSum += weights[i];
237
- if (randomNum < weightSum) return elements[i];
238
- }
239
- }
240
- function randomElement(object) {
241
- if (checkEmpty(object)) return void 0;
242
- const values = Array.isArray(object) ? object : Object.values(object);
243
- if (values.length === 0) return void 0;
244
- return values[Math.floor(Math.random() * values.length)];
245
- }
246
- function mulberry32(seed) {
247
- if (typeof seed === "string") {
248
- let h = 0;
249
- for (let i = 0; i < seed.length; i++) h = Math.imul(h ^ seed.charCodeAt(i), 2654435761);
250
- seed = h >>> 0;
251
- }
252
- return function() {
253
- seed = seed + 1831565813 | 0;
254
- let t = seed;
255
- t = Math.imul(t ^ t >>> 15, t | 1);
256
- t ^= t + Math.imul(t ^ t >>> 7, t | 61);
257
- return ((t ^ t >>> 14) >>> 0) / 4294967296;
258
- };
259
- }
260
- function seedHex(seed, length) {
261
- const rng = mulberry32(String(seed));
262
- let result = "";
263
- while (result.length < length) result += Math.floor(rng() * 4294967296).toString(16).padStart(8, "0");
264
- return result.slice(0, length);
265
- }
266
- function cookiesFromResponse(response, decodeValues = false) {
267
- const obj = {};
268
- const cookies = set_cookie_parser.default.parse(response, { decodeValues });
269
- for (const cookie of cookies) obj[cookie.name] = cookie.value;
270
- return obj;
271
- }
272
- function cookiesToHeader(cookies) {
273
- if (!cookies) return "";
274
- return Object.entries(cookies).filter(([, value]) => value !== null && value !== void 0).map(([key, value]) => `${key}=${value}`).join("; ");
275
- }
276
- function cookiesFromHeader(header) {
277
- const cookies = {};
278
- if (!header) return cookies;
279
- header.split(";").forEach((cookie) => {
280
- const trimmed = cookie.trim();
281
- if (!trimmed.includes("=")) return;
282
- const [key, ...valueParts] = trimmed.split("=");
283
- const trimmedKey = key.trim();
284
- if (trimmedKey) cookies[trimmedKey] = valueParts.join("=").trim();
285
- });
286
- return cookies;
287
- }
288
- function isTransientHttpCode(httpCode) {
289
- return !httpCode || isNaN(httpCode) || httpCode === 100 || httpCode === 402 || httpCode === 407 || 460 <= httpCode && httpCode < 470 || 500 <= httpCode;
290
- }
291
- function getResponseError(error, limit = 200) {
292
- let response;
293
- if (error?.response?.status && error.response.data) response = `${error.response.status}|${error.response.data}`;
294
- else if (error?.response?.data) response = error.response.data;
295
- return limitString(response || error.message, limit).trim();
296
- }
297
- function normalizeProxy(proxy, protocol = "http") {
298
- proxy = proxy?.trim();
299
- if (!proxy) return null;
300
- const schemeMatch = proxy.match(/^([a-z][a-z0-9+.-]*):\/\/(.+)$/i);
301
- if (schemeMatch) {
302
- protocol = schemeMatch[1];
303
- proxy = schemeMatch[2];
304
- }
305
- let auth = "";
306
- let body = proxy;
307
- const atIdx = body.lastIndexOf("@");
308
- if (atIdx !== -1) {
309
- auth = body.slice(0, atIdx) + "@";
310
- body = body.slice(atIdx + 1);
311
- }
312
- if (!auth) {
313
- const parts = body.split(":");
314
- const isPort = (s) => /^\d+$/.test(s) && +s >= 1 && +s <= 65535;
315
- const isHost = (s) => s.includes(".") || /[a-z]/i.test(s);
316
- if (parts.length === 4) if (isPort(parts[3]) && !isPort(parts[1])) {
317
- auth = `${parts[0]}:${parts[1]}@`;
318
- body = `${parts[2]}:${parts[3]}`;
319
- } else if (isPort(parts[1]) && !isPort(parts[3])) {
320
- auth = `${parts[2]}:${parts[3]}@`;
321
- body = `${parts[0]}:${parts[1]}`;
322
- } else if (isHost(parts[2]) && !isHost(parts[0])) {
323
- auth = `${parts[0]}:${parts[1]}@`;
324
- body = `${parts[2]}:${parts[3]}`;
325
- } else {
326
- auth = `${parts[2]}:${parts[3]}@`;
327
- body = `${parts[0]}:${parts[1]}`;
328
- }
329
- else if (parts.length === 5) if (isPort(parts[3]) && isPort(parts[4]) && !isPort(parts[1])) {
330
- auth = `${parts[0]}:${parts[1]}@`;
331
- body = `${parts[2]}:${parts[3]}:${parts[4]}`;
332
- } else if (isPort(parts[1]) && isPort(parts[2]) && !isPort(parts[3])) {
333
- auth = `${parts[3]}:${parts[4]}@`;
334
- body = `${parts[0]}:${parts[1]}:${parts[2]}`;
335
- } else if (isHost(parts[2]) && !isHost(parts[0])) {
336
- auth = `${parts[0]}:${parts[1]}@`;
337
- body = `${parts[2]}:${parts[3]}:${parts[4]}`;
338
- } else {
339
- auth = `${parts[3]}:${parts[4]}@`;
340
- body = `${parts[0]}:${parts[1]}:${parts[2]}`;
341
- }
342
- }
343
- const parts = body.split(":");
344
- if (parts.length === 3) {
345
- const start = Number(parts[1]);
346
- const end = Number(parts[2]);
347
- if (Number.isInteger(start) && Number.isInteger(end) && start >= 0 && start <= end) body = `${parts[0]}:${randomInteger(start, end + 1)}`;
348
- }
349
- return `${protocol}://${auth}${body}`;
350
- }
351
- function parseProxy(proxy, protocol = "http") {
352
- const normalized = normalizeProxy(proxy, protocol);
353
- if (!normalized) return null;
354
- const [scheme, rest] = normalized.split("://");
355
- const atIdx = rest.lastIndexOf("@");
356
- const authPart = atIdx === -1 ? null : rest.slice(0, atIdx);
357
- const [host, port] = (atIdx === -1 ? rest : rest.slice(atIdx + 1)).split(":");
358
- const result = {
359
- protocol: scheme,
360
- host,
361
- port: parseInt(port, 10)
362
- };
363
- if (authPart !== null) {
364
- const colonIdx = authPart.indexOf(":");
365
- const [username, password] = colonIdx === -1 ? [authPart, ""] : [authPart.slice(0, colonIdx), authPart.slice(colonIdx + 1)];
366
- result.auth = {
367
- username,
368
- password
369
- };
370
- }
371
- return result;
372
- }
373
- function proxyValue(rawProxy, replacements = {}) {
374
- const list = splitTrim(rawProxy || "");
375
- if (list.length === 0) return null;
376
- const picked = list[randomInteger(0, list.length)];
377
- let result = normalizeProxy(picked);
378
- if (!result) return null;
379
- if (result.includes("{")) {
380
- const { SESSION, ...rest } = replacements;
381
- let sessionValue;
382
- if (!SESSION && SESSION !== 0) sessionValue = randomHex(8);
383
- else if (typeof SESSION === "function") sessionValue = SESSION();
384
- else sessionValue = seedHex(String(SESSION), 8);
385
- result = result.replace("{SESSION}", sessionValue);
386
- for (const [key, value] of Object.entries(rest)) {
387
- const v = typeof value === "function" ? value() : String(value);
388
- result = result.replace(`{${key}}`, v);
389
- }
390
- }
391
- return result;
392
- }
393
- //#endregion
394
- Object.defineProperty(exports, "CONSTANTS", {
395
- enumerable: true,
396
- get: function() {
397
- return CONSTANTS;
398
- }
399
- });
400
- Object.defineProperty(exports, "Exception", {
401
- enumerable: true,
402
- get: function() {
403
- return Exception;
404
- }
405
- });
406
- Object.defineProperty(exports, "__toESM", {
407
- enumerable: true,
408
- get: function() {
409
- return __toESM;
410
- }
411
- });
412
- Object.defineProperty(exports, "checkEmpty", {
413
- enumerable: true,
414
- get: function() {
415
- return checkEmpty;
416
- }
417
- });
418
- Object.defineProperty(exports, "coerceObjectIntegers", {
419
- enumerable: true,
420
- get: function() {
421
- return coerceObjectIntegers;
422
- }
423
- });
424
- Object.defineProperty(exports, "coerceObjectNumbers", {
425
- enumerable: true,
426
- get: function() {
427
- return coerceObjectNumbers;
428
- }
429
- });
430
- Object.defineProperty(exports, "cookiesFromHeader", {
431
- enumerable: true,
432
- get: function() {
433
- return cookiesFromHeader;
434
- }
435
- });
436
- Object.defineProperty(exports, "cookiesFromResponse", {
437
- enumerable: true,
438
- get: function() {
439
- return cookiesFromResponse;
440
- }
441
- });
442
- Object.defineProperty(exports, "cookiesToHeader", {
443
- enumerable: true,
444
- get: function() {
445
- return cookiesToHeader;
446
- }
447
- });
448
- Object.defineProperty(exports, "findNodeByKey", {
449
- enumerable: true,
450
- get: function() {
451
- return findNodeByKey;
452
- }
453
- });
454
- Object.defineProperty(exports, "forever", {
455
- enumerable: true,
456
- get: function() {
457
- return forever;
458
- }
459
- });
460
- Object.defineProperty(exports, "getResponseError", {
461
- enumerable: true,
462
- get: function() {
463
- return getResponseError;
464
- }
465
- });
466
- Object.defineProperty(exports, "isInt32", {
467
- enumerable: true,
468
- get: function() {
469
- return isInt32;
470
- }
471
- });
472
- Object.defineProperty(exports, "isPositiveNumber", {
473
- enumerable: true,
474
- get: function() {
475
- return isPositiveNumber;
476
- }
477
- });
478
- Object.defineProperty(exports, "isTransientHttpCode", {
479
- enumerable: true,
480
- get: function() {
481
- return isTransientHttpCode;
482
- }
483
- });
484
- Object.defineProperty(exports, "isValidURL", {
485
- enumerable: true,
486
- get: function() {
487
- return isValidURL;
488
- }
489
- });
490
- Object.defineProperty(exports, "limitString", {
491
- enumerable: true,
492
- get: function() {
493
- return limitString;
494
- }
495
- });
496
- Object.defineProperty(exports, "mulberry32", {
497
- enumerable: true,
498
- get: function() {
499
- return mulberry32;
500
- }
501
- });
502
- Object.defineProperty(exports, "normalizeProxy", {
503
- enumerable: true,
504
- get: function() {
505
- return normalizeProxy;
506
- }
507
- });
508
- Object.defineProperty(exports, "objectStringify", {
509
- enumerable: true,
510
- get: function() {
511
- return objectStringify;
512
- }
513
- });
514
- Object.defineProperty(exports, "parseProxy", {
515
- enumerable: true,
516
- get: function() {
517
- return parseProxy;
518
- }
519
- });
520
- Object.defineProperty(exports, "pascalCase", {
521
- enumerable: true,
522
- get: function() {
523
- return pascalCase;
524
- }
525
- });
526
- Object.defineProperty(exports, "promiseSilent", {
527
- enumerable: true,
528
- get: function() {
529
- return promiseSilent;
530
- }
531
- });
532
- Object.defineProperty(exports, "promiseTimeout", {
533
- enumerable: true,
534
- get: function() {
535
- return promiseTimeout;
536
- }
537
- });
538
- Object.defineProperty(exports, "proxyValue", {
539
- enumerable: true,
540
- get: function() {
541
- return proxyValue;
542
- }
543
- });
544
- Object.defineProperty(exports, "randomBoolean", {
545
- enumerable: true,
546
- get: function() {
547
- return randomBoolean;
548
- }
549
- });
550
- Object.defineProperty(exports, "randomElement", {
551
- enumerable: true,
552
- get: function() {
553
- return randomElement;
554
- }
555
- });
556
- Object.defineProperty(exports, "randomHex", {
557
- enumerable: true,
558
- get: function() {
559
- return randomHex;
560
- }
561
- });
562
- Object.defineProperty(exports, "randomInteger", {
563
- enumerable: true,
564
- get: function() {
565
- return randomInteger;
566
- }
567
- });
568
- Object.defineProperty(exports, "randomString", {
569
- enumerable: true,
570
- get: function() {
571
- return randomString;
572
- }
573
- });
574
- Object.defineProperty(exports, "randomUuid", {
575
- enumerable: true,
576
- get: function() {
577
- return randomUuid;
578
- }
579
- });
580
- Object.defineProperty(exports, "randomWeighted", {
581
- enumerable: true,
582
- get: function() {
583
- return randomWeighted;
584
- }
585
- });
586
- Object.defineProperty(exports, "retry", {
587
- enumerable: true,
588
- get: function() {
589
- return retry;
590
- }
591
- });
592
- Object.defineProperty(exports, "safeString", {
593
- enumerable: true,
594
- get: function() {
595
- return safeString;
596
- }
597
- });
598
- Object.defineProperty(exports, "seedHex", {
599
- enumerable: true,
600
- get: function() {
601
- return seedHex;
602
- }
603
- });
604
- Object.defineProperty(exports, "shuffleObject", {
605
- enumerable: true,
606
- get: function() {
607
- return shuffleObject;
608
- }
609
- });
610
- Object.defineProperty(exports, "shuffleString", {
611
- enumerable: true,
612
- get: function() {
613
- return shuffleString;
614
- }
615
- });
616
- Object.defineProperty(exports, "sleep", {
617
- enumerable: true,
618
- get: function() {
619
- return sleep;
620
- }
621
- });
622
- Object.defineProperty(exports, "sleepMs", {
623
- enumerable: true,
624
- get: function() {
625
- return sleepMs;
626
- }
627
- });
628
- Object.defineProperty(exports, "splitTrim", {
629
- enumerable: true,
630
- get: function() {
631
- return splitTrim;
632
- }
633
- });
634
- Object.defineProperty(exports, "time", {
635
- enumerable: true,
636
- get: function() {
637
- return time;
638
- }
639
- });
640
- Object.defineProperty(exports, "titleCase", {
641
- enumerable: true,
642
- get: function() {
643
- return titleCase;
644
- }
645
- });
646
- Object.defineProperty(exports, "waitForProperty", {
647
- enumerable: true,
648
- get: function() {
649
- return waitForProperty;
650
- }
651
- });