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/README.md CHANGED
@@ -57,11 +57,12 @@ const axios = require("axios");
57
57
  console.log(helper.pascalCase("pascal case"));
58
58
  console.log(helper.upperCaseFirst("first letter upper"));
59
59
  console.log(helper.lowerCaseFirst("First Letter Lower"));
60
- console.log(helper.titleString("THIS mUsT be Title"));
60
+ console.log(helper.titleCase("THIS mUsT be Title"));
61
61
  console.log(helper.limitString("LONG TEXT", 7));
62
62
  console.log(helper.safeString("<strong>SAFE TEXT</strong>"));
63
63
  console.log(helper.randomString(32, true, true));
64
64
  console.log(helper.randomHex(8));
65
+ console.log(helper.randomInteger(100, 1000));
65
66
  console.log(helper.randomUuid(true));
66
67
  console.log(helper.randomWeighted({strongProbability: 1000, lowProbability: 1}));
67
68
  console.log(nodeHelper.tokenString(32, true, true));
@@ -78,7 +79,7 @@ const axios = require("axios");
78
79
  const proxy = nodeHelper.formatProxy("127.0.0.1:8080:id:pw-{SESSION}");
79
80
  console.log(proxy);
80
81
  console.log(nodeHelper.proxyObject(proxy));
81
- console.log(await nodeHelper.proxify({mode: 4, proxy}));
82
+ console.log(nodeHelper.proxyValue(proxy));
82
83
  console.log(nodeHelper.serverIp());
83
84
  console.log("HTTP CODE: 400 (Bad Request) ?", helper.isIntlHttpCode(401));
84
85
  console.log("HTTP CODE: 407 (Failed Proxy Auth) ?", helper.isIntlHttpCode(407));
@@ -117,6 +118,7 @@ LONG...
117
118
  SAFE TEXT
118
119
  sP3jTNwe1rRrW1TVAPb4HAXNFjJB2mWb
119
120
  f70f7212
121
+ 376
120
122
  f07fe6b1-46d5-4f30-8138-f263f4916e65
121
123
  strongProbability
122
124
  JT4tXSI7YdIYDGbzLmHkItZ32vgi5aos
package/cjs/index.js CHANGED
@@ -1,186 +1,186 @@
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
- }
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
+ }
186
186
  //# sourceMappingURL=index.js.map