melperjs 17.1.1 → 17.2.1

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.
package/README.md CHANGED
@@ -14,6 +14,11 @@ npm i melperjs
14
14
 
15
15
  See the [docs folder](docs/README.md) for the full API reference.
16
16
 
17
+ ## Support
18
+
19
+ If this project helps you, please consider giving it a [Star ⭐️](https://github.com/mahelbir/melperjs) on GitHub.
20
+ This will encourage us to continue developing and maintaining this project.
21
+
17
22
  ## License
18
23
 
19
24
  The MIT License (MIT). Please see [License File](LICENSE) for more information.
package/dist/general.cjs CHANGED
@@ -1,44 +1,426 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_general = require("./general-C6nIgKnW.cjs");
3
- exports.CONSTANTS = require_general.CONSTANTS;
4
- exports.Exception = require_general.Exception;
5
- exports.checkEmpty = require_general.checkEmpty;
6
- exports.coerceObjectIntegers = require_general.coerceObjectIntegers;
7
- exports.coerceObjectNumbers = require_general.coerceObjectNumbers;
8
- exports.cookiesFromHeader = require_general.cookiesFromHeader;
9
- exports.cookiesFromResponse = require_general.cookiesFromResponse;
10
- exports.cookiesToHeader = require_general.cookiesToHeader;
11
- exports.findNodeByKey = require_general.findNodeByKey;
12
- exports.forever = require_general.forever;
13
- exports.getResponseError = require_general.getResponseError;
14
- exports.isInt32 = require_general.isInt32;
15
- exports.isPositiveNumber = require_general.isPositiveNumber;
16
- exports.isTransientHttpCode = require_general.isTransientHttpCode;
17
- exports.isValidURL = require_general.isValidURL;
18
- exports.limitString = require_general.limitString;
19
- exports.mulberry32 = require_general.mulberry32;
20
- exports.normalizeProxy = require_general.normalizeProxy;
21
- exports.objectStringify = require_general.objectStringify;
22
- exports.parseProxy = require_general.parseProxy;
23
- exports.pascalCase = require_general.pascalCase;
24
- exports.promiseSilent = require_general.promiseSilent;
25
- exports.promiseTimeout = require_general.promiseTimeout;
26
- exports.proxyValue = require_general.proxyValue;
27
- exports.randomBoolean = require_general.randomBoolean;
28
- exports.randomElement = require_general.randomElement;
29
- exports.randomHex = require_general.randomHex;
30
- exports.randomInteger = require_general.randomInteger;
31
- exports.randomString = require_general.randomString;
32
- exports.randomUuid = require_general.randomUuid;
33
- exports.randomWeighted = require_general.randomWeighted;
34
- exports.retry = require_general.retry;
35
- exports.safeString = require_general.safeString;
36
- exports.seedHex = require_general.seedHex;
37
- exports.shuffleObject = require_general.shuffleObject;
38
- exports.shuffleString = require_general.shuffleString;
39
- exports.sleep = require_general.sleep;
40
- exports.sleepMs = require_general.sleepMs;
41
- exports.splitTrim = require_general.splitTrim;
42
- exports.time = require_general.time;
43
- exports.titleCase = require_general.titleCase;
44
- exports.waitForProperty = require_general.waitForProperty;
2
+ const require_rolldown_runtime = require("./rolldown-runtime-D6vf50IK.cjs");
3
+ let xss = require("xss");
4
+ xss = require_rolldown_runtime.__toESM(xss, 1);
5
+ let set_cookie_parser = require("set-cookie-parser");
6
+ set_cookie_parser = require_rolldown_runtime.__toESM(set_cookie_parser, 1);
7
+ let es_toolkit_string = require("es-toolkit/string");
8
+ let es_toolkit_array = require("es-toolkit/array");
9
+ let es_toolkit_compat_isEmpty = require("es-toolkit/compat/isEmpty");
10
+ es_toolkit_compat_isEmpty = require_rolldown_runtime.__toESM(es_toolkit_compat_isEmpty, 1);
11
+ //#region src/general.js
12
+ const CONSTANTS = {
13
+ LOWER_CASE: "abcdefghijklmnopqrstuvwxyz",
14
+ UPPER_CASE: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
15
+ HEXADECIMAL: "0123456789abcdef",
16
+ NUMBERS: "0123456789",
17
+ INT32_MIN: -2147483648,
18
+ INT32_MAX: 2147483647
19
+ };
20
+ const NUMBER_PATTERN = /^-?\d+(\.\d+)?(e[+-]?\d+)?$/i;
21
+ const INTEGER_PATTERN = /^-?\d+$/;
22
+ function Exception(message, response = {}, name = null) {
23
+ const error = new Error(message);
24
+ error.name = name || "Exception";
25
+ error.response = response;
26
+ if (checkEmpty(response)) error.response = {};
27
+ return error;
28
+ }
29
+ function time() {
30
+ return Math.floor(Date.now() / 1e3);
31
+ }
32
+ function sleepMs(milliseconds) {
33
+ return new Promise((resolve) => setTimeout(resolve, milliseconds));
34
+ }
35
+ function sleep(seconds) {
36
+ return sleepMs(seconds * 1e3);
37
+ }
38
+ function promiseTimeout(milliseconds, promise) {
39
+ let timer;
40
+ const timeout = new Promise((_, reject) => {
41
+ timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Promise timed out after ${milliseconds}ms`)), milliseconds);
42
+ });
43
+ return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
44
+ }
45
+ function promiseSilent(promise) {
46
+ return promise?.then(() => {})?.catch(() => {});
47
+ }
48
+ async function forever(delayMs, task, onError = null, onFinally = null) {
49
+ if (!isPositiveNumber(delayMs)) throw new Error("delayMs must be a positive number");
50
+ const update = (value) => {
51
+ if (isPositiveNumber(value)) delayMs = value;
52
+ };
53
+ while (true) try {
54
+ update(await task());
55
+ } catch (error) {
56
+ if (onError) update(await onError(error));
57
+ } finally {
58
+ if (onFinally) try {
59
+ update(await onFinally());
60
+ } catch {}
61
+ await sleepMs(delayMs);
62
+ }
63
+ }
64
+ async function retry(task, maxAttempts = 1, onError = null, { delayMs = 0, backoffFactor = 1 } = {}) {
65
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) try {
66
+ return await task();
67
+ } catch (error) {
68
+ if (onError) await onError(error, attempt);
69
+ if (attempt >= maxAttempts) throw error;
70
+ if (delayMs > 0) await sleepMs(delayMs * backoffFactor ** (attempt - 1));
71
+ }
72
+ }
73
+ function isValidURL(url) {
74
+ try {
75
+ new URL(url);
76
+ return true;
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+ function splitTrim(string, separator = null) {
82
+ return string.split(separator ?? /\r?\n/).map((item) => item.trim()).filter(Boolean);
83
+ }
84
+ function pascalCase(string) {
85
+ return (0, es_toolkit_string.upperFirst)((0, es_toolkit_string.camelCase)(string));
86
+ }
87
+ function titleCase(string, separator = " ") {
88
+ return (string || "").split(separator).map(es_toolkit_string.upperFirst).join(separator);
89
+ }
90
+ function castString(value) {
91
+ if (value == null) return "";
92
+ if (typeof value === "string") return value;
93
+ if (typeof value === "object") try {
94
+ return JSON.stringify(value);
95
+ } catch {
96
+ return "{}";
97
+ }
98
+ return String(value);
99
+ }
100
+ function limitString(string, limit = 35, omission = "...") {
101
+ string = string || "";
102
+ if (string.length <= limit) return string;
103
+ return string.slice(0, limit - omission.length) + omission;
104
+ }
105
+ function safeString(string) {
106
+ return (0, xss.default)(string || "", {
107
+ whiteList: {},
108
+ stripIgnoreTag: true,
109
+ stripIgnoreTagBody: [
110
+ "script",
111
+ "style",
112
+ "iframe",
113
+ "object",
114
+ "embed",
115
+ "form"
116
+ ],
117
+ css: false
118
+ });
119
+ }
120
+ function shuffleString(string) {
121
+ return (0, es_toolkit_array.shuffle)(string.split("")).join("");
122
+ }
123
+ function randomBoolean() {
124
+ return Math.random() < .5;
125
+ }
126
+ function randomString(length, useNumbers = true, useUppercase = false) {
127
+ let characters = CONSTANTS.LOWER_CASE;
128
+ if (useUppercase) characters += CONSTANTS.UPPER_CASE;
129
+ if (useNumbers) characters += CONSTANTS.NUMBERS;
130
+ let result = "";
131
+ for (let i = 0; i < length; i++) result += characters[Math.random() * characters.length | 0];
132
+ return result;
133
+ }
134
+ function randomHex(length) {
135
+ let result = "";
136
+ for (let i = 0; i < length; i++) result += CONSTANTS.HEXADECIMAL[Math.random() * 16 | 0];
137
+ return result;
138
+ }
139
+ function randomInteger(min, max = void 0) {
140
+ if (typeof max === "undefined") {
141
+ max = min;
142
+ min = 0;
143
+ }
144
+ if (typeof min !== "number" || typeof max !== "number") throw new Error("min and max must be numerical values");
145
+ if (max <= min) throw new Error("max must be greater than min");
146
+ return Math.floor(Math.random() * (max - min)) + min;
147
+ }
148
+ function randomUuid(useDashes = true) {
149
+ const uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
150
+ const r = Math.random() * 16 | 0;
151
+ return (c === "x" ? r : r & 3 | 8).toString(16);
152
+ });
153
+ return useDashes ? uuid : uuid.replaceAll("-", "");
154
+ }
155
+ function randomWeighted(object) {
156
+ if (checkEmpty(object)) return void 0;
157
+ const elements = Object.keys(object);
158
+ const weights = Object.values(object);
159
+ const totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
160
+ const randomNum = Math.random() * totalWeight;
161
+ let weightSum = 0;
162
+ for (let i = 0; i < elements.length; i++) {
163
+ weightSum += weights[i];
164
+ if (randomNum < weightSum) return elements[i];
165
+ }
166
+ }
167
+ function randomElement(object) {
168
+ if (checkEmpty(object)) return void 0;
169
+ const values = Array.isArray(object) ? object : Object.values(object);
170
+ if (values.length === 0) return void 0;
171
+ return values[Math.floor(Math.random() * values.length)];
172
+ }
173
+ function mulberry32(seed) {
174
+ if (typeof seed === "string") {
175
+ let h = 0;
176
+ for (let i = 0; i < seed.length; i++) h = Math.imul(h ^ seed.charCodeAt(i), 2654435761);
177
+ seed = h >>> 0;
178
+ }
179
+ return function() {
180
+ seed = seed + 1831565813 | 0;
181
+ let t = seed;
182
+ t = Math.imul(t ^ t >>> 15, t | 1);
183
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
184
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
185
+ };
186
+ }
187
+ function seedHex(seed, length) {
188
+ const rng = mulberry32(String(seed));
189
+ let result = "";
190
+ while (result.length < length) result += Math.floor(rng() * 4294967296).toString(16).padStart(8, "0");
191
+ return result.slice(0, length);
192
+ }
193
+ function checkEmpty(value) {
194
+ if (typeof value === "number") return value === 0;
195
+ return (0, es_toolkit_compat_isEmpty.default)(value);
196
+ }
197
+ function isInt32(value) {
198
+ return Number.isInteger(value) && value >= CONSTANTS.INT32_MIN && value <= CONSTANTS.INT32_MAX;
199
+ }
200
+ function isPositiveNumber(value) {
201
+ return Number.isFinite(value) && value > 0;
202
+ }
203
+ function coerceObjectNumbers(object) {
204
+ for (const key of Object.keys(object)) {
205
+ const value = object[key];
206
+ if (typeof value === "string" && NUMBER_PATTERN.test(value)) object[key] = parseFloat(value);
207
+ }
208
+ return object;
209
+ }
210
+ function coerceObjectIntegers(object) {
211
+ for (const key of Object.keys(object)) {
212
+ const value = object[key];
213
+ if (typeof value === "string" && INTEGER_PATTERN.test(value)) object[key] = parseInt(value);
214
+ }
215
+ return object;
216
+ }
217
+ function findNodeByKey(key, node, pair = null) {
218
+ if (node && typeof node === "object") {
219
+ if (Object.hasOwn(node, key) && (pair === null || node[key] === pair)) return node;
220
+ for (const childKey of Object.keys(node)) {
221
+ const result = findNodeByKey(key, node[childKey], pair);
222
+ if (result) return result;
223
+ }
224
+ }
225
+ return null;
226
+ }
227
+ function waitForProperty(object, property, timeoutMs, interval = 100) {
228
+ return new Promise((resolve, reject) => {
229
+ if (Object.hasOwn(object, property)) {
230
+ resolve(object[property]);
231
+ return;
232
+ }
233
+ const startTime = Date.now();
234
+ const checkProperty = setInterval(() => {
235
+ if (Object.hasOwn(object, property)) {
236
+ clearInterval(checkProperty);
237
+ resolve(object[property]);
238
+ } else if (Date.now() - startTime >= timeoutMs) {
239
+ clearInterval(checkProperty);
240
+ reject(/* @__PURE__ */ new Error(`Property "${property}" did not appear within ${timeoutMs}ms`));
241
+ }
242
+ }, interval);
243
+ });
244
+ }
245
+ function shuffleObject(object) {
246
+ return Object.fromEntries((0, es_toolkit_array.shuffle)(Object.entries(object)));
247
+ }
248
+ function objectStringify(object) {
249
+ for (const key of Object.keys(object)) {
250
+ const value = object[key];
251
+ if (value !== null && typeof value === "object") objectStringify(value);
252
+ else object[key] = String(value);
253
+ }
254
+ return object;
255
+ }
256
+ function cookiesFromResponse(response, decodeValues = false) {
257
+ const obj = {};
258
+ const cookies = set_cookie_parser.default.parse(response, { decodeValues });
259
+ for (const cookie of cookies) obj[cookie.name] = cookie.value;
260
+ return obj;
261
+ }
262
+ function cookiesToHeader(cookies) {
263
+ if (!cookies) return "";
264
+ return Object.entries(cookies).filter(([, value]) => value !== null && value !== void 0).map(([key, value]) => `${key}=${value}`).join("; ");
265
+ }
266
+ function cookiesFromHeader(header) {
267
+ const cookies = {};
268
+ if (!header) return cookies;
269
+ header.split(";").forEach((cookie) => {
270
+ const trimmed = cookie.trim();
271
+ if (!trimmed.includes("=")) return;
272
+ const [key, ...valueParts] = trimmed.split("=");
273
+ const trimmedKey = key.trim();
274
+ if (trimmedKey) cookies[trimmedKey] = valueParts.join("=").trim();
275
+ });
276
+ return cookies;
277
+ }
278
+ function isTransientHttpCode(httpCode) {
279
+ return !httpCode || isNaN(httpCode) || httpCode === 100 || httpCode === 402 || httpCode === 407 || 460 <= httpCode && httpCode < 470 || 500 <= httpCode;
280
+ }
281
+ function getResponseError(error, limit = 200) {
282
+ let response;
283
+ if (error?.response?.status && error.response.data) response = `${error.response.status}|${error.response.data}`;
284
+ else if (error?.response?.data) response = error.response.data;
285
+ return limitString(response || error.message, limit).trim();
286
+ }
287
+ function normalizeProxy(proxy, protocol = "http") {
288
+ proxy = proxy?.trim();
289
+ if (!proxy) return null;
290
+ const schemeMatch = proxy.match(/^([a-z][a-z0-9+.-]*):\/\/(.+)$/i);
291
+ if (schemeMatch) {
292
+ protocol = schemeMatch[1];
293
+ proxy = schemeMatch[2];
294
+ }
295
+ let auth = "";
296
+ let body = proxy;
297
+ const atIdx = body.lastIndexOf("@");
298
+ if (atIdx !== -1) {
299
+ auth = body.slice(0, atIdx) + "@";
300
+ body = body.slice(atIdx + 1);
301
+ }
302
+ if (!auth) {
303
+ const parts = body.split(":");
304
+ const isPort = (s) => /^\d+$/.test(s) && +s >= 1 && +s <= 65535;
305
+ const isHost = (s) => s.includes(".") || /[a-z]/i.test(s);
306
+ if (parts.length === 4) if (isPort(parts[3]) && !isPort(parts[1])) {
307
+ auth = `${parts[0]}:${parts[1]}@`;
308
+ body = `${parts[2]}:${parts[3]}`;
309
+ } else if (isPort(parts[1]) && !isPort(parts[3])) {
310
+ auth = `${parts[2]}:${parts[3]}@`;
311
+ body = `${parts[0]}:${parts[1]}`;
312
+ } else if (isHost(parts[2]) && !isHost(parts[0])) {
313
+ auth = `${parts[0]}:${parts[1]}@`;
314
+ body = `${parts[2]}:${parts[3]}`;
315
+ } else {
316
+ auth = `${parts[2]}:${parts[3]}@`;
317
+ body = `${parts[0]}:${parts[1]}`;
318
+ }
319
+ else if (parts.length === 5) if (isPort(parts[3]) && isPort(parts[4]) && !isPort(parts[1])) {
320
+ auth = `${parts[0]}:${parts[1]}@`;
321
+ body = `${parts[2]}:${parts[3]}:${parts[4]}`;
322
+ } else if (isPort(parts[1]) && isPort(parts[2]) && !isPort(parts[3])) {
323
+ auth = `${parts[3]}:${parts[4]}@`;
324
+ body = `${parts[0]}:${parts[1]}:${parts[2]}`;
325
+ } else if (isHost(parts[2]) && !isHost(parts[0])) {
326
+ auth = `${parts[0]}:${parts[1]}@`;
327
+ body = `${parts[2]}:${parts[3]}:${parts[4]}`;
328
+ } else {
329
+ auth = `${parts[3]}:${parts[4]}@`;
330
+ body = `${parts[0]}:${parts[1]}:${parts[2]}`;
331
+ }
332
+ }
333
+ const parts = body.split(":");
334
+ if (parts.length === 3) {
335
+ const start = Number(parts[1]);
336
+ const end = Number(parts[2]);
337
+ if (Number.isInteger(start) && Number.isInteger(end) && start >= 0 && start <= end) body = `${parts[0]}:${randomInteger(start, end + 1)}`;
338
+ }
339
+ return `${protocol}://${auth}${body}`;
340
+ }
341
+ function parseProxy(proxy, protocol = "http") {
342
+ const normalized = normalizeProxy(proxy, protocol);
343
+ if (!normalized) return null;
344
+ const [scheme, rest] = normalized.split("://");
345
+ const atIdx = rest.lastIndexOf("@");
346
+ const authPart = atIdx === -1 ? null : rest.slice(0, atIdx);
347
+ const [host, port] = (atIdx === -1 ? rest : rest.slice(atIdx + 1)).split(":");
348
+ const result = {
349
+ protocol: scheme,
350
+ host,
351
+ port: parseInt(port, 10)
352
+ };
353
+ if (authPart !== null) {
354
+ const colonIdx = authPart.indexOf(":");
355
+ const [username, password] = colonIdx === -1 ? [authPart, ""] : [authPart.slice(0, colonIdx), authPart.slice(colonIdx + 1)];
356
+ result.auth = {
357
+ username,
358
+ password
359
+ };
360
+ }
361
+ return result;
362
+ }
363
+ function proxyValue(rawProxy, replacements = {}) {
364
+ const list = splitTrim(rawProxy || "");
365
+ if (list.length === 0) return null;
366
+ const picked = list[randomInteger(0, list.length)];
367
+ let result = normalizeProxy(picked);
368
+ if (!result) return null;
369
+ if (result.includes("{")) {
370
+ const { SESSION, ...rest } = replacements;
371
+ let sessionValue;
372
+ if (!SESSION && SESSION !== 0) sessionValue = randomHex(8);
373
+ else if (typeof SESSION === "function") sessionValue = SESSION();
374
+ else sessionValue = seedHex(String(SESSION), 8);
375
+ result = result.replace("{SESSION}", sessionValue);
376
+ for (const [key, value] of Object.entries(rest)) {
377
+ const v = typeof value === "function" ? value() : String(value);
378
+ result = result.replace(`{${key}}`, v);
379
+ }
380
+ }
381
+ return result;
382
+ }
383
+ //#endregion
384
+ exports.CONSTANTS = CONSTANTS;
385
+ exports.Exception = Exception;
386
+ exports.castString = castString;
387
+ exports.checkEmpty = checkEmpty;
388
+ exports.coerceObjectIntegers = coerceObjectIntegers;
389
+ exports.coerceObjectNumbers = coerceObjectNumbers;
390
+ exports.cookiesFromHeader = cookiesFromHeader;
391
+ exports.cookiesFromResponse = cookiesFromResponse;
392
+ exports.cookiesToHeader = cookiesToHeader;
393
+ exports.findNodeByKey = findNodeByKey;
394
+ exports.forever = forever;
395
+ exports.getResponseError = getResponseError;
396
+ exports.isInt32 = isInt32;
397
+ exports.isPositiveNumber = isPositiveNumber;
398
+ exports.isTransientHttpCode = isTransientHttpCode;
399
+ exports.isValidURL = isValidURL;
400
+ exports.limitString = limitString;
401
+ exports.mulberry32 = mulberry32;
402
+ exports.normalizeProxy = normalizeProxy;
403
+ exports.objectStringify = objectStringify;
404
+ exports.parseProxy = parseProxy;
405
+ exports.pascalCase = pascalCase;
406
+ exports.promiseSilent = promiseSilent;
407
+ exports.promiseTimeout = promiseTimeout;
408
+ exports.proxyValue = proxyValue;
409
+ exports.randomBoolean = randomBoolean;
410
+ exports.randomElement = randomElement;
411
+ exports.randomHex = randomHex;
412
+ exports.randomInteger = randomInteger;
413
+ exports.randomString = randomString;
414
+ exports.randomUuid = randomUuid;
415
+ exports.randomWeighted = randomWeighted;
416
+ exports.retry = retry;
417
+ exports.safeString = safeString;
418
+ exports.seedHex = seedHex;
419
+ exports.shuffleObject = shuffleObject;
420
+ exports.shuffleString = shuffleString;
421
+ exports.sleep = sleep;
422
+ exports.sleepMs = sleepMs;
423
+ exports.splitTrim = splitTrim;
424
+ exports.time = time;
425
+ exports.titleCase = titleCase;
426
+ exports.waitForProperty = waitForProperty;
package/dist/general.mjs CHANGED
@@ -76,74 +76,21 @@ function isValidURL(url) {
76
76
  function splitTrim(string, separator = null) {
77
77
  return string.split(separator ?? /\r?\n/).map((item) => item.trim()).filter(Boolean);
78
78
  }
79
- function checkEmpty(value) {
80
- if (typeof value === "number") return value === 0;
81
- return isEmpty(value);
82
- }
83
79
  function pascalCase(string) {
84
80
  return upperFirst(camelCase(string));
85
81
  }
86
82
  function titleCase(string, separator = " ") {
87
83
  return (string || "").split(separator).map(upperFirst).join(separator);
88
84
  }
89
- function isInt32(value) {
90
- return Number.isInteger(value) && value >= CONSTANTS.INT32_MIN && value <= CONSTANTS.INT32_MAX;
91
- }
92
- function isPositiveNumber(value) {
93
- return Number.isFinite(value) && value > 0;
94
- }
95
- function coerceObjectNumbers(object) {
96
- for (const key of Object.keys(object)) {
97
- const value = object[key];
98
- if (typeof value === "string" && NUMBER_PATTERN.test(value)) object[key] = parseFloat(value);
99
- }
100
- return object;
101
- }
102
- function coerceObjectIntegers(object) {
103
- for (const key of Object.keys(object)) {
104
- const value = object[key];
105
- if (typeof value === "string" && INTEGER_PATTERN.test(value)) object[key] = parseInt(value);
106
- }
107
- return object;
108
- }
109
- function findNodeByKey(key, node, pair = null) {
110
- if (node && typeof node === "object") {
111
- if (Object.hasOwn(node, key) && (pair === null || node[key] === pair)) return node;
112
- for (const childKey of Object.keys(node)) {
113
- const result = findNodeByKey(key, node[childKey], pair);
114
- if (result) return result;
115
- }
116
- }
117
- return null;
118
- }
119
- function waitForProperty(object, property, timeoutMs, interval = 100) {
120
- return new Promise((resolve, reject) => {
121
- if (Object.hasOwn(object, property)) {
122
- resolve(object[property]);
123
- return;
124
- }
125
- const startTime = Date.now();
126
- const checkProperty = setInterval(() => {
127
- if (Object.hasOwn(object, property)) {
128
- clearInterval(checkProperty);
129
- resolve(object[property]);
130
- } else if (Date.now() - startTime >= timeoutMs) {
131
- clearInterval(checkProperty);
132
- reject(/* @__PURE__ */ new Error(`Property "${property}" did not appear within ${timeoutMs}ms`));
133
- }
134
- }, interval);
135
- });
136
- }
137
- function shuffleObject(object) {
138
- return Object.fromEntries(shuffle(Object.entries(object)));
139
- }
140
- function objectStringify(object) {
141
- for (const key of Object.keys(object)) {
142
- const value = object[key];
143
- if (value !== null && typeof value === "object") objectStringify(value);
144
- else object[key] = String(value);
85
+ function castString(value) {
86
+ if (value == null) return "";
87
+ if (typeof value === "string") return value;
88
+ if (typeof value === "object") try {
89
+ return JSON.stringify(value);
90
+ } catch {
91
+ return "{}";
145
92
  }
146
- return object;
93
+ return String(value);
147
94
  }
148
95
  function limitString(string, limit = 35, omission = "...") {
149
96
  string = string || "";
@@ -238,6 +185,69 @@ function seedHex(seed, length) {
238
185
  while (result.length < length) result += Math.floor(rng() * 4294967296).toString(16).padStart(8, "0");
239
186
  return result.slice(0, length);
240
187
  }
188
+ function checkEmpty(value) {
189
+ if (typeof value === "number") return value === 0;
190
+ return isEmpty(value);
191
+ }
192
+ function isInt32(value) {
193
+ return Number.isInteger(value) && value >= CONSTANTS.INT32_MIN && value <= CONSTANTS.INT32_MAX;
194
+ }
195
+ function isPositiveNumber(value) {
196
+ return Number.isFinite(value) && value > 0;
197
+ }
198
+ function coerceObjectNumbers(object) {
199
+ for (const key of Object.keys(object)) {
200
+ const value = object[key];
201
+ if (typeof value === "string" && NUMBER_PATTERN.test(value)) object[key] = parseFloat(value);
202
+ }
203
+ return object;
204
+ }
205
+ function coerceObjectIntegers(object) {
206
+ for (const key of Object.keys(object)) {
207
+ const value = object[key];
208
+ if (typeof value === "string" && INTEGER_PATTERN.test(value)) object[key] = parseInt(value);
209
+ }
210
+ return object;
211
+ }
212
+ function findNodeByKey(key, node, pair = null) {
213
+ if (node && typeof node === "object") {
214
+ if (Object.hasOwn(node, key) && (pair === null || node[key] === pair)) return node;
215
+ for (const childKey of Object.keys(node)) {
216
+ const result = findNodeByKey(key, node[childKey], pair);
217
+ if (result) return result;
218
+ }
219
+ }
220
+ return null;
221
+ }
222
+ function waitForProperty(object, property, timeoutMs, interval = 100) {
223
+ return new Promise((resolve, reject) => {
224
+ if (Object.hasOwn(object, property)) {
225
+ resolve(object[property]);
226
+ return;
227
+ }
228
+ const startTime = Date.now();
229
+ const checkProperty = setInterval(() => {
230
+ if (Object.hasOwn(object, property)) {
231
+ clearInterval(checkProperty);
232
+ resolve(object[property]);
233
+ } else if (Date.now() - startTime >= timeoutMs) {
234
+ clearInterval(checkProperty);
235
+ reject(/* @__PURE__ */ new Error(`Property "${property}" did not appear within ${timeoutMs}ms`));
236
+ }
237
+ }, interval);
238
+ });
239
+ }
240
+ function shuffleObject(object) {
241
+ return Object.fromEntries(shuffle(Object.entries(object)));
242
+ }
243
+ function objectStringify(object) {
244
+ for (const key of Object.keys(object)) {
245
+ const value = object[key];
246
+ if (value !== null && typeof value === "object") objectStringify(value);
247
+ else object[key] = String(value);
248
+ }
249
+ return object;
250
+ }
241
251
  function cookiesFromResponse(response, decodeValues = false) {
242
252
  const obj = {};
243
253
  const cookies = setCookieParser.parse(response, { decodeValues });
@@ -366,4 +376,4 @@ function proxyValue(rawProxy, replacements = {}) {
366
376
  return result;
367
377
  }
368
378
  //#endregion
369
- export { CONSTANTS, Exception, checkEmpty, coerceObjectIntegers, coerceObjectNumbers, cookiesFromHeader, cookiesFromResponse, cookiesToHeader, findNodeByKey, forever, getResponseError, isInt32, isPositiveNumber, isTransientHttpCode, isValidURL, limitString, mulberry32, normalizeProxy, objectStringify, parseProxy, pascalCase, promiseSilent, promiseTimeout, proxyValue, randomBoolean, randomElement, randomHex, randomInteger, randomString, randomUuid, randomWeighted, retry, safeString, seedHex, shuffleObject, shuffleString, sleep, sleepMs, splitTrim, time, titleCase, waitForProperty };
379
+ export { CONSTANTS, Exception, castString, checkEmpty, coerceObjectIntegers, coerceObjectNumbers, cookiesFromHeader, cookiesFromResponse, cookiesToHeader, findNodeByKey, forever, getResponseError, isInt32, isPositiveNumber, isTransientHttpCode, isValidURL, limitString, mulberry32, normalizeProxy, objectStringify, parseProxy, pascalCase, promiseSilent, promiseTimeout, proxyValue, randomBoolean, randomElement, randomHex, randomInteger, randomString, randomUuid, randomWeighted, retry, safeString, seedHex, shuffleObject, shuffleString, sleep, sleepMs, splitTrim, time, titleCase, waitForProperty };
package/dist/node.cjs CHANGED
@@ -1,16 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_general = require("./general-C6nIgKnW.cjs");
2
+ const require_rolldown_runtime = require("./rolldown-runtime-D6vf50IK.cjs");
3
+ const require_general = require("./general.cjs");
3
4
  let fs = require("fs");
4
- fs = require_general.__toESM(fs, 1);
5
+ fs = require_rolldown_runtime.__toESM(fs, 1);
5
6
  let path = require("path");
6
- path = require_general.__toESM(path, 1);
7
+ path = require_rolldown_runtime.__toESM(path, 1);
7
8
  let crypto = require("crypto");
8
- crypto = require_general.__toESM(crypto, 1);
9
+ crypto = require_rolldown_runtime.__toESM(crypto, 1);
9
10
  let os = require("os");
10
11
  let child_process = require("child_process");
11
12
  let util = require("util");
12
13
  let bcryptjs = require("bcryptjs");
13
- bcryptjs = require_general.__toESM(bcryptjs, 1);
14
+ bcryptjs = require_rolldown_runtime.__toESM(bcryptjs, 1);
14
15
  //#region src/node.js
15
16
  const execAsync = (0, util.promisify)(child_process.exec);
16
17
  function secureRandomBoolean() {
@@ -108,6 +109,10 @@ function writeJsonFileSync(filePath, data) {
108
109
  const jsonData = JSON.stringify(data);
109
110
  return fs.default.writeFileSync(filePath, jsonData, "utf8");
110
111
  }
112
+ function createNumberedDirs(mainDirectory, start = 0, end = 9) {
113
+ fs.default.mkdirSync(mainDirectory, { recursive: true });
114
+ for (let i = start; i <= end; i++) fs.default.mkdirSync(path.default.join(mainDirectory, `${i}`), { recursive: true });
115
+ }
111
116
  async function clearDirectory(directoryPath, keepDir = true) {
112
117
  await fs.promises.rm(directoryPath, {
113
118
  recursive: true,
@@ -115,10 +120,6 @@ async function clearDirectory(directoryPath, keepDir = true) {
115
120
  });
116
121
  if (keepDir) await fs.promises.mkdir(directoryPath, { recursive: true });
117
122
  }
118
- function createNumberedDirs(mainDirectory, start = 0, end = 9) {
119
- fs.default.mkdirSync(mainDirectory, { recursive: true });
120
- for (let i = start; i <= end; i++) fs.default.mkdirSync(path.default.join(mainDirectory, `${i}`), { recursive: true });
121
- }
122
123
  async function executeCommand(command) {
123
124
  const { stdout } = await execAsync(command);
124
125
  return stdout.trim();