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 +20 -2
- package/README.md +55 -35
- package/cjs/index.js +185 -190
- package/cjs/index.js.map +1 -1
- package/cjs/node.js +195 -0
- package/cjs/node.js.map +1 -0
- package/lib/index.js +235 -0
- package/lib/index.js.map +1 -0
- package/mjs/index.js +156 -234
- package/mjs/index.js.map +1 -1
- package/mjs/node.js +176 -0
- package/mjs/node.js.map +1 -0
- package/package.json +14 -6
- package/src/index.js +38 -7
- package/src/node.js +155 -0
- package/test/script.js +48 -38
- package/mjs/package.json +0 -3
package/.babelrc
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
"development": {
|
|
4
4
|
"presets": [
|
|
5
5
|
[
|
|
6
|
-
"babel
|
|
6
|
+
"@babel/preset-env",
|
|
7
7
|
{
|
|
8
8
|
"targets": {
|
|
9
|
-
"node": "
|
|
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
|
-
|
|
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.
|
|
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("
|
|
47
|
-
console.log("1 empty", helper.checkEmpty(1));
|
|
48
|
-
console.log("
|
|
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.
|
|
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 =
|
|
73
|
+
const password = nodeHelper.hashBcrypt("plain");
|
|
64
74
|
console.log(password)
|
|
65
|
-
console.log("passwordHash",
|
|
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(
|
|
82
|
+
console.log(nodeHelper.proxyValue(proxy));
|
|
73
83
|
console.log(nodeHelper.serverIp());
|
|
74
|
-
console.log("HTTP CODE:
|
|
75
|
-
console.log("HTTP CODE: 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
|
-
|
|
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:
|
|
100
|
+
response: { status: 400 }
|
|
86
101
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
93
|
-
1 empty false
|
|
94
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
119
|
+
sP3jTNwe1rRrW1TVAPb4HAXNFjJB2mWb
|
|
120
|
+
f70f7212
|
|
121
|
+
376
|
|
122
|
+
f07fe6b1-46d5-4f30-8138-f263f4916e65
|
|
103
123
|
strongProbability
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
124
|
+
JT4tXSI7YdIYDGbzLmHkItZ32vgi5aos
|
|
125
|
+
52c0da20
|
|
126
|
+
3e4374f4-11d9-4174-b337-dbf8d7fa2d41
|
|
107
127
|
strongProbability
|
|
108
128
|
8d777f385d3dfec8815d20f7496026dc
|
|
109
|
-
$2b$10$
|
|
110
|
-
passwordHash true
|
|
129
|
+
$2b$10$DTITmEyk1IcWfG1qaVEvyOgLReqOI97X/LufbbV/nvOU8DspBNMOS
|
|
130
|
+
passwordHash verified ? true
|
|
111
131
|
{
|
|
112
|
-
'1P_JAR': '2023-
|
|
113
|
-
AEC: '
|
|
114
|
-
NID: '511=
|
|
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-
|
|
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-
|
|
144
|
+
http://id:pw-749756be@127.0.0.1:8080
|
|
125
145
|
127.0.0.1
|
|
126
|
-
HTTP CODE:
|
|
127
|
-
HTTP CODE: 407
|
|
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 =
|
|
7
|
-
exports.Exception = Exception;
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
14
|
-
exports.
|
|
15
|
-
exports.
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
25
|
-
exports.
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
var _xss = require("xss");
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
str
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
str
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
str
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
let
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|