melperjs 4.0.0 → 6.0.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.
package/.babelrc CHANGED
@@ -3,10 +3,10 @@
3
3
  "development": {
4
4
  "presets": [
5
5
  [
6
- "babel-preset-env",
6
+ "@babel/preset-env",
7
7
  {
8
8
  "targets": {
9
- "node": "current"
9
+ "node": "18"
10
10
  }
11
11
  }
12
12
  ]
@@ -15,6 +15,21 @@
15
15
  ]
16
16
  },
17
17
  "module": {
18
+ "presets": [
19
+ [
20
+ "@babel/preset-env",
21
+ {
22
+ "targets": {
23
+ "node": "18"
24
+ },
25
+ "modules": false
26
+ }
27
+ ]
28
+ ],
29
+ "plugins": [
30
+ ]
31
+ },
32
+ "browser": {
18
33
  "presets": [
19
34
  [
20
35
  "@babel/preset-env",
@@ -27,6 +42,9 @@
27
42
  ]
28
43
  ],
29
44
  "plugins": [
45
+ ],
46
+ "ignore": [
47
+ "./src/node.js"
30
48
  ]
31
49
  }
32
50
  },
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MELPERJS
2
2
 
3
- Node.js module to use predefined common functions and utilities
3
+ Javascript module to use predefined common functions and utilities
4
4
 
5
5
  ## Installation
6
6
 
@@ -21,7 +21,8 @@ const nodeHelper = require("melperjs/node");
21
21
  const axios = require("axios");
22
22
 
23
23
  (async () => {
24
- console.log(helper.Exception("something went wrong", {status: 500}, "axios error"));
24
+ console.log(helper.CONSTANTS);
25
+ console.log(helper.Exception("something went wrong", {status: 400}, "bad request error"));
25
26
  console.log(helper.time());
26
27
  await helper.sleepMs(1000);
27
28
  console.log(helper.time());
@@ -31,7 +32,13 @@ const axios = require("axios");
31
32
  await helper.promiseTimeout(1000, helper.sleepMs(2000));
32
33
  } catch (e) {
33
34
  console.error(e.message);
35
+ console.log("Timeout, Internal Error ?", helper.isIntlError(e));
34
36
  }
37
+ console.log(helper.splitLines(`
38
+ 2.satır
39
+
40
+ 4.satır
41
+ `))
35
42
  console.log(helper.findKeyNode("c", {
36
43
  a: {
37
44
  b: {
@@ -43,16 +50,19 @@ const axios = require("axios");
43
50
  }
44
51
  }
45
52
  }));
46
- console.log("str empty", helper.checkEmpty(""));
47
- console.log("1 empty", helper.checkEmpty(1));
48
- console.log("[] empty", helper.checkEmpty([]));
53
+ console.log("'' empty ?", helper.checkEmpty(''));
54
+ console.log("1 empty ?", helper.checkEmpty(1));
55
+ console.log("0 empty ?", helper.checkEmpty(1));
56
+ console.log("[] empty ?", helper.checkEmpty([]));
57
+ console.log(helper.pascalCase("pascal case"));
49
58
  console.log(helper.upperCaseFirst("first letter upper"));
50
59
  console.log(helper.lowerCaseFirst("First Letter Lower"));
51
- console.log(helper.titleString("THIS mUsT be Title"));
60
+ console.log(helper.titleCase("THIS mUsT be Title"));
52
61
  console.log(helper.limitString("LONG TEXT", 7));
53
62
  console.log(helper.safeString("<strong>SAFE TEXT</strong>"));
54
63
  console.log(helper.randomString(32, true, true));
55
64
  console.log(helper.randomHex(8));
65
+ console.log(helper.randomInteger(100, 1000));
56
66
  console.log(helper.randomUuid(true));
57
67
  console.log(helper.randomWeighted({strongProbability: 1000, lowProbability: 1}));
58
68
  console.log(nodeHelper.tokenString(32, true, true));
@@ -60,60 +70,70 @@ const axios = require("axios");
60
70
  console.log(nodeHelper.tokenUuid(true));
61
71
  console.log(nodeHelper.tokenWeighted({strongProbability: 1000, lowProbability: 1}));
62
72
  console.log(nodeHelper.md5("data"));
63
- const password = helper.hashBcrypt("plain");
73
+ const password = nodeHelper.hashBcrypt("plain");
64
74
  console.log(password)
65
- console.log("passwordHash", helper.verifyBcrypt("plain", password));
75
+ console.log("passwordHash verified ?", nodeHelper.verifyBcrypt("plain", password));
66
76
  const cookies = helper.cookieDict(await axios.get("https://google.com"));
67
77
  console.log(cookies);
68
78
  console.log(helper.cookieHeader(cookies));
69
79
  const proxy = nodeHelper.formatProxy("127.0.0.1:8080:id:pw-{SESSION}");
70
80
  console.log(proxy);
71
81
  console.log(nodeHelper.proxyObject(proxy));
72
- console.log(await nodeHelper.proxify({mode: 4, proxy}));
82
+ console.log(nodeHelper.proxyValue(proxy));
73
83
  console.log(nodeHelper.serverIp());
74
- console.log("HTTP CODE: 401 FOREIGN", helper.foreignHttpError(401));
75
- console.log("HTTP CODE: 407 FOREIGN (Failed Proxy Auth)", helper.foreignHttpError(407));
84
+ console.log("HTTP CODE: 400 (Bad Request) ?", helper.isIntlHttpCode(401));
85
+ console.log("HTTP CODE: 407 (Failed Proxy Auth) ?", helper.isIntlHttpCode(407));
76
86
  nodeHelper.createNumDir("test");
77
- nodeHelper.createDir("test");
78
87
  console.log("VERSIONED BY .GIT", "v" + nodeHelper.getVersion());
79
88
  })();
80
89
 
81
90
  /*
82
91
  {
83
- name: 'AxiosError',
92
+ LOWER_CASE: 'abcdefghijklmnopqrstuvwxyz',
93
+ UPPER_CASE: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
94
+ HEXADECIMAL: '0123456789abcdef',
95
+ NUMBERS: '0123456789'
96
+ }
97
+ {
98
+ name: 'BadRequestError',
84
99
  message: 'something went wrong',
85
- response: { status: 500 }
100
+ response: { status: 400 }
86
101
  }
87
- 1700529489
88
- 1700529490
89
- 1700529491
102
+ 1701697141
103
+ 1701697142
104
+ 1701697143
90
105
  Promise timed out after 1000ms
106
+ Timeout, Internal Error ? true
107
+ [ '2.satır', '4.satır' ]
91
108
  { x: 1, y: 2, c: { d: true } }
92
- str empty true
93
- 1 empty false
94
- [] empty true
109
+ '' empty ? true
110
+ 1 empty ? false
111
+ 0 empty ? false
112
+ [] empty ? true
113
+ PascalCase
95
114
  First letter upper
96
115
  first Letter Lower
97
116
  This Must Be Title
98
117
  LONG...
99
118
  SAFE TEXT
100
- 15WY89Q4yAMCzPmNsU0ANGX2eiOz7Gfy
101
- 9eb93429
102
- 7e1fb299-251c-4a75-bb37-f7cc3a730121
119
+ sP3jTNwe1rRrW1TVAPb4HAXNFjJB2mWb
120
+ f70f7212
121
+ 376
122
+ f07fe6b1-46d5-4f30-8138-f263f4916e65
103
123
  strongProbability
104
- STIhrofUYVAQ4anplyJW2T7GEwSJkuk7
105
- 6db791a1
106
- 0cbef42d-a277-4f66-8bcc-e4de337c2b56
124
+ JT4tXSI7YdIYDGbzLmHkItZ32vgi5aos
125
+ 52c0da20
126
+ 3e4374f4-11d9-4174-b337-dbf8d7fa2d41
107
127
  strongProbability
108
128
  8d777f385d3dfec8815d20f7496026dc
109
- $2b$10$IsuTscKKHbcf6sBp7BrCOOcg6A8v32G9UxzdYN3Y6xyMaUynweYX2
110
- passwordHash true
129
+ $2b$10$DTITmEyk1IcWfG1qaVEvyOgLReqOI97X/LufbbV/nvOU8DspBNMOS
130
+ passwordHash verified ? true
111
131
  {
112
- '1P_JAR': '2023-11-21-01',
113
- AEC: 'Ackid1TlDwA2YJw3rzP5t3x5vBdxZt-4AzkhdwLahUVpj3vhdVHvPlw0VWM',
114
- NID: '511=tD21gyuziCvCgZSQZd5h_xDFOF6df8AhkFy0iXq9MwHG9K8J3FEkT7L0CACgjJhGDVQFoZG_Pwi2Wo8Kf7NnmvcNGVmk-lDhY768PI9sVSUmSHIYwpfsuVvG4NwNwk3iPNKmbqaC_H-YVGZhEJVn2c6YYUVxE0oEDtfuyPhGOXw'
132
+ '1P_JAR': '2023-12-04-13',
133
+ AEC: 'Ackid1Q9P_jk5EM2S_PU_QT-RUEu0syeyPMuCOLYbtlkX5gvB1zRTPytuw',
134
+ NID: '511=jBXxJSukq7Ku4449skx8tmFlqkM-nKwhaQ4hukE0F-jntKrI8daHyoAS6npvlujAMKU966ZMNGE6wu8xYc2PciilTQrKxgRyJv1QsdNIc6y_mlrLfuOfLXkwDuf0YWdS0Or3Aq6wHR87o0paAAcYAntlopexVF7NpQ6yifGe57c'
115
135
  }
116
- 1P_JAR=2023-11-21-01;AEC=Ackid1TlDwA2YJw3rzP5t3x5vBdxZt-4AzkhdwLahUVpj3vhdVHvPlw0VWM;NID=511=tD21gyuziCvCgZSQZd5h_xDFOF6df8AhkFy0iXq9MwHG9K8J3FEkT7L0CACgjJhGDVQFoZG_Pwi2Wo8Kf7NnmvcNGVmk-lDhY768PI9sVSUmSHIYwpfsuVvG4NwNwk3iPNKmbqaC_H-YVGZhEJVn2c6YYUVxE0oEDtfuyPhGOXw
136
+ 1P_JAR=2023-12-04-13;AEC=Ackid1Q9P_jk5EM2S_PU_QT-RUEu0syeyPMuCOLYbtlkX5gvB1zRTPytuw;NID=511=jBXxJSukq7Ku4449skx8tmFlqkM-nKwhaQ4hukE0F-jntKrI8daHyoAS6npvlujAMKU966ZMNGE6wu8xYc2PciilTQrKxgRyJv1QsdNIc6y_mlrLfuOfLXkwDuf0YWdS0Or3Aq6wHR87o0paAAcYAntlopexVF7NpQ6yifGe57c
117
137
  http://id:pw-{SESSION}@127.0.0.1:8080
118
138
  {
119
139
  protocol: 'http',
@@ -121,10 +141,10 @@ http://id:pw-{SESSION}@127.0.0.1:8080
121
141
  port: 8080,
122
142
  auth: { username: 'id', password: 'pw-{SESSION}' }
123
143
  }
124
- http://id:pw-527ef984@127.0.0.1:8080
144
+ http://id:pw-749756be@127.0.0.1:8080
125
145
  127.0.0.1
126
- HTTP CODE: 401 FOREIGN false
127
- HTTP CODE: 407 FOREIGN (Failed Proxy Auth) true
146
+ HTTP CODE: 400 (Bad Request) ? false
147
+ HTTP CODE: 407 (Failed Proxy Auth) ? true
128
148
  VERSIONED BY .GIT v2310.15182
129
149
  */
130
150
  ```
package/cjs/index.js CHANGED
@@ -1,191 +1,186 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CONSTANTS = undefined;
7
- exports.Exception = Exception;
8
- exports.time = time;
9
- exports.sleepMs = sleepMs;
10
- exports.sleep = sleep;
11
- exports.promiseTimeout = promiseTimeout;
12
- exports.splitLines = splitLines;
13
- exports.findKeyNode = findKeyNode;
14
- exports.checkEmpty = checkEmpty;
15
- exports.pascalCase = pascalCase;
16
- exports.upperCaseFirst = upperCaseFirst;
17
- exports.lowerCaseFirst = lowerCaseFirst;
18
- exports.titleString = titleString;
19
- exports.limitString = limitString;
20
- exports.safeString = safeString;
21
- exports.randomString = randomString;
22
- exports.randomHex = randomHex;
23
- exports.randomUuid = randomUuid;
24
- exports.randomWeighted = randomWeighted;
25
- exports.cookieDict = cookieDict;
26
- exports.cookieHeader = cookieHeader;
27
- exports.isIntlHttpCode = isIntlHttpCode;
28
- exports.isIntlError = isIntlError;
29
- var _xss = require("xss");
30
- var _xss2 = _interopRequireDefault(_xss);
31
- var _camelCase = require("lodash/camelCase.js");
32
- var _camelCase2 = _interopRequireDefault(_camelCase);
33
- var _capitalize = require("lodash/capitalize.js");
34
- var _capitalize2 = _interopRequireDefault(_capitalize);
35
- var _isEmpty = require("lodash/isEmpty.js");
36
- var _isEmpty2 = _interopRequireDefault(_isEmpty);
37
- var _setCookieParser = require("set-cookie-parser");
38
- var _setCookieParser2 = _interopRequireDefault(_setCookieParser);
39
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
- const CONSTANTS = exports.CONSTANTS = {
41
- LOWER_CASE: "abcdefghijklmnopqrstuvwxyz",
42
- UPPER_CASE: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
43
- HEXADECIMAL: "0123456789abcdef",
44
- NUMBERS: "0123456789"
45
- };
46
- function Exception(message, response = {}, name = null) {
47
- response.status = response.status || 400;
48
- return {
49
- name: pascalCase(name),
50
- message,
51
- response
52
- };
53
- }
54
- function time() {
55
- return Math.floor(Date.now() / 1000);
56
- }
57
- async function sleepMs(milliseconds) {
58
- return new Promise(resolve => setTimeout(resolve, milliseconds));
59
- }
60
- async function sleep(seconds) {
61
- return await sleepMs(seconds * 1000);
62
- }
63
- function promiseTimeout(milliseconds, promise) {
64
- return new Promise((resolve, reject) => {
65
- const timer = setTimeout(() => {
66
- reject(new Error('Promise timed out after ' + milliseconds + 'ms'));
67
- }, milliseconds);
68
- promise.then(value => {
69
- clearTimeout(timer);
70
- resolve(value);
71
- }).catch(reason => {
72
- clearTimeout(timer);
73
- reject(reason);
74
- });
75
- });
76
- }
77
- function splitLines(text) {
78
- return text.split(/\r?\n/).filter(item => !checkEmpty(item)).map(item => item.trim());
79
- }
80
- function findKeyNode(key, node, pair = null) {
81
- if (node && node.hasOwnProperty(key) && (pair ? node[key] === pair : true)) {
82
- return node;
83
- } else if (typeof node === 'object') {
84
- for (let index in node) {
85
- const result = findKeyNode(key, node[index], pair);
86
- if (result) {
87
- return result;
88
- }
89
- }
90
- }
91
- return null;
92
- }
93
- function checkEmpty(value) {
94
- if (typeof value === "number") {
95
- return value === 0;
96
- } else {
97
- return (0, _isEmpty2.default)(value);
98
- }
99
- }
100
- function pascalCase(str) {
101
- return upperCaseFirst((0, _camelCase2.default)(str));
102
- }
103
- function upperCaseFirst(str) {
104
- str = str || "";
105
- return str[0].toUpperCase() + str.slice(1);
106
- }
107
- function lowerCaseFirst(str) {
108
- str = str || "";
109
- return str[0].toLowerCase() + str.slice(1);
110
- }
111
- function titleString(str) {
112
- str = str || "";
113
- return str.split(' ').map(word => (0, _capitalize2.default)(word)).join(' ');
114
- }
115
- function limitString(str, limit = 35) {
116
- str = str || "";
117
- if (str.length <= limit) {
118
- return str;
119
- } else {
120
- return str.substring(0, limit - 3) + "...";
121
- }
122
- }
123
- function safeString(str) {
124
- str = str || "";
125
- return (0, _xss2.default)(str, {
126
- whiteList: {},
127
- stripIgnoreTag: true,
128
- stripIgnoreTagBody: ["script"]
129
- });
130
- }
131
- function randomString(length, useNumbers = true, useUppercase = false) {
132
- let characters = CONSTANTS.LOWER_CASE;
133
- if (useUppercase) characters += CONSTANTS.UPPER_CASE;
134
- if (useNumbers) characters += CONSTANTS.NUMBERS;
135
- let randomString = '';
136
- for (let i = 0; i < length; i++) {
137
- const randomIndex = Math.floor(Math.random() * characters.length);
138
- randomString += characters[randomIndex];
139
- }
140
- return randomString;
141
- }
142
- function randomHex(length) {
143
- let result = '';
144
- for (let i = 0; i < length; i++) {
145
- const randomIndex = Math.floor(Math.random() * CONSTANTS.HEXADECIMAL.length);
146
- result += CONSTANTS.HEXADECIMAL[randomIndex];
147
- }
148
- return result;
149
- }
150
- function randomUuid(useDashes = true) {
151
- let d = Date.now();
152
- const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
153
- const r = (d + Math.random() * 16) % 16 | 0;
154
- d = Math.floor(d / 16);
155
- return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
156
- });
157
- return useDashes ? uuid : uuid.replaceAll("-", "");
158
- }
159
- function randomWeighted(dict, randomFunc = totalWeight => Math.random() * totalWeight) {
160
- let elements = Object.keys(dict);
161
- let weights = Object.values(dict);
162
- let totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
163
- let randomNum = randomFunc(totalWeight);
164
- let weightSum = 0;
165
- for (let i = 0; i < elements.length; i++) {
166
- weightSum += weights[i];
167
- if (randomNum <= weightSum) {
168
- return elements[i];
169
- }
170
- }
171
- }
172
- function cookieDict(res, decodeValues = false) {
173
- let dict = {};
174
- const cookies = _setCookieParser2.default.parse(res, {
175
- decodeValues: decodeValues
176
- });
177
- for (let cookie of cookies) {
178
- dict[cookie.name] = cookie.value;
179
- }
180
- return dict;
181
- }
182
- function cookieHeader(cookieDict) {
183
- return Object.entries(cookieDict).map(([key, value]) => `${key}=${value}`).join(';');
184
- }
185
- function isIntlHttpCode(httpCode) {
186
- return httpCode === undefined || httpCode === null || httpCode === 0 || httpCode === 402 || httpCode === 407 || httpCode === 466 || 500 <= httpCode;
187
- }
188
- function isIntlError(e) {
189
- return e?.message?.toLowerCase?.()?.includes?.("timeout") || e?.message?.toLowerCase?.()?.includes?.("aborted") || e?.message?.toLowerCase?.()?.includes?.("tls connection") || e?.message?.toLowerCase?.()?.includes?.("socket hang") || isIntlHttpCode(e?.response?.status);
190
- }
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CONSTANTS = void 0;
7
+ exports.Exception = Exception;
8
+ exports.checkEmpty = checkEmpty;
9
+ exports.cookieDict = cookieDict;
10
+ exports.cookieHeader = cookieHeader;
11
+ exports.findKeyNode = findKeyNode;
12
+ exports.isIntlError = isIntlError;
13
+ exports.isIntlHttpCode = isIntlHttpCode;
14
+ exports.limitString = limitString;
15
+ exports.lowerCaseFirst = lowerCaseFirst;
16
+ exports.pascalCase = pascalCase;
17
+ exports.promiseTimeout = promiseTimeout;
18
+ exports.randomHex = randomHex;
19
+ exports.randomString = randomString;
20
+ exports.randomUuid = randomUuid;
21
+ exports.randomWeighted = randomWeighted;
22
+ exports.safeString = safeString;
23
+ exports.sleep = sleep;
24
+ exports.sleepMs = sleepMs;
25
+ exports.splitLines = splitLines;
26
+ exports.time = time;
27
+ exports.titleString = titleString;
28
+ exports.upperCaseFirst = upperCaseFirst;
29
+ var _xss = _interopRequireDefault(require("xss"));
30
+ var _camelCase = _interopRequireDefault(require("lodash/camelCase.js"));
31
+ var _capitalize = _interopRequireDefault(require("lodash/capitalize.js"));
32
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty.js"));
33
+ var _setCookieParser = _interopRequireDefault(require("set-cookie-parser"));
34
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+ const CONSTANTS = exports.CONSTANTS = {
36
+ LOWER_CASE: "abcdefghijklmnopqrstuvwxyz",
37
+ UPPER_CASE: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
38
+ HEXADECIMAL: "0123456789abcdef",
39
+ NUMBERS: "0123456789"
40
+ };
41
+ function Exception(message, response = {}, name = null) {
42
+ response.status = response.status || 400;
43
+ return {
44
+ name: pascalCase(name),
45
+ message,
46
+ response
47
+ };
48
+ }
49
+ function time() {
50
+ return Math.floor(Date.now() / 1000);
51
+ }
52
+ async function sleepMs(milliseconds) {
53
+ return new Promise(resolve => setTimeout(resolve, milliseconds));
54
+ }
55
+ async function sleep(seconds) {
56
+ return await sleepMs(seconds * 1000);
57
+ }
58
+ function promiseTimeout(milliseconds, promise) {
59
+ return new Promise((resolve, reject) => {
60
+ const timer = setTimeout(() => {
61
+ reject(new Error('Promise timed out after ' + milliseconds + 'ms'));
62
+ }, milliseconds);
63
+ promise.then(value => {
64
+ clearTimeout(timer);
65
+ resolve(value);
66
+ }).catch(reason => {
67
+ clearTimeout(timer);
68
+ reject(reason);
69
+ });
70
+ });
71
+ }
72
+ function splitLines(text) {
73
+ return text.split(/\r?\n/).filter(item => !checkEmpty(item)).map(item => item.trim());
74
+ }
75
+ function findKeyNode(key, node, pair = null) {
76
+ if (node && node.hasOwnProperty(key) && (pair ? node[key] === pair : true)) {
77
+ return node;
78
+ } else if (typeof node === 'object') {
79
+ for (let index in node) {
80
+ const result = findKeyNode(key, node[index], pair);
81
+ if (result) {
82
+ return result;
83
+ }
84
+ }
85
+ }
86
+ return null;
87
+ }
88
+ function checkEmpty(value) {
89
+ if (typeof value === "number") {
90
+ return value === 0;
91
+ } else {
92
+ return (0, _isEmpty.default)(value);
93
+ }
94
+ }
95
+ function pascalCase(str) {
96
+ return upperCaseFirst((0, _camelCase.default)(str));
97
+ }
98
+ function upperCaseFirst(str) {
99
+ str = str || "";
100
+ return str[0].toUpperCase() + str.slice(1);
101
+ }
102
+ function lowerCaseFirst(str) {
103
+ str = str || "";
104
+ return str[0].toLowerCase() + str.slice(1);
105
+ }
106
+ function titleString(str) {
107
+ str = str || "";
108
+ return str.split(' ').map(word => (0, _capitalize.default)(word)).join(' ');
109
+ }
110
+ function limitString(str, limit = 35) {
111
+ str = str || "";
112
+ if (str.length <= limit) {
113
+ return str;
114
+ } else {
115
+ return str.substring(0, limit - 3) + "...";
116
+ }
117
+ }
118
+ function safeString(str) {
119
+ str = str || "";
120
+ return (0, _xss.default)(str, {
121
+ whiteList: {},
122
+ stripIgnoreTag: true,
123
+ stripIgnoreTagBody: ["script"]
124
+ });
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 randomString = '';
131
+ for (let i = 0; i < length; i++) {
132
+ const randomIndex = Math.floor(Math.random() * characters.length);
133
+ randomString += characters[randomIndex];
134
+ }
135
+ return randomString;
136
+ }
137
+ function randomHex(length) {
138
+ let result = '';
139
+ for (let i = 0; i < length; i++) {
140
+ const randomIndex = Math.floor(Math.random() * CONSTANTS.HEXADECIMAL.length);
141
+ result += CONSTANTS.HEXADECIMAL[randomIndex];
142
+ }
143
+ return result;
144
+ }
145
+ function randomUuid(useDashes = true) {
146
+ let d = Date.now();
147
+ const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
148
+ const r = (d + Math.random() * 16) % 16 | 0;
149
+ d = Math.floor(d / 16);
150
+ return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
151
+ });
152
+ return useDashes ? uuid : uuid.replaceAll("-", "");
153
+ }
154
+ function randomWeighted(dict, randomFunc = totalWeight => Math.random() * totalWeight) {
155
+ let elements = Object.keys(dict);
156
+ let weights = Object.values(dict);
157
+ let totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
158
+ let randomNum = randomFunc(totalWeight);
159
+ let weightSum = 0;
160
+ for (let i = 0; i < elements.length; i++) {
161
+ weightSum += weights[i];
162
+ if (randomNum <= weightSum) {
163
+ return elements[i];
164
+ }
165
+ }
166
+ }
167
+ function cookieDict(res, decodeValues = false) {
168
+ let dict = {};
169
+ const cookies = _setCookieParser.default.parse(res, {
170
+ decodeValues: decodeValues
171
+ });
172
+ for (let cookie of cookies) {
173
+ dict[cookie.name] = cookie.value;
174
+ }
175
+ return dict;
176
+ }
177
+ function cookieHeader(cookieDict) {
178
+ return Object.entries(cookieDict).map(([key, value]) => `${key}=${value}`).join(';');
179
+ }
180
+ function isIntlHttpCode(httpCode) {
181
+ return httpCode === undefined || httpCode === null || httpCode === 0 || httpCode === 402 || httpCode === 407 || httpCode === 466 || 500 <= httpCode;
182
+ }
183
+ function isIntlError(e) {
184
+ return e?.message?.toLowerCase?.()?.includes?.("timeout") || e?.message?.toLowerCase?.()?.includes?.("aborted") || e?.message?.toLowerCase?.()?.includes?.("tls connection") || e?.message?.toLowerCase?.()?.includes?.("socket hang") || isIntlHttpCode(e?.response?.status);
185
+ }
191
186
  //# sourceMappingURL=index.js.map