melperjs 9.0.0 → 10.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/README.md +3 -0
- package/lib/cjs/index.js +22 -2
- package/lib/cjs/node.js +21 -5
- package/lib/esm/index.js +19 -1
- package/lib/esm/node.js +19 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,6 +90,7 @@ console.log(helper.objectStringify({
|
|
|
90
90
|
}));
|
|
91
91
|
console.log(helper.limitString("LONG TEXT", 7));
|
|
92
92
|
console.log(helper.safeString("<strong>SAFE TEXT</strong>"));
|
|
93
|
+
console.log(helper.shuffleString("ABC123"));
|
|
93
94
|
console.log(helper.randomString(32, true, true));
|
|
94
95
|
console.log(helper.randomHex(8));
|
|
95
96
|
console.log(helper.randomInteger(100, 1000));
|
|
@@ -105,6 +106,8 @@ console.log(nodeHelper.md5("data"));
|
|
|
105
106
|
const password = nodeHelper.hashBcrypt("plain", "encryptionKey");
|
|
106
107
|
console.log(password)
|
|
107
108
|
console.log("passwordHash verified ?", nodeHelper.verifyBcrypt("plain", password, "encryptionKey"));
|
|
109
|
+
console.log(await nodeHelper.executeCommand("python --version"));
|
|
110
|
+
console.log(helper.indexByTime(5));
|
|
108
111
|
const cookies = helper.cookieDict(await axios.get("https://google.com"));
|
|
109
112
|
console.log(cookies);
|
|
110
113
|
console.log(helper.cookieHeader(cookies));
|
package/lib/cjs/index.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.cookieDict = cookieDict;
|
|
|
10
10
|
exports.cookieHeader = cookieHeader;
|
|
11
11
|
exports.findKeyNode = findKeyNode;
|
|
12
12
|
exports.forever = forever;
|
|
13
|
+
exports.indexByTime = indexByTime;
|
|
13
14
|
exports.isIntlError = isIntlError;
|
|
14
15
|
exports.isIntlHttpCode = isIntlHttpCode;
|
|
15
16
|
exports.limitString = limitString;
|
|
@@ -26,6 +27,7 @@ exports.randomString = randomString;
|
|
|
26
27
|
exports.randomUuid = randomUuid;
|
|
27
28
|
exports.randomWeighted = randomWeighted;
|
|
28
29
|
exports.safeString = safeString;
|
|
30
|
+
exports.shuffleString = shuffleString;
|
|
29
31
|
exports.sleep = sleep;
|
|
30
32
|
exports.sleepMs = sleepMs;
|
|
31
33
|
exports.splitClear = splitClear;
|
|
@@ -36,7 +38,8 @@ var _setCookieParser = _interopRequireDefault(require("set-cookie-parser"));
|
|
|
36
38
|
var _camelCase = _interopRequireDefault(require("lodash/camelCase.js"));
|
|
37
39
|
var _upperFirst = _interopRequireDefault(require("lodash/upperFirst.js"));
|
|
38
40
|
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty.js"));
|
|
39
|
-
|
|
41
|
+
var _shuffle = _interopRequireDefault(require("lodash/shuffle.js"));
|
|
42
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
40
43
|
const CONSTANTS = exports.CONSTANTS = {
|
|
41
44
|
LOWER_CASE: "abcdefghijklmnopqrstuvwxyz",
|
|
42
45
|
UPPER_CASE: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
@@ -95,7 +98,7 @@ function promiseTimeout(milliseconds, promise) {
|
|
|
95
98
|
});
|
|
96
99
|
}
|
|
97
100
|
function promiseSilent(promise) {
|
|
98
|
-
promise.then(() => {}).catch(() => {});
|
|
101
|
+
return promise.then(() => {}).catch(() => {});
|
|
99
102
|
}
|
|
100
103
|
function splitClear(rawText, separator = null) {
|
|
101
104
|
separator = separator ?? /\r?\n/;
|
|
@@ -182,6 +185,11 @@ function safeString(str) {
|
|
|
182
185
|
stripIgnoreTagBody: ["script"]
|
|
183
186
|
});
|
|
184
187
|
}
|
|
188
|
+
function shuffleString(str) {
|
|
189
|
+
const collection = str.split('');
|
|
190
|
+
const shuffled = (0, _shuffle.default)(collection);
|
|
191
|
+
return shuffled.join('');
|
|
192
|
+
}
|
|
185
193
|
function randomString(length, useNumbers = true, useUppercase = false) {
|
|
186
194
|
let characters = CONSTANTS.LOWER_CASE;
|
|
187
195
|
if (useUppercase) characters += CONSTANTS.UPPER_CASE;
|
|
@@ -255,6 +263,18 @@ function randomElement(obj) {
|
|
|
255
263
|
return obj[randomElement(Object.keys(obj))];
|
|
256
264
|
}
|
|
257
265
|
}
|
|
266
|
+
function indexByTime(index) {
|
|
267
|
+
const date = new Date();
|
|
268
|
+
const hour = date.getHours();
|
|
269
|
+
const minute = date.getMinutes();
|
|
270
|
+
if (hour < 20) {
|
|
271
|
+
return (index + hour) % 10;
|
|
272
|
+
} else {
|
|
273
|
+
const totalMinutes = (hour - 20) * 60 + minute;
|
|
274
|
+
const minuteIndex = Math.floor(totalMinutes / 24);
|
|
275
|
+
return (index + minuteIndex) % 10;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
258
278
|
function cookieDict(res, decodeValues = false) {
|
|
259
279
|
let dict = {};
|
|
260
280
|
const cookies = _setCookieParser.default.parse(res, {
|
package/lib/cjs/node.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createNumDir = createNumDir;
|
|
7
|
+
exports.executeCommand = executeCommand;
|
|
7
8
|
exports.formatProxy = formatProxy;
|
|
8
9
|
exports.getVersion = getVersion;
|
|
9
10
|
exports.hashBcrypt = hashBcrypt;
|
|
@@ -28,9 +29,9 @@ var _os = require("os");
|
|
|
28
29
|
var _child_process = require("child_process");
|
|
29
30
|
var _bcryptjs = _interopRequireDefault(require("bcryptjs"));
|
|
30
31
|
var _index = require("./index.js");
|
|
31
|
-
function _interopRequireDefault(
|
|
32
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
32
33
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
33
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
|
34
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
34
35
|
function tokenString(length, useNumbers = true, useUppercase = false) {
|
|
35
36
|
const lowercaseChars = _index.CONSTANTS.LOWER_CASE;
|
|
36
37
|
const uppercaseChars = _index.CONSTANTS.UPPER_CASE;
|
|
@@ -65,6 +66,19 @@ function tokenElement(obj) {
|
|
|
65
66
|
return obj[tokenElement(Object.keys(obj))];
|
|
66
67
|
}
|
|
67
68
|
}
|
|
69
|
+
function executeCommand(command) {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
(0, _child_process.exec)(command, (error, stdout, stderr) => {
|
|
72
|
+
if (error) {
|
|
73
|
+
reject(error);
|
|
74
|
+
} else if (stderr) {
|
|
75
|
+
reject(stderr);
|
|
76
|
+
} else {
|
|
77
|
+
resolve(stdout.trim());
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
68
82
|
function serverIp() {
|
|
69
83
|
const interfaces = (0, _os.networkInterfaces)();
|
|
70
84
|
for (const devName in interfaces) {
|
|
@@ -85,9 +99,9 @@ function getVersion() {
|
|
|
85
99
|
const day = formatDatePart(date.getDate());
|
|
86
100
|
const hour = formatDatePart(date.getHours());
|
|
87
101
|
const minute = formatDatePart(date.getMinutes());
|
|
88
|
-
return
|
|
102
|
+
return `${year}${month}${day}.${hour}${minute}`;
|
|
89
103
|
} catch {
|
|
90
|
-
return 1.0;
|
|
104
|
+
return "1.0";
|
|
91
105
|
}
|
|
92
106
|
}
|
|
93
107
|
function createNumDir(mainDirectory) {
|
|
@@ -96,7 +110,9 @@ function createNumDir(mainDirectory) {
|
|
|
96
110
|
});
|
|
97
111
|
for (let i = 0; i <= 9; i++) {
|
|
98
112
|
try {
|
|
99
|
-
_fs.default.mkdirSync(_path.default.join(mainDirectory, i.toString())
|
|
113
|
+
_fs.default.mkdirSync(_path.default.join(mainDirectory, i.toString()), {
|
|
114
|
+
recursive: true
|
|
115
|
+
});
|
|
100
116
|
} catch (e) {
|
|
101
117
|
console.error(`createNumDir:${i}`, e.message);
|
|
102
118
|
}
|
package/lib/esm/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import setCookieParser from "set-cookie-parser";
|
|
|
3
3
|
import camelCase from "lodash/camelCase.js";
|
|
4
4
|
import upperFirst from "lodash/upperFirst.js";
|
|
5
5
|
import isEmpty from "lodash/isEmpty.js";
|
|
6
|
+
import shuffle from "lodash/shuffle.js";
|
|
6
7
|
export const CONSTANTS = {
|
|
7
8
|
LOWER_CASE: "abcdefghijklmnopqrstuvwxyz",
|
|
8
9
|
UPPER_CASE: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
@@ -61,7 +62,7 @@ export function promiseTimeout(milliseconds, promise) {
|
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
export function promiseSilent(promise) {
|
|
64
|
-
promise.then(() => {}).catch(() => {});
|
|
65
|
+
return promise.then(() => {}).catch(() => {});
|
|
65
66
|
}
|
|
66
67
|
export function splitClear(rawText, separator = null) {
|
|
67
68
|
separator = separator ?? /\r?\n/;
|
|
@@ -148,6 +149,11 @@ export function safeString(str) {
|
|
|
148
149
|
stripIgnoreTagBody: ["script"]
|
|
149
150
|
});
|
|
150
151
|
}
|
|
152
|
+
export function shuffleString(str) {
|
|
153
|
+
const collection = str.split('');
|
|
154
|
+
const shuffled = shuffle(collection);
|
|
155
|
+
return shuffled.join('');
|
|
156
|
+
}
|
|
151
157
|
export function randomString(length, useNumbers = true, useUppercase = false) {
|
|
152
158
|
let characters = CONSTANTS.LOWER_CASE;
|
|
153
159
|
if (useUppercase) characters += CONSTANTS.UPPER_CASE;
|
|
@@ -221,6 +227,18 @@ export function randomElement(obj) {
|
|
|
221
227
|
return obj[randomElement(Object.keys(obj))];
|
|
222
228
|
}
|
|
223
229
|
}
|
|
230
|
+
export function indexByTime(index) {
|
|
231
|
+
const date = new Date();
|
|
232
|
+
const hour = date.getHours();
|
|
233
|
+
const minute = date.getMinutes();
|
|
234
|
+
if (hour < 20) {
|
|
235
|
+
return (index + hour) % 10;
|
|
236
|
+
} else {
|
|
237
|
+
const totalMinutes = (hour - 20) * 60 + minute;
|
|
238
|
+
const minuteIndex = Math.floor(totalMinutes / 24);
|
|
239
|
+
return (index + minuteIndex) % 10;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
224
242
|
export function cookieDict(res, decodeValues = false) {
|
|
225
243
|
let dict = {};
|
|
226
244
|
const cookies = setCookieParser.parse(res, {
|
package/lib/esm/node.js
CHANGED
|
@@ -3,7 +3,7 @@ import { promises as fsp } from "fs";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import crypto from "crypto";
|
|
5
5
|
import { networkInterfaces } from "os";
|
|
6
|
-
import { execSync } from "child_process";
|
|
6
|
+
import { exec, execSync } from "child_process";
|
|
7
7
|
import bcrypt from "bcryptjs";
|
|
8
8
|
import { CONSTANTS, randomWeighted, splitClear } from "./index.js";
|
|
9
9
|
export function tokenString(length, useNumbers = true, useUppercase = false) {
|
|
@@ -40,6 +40,19 @@ export function tokenElement(obj) {
|
|
|
40
40
|
return obj[tokenElement(Object.keys(obj))];
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
export function executeCommand(command) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
exec(command, (error, stdout, stderr) => {
|
|
46
|
+
if (error) {
|
|
47
|
+
reject(error);
|
|
48
|
+
} else if (stderr) {
|
|
49
|
+
reject(stderr);
|
|
50
|
+
} else {
|
|
51
|
+
resolve(stdout.trim());
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
43
56
|
export function serverIp() {
|
|
44
57
|
const interfaces = networkInterfaces();
|
|
45
58
|
for (const devName in interfaces) {
|
|
@@ -60,9 +73,9 @@ export function getVersion() {
|
|
|
60
73
|
const day = formatDatePart(date.getDate());
|
|
61
74
|
const hour = formatDatePart(date.getHours());
|
|
62
75
|
const minute = formatDatePart(date.getMinutes());
|
|
63
|
-
return
|
|
76
|
+
return `${year}${month}${day}.${hour}${minute}`;
|
|
64
77
|
} catch {
|
|
65
|
-
return 1.0;
|
|
78
|
+
return "1.0";
|
|
66
79
|
}
|
|
67
80
|
}
|
|
68
81
|
export function createNumDir(mainDirectory) {
|
|
@@ -71,7 +84,9 @@ export function createNumDir(mainDirectory) {
|
|
|
71
84
|
});
|
|
72
85
|
for (let i = 0; i <= 9; i++) {
|
|
73
86
|
try {
|
|
74
|
-
fs.mkdirSync(path.join(mainDirectory, i.toString())
|
|
87
|
+
fs.mkdirSync(path.join(mainDirectory, i.toString()), {
|
|
88
|
+
recursive: true
|
|
89
|
+
});
|
|
75
90
|
} catch (e) {
|
|
76
91
|
console.error(`createNumDir:${i}`, e.message);
|
|
77
92
|
}
|