melperjs 5.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/src/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import xss from "xss";
2
+ import setCookieParser from "set-cookie-parser";
2
3
  import camelCase from "lodash/camelCase.js";
3
4
  import capitalize from "lodash/capitalize.js";
4
5
  import isEmpty from "lodash/isEmpty.js";
5
- import setCookieParser from "set-cookie-parser";
6
6
 
7
7
 
8
8
  export const CONSTANTS = {
@@ -17,8 +17,8 @@ export function Exception(message, response = {}, name = null) {
17
17
  return {
18
18
  name: pascalCase(name),
19
19
  message,
20
- response,
21
- }
20
+ response
21
+ };
22
22
  }
23
23
 
24
24
  export function time() {
@@ -91,7 +91,7 @@ export function lowerCaseFirst(str) {
91
91
  return str[0].toLowerCase() + str.slice(1);
92
92
  }
93
93
 
94
- export function titleString(str) {
94
+ export function titleCase(str) {
95
95
  str = str || "";
96
96
  return str
97
97
  .split(' ')
@@ -142,6 +142,36 @@ export function randomHex(length) {
142
142
  return result;
143
143
  }
144
144
 
145
+ export function randomInteger(min, max, callback) {
146
+ const minNotSpecified = typeof max === 'undefined' || typeof max === 'function';
147
+
148
+ if (minNotSpecified) {
149
+ callback = max;
150
+ max = min;
151
+ min = 0;
152
+ }
153
+
154
+ const isSync = typeof callback === 'undefined';
155
+
156
+ if (typeof min !== 'number' || typeof max !== 'number') {
157
+ throw new Error('min and max must be numerical values');
158
+ }
159
+ if (max <= min) {
160
+ throw new Error('max must be greater than min');
161
+ }
162
+
163
+ const randomNumber = Math.floor(Math.random() * (max - min)) + min;
164
+
165
+ if (isSync) {
166
+ return randomNumber;
167
+ } else {
168
+ if (typeof callback !== 'function') {
169
+ throw new Error('callback must be a function');
170
+ }
171
+ callback(randomNumber);
172
+ }
173
+ }
174
+
145
175
  export function randomUuid(useDashes = true) {
146
176
  let d = Date.now();
147
177
  const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
@@ -189,9 +219,10 @@ export function isIntlHttpCode(httpCode) {
189
219
  httpCode === undefined ||
190
220
  httpCode === null ||
191
221
  httpCode === 0 ||
222
+ httpCode === 100 ||
192
223
  httpCode === 402 ||
193
224
  httpCode === 407 ||
194
- httpCode === 466 ||
225
+ (460 <= httpCode && httpCode < 470) ||
195
226
  500 <= httpCode
196
227
  );
197
228
  }
package/src/node.js CHANGED
@@ -5,10 +5,8 @@ import {networkInterfaces} from "os";
5
5
  import {execSync} from "child_process";
6
6
 
7
7
  import bcrypt from "bcrypt";
8
- import axios from "axios";
9
- import {HttpsProxyAgent} from "hpagent";
10
8
 
11
- import {CONSTANTS, randomWeighted, sleep} from "./index.js";
9
+ import {CONSTANTS, randomWeighted, splitLines} from "./index.js";
12
10
 
13
11
 
14
12
  export function tokenString(length, useNumbers = true, useUppercase = false) {
@@ -144,50 +142,14 @@ export function proxyObject(...args) {
144
142
  return proxy;
145
143
  }
146
144
 
147
- export async function proxify(proxyConfig, callback = formatProxy) {
148
- proxyConfig = proxyConfig || {};
149
- const timeout = 7000;
150
- if (proxyConfig.mode === 1) {
151
- return callback(proxyConfig.proxy);
152
- } else if (proxyConfig.mode === 2) {
153
- const proxy = callback(proxyConfig.proxy);
154
- try {
155
- await axios.get(proxyConfig.resetApi, {timeout});
156
- } catch {
157
- return false;
158
- }
159
- await sleep(5);
160
- for (let i = 0; i < 5; i++) {
161
- try {
162
- const res = await axios.get("https://api64.ipify.org", {
163
- timeout,
164
- httpsAgent: new HttpsProxyAgent({proxy, timeout: 7000})
165
- });
166
- if (res.status === 200)
167
- return proxy;
168
- } catch {
169
- await sleep(3);
170
- }
171
- }
172
- } else if (proxyConfig.mode === 3) {
173
- try {
174
- const res = await axios.get(proxyConfig.resetApi, {timeout});
175
- if (res.status === 200)
176
- return callback(proxyConfig.proxy);
177
- } catch {
178
- return false;
179
- }
180
- } else if (proxyConfig.mode === 4) {
181
- return callback(proxyConfig.proxy).replace("{SESSION}", tokenHex(8));
182
- } else if (proxyConfig.mode === 5) {
183
- try {
184
- const lines = proxyConfig.proxy.split("\n");
185
- const line = lines[crypto.randomInt(0, lines.length)];
186
- return callback(line);
187
- } catch {
188
- return false;
189
- }
190
- }
191
-
192
- return null;
145
+ export function proxyValue(proxies) {
146
+ let proxy;
147
+ proxies = proxies || "";
148
+ proxies = splitLines(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;
193
155
  }
package/test/script.js CHANGED
@@ -40,11 +40,12 @@ import * as nodeHelper from "../src/node.js";
40
40
  console.log(helper.pascalCase("pascal case"));
41
41
  console.log(helper.upperCaseFirst("first letter upper"));
42
42
  console.log(helper.lowerCaseFirst("First Letter Lower"));
43
- console.log(helper.titleString("THIS mUsT be Title"));
43
+ console.log(helper.titleCase("THIS mUsT be Title"));
44
44
  console.log(helper.limitString("LONG TEXT", 7));
45
45
  console.log(helper.safeString("<strong>SAFE TEXT</strong>"));
46
46
  console.log(helper.randomString(32, true, true));
47
47
  console.log(helper.randomHex(8));
48
+ console.log(helper.randomInteger(100, 1000));
48
49
  console.log(helper.randomUuid(true));
49
50
  console.log(helper.randomWeighted({strongProbability: 1000, lowProbability: 1}));
50
51
  console.log(nodeHelper.tokenString(32, true, true));
@@ -61,7 +62,7 @@ import * as nodeHelper from "../src/node.js";
61
62
  const proxy = nodeHelper.formatProxy("127.0.0.1:8080:id:pw-{SESSION}");
62
63
  console.log(proxy);
63
64
  console.log(nodeHelper.proxyObject(proxy));
64
- console.log(await nodeHelper.proxify({mode: 4, proxy}));
65
+ console.log(nodeHelper.proxyValue(proxy));
65
66
  console.log(nodeHelper.serverIp());
66
67
  console.log("HTTP CODE: 400 (Bad Request) ?", helper.isIntlHttpCode(401));
67
68
  console.log("HTTP CODE: 407 (Failed Proxy Auth) ?", helper.isIntlHttpCode(407));