melperjs 3.0.0 → 5.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 CHANGED
@@ -1,14 +1,52 @@
1
1
  {
2
- "presets": [
3
- ["@babel/preset-env", {
2
+ "env": {
3
+ "development": {
4
+ "presets": [
5
+ [
6
+ "@babel/preset-env",
7
+ {
4
8
  "targets": {
5
- "node": "current"
9
+ "node": "18"
6
10
  }
7
- }]
8
- ],
9
- "plugins": [
10
- ["@babel/plugin-transform-modules-commonjs", {
11
- "allowTopLevelThis": true
12
- }]
13
- ]
14
- }
11
+ }
12
+ ]
13
+ ],
14
+ "plugins": [
15
+ ]
16
+ },
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": {
33
+ "presets": [
34
+ [
35
+ "@babel/preset-env",
36
+ {
37
+ "targets": {
38
+ "browsers": "last 2 versions, ie 10-11"
39
+ },
40
+ "modules": false
41
+ }
42
+ ]
43
+ ],
44
+ "plugins": [
45
+ ],
46
+ "ignore": [
47
+ "./src/node.js"
48
+ ]
49
+ }
50
+ },
51
+ "sourceMaps": true
52
+ }
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MELPERJS
2
2
 
3
- Node.js module to use predefined common functions and utilities
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.Exception("something went wrong", {status: 500}, "axios error"));
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,9 +50,11 @@ const axios = require("axios");
43
50
  }
44
51
  }
45
52
  }));
46
- console.log("str empty", helper.checkEmpty(""));
47
- console.log("1 empty", helper.checkEmpty(1));
48
- console.log("[] empty", helper.checkEmpty([]));
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
60
  console.log(helper.titleString("THIS mUsT be Title"));
@@ -60,9 +69,9 @@ const axios = require("axios");
60
69
  console.log(nodeHelper.tokenUuid(true));
61
70
  console.log(nodeHelper.tokenWeighted({strongProbability: 1000, lowProbability: 1}));
62
71
  console.log(nodeHelper.md5("data"));
63
- const password = helper.hashBcrypt("plain");
72
+ const password = nodeHelper.hashBcrypt("plain");
64
73
  console.log(password)
65
- console.log("passwordHash", helper.verifyBcrypt("plain", password));
74
+ console.log("passwordHash verified ?", nodeHelper.verifyBcrypt("plain", password));
66
75
  const cookies = helper.cookieDict(await axios.get("https://google.com"));
67
76
  console.log(cookies);
68
77
  console.log(helper.cookieHeader(cookies));
@@ -71,49 +80,58 @@ const axios = require("axios");
71
80
  console.log(nodeHelper.proxyObject(proxy));
72
81
  console.log(await nodeHelper.proxify({mode: 4, proxy}));
73
82
  console.log(nodeHelper.serverIp());
74
- console.log("HTTP CODE: 401 FOREIGN", helper.foreignHttpError(401));
75
- console.log("HTTP CODE: 407 FOREIGN (Failed Proxy Auth)", helper.foreignHttpError(407));
83
+ console.log("HTTP CODE: 400 (Bad Request) ?", helper.isIntlHttpCode(401));
84
+ console.log("HTTP CODE: 407 (Failed Proxy Auth) ?", helper.isIntlHttpCode(407));
76
85
  nodeHelper.createNumDir("test");
77
- nodeHelper.createDir("test");
78
86
  console.log("VERSIONED BY .GIT", "v" + nodeHelper.getVersion());
79
87
  })();
80
88
 
81
89
  /*
82
90
  {
83
- name: 'AxiosError',
91
+ LOWER_CASE: 'abcdefghijklmnopqrstuvwxyz',
92
+ UPPER_CASE: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
93
+ HEXADECIMAL: '0123456789abcdef',
94
+ NUMBERS: '0123456789'
95
+ }
96
+ {
97
+ name: 'BadRequestError',
84
98
  message: 'something went wrong',
85
- response: { status: 500 }
99
+ response: { status: 400 }
86
100
  }
87
- 1700529489
88
- 1700529490
89
- 1700529491
101
+ 1701697141
102
+ 1701697142
103
+ 1701697143
90
104
  Promise timed out after 1000ms
105
+ Timeout, Internal Error ? true
106
+ [ '2.satır', '4.satır' ]
91
107
  { x: 1, y: 2, c: { d: true } }
92
- str empty true
93
- 1 empty false
94
- [] empty true
108
+ '' empty ? true
109
+ 1 empty ? false
110
+ 0 empty ? false
111
+ [] empty ? true
112
+ PascalCase
95
113
  First letter upper
96
114
  first Letter Lower
97
115
  This Must Be Title
98
116
  LONG...
99
117
  SAFE TEXT
100
- 15WY89Q4yAMCzPmNsU0ANGX2eiOz7Gfy
101
- 9eb93429
102
- 7e1fb299-251c-4a75-bb37-f7cc3a730121
118
+ sP3jTNwe1rRrW1TVAPb4HAXNFjJB2mWb
119
+ f70f7212
120
+ f07fe6b1-46d5-4f30-8138-f263f4916e65
103
121
  strongProbability
104
- STIhrofUYVAQ4anplyJW2T7GEwSJkuk7
105
- 6db791a1
106
- 0cbef42d-a277-4f66-8bcc-e4de337c2b56
122
+ JT4tXSI7YdIYDGbzLmHkItZ32vgi5aos
123
+ 52c0da20
124
+ 3e4374f4-11d9-4174-b337-dbf8d7fa2d41
107
125
  strongProbability
108
126
  8d777f385d3dfec8815d20f7496026dc
109
- $2b$10$IsuTscKKHbcf6sBp7BrCOOcg6A8v32G9UxzdYN3Y6xyMaUynweYX2
110
- passwordHash true
127
+ $2b$10$DTITmEyk1IcWfG1qaVEvyOgLReqOI97X/LufbbV/nvOU8DspBNMOS
128
+ passwordHash verified ? true
111
129
  {
112
- '1P_JAR': '2023-11-21-01',
113
- AEC: 'Ackid1TlDwA2YJw3rzP5t3x5vBdxZt-4AzkhdwLahUVpj3vhdVHvPlw0VWM',
114
- NID: '511=tD21gyuziCvCgZSQZd5h_xDFOF6df8AhkFy0iXq9MwHG9K8J3FEkT7L0CACgjJhGDVQFoZG_Pwi2Wo8Kf7NnmvcNGVmk-lDhY768PI9sVSUmSHIYwpfsuVvG4NwNwk3iPNKmbqaC_H-YVGZhEJVn2c6YYUVxE0oEDtfuyPhGOXw'
130
+ '1P_JAR': '2023-12-04-13',
131
+ AEC: 'Ackid1Q9P_jk5EM2S_PU_QT-RUEu0syeyPMuCOLYbtlkX5gvB1zRTPytuw',
132
+ NID: '511=jBXxJSukq7Ku4449skx8tmFlqkM-nKwhaQ4hukE0F-jntKrI8daHyoAS6npvlujAMKU966ZMNGE6wu8xYc2PciilTQrKxgRyJv1QsdNIc6y_mlrLfuOfLXkwDuf0YWdS0Or3Aq6wHR87o0paAAcYAntlopexVF7NpQ6yifGe57c'
115
133
  }
116
- 1P_JAR=2023-11-21-01;AEC=Ackid1TlDwA2YJw3rzP5t3x5vBdxZt-4AzkhdwLahUVpj3vhdVHvPlw0VWM;NID=511=tD21gyuziCvCgZSQZd5h_xDFOF6df8AhkFy0iXq9MwHG9K8J3FEkT7L0CACgjJhGDVQFoZG_Pwi2Wo8Kf7NnmvcNGVmk-lDhY768PI9sVSUmSHIYwpfsuVvG4NwNwk3iPNKmbqaC_H-YVGZhEJVn2c6YYUVxE0oEDtfuyPhGOXw
134
+ 1P_JAR=2023-12-04-13;AEC=Ackid1Q9P_jk5EM2S_PU_QT-RUEu0syeyPMuCOLYbtlkX5gvB1zRTPytuw;NID=511=jBXxJSukq7Ku4449skx8tmFlqkM-nKwhaQ4hukE0F-jntKrI8daHyoAS6npvlujAMKU966ZMNGE6wu8xYc2PciilTQrKxgRyJv1QsdNIc6y_mlrLfuOfLXkwDuf0YWdS0Or3Aq6wHR87o0paAAcYAntlopexVF7NpQ6yifGe57c
117
135
  http://id:pw-{SESSION}@127.0.0.1:8080
118
136
  {
119
137
  protocol: 'http',
@@ -121,10 +139,10 @@ http://id:pw-{SESSION}@127.0.0.1:8080
121
139
  port: 8080,
122
140
  auth: { username: 'id', password: 'pw-{SESSION}' }
123
141
  }
124
- http://id:pw-527ef984@127.0.0.1:8080
142
+ http://id:pw-749756be@127.0.0.1:8080
125
143
  127.0.0.1
126
- HTTP CODE: 401 FOREIGN false
127
- HTTP CODE: 407 FOREIGN (Failed Proxy Auth) true
144
+ HTTP CODE: 400 (Bad Request) ? false
145
+ HTTP CODE: 407 (Failed Proxy Auth) ? true
128
146
  VERSIONED BY .GIT v2310.15182
129
147
  */
130
148
  ```
package/cjs/index.js ADDED
@@ -0,0 +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
+ }
186
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_xss","_interopRequireDefault","require","_camelCase","_capitalize","_isEmpty","_setCookieParser","obj","__esModule","default","CONSTANTS","exports","LOWER_CASE","UPPER_CASE","HEXADECIMAL","NUMBERS","Exception","message","response","name","status","pascalCase","time","Math","floor","Date","now","sleepMs","milliseconds","Promise","resolve","setTimeout","sleep","seconds","promiseTimeout","promise","reject","timer","Error","then","value","clearTimeout","catch","reason","splitLines","text","split","filter","item","checkEmpty","map","trim","findKeyNode","key","node","pair","hasOwnProperty","index","result","isEmpty","str","upperCaseFirst","camelCase","toUpperCase","slice","lowerCaseFirst","toLowerCase","titleString","word","capitalize","join","limitString","limit","length","substring","safeString","xss","whiteList","stripIgnoreTag","stripIgnoreTagBody","randomString","useNumbers","useUppercase","characters","i","randomIndex","random","randomHex","randomUuid","useDashes","d","uuid","replace","c","r","toString","replaceAll","randomWeighted","dict","randomFunc","totalWeight","elements","Object","keys","weights","values","reduce","sum","weight","randomNum","weightSum","cookieDict","res","decodeValues","cookies","setCookieParser","parse","cookie","cookieHeader","entries","isIntlHttpCode","httpCode","undefined","isIntlError","e","includes"],"sources":["../src/index.js"],"sourcesContent":["import xss from \"xss\";\r\nimport camelCase from \"lodash/camelCase.js\";\r\nimport capitalize from \"lodash/capitalize.js\";\r\nimport isEmpty from \"lodash/isEmpty.js\";\r\nimport setCookieParser from \"set-cookie-parser\";\r\n\r\n\r\nexport const CONSTANTS = {\r\n LOWER_CASE: \"abcdefghijklmnopqrstuvwxyz\",\r\n UPPER_CASE: \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",\r\n HEXADECIMAL: \"0123456789abcdef\",\r\n NUMBERS: \"0123456789\",\r\n};\r\n\r\nexport function Exception(message, response = {}, name = null) {\r\n response.status = response.status || 400;\r\n return {\r\n name: pascalCase(name),\r\n message,\r\n response,\r\n }\r\n}\r\n\r\nexport function time() {\r\n return Math.floor(Date.now() / 1000);\r\n}\r\n\r\nexport async function sleepMs(milliseconds) {\r\n return new Promise(resolve => setTimeout(resolve, milliseconds));\r\n}\r\n\r\nexport async function sleep(seconds) {\r\n return await sleepMs(seconds * 1000);\r\n}\r\n\r\nexport function promiseTimeout(milliseconds, promise) {\r\n return new Promise((resolve, reject) => {\r\n const timer = setTimeout(() => {\r\n reject(new Error('Promise timed out after ' + milliseconds + 'ms'));\r\n }, milliseconds);\r\n\r\n promise\r\n .then(value => {\r\n clearTimeout(timer);\r\n resolve(value);\r\n })\r\n .catch(reason => {\r\n clearTimeout(timer);\r\n reject(reason);\r\n });\r\n });\r\n}\r\n\r\nexport function splitLines(text) {\r\n return text.split(/\\r?\\n/).filter(item => !checkEmpty(item)).map(item => item.trim());\r\n}\r\n\r\nexport function findKeyNode(key, node, pair = null) {\r\n if (node && node.hasOwnProperty(key) && (pair ? node[key] === pair : true)) {\r\n return node;\r\n } else if (typeof node === 'object') {\r\n for (let index in node) {\r\n const result = findKeyNode(key, node[index], pair);\r\n if (result) {\r\n return result;\r\n }\r\n }\r\n }\r\n return null;\r\n}\r\n\r\nexport function checkEmpty(value) {\r\n if (typeof value === \"number\") {\r\n return value === 0;\r\n } else {\r\n return isEmpty(value);\r\n }\r\n}\r\n\r\nexport function pascalCase(str) {\r\n return upperCaseFirst(camelCase(str));\r\n}\r\n\r\nexport function upperCaseFirst(str) {\r\n str = str || \"\";\r\n return str[0].toUpperCase() + str.slice(1);\r\n}\r\n\r\nexport function lowerCaseFirst(str) {\r\n str = str || \"\";\r\n return str[0].toLowerCase() + str.slice(1);\r\n}\r\n\r\nexport function titleString(str) {\r\n str = str || \"\";\r\n return str\r\n .split(' ')\r\n .map(word => capitalize(word))\r\n .join(' ');\r\n}\r\n\r\nexport function limitString(str, limit = 35) {\r\n str = str || \"\";\r\n if (str.length <= limit) {\r\n return str;\r\n } else {\r\n return str.substring(0, limit - 3) + \"...\";\r\n }\r\n}\r\n\r\nexport function safeString(str) {\r\n str = str || \"\";\r\n return xss(str, {\r\n whiteList: {},\r\n stripIgnoreTag: true,\r\n stripIgnoreTagBody: [\"script\"]\r\n });\r\n}\r\n\r\nexport function randomString(length, useNumbers = true, useUppercase = false) {\r\n\r\n let characters = CONSTANTS.LOWER_CASE;\r\n if (useUppercase) characters += CONSTANTS.UPPER_CASE;\r\n if (useNumbers) characters += CONSTANTS.NUMBERS;\r\n\r\n let randomString = '';\r\n for (let i = 0; i < length; i++) {\r\n const randomIndex = Math.floor(Math.random() * characters.length);\r\n randomString += characters[randomIndex];\r\n }\r\n\r\n return randomString;\r\n}\r\n\r\nexport function randomHex(length) {\r\n let result = '';\r\n for (let i = 0; i < length; i++) {\r\n const randomIndex = Math.floor(Math.random() * CONSTANTS.HEXADECIMAL.length);\r\n result += CONSTANTS.HEXADECIMAL[randomIndex];\r\n }\r\n\r\n return result;\r\n}\r\n\r\nexport function randomUuid(useDashes = true) {\r\n let d = Date.now();\r\n const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\r\n const r = (d + Math.random() * 16) % 16 | 0;\r\n d = Math.floor(d / 16);\r\n return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);\r\n });\r\n return useDashes ? uuid : uuid.replaceAll(\"-\", \"\");\r\n}\r\n\r\nexport function randomWeighted(dict, randomFunc = (totalWeight) => Math.random() * totalWeight) {\r\n let elements = Object.keys(dict);\r\n let weights = Object.values(dict);\r\n\r\n let totalWeight = weights.reduce((sum, weight) => sum + weight, 0);\r\n\r\n let randomNum = randomFunc(totalWeight);\r\n let weightSum = 0;\r\n\r\n for (let i = 0; i < elements.length; i++) {\r\n weightSum += weights[i];\r\n if (randomNum <= weightSum) {\r\n return elements[i];\r\n }\r\n }\r\n}\r\n\r\nexport function cookieDict(res, decodeValues = false) {\r\n let dict = {};\r\n const cookies = setCookieParser.parse(res, {decodeValues: decodeValues});\r\n for (let cookie of cookies) {\r\n dict[cookie.name] = cookie.value;\r\n }\r\n return dict;\r\n}\r\n\r\nexport function cookieHeader(cookieDict) {\r\n return Object.entries(cookieDict)\r\n .map(([key, value]) => `${key}=${value}`)\r\n .join(';')\r\n}\r\n\r\nexport function isIntlHttpCode(httpCode) {\r\n return (\r\n httpCode === undefined ||\r\n httpCode === null ||\r\n httpCode === 0 ||\r\n httpCode === 402 ||\r\n httpCode === 407 ||\r\n httpCode === 466 ||\r\n 500 <= httpCode\r\n );\r\n}\r\n\r\nexport function isIntlError(e) {\r\n return (\r\n e?.message?.toLowerCase?.()?.includes?.(\"timeout\") ||\r\n e?.message?.toLowerCase?.()?.includes?.(\"aborted\") ||\r\n e?.message?.toLowerCase?.()?.includes?.(\"tls connection\") ||\r\n e?.message?.toLowerCase?.()?.includes?.(\"socket hang\") ||\r\n isIntlHttpCode(e?.response?.status)\r\n )\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,gBAAA,GAAAL,sBAAA,CAAAC,OAAA;AAAgD,SAAAD,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGzC,MAAMG,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG;EACrBE,UAAU,EAAE,4BAA4B;EACxCC,UAAU,EAAE,4BAA4B;EACxCC,WAAW,EAAE,kBAAkB;EAC/BC,OAAO,EAAE;AACb,CAAC;AAEM,SAASC,SAASA,CAACC,OAAO,EAAEC,QAAQ,GAAG,CAAC,CAAC,EAAEC,IAAI,GAAG,IAAI,EAAE;EAC3DD,QAAQ,CAACE,MAAM,GAAGF,QAAQ,CAACE,MAAM,IAAI,GAAG;EACxC,OAAO;IACHD,IAAI,EAAEE,UAAU,CAACF,IAAI,CAAC;IACtBF,OAAO;IACPC;EACJ,CAAC;AACL;AAEO,SAASI,IAAIA,CAAA,EAAG;EACnB,OAAOC,IAAI,CAACC,KAAK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AAEiD,WAAW,GAAG,CAAC,EAAE2D,QAAQ,GAAG,SAAS,CAAC,IAClDD,CAAC,EAAE3G,OAAO,EAAEiD,WAAW,GAAG,CAAC,EAAE2D,QAAQ,GAAG,SAAS,CAAC,IAClDD,CAAC,EAAE3G,OAAO,EAAEiD,WAAW,GAAG,CAAC,EAAE2D,QAAQ,GAAG,gBAAgB,CAAC,IACzDD,CAAC,EAAE3G,OAAO,EAAEiD,WAAW,GAAG,CAAC,EAAE2D,QAAQ,GAAG,aAAa,CAAC,IACtDL,cAAc,CAACI,CAAC,EAAE1G,QAAQ,EAAEE,MAAM,CAAC;AAE3C"}
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createDir = createDir;
7
6
  exports.createNumDir = createNumDir;
8
7
  exports.formatProxy = formatProxy;
9
8
  exports.getVersion = getVersion;
9
+ exports.hashBcrypt = hashBcrypt;
10
10
  exports.md5 = md5;
11
11
  exports.proxify = proxify;
12
12
  exports.proxyObject = proxyObject;
@@ -15,19 +15,21 @@ exports.tokenHex = tokenHex;
15
15
  exports.tokenString = tokenString;
16
16
  exports.tokenUuid = tokenUuid;
17
17
  exports.tokenWeighted = tokenWeighted;
18
+ exports.verifyBcrypt = verifyBcrypt;
18
19
  var _fs = _interopRequireDefault(require("fs"));
19
20
  var _path = _interopRequireDefault(require("path"));
20
21
  var _crypto = _interopRequireDefault(require("crypto"));
21
22
  var _os = require("os");
22
23
  var _child_process = require("child_process");
24
+ var _bcrypt = _interopRequireDefault(require("bcrypt"));
23
25
  var _axios = _interopRequireDefault(require("axios"));
24
26
  var _hpagent = require("hpagent");
25
27
  var _index = require("./index.js");
26
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
29
  function tokenString(length, useNumbers = true, useUppercase = false) {
28
- const lowercaseChars = 'abcdefghijklmnopqrstuvwxyz';
29
- const uppercaseChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
30
- const numbers = '0123456789';
30
+ const lowercaseChars = _index.CONSTANTS.LOWER_CASE;
31
+ const uppercaseChars = _index.CONSTANTS.UPPER_CASE;
32
+ const numbers = _index.CONSTANTS.NUMBERS;
31
33
  let characters = lowercaseChars;
32
34
  if (useUppercase) characters += uppercaseChars;
33
35
  if (useNumbers) characters += numbers;
@@ -76,20 +78,13 @@ function getVersion() {
76
78
  return 1.0;
77
79
  }
78
80
  }
79
- function createDir(directory) {
80
- if (!_fs.default.existsSync(directory)) {
81
- _fs.default.mkdirSync(directory, {
82
- recursive: true
83
- });
84
- return true;
85
- }
86
- return false;
87
- }
88
81
  function createNumDir(mainDirectory) {
89
- createDir(mainDirectory);
82
+ _fs.default.mkdirSync(mainDirectory, {
83
+ recursive: true
84
+ });
90
85
  for (let i = 0; i <= 9; i++) {
91
86
  try {
92
- createDir(_path.default.join(mainDirectory, i.toString()));
87
+ _fs.default.mkdirSync(_path.default.join(mainDirectory, i.toString()));
93
88
  } catch (e) {
94
89
  console.error(`createNumDir:${i}`, e.message);
95
90
  }
@@ -98,6 +93,12 @@ function createNumDir(mainDirectory) {
98
93
  function md5(data) {
99
94
  return _crypto.default.createHash('md5').update(data).digest("hex");
100
95
  }
96
+ function hashBcrypt(plainText) {
97
+ return _bcrypt.default.hashSync(plainText, _bcrypt.default.genSaltSync(10));
98
+ }
99
+ function verifyBcrypt(plainText, hash) {
100
+ return _bcrypt.default.compareSync(plainText, hash);
101
+ }
101
102
  function formatProxy(proxy, protocol = "http") {
102
103
  proxy = proxy.trim();
103
104
  const splitByProtocol = proxy.split("://");
@@ -190,4 +191,5 @@ async function proxify(proxyConfig, callback = formatProxy) {
190
191
  }
191
192
  }
192
193
  return null;
193
- }
194
+ }
195
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","names":["_fs","_interopRequireDefault","require","_path","_crypto","_os","_child_process","_bcrypt","_axios","_hpagent","_index","obj","__esModule","default","tokenString","length","useNumbers","useUppercase","lowercaseChars","CONSTANTS","LOWER_CASE","uppercaseChars","UPPER_CASE","numbers","NUMBERS","characters","randomString","byte","crypto","randomBytes","index","tokenHex","Math","ceil","toString","slice","tokenUuid","useDashes","uuid","randomUUID","replaceAll","tokenWeighted","dict","randomWeighted","randomInt","serverIp","interfaces","networkInterfaces","devName","interfaceValue","i","alias","family","address","startsWith","internal","getVersion","date","Date","execSync","trim","formatDatePart","value","padStart","year","getFullYear","month","getMonth","day","getDate","hour","getHours","minute","getMinutes","parseFloat","createNumDir","mainDirectory","fs","mkdirSync","recursive","path","join","e","console","error","message","md5","data","createHash","update","digest","hashBcrypt","plainText","bcrypt","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","proxify","proxyConfig","callback","timeout","mode","axios","get","resetApi","sleep","res","httpsAgent","HttpsProxyAgent","status","replace","lines","line"],"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\nimport axios from \"axios\";\r\nimport {HttpsProxyAgent} from \"hpagent\";\r\n\r\nimport {CONSTANTS, randomWeighted, sleep} 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) {\r\n return bcrypt.hashSync(plainText, bcrypt.genSaltSync(10));\r\n}\r\n\r\nexport function verifyBcrypt(plainText, hash) {\r\n return bcrypt.compareSync(plainText, 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 async function proxify(proxyConfig, callback = formatProxy) {\r\n proxyConfig = proxyConfig || {};\r\n const timeout = 7000;\r\n if (proxyConfig.mode === 1) {\r\n return callback(proxyConfig.proxy);\r\n } else if (proxyConfig.mode === 2) {\r\n const proxy = callback(proxyConfig.proxy);\r\n try {\r\n await axios.get(proxyConfig.resetApi, {timeout});\r\n } catch {\r\n return false;\r\n }\r\n await sleep(5);\r\n for (let i = 0; i < 5; i++) {\r\n try {\r\n const res = await axios.get(\"https://api64.ipify.org\", {\r\n timeout,\r\n httpsAgent: new HttpsProxyAgent({proxy, timeout: 7000})\r\n });\r\n if (res.status === 200)\r\n return proxy;\r\n } catch {\r\n await sleep(3);\r\n }\r\n }\r\n } else if (proxyConfig.mode === 3) {\r\n try {\r\n const res = await axios.get(proxyConfig.resetApi, {timeout});\r\n if (res.status === 200)\r\n return callback(proxyConfig.proxy);\r\n } catch {\r\n return false;\r\n }\r\n } else if (proxyConfig.mode === 4) {\r\n return callback(proxyConfig.proxy).replace(\"{SESSION}\", tokenHex(8));\r\n } else if (proxyConfig.mode === 5) {\r\n try {\r\n const lines = proxyConfig.proxy.split(\"\\n\");\r\n const line = lines[crypto.randomInt(0, lines.length)];\r\n return callback(line);\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n return null;\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,GAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AAEA,IAAAK,OAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,MAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,QAAA,GAAAP,OAAA;AAEA,IAAAQ,MAAA,GAAAR,OAAA;AAA4D,SAAAD,uBAAAU,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGrD,SAASG,WAAWA,CAACC,MAAM,EAAEC,UAAU,GAAG,IAAI,EAAEC,YAAY,GAAG,KAAK,EAAE;EACzE,MAAMC,cAAc,GAAGC,gBAAS,CAACC,UAAU;EAC3C,MAAMC,cAAc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