melperjs 7.2.0 → 8.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/mjs/node.js DELETED
@@ -1,133 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import crypto from "crypto";
4
- import { networkInterfaces } from "os";
5
- import { execSync } from "child_process";
6
- import bcrypt from "bcrypt";
7
- import { CONSTANTS, randomWeighted, splitClear } from "./index.js";
8
- export function tokenString(length, useNumbers = true, useUppercase = false) {
9
- const lowercaseChars = CONSTANTS.LOWER_CASE;
10
- const uppercaseChars = CONSTANTS.UPPER_CASE;
11
- const numbers = CONSTANTS.NUMBERS;
12
- let characters = lowercaseChars;
13
- if (useUppercase) characters += uppercaseChars;
14
- if (useNumbers) characters += numbers;
15
- let randomString = '';
16
- while (randomString.length < length) {
17
- const byte = crypto.randomBytes(1)[0];
18
- const index = byte % characters.length;
19
- if (byte < 256 - 256 % characters.length) {
20
- randomString += characters[index];
21
- }
22
- }
23
- return randomString;
24
- }
25
- export function tokenHex(length) {
26
- return crypto.randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length);
27
- }
28
- export function tokenUuid(useDashes = true) {
29
- const uuid = crypto.randomUUID().toString();
30
- return useDashes ? uuid : uuid.replaceAll("-", "");
31
- }
32
- export function tokenWeighted(dict) {
33
- return randomWeighted(dict, crypto.randomInt);
34
- }
35
- export function serverIp() {
36
- const interfaces = networkInterfaces();
37
- for (const devName in interfaces) {
38
- const interfaceValue = interfaces[devName];
39
- for (let i = 0; i < interfaceValue.length; i++) {
40
- const alias = interfaceValue[i];
41
- if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.address.startsWith("192.168.") && !alias.internal) return alias.address;
42
- }
43
- }
44
- return '127.0.0.1';
45
- }
46
- export function getVersion() {
47
- try {
48
- const date = new Date(execSync('git show -s --format=%ci HEAD').toString().trim());
49
- const formatDatePart = value => value.toString().padStart(2, '0');
50
- const year = date.getFullYear().toString().slice(-2);
51
- const month = formatDatePart(date.getMonth() + 1);
52
- const day = formatDatePart(date.getDate());
53
- const hour = formatDatePart(date.getHours());
54
- const minute = formatDatePart(date.getMinutes());
55
- return parseFloat(`${year}${month}${day}.${hour}${minute}`);
56
- } catch {
57
- return 1.0;
58
- }
59
- }
60
- export function createNumDir(mainDirectory) {
61
- fs.mkdirSync(mainDirectory, {
62
- recursive: true
63
- });
64
- for (let i = 0; i <= 9; i++) {
65
- try {
66
- fs.mkdirSync(path.join(mainDirectory, i.toString()));
67
- } catch (e) {
68
- console.error(`createNumDir:${i}`, e.message);
69
- }
70
- }
71
- }
72
- export function md5(data) {
73
- return crypto.createHash('md5').update(data).digest("hex");
74
- }
75
- export function hashBcrypt(plainText, encryptionKey = "") {
76
- return bcrypt.hashSync(plainText + encryptionKey, bcrypt.genSaltSync(10));
77
- }
78
- export function verifyBcrypt(plainText, hash, encryptionKey = "") {
79
- return bcrypt.compareSync(plainText + encryptionKey, hash);
80
- }
81
- export function formatProxy(proxy, protocol = "http") {
82
- proxy = proxy.trim();
83
- const splitByProtocol = proxy.split("://");
84
- if (1 < splitByProtocol.length) protocol = splitByProtocol[0];
85
- proxy = splitByProtocol[splitByProtocol.length - 1];
86
- if (!proxy.includes("@")) {
87
- const proxyParts = proxy.split(":");
88
- if (4 <= proxyParts.length) {
89
- proxy = `${proxyParts[proxyParts.length - 2]}:${proxyParts[proxyParts.length - 1]}@`;
90
- proxyParts.pop();
91
- proxyParts.pop();
92
- proxy += proxyParts.join(":");
93
- }
94
- }
95
- const proxyParts = proxy.split(':');
96
- const proxyEnd = parseInt(proxyParts[proxyParts.length - 1]);
97
- const proxyStart = proxyParts[proxyParts.length - 2];
98
- if (!proxyStart.includes(".")) {
99
- proxyParts.pop();
100
- proxyParts[proxyParts.length - 1] = crypto.randomInt(parseInt(proxyStart), proxyEnd + 1).toString();
101
- }
102
- return protocol + "://" + proxyParts.join(':');
103
- }
104
- export function proxyObject(...args) {
105
- let proxy = formatProxy(...args);
106
- const splitByProtocol = proxy.split('://');
107
- const splitById = splitByProtocol[splitByProtocol.length - 1].split('@');
108
- const splitByConn = splitById[splitById.length - 1].split(':');
109
- proxy = {
110
- protocol: splitByProtocol[0],
111
- host: splitByConn[0],
112
- port: parseInt(splitByConn[1])
113
- };
114
- if (1 < splitById.length) {
115
- const splitByAuth = splitById[0].split(':');
116
- proxy.auth = {
117
- username: splitByAuth[0],
118
- password: splitByAuth[1]
119
- };
120
- }
121
- return proxy;
122
- }
123
- export function proxyValue(proxies) {
124
- let proxy;
125
- proxies = proxies || "";
126
- proxies = splitClear(proxies);
127
- if (proxies.length < 1) return null;
128
- proxy = proxies[crypto.randomInt(0, proxies.length)];
129
- proxy = formatProxy(proxy);
130
- proxy = proxy.replace("{SESSION}", tokenHex(8));
131
- return proxy || null;
132
- }
133
- //# sourceMappingURL=node.js.map
package/mjs/node.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"node.js","names":["fs","path","crypto","networkInterfaces","execSync","bcrypt","CONSTANTS","randomWeighted","splitClear","tokenString","length","useNumbers","useUppercase","lowercaseChars","LOWER_CASE","uppercaseChars","UPPER_CASE","numbers","NUMBERS","characters","randomString","byte","randomBytes","index","tokenHex","Math","ceil","toString","slice","tokenUuid","useDashes","uuid","randomUUID","replaceAll","tokenWeighted","dict","randomInt","serverIp","interfaces","devName","interfaceValue","i","alias","family","address","startsWith","internal","getVersion","date","Date","trim","formatDatePart","value","padStart","year","getFullYear","month","getMonth","day","getDate","hour","getHours","minute","getMinutes","parseFloat","createNumDir","mainDirectory","mkdirSync","recursive","join","e","console","error","message","md5","data","createHash","update","digest","hashBcrypt","plainText","encryptionKey","hashSync","genSaltSync","verifyBcrypt","hash","compareSync","formatProxy","proxy","protocol","splitByProtocol","split","includes","proxyParts","pop","proxyEnd","parseInt","proxyStart","proxyObject","args","splitById","splitByConn","host","port","splitByAuth","auth","username","password","proxyValue","proxies","replace"],"sources":["../src/node.js"],"sourcesContent":["import fs from \"fs\";\r\nimport path from \"path\";\r\nimport crypto from \"crypto\";\r\nimport {networkInterfaces} from \"os\";\r\nimport {execSync} from \"child_process\";\r\n\r\nimport bcrypt from \"bcrypt\";\r\n\r\nimport {CONSTANTS, randomWeighted, splitClear} from \"./index.js\";\r\n\r\n\r\nexport function tokenString(length, useNumbers = true, useUppercase = false) {\r\n const lowercaseChars = CONSTANTS.LOWER_CASE;\r\n const uppercaseChars = CONSTANTS.UPPER_CASE;\r\n const numbers = CONSTANTS.NUMBERS;\r\n\r\n let characters = lowercaseChars;\r\n if (useUppercase) characters += uppercaseChars;\r\n if (useNumbers) characters += numbers;\r\n\r\n let randomString = '';\r\n while (randomString.length < length) {\r\n const byte = crypto.randomBytes(1)[0];\r\n const index = byte % characters.length;\r\n if (byte < (256 - (256 % characters.length))) {\r\n randomString += characters[index];\r\n }\r\n }\r\n\r\n return randomString;\r\n}\r\n\r\nexport function tokenHex(length) {\r\n return crypto\r\n .randomBytes(Math.ceil(length / 2))\r\n .toString('hex')\r\n .slice(0, length);\r\n}\r\n\r\nexport function tokenUuid(useDashes = true) {\r\n const uuid = crypto.randomUUID().toString();\r\n return useDashes ? uuid : uuid.replaceAll(\"-\", \"\")\r\n}\r\n\r\nexport function tokenWeighted(dict) {\r\n return randomWeighted(dict, crypto.randomInt);\r\n}\r\n\r\nexport function serverIp() {\r\n const interfaces = networkInterfaces();\r\n for (const devName in interfaces) {\r\n const interfaceValue = interfaces[devName];\r\n for (let i = 0; i < interfaceValue.length; i++) {\r\n const alias = interfaceValue[i];\r\n if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.address.startsWith(\"192.168.\") && !alias.internal)\r\n return alias.address;\r\n }\r\n }\r\n return '127.0.0.1';\r\n}\r\n\r\nexport function getVersion() {\r\n try {\r\n const date = new Date(execSync('git show -s --format=%ci HEAD').toString().trim());\r\n const formatDatePart = (value) => value.toString().padStart(2, '0');\r\n const year = date.getFullYear().toString().slice(-2);\r\n const month = formatDatePart(date.getMonth() + 1);\r\n const day = formatDatePart(date.getDate());\r\n const hour = formatDatePart(date.getHours());\r\n const minute = formatDatePart(date.getMinutes());\r\n return parseFloat(`${year}${month}${day}.${hour}${minute}`);\r\n } catch {\r\n return 1.0;\r\n }\r\n}\r\n\r\nexport function createNumDir(mainDirectory) {\r\n fs.mkdirSync(mainDirectory, {recursive: true});\r\n for (let i = 0; i <= 9; i++) {\r\n try {\r\n fs.mkdirSync(path.join(mainDirectory, i.toString()));\r\n } catch (e) {\r\n console.error(`createNumDir:${i}`, e.message);\r\n }\r\n }\r\n}\r\n\r\nexport function md5(data) {\r\n return crypto.createHash('md5').update(data).digest(\"hex\");\r\n}\r\n\r\nexport function hashBcrypt(plainText, encryptionKey = \"\") {\r\n return bcrypt.hashSync(plainText + encryptionKey, bcrypt.genSaltSync(10));\r\n}\r\n\r\nexport function verifyBcrypt(plainText, hash, encryptionKey = \"\") {\r\n return bcrypt.compareSync(plainText + encryptionKey, hash);\r\n}\r\n\r\nexport function formatProxy(proxy, protocol = \"http\") {\r\n proxy = proxy.trim();\r\n const splitByProtocol = proxy.split(\"://\");\r\n if (1 < splitByProtocol.length)\r\n protocol = splitByProtocol[0];\r\n proxy = splitByProtocol[splitByProtocol.length - 1];\r\n if (!proxy.includes(\"@\")) {\r\n const proxyParts = proxy.split(\":\");\r\n if (4 <= proxyParts.length) {\r\n proxy = `${proxyParts[proxyParts.length - 2]}:${proxyParts[proxyParts.length - 1]}@`;\r\n proxyParts.pop();\r\n proxyParts.pop();\r\n proxy += proxyParts.join(\":\");\r\n }\r\n }\r\n const proxyParts = proxy.split(':');\r\n const proxyEnd = parseInt(proxyParts[proxyParts.length - 1]);\r\n const proxyStart = proxyParts[proxyParts.length - 2];\r\n if (!proxyStart.includes(\".\")) {\r\n proxyParts.pop();\r\n proxyParts[proxyParts.length - 1] = crypto.randomInt(parseInt(proxyStart), proxyEnd + 1).toString();\r\n }\r\n return protocol + \"://\" + proxyParts.join(':');\r\n}\r\n\r\nexport function proxyObject(...args) {\r\n let proxy = formatProxy(...args);\r\n const splitByProtocol = proxy.split('://');\r\n const splitById = splitByProtocol[splitByProtocol.length - 1].split('@');\r\n const splitByConn = splitById[splitById.length - 1].split(':');\r\n proxy = {\r\n protocol: splitByProtocol[0],\r\n host: splitByConn[0],\r\n port: parseInt(splitByConn[1]),\r\n };\r\n if (1 < splitById.length) {\r\n const splitByAuth = splitById[0].split(':');\r\n proxy.auth = {\r\n username: splitByAuth[0],\r\n password: splitByAuth[1]\r\n };\r\n }\r\n return proxy;\r\n}\r\n\r\nexport function proxyValue(proxies) {\r\n let proxy;\r\n proxies = proxies || \"\";\r\n proxies = splitClear(proxies);\r\n if (proxies.length < 1)\r\n return null;\r\n proxy = proxies[crypto.randomInt(0, proxies.length)];\r\n proxy = formatProxy(proxy);\r\n proxy = proxy.replace(\"{SESSION}\", tokenHex(8));\r\n return proxy || null;\r\n}"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,MAAM,MAAM,QAAQ;AAC3B,SAAQC,iBAAiB,QAAO,IAAI;AACpC,SAAQC,QAAQ,QAAO,eAAe;AAEtC,OAAOC,MAAM,MAAM,QAAQ;AAE3B,SAAQC,SAAS,EAAEC,cAAc,EAAEC,UAAU,QAAO,YAAY;AAGhE,OAAO,SAASC,WAAWA,CAACC,MAAM,EAAEC,UAAU,GAAG,IAAI,EAAEC,YAAY,GAAG,KAAK,EAAE;EACzE,MAAMC,cAAc,GAAGP,SAAS,CAACQ,UAAU;EAC3C,MAAMC,cAAc,GAAGT,SAAS,CAACU,UAAU;EAC3C,MAAMC,OAAO,GAAGX,SAAS,CAACY,OAAO;EAEjC,IAAIC,UAAU,GAAGN,cAAc;EAC/B,IAAID,YAAY,EAAEO,UAAU,IAAIJ,cAAc;EAC9C,IAAIJ,UAAU,EAAEQ,UAAU,IAAIF,OAAO;EAErC,IAAIG,YAAY,GAAG,EAAE;EACrB,OAAOA,YAAY,CAACV,MA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src/index.js DELETED
@@ -1,263 +0,0 @@
1
- import xss from "xss";
2
- import setCookieParser from "set-cookie-parser";
3
- import camelCase from "lodash/camelCase.js";
4
- import capitalize from "lodash/capitalize.js";
5
- import isEmpty from "lodash/isEmpty.js";
6
-
7
-
8
- export const CONSTANTS = {
9
- LOWER_CASE: "abcdefghijklmnopqrstuvwxyz",
10
- UPPER_CASE: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
11
- HEXADECIMAL: "0123456789abcdef",
12
- NUMBERS: "0123456789",
13
- };
14
-
15
- export function Exception(message, response = {}, name = null) {
16
- class ExceptionClass extends Error {
17
- constructor(message, response, name) {
18
- super(message);
19
- response.status = response.status || 400;
20
- this.response = response;
21
- this.name = name ? pascalCase(name) : "Exception";
22
- }
23
- }
24
-
25
- return new ExceptionClass(message, response, name);
26
- }
27
-
28
- export function time() {
29
- return Math.floor(Date.now() / 1000);
30
- }
31
-
32
- export async function sleepMs(milliseconds) {
33
- return new Promise(resolve => setTimeout(resolve, milliseconds));
34
- }
35
-
36
- export async function sleep(seconds) {
37
- return await sleepMs(seconds * 1000);
38
- }
39
-
40
- export function promiseTimeout(milliseconds, promise) {
41
- return new Promise((resolve, reject) => {
42
- const timer = setTimeout(() => {
43
- reject(new Error('Promise timed out after ' + milliseconds + 'ms'));
44
- }, milliseconds);
45
-
46
- promise
47
- .then(value => {
48
- clearTimeout(timer);
49
- resolve(value);
50
- })
51
- .catch(reason => {
52
- clearTimeout(timer);
53
- reject(reason);
54
- });
55
- });
56
- }
57
-
58
- export function splitClear(rawText, separator = /\r?\n/) {
59
- return rawText.split(separator).map(item => item.trim()).filter(item => !isEmpty(item));
60
- }
61
-
62
- export function findKeyNode(key, node, pair = null) {
63
- if (node && node.hasOwnProperty(key) && (pair ? node[key] === pair : true)) {
64
- return node;
65
- } else if (typeof node === 'object') {
66
- for (let index in node) {
67
- const result = findKeyNode(key, node[index], pair);
68
- if (result) {
69
- return result;
70
- }
71
- }
72
- }
73
- return null;
74
- }
75
-
76
- export function checkEmpty(value) {
77
- if (typeof value === "number") {
78
- return value === 0;
79
- } else {
80
- return isEmpty(value);
81
- }
82
- }
83
-
84
- export function upperCaseFirst(str) {
85
- str = str || "";
86
- if (str.length < 1)
87
- return "";
88
- return str[0].toUpperCase() + str.slice(1);
89
- }
90
-
91
- export function lowerCaseFirst(str) {
92
- str = str || "";
93
- if (str.length < 1)
94
- return "";
95
- return str[0].toLowerCase() + str.slice(1);
96
- }
97
-
98
- export function pascalCase(str) {
99
- return upperCaseFirst(camelCase(str));
100
- }
101
-
102
- export function titleCase(str) {
103
- str = str || "";
104
- return str
105
- .split(' ')
106
- .map(word => capitalize(word))
107
- .join(' ');
108
- }
109
-
110
- export function objectStringify(obj) {
111
- for (let key in obj) {
112
- if (obj.hasOwnProperty(key)) {
113
- if (typeof obj[key] === 'object' && obj[key] !== null) {
114
- objectStringify(obj[key]);
115
- } else {
116
- if (obj[key]?.toString) {
117
- obj[key] = obj[key].toString();
118
- } else {
119
- obj[key] = String(obj[key]);
120
- }
121
- }
122
- }
123
- }
124
- return obj;
125
- }
126
-
127
- export function limitString(str, limit = 35, omission = "...") {
128
- str = str || "";
129
- if (str.length <= limit) {
130
- return str;
131
- } else {
132
- return str.substring(0, limit - omission.length) + omission;
133
- }
134
- }
135
-
136
- export function safeString(str) {
137
- str = str || "";
138
- return xss(str, {
139
- whiteList: {},
140
- stripIgnoreTag: true,
141
- stripIgnoreTagBody: ["script"]
142
- });
143
- }
144
-
145
- export function randomString(length, useNumbers = true, useUppercase = false) {
146
-
147
- let characters = CONSTANTS.LOWER_CASE;
148
- if (useUppercase) characters += CONSTANTS.UPPER_CASE;
149
- if (useNumbers) characters += CONSTANTS.NUMBERS;
150
-
151
- let randomString = '';
152
- for (let i = 0; i < length; i++) {
153
- const randomIndex = Math.floor(Math.random() * characters.length);
154
- randomString += characters[randomIndex];
155
- }
156
-
157
- return randomString;
158
- }
159
-
160
- export function randomHex(length) {
161
- let result = '';
162
- for (let i = 0; i < length; i++) {
163
- const randomIndex = Math.floor(Math.random() * CONSTANTS.HEXADECIMAL.length);
164
- result += CONSTANTS.HEXADECIMAL[randomIndex];
165
- }
166
-
167
- return result;
168
- }
169
-
170
- export function randomInteger(min, max, callback) {
171
- const minNotSpecified = typeof max === 'undefined' || typeof max === 'function';
172
-
173
- if (minNotSpecified) {
174
- callback = max;
175
- max = min;
176
- min = 0;
177
- }
178
-
179
- const isSync = typeof callback === 'undefined';
180
-
181
- if (typeof min !== 'number' || typeof max !== 'number') {
182
- throw new Error('min and max must be numerical values');
183
- }
184
- if (max <= min) {
185
- throw new Error('max must be greater than min');
186
- }
187
-
188
- const randomNumber = Math.floor(Math.random() * (max - min)) + min;
189
-
190
- if (isSync) {
191
- return randomNumber;
192
- } else {
193
- if (typeof callback !== 'function') {
194
- throw new Error('callback must be a function');
195
- }
196
- callback(randomNumber);
197
- }
198
- }
199
-
200
- export function randomUuid(useDashes = true) {
201
- let d = Date.now();
202
- const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
203
- const r = (d + Math.random() * 16) % 16 | 0;
204
- d = Math.floor(d / 16);
205
- return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
206
- });
207
- return useDashes ? uuid : uuid.replaceAll("-", "");
208
- }
209
-
210
- export function randomWeighted(dict, randomFunc = (totalWeight) => Math.random() * totalWeight) {
211
- let elements = Object.keys(dict);
212
- let weights = Object.values(dict);
213
-
214
- let totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
215
-
216
- let randomNum = randomFunc(totalWeight);
217
- let weightSum = 0;
218
-
219
- for (let i = 0; i < elements.length; i++) {
220
- weightSum += weights[i];
221
- if (randomNum <= weightSum) {
222
- return elements[i];
223
- }
224
- }
225
- }
226
-
227
- export function cookieDict(res, decodeValues = false) {
228
- let dict = {};
229
- const cookies = setCookieParser.parse(res, {decodeValues: decodeValues});
230
- for (let cookie of cookies) {
231
- dict[cookie.name] = cookie.value;
232
- }
233
- return dict;
234
- }
235
-
236
- export function cookieHeader(cookieDict) {
237
- return Object.entries(cookieDict)
238
- .map(([key, value]) => `${key}=${value}`)
239
- .join(';')
240
- }
241
-
242
- export function isIntlHttpCode(httpCode) {
243
- return (
244
- httpCode === undefined ||
245
- httpCode === null ||
246
- httpCode === 0 ||
247
- httpCode === 100 ||
248
- httpCode === 402 ||
249
- httpCode === 407 ||
250
- (460 <= httpCode && httpCode < 470) ||
251
- 500 <= httpCode
252
- );
253
- }
254
-
255
- export function isIntlError(e) {
256
- return (
257
- e?.message?.toLowerCase?.()?.includes?.("timeout") ||
258
- e?.message?.toLowerCase?.()?.includes?.("aborted") ||
259
- e?.message?.toLowerCase?.()?.includes?.("tls connection") ||
260
- e?.message?.toLowerCase?.()?.includes?.("socket hang") ||
261
- isIntlHttpCode(e?.response?.status)
262
- )
263
- }
package/src/node.js DELETED
@@ -1,155 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import crypto from "crypto";
4
- import {networkInterfaces} from "os";
5
- import {execSync} from "child_process";
6
-
7
- import bcrypt from "bcrypt";
8
-
9
- import {CONSTANTS, randomWeighted, splitClear} from "./index.js";
10
-
11
-
12
- export function tokenString(length, useNumbers = true, useUppercase = false) {
13
- const lowercaseChars = CONSTANTS.LOWER_CASE;
14
- const uppercaseChars = CONSTANTS.UPPER_CASE;
15
- const numbers = CONSTANTS.NUMBERS;
16
-
17
- let characters = lowercaseChars;
18
- if (useUppercase) characters += uppercaseChars;
19
- if (useNumbers) characters += numbers;
20
-
21
- let randomString = '';
22
- while (randomString.length < length) {
23
- const byte = crypto.randomBytes(1)[0];
24
- const index = byte % characters.length;
25
- if (byte < (256 - (256 % characters.length))) {
26
- randomString += characters[index];
27
- }
28
- }
29
-
30
- return randomString;
31
- }
32
-
33
- export function tokenHex(length) {
34
- return crypto
35
- .randomBytes(Math.ceil(length / 2))
36
- .toString('hex')
37
- .slice(0, length);
38
- }
39
-
40
- export function tokenUuid(useDashes = true) {
41
- const uuid = crypto.randomUUID().toString();
42
- return useDashes ? uuid : uuid.replaceAll("-", "")
43
- }
44
-
45
- export function tokenWeighted(dict) {
46
- return randomWeighted(dict, crypto.randomInt);
47
- }
48
-
49
- export function serverIp() {
50
- const interfaces = networkInterfaces();
51
- for (const devName in interfaces) {
52
- const interfaceValue = interfaces[devName];
53
- for (let i = 0; i < interfaceValue.length; i++) {
54
- const alias = interfaceValue[i];
55
- if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.address.startsWith("192.168.") && !alias.internal)
56
- return alias.address;
57
- }
58
- }
59
- return '127.0.0.1';
60
- }
61
-
62
- export function getVersion() {
63
- try {
64
- const date = new Date(execSync('git show -s --format=%ci HEAD').toString().trim());
65
- const formatDatePart = (value) => value.toString().padStart(2, '0');
66
- const year = date.getFullYear().toString().slice(-2);
67
- const month = formatDatePart(date.getMonth() + 1);
68
- const day = formatDatePart(date.getDate());
69
- const hour = formatDatePart(date.getHours());
70
- const minute = formatDatePart(date.getMinutes());
71
- return parseFloat(`${year}${month}${day}.${hour}${minute}`);
72
- } catch {
73
- return 1.0;
74
- }
75
- }
76
-
77
- export function createNumDir(mainDirectory) {
78
- fs.mkdirSync(mainDirectory, {recursive: true});
79
- for (let i = 0; i <= 9; i++) {
80
- try {
81
- fs.mkdirSync(path.join(mainDirectory, i.toString()));
82
- } catch (e) {
83
- console.error(`createNumDir:${i}`, e.message);
84
- }
85
- }
86
- }
87
-
88
- export function md5(data) {
89
- return crypto.createHash('md5').update(data).digest("hex");
90
- }
91
-
92
- export function hashBcrypt(plainText, encryptionKey = "") {
93
- return bcrypt.hashSync(plainText + encryptionKey, bcrypt.genSaltSync(10));
94
- }
95
-
96
- export function verifyBcrypt(plainText, hash, encryptionKey = "") {
97
- return bcrypt.compareSync(plainText + encryptionKey, hash);
98
- }
99
-
100
- export function formatProxy(proxy, protocol = "http") {
101
- proxy = proxy.trim();
102
- const splitByProtocol = proxy.split("://");
103
- if (1 < splitByProtocol.length)
104
- protocol = splitByProtocol[0];
105
- proxy = splitByProtocol[splitByProtocol.length - 1];
106
- if (!proxy.includes("@")) {
107
- const proxyParts = proxy.split(":");
108
- if (4 <= proxyParts.length) {
109
- proxy = `${proxyParts[proxyParts.length - 2]}:${proxyParts[proxyParts.length - 1]}@`;
110
- proxyParts.pop();
111
- proxyParts.pop();
112
- proxy += proxyParts.join(":");
113
- }
114
- }
115
- const proxyParts = proxy.split(':');
116
- const proxyEnd = parseInt(proxyParts[proxyParts.length - 1]);
117
- const proxyStart = proxyParts[proxyParts.length - 2];
118
- if (!proxyStart.includes(".")) {
119
- proxyParts.pop();
120
- proxyParts[proxyParts.length - 1] = crypto.randomInt(parseInt(proxyStart), proxyEnd + 1).toString();
121
- }
122
- return protocol + "://" + proxyParts.join(':');
123
- }
124
-
125
- export function proxyObject(...args) {
126
- let proxy = formatProxy(...args);
127
- const splitByProtocol = proxy.split('://');
128
- const splitById = splitByProtocol[splitByProtocol.length - 1].split('@');
129
- const splitByConn = splitById[splitById.length - 1].split(':');
130
- proxy = {
131
- protocol: splitByProtocol[0],
132
- host: splitByConn[0],
133
- port: parseInt(splitByConn[1]),
134
- };
135
- if (1 < splitById.length) {
136
- const splitByAuth = splitById[0].split(':');
137
- proxy.auth = {
138
- username: splitByAuth[0],
139
- password: splitByAuth[1]
140
- };
141
- }
142
- return proxy;
143
- }
144
-
145
- export function proxyValue(proxies) {
146
- let proxy;
147
- proxies = proxies || "";
148
- proxies = splitClear(proxies);
149
- if (proxies.length < 1)
150
- return null;
151
- proxy = proxies[crypto.randomInt(0, proxies.length)];
152
- proxy = formatProxy(proxy);
153
- proxy = proxy.replace("{SESSION}", tokenHex(8));
154
- return proxy || null;
155
- }
package/test/script.js DELETED
@@ -1,82 +0,0 @@
1
- import axios from "axios"
2
- import * as helper from "../src/index.js";
3
- import * as nodeHelper from "../src/node.js";
4
-
5
-
6
- (async () => {
7
- console.log(helper.CONSTANTS);
8
- console.log(helper.Exception("something went wrong", {status: 400}, "bad request error"));
9
- console.log(helper.time());
10
- await helper.sleepMs(1000);
11
- console.log(helper.time());
12
- await helper.sleep(1);
13
- console.log(helper.time());
14
- try {
15
- await helper.promiseTimeout(1000, helper.sleepMs(2000));
16
- } catch (e) {
17
- console.error(e.message);
18
- console.log("Timeout, Internal Error ?", helper.isIntlError(e));
19
- }
20
- console.log(helper.splitClear(`
21
- 2.satır
22
-
23
- 4.satır
24
- `))
25
- console.log(helper.findKeyNode("c", {
26
- a: {
27
- b: {
28
- x: 1,
29
- y: 2,
30
- c: {
31
- d: true
32
- }
33
- }
34
- }
35
- }));
36
- console.log("'' empty ?", helper.checkEmpty(''));
37
- console.log("1 empty ?", helper.checkEmpty(1));
38
- console.log("0 empty ?", helper.checkEmpty(1));
39
- console.log("[] empty ?", helper.checkEmpty([]));
40
- console.log(helper.pascalCase("pascal case"));
41
- console.log(helper.upperCaseFirst("first letter upper"));
42
- console.log(helper.lowerCaseFirst("First Letter Lower"));
43
- console.log(helper.titleCase("THIS mUsT be Title"));
44
- console.log(helper.objectStringify({
45
- a: "hello",
46
- b: 1,
47
- c: undefined,
48
- d: null,
49
- e: {
50
- ea: 2
51
- },
52
- f: [3,4,5],
53
- g: false
54
- }));
55
- console.log(helper.limitString("LONG TEXT", 7));
56
- console.log(helper.safeString("<strong>SAFE TEXT</strong>"));
57
- console.log(helper.randomString(32, true, true));
58
- console.log(helper.randomHex(8));
59
- console.log(helper.randomInteger(100, 1000));
60
- console.log(helper.randomUuid(true));
61
- console.log(helper.randomWeighted({strongProbability: 1000, lowProbability: 1}));
62
- console.log(nodeHelper.tokenString(32, true, true));
63
- console.log(nodeHelper.tokenHex(8));
64
- console.log(nodeHelper.tokenUuid(true));
65
- console.log(nodeHelper.tokenWeighted({strongProbability: 1000, lowProbability: 1}));
66
- console.log(nodeHelper.md5("data"));
67
- const password = nodeHelper.hashBcrypt("plain", "encryptionKey");
68
- console.log(password)
69
- console.log("passwordHash verified ?", nodeHelper.verifyBcrypt("plain", password, "encryptionKey"));
70
- const cookies = helper.cookieDict(await axios.get("https://google.com"));
71
- console.log(cookies);
72
- console.log(helper.cookieHeader(cookies));
73
- const proxy = nodeHelper.formatProxy("127.0.0.1:8080:id:pw-{SESSION}");
74
- console.log(proxy);
75
- console.log(nodeHelper.proxyObject(proxy));
76
- console.log(nodeHelper.proxyValue(proxy));
77
- console.log(nodeHelper.serverIp());
78
- console.log("HTTP CODE: 400 (Bad Request) ?", helper.isIntlHttpCode(401));
79
- console.log("HTTP CODE: 407 (Failed Proxy Auth) ?", helper.isIntlHttpCode(407));
80
- nodeHelper.createNumDir("test");
81
- console.log("VERSIONED BY .GIT", "v" + nodeHelper.getVersion());
82
- })();
File without changes
File without changes