melperjs 2.0.1 → 4.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,34 @@
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": "current"
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
+ "browsers": "last 2 versions, ie 10-11"
24
+ },
25
+ "modules": false
26
+ }
27
+ ]
28
+ ],
29
+ "plugins": [
30
+ ]
31
+ }
32
+ },
33
+ "sourceMaps": true
34
+ }
package/README.md CHANGED
@@ -21,7 +21,7 @@ const nodeHelper = require("melperjs/node");
21
21
  const axios = require("axios");
22
22
 
23
23
  (async () => {
24
- console.log(helper.Exception("something went wrong"));
24
+ console.log(helper.Exception("something went wrong", {status: 500}, "axios error"));
25
25
  console.log(helper.time());
26
26
  await helper.sleepMs(1000);
27
27
  console.log(helper.time());
@@ -43,8 +43,12 @@ const axios = require("axios");
43
43
  }
44
44
  }
45
45
  }));
46
- console.log("1 empty", helper.isEmpty(1));
47
- console.log("[] empty", helper.isEmpty([]));
46
+ console.log("str empty", helper.checkEmpty(""));
47
+ console.log("1 empty", helper.checkEmpty(1));
48
+ console.log("[] empty", helper.checkEmpty([]));
49
+ console.log(helper.upperCaseFirst("first letter upper"));
50
+ console.log(helper.lowerCaseFirst("First Letter Lower"));
51
+ console.log(helper.titleString("THIS mUsT be Title"));
48
52
  console.log(helper.limitString("LONG TEXT", 7));
49
53
  console.log(helper.safeString("<strong>SAFE TEXT</strong>"));
50
54
  console.log(helper.randomString(32, true, true));
@@ -75,33 +79,41 @@ const axios = require("axios");
75
79
  })();
76
80
 
77
81
  /*
78
- { message: 'something went wrong', response: { status: 400 } }
79
- 1700522762
80
- 1700522763
81
- 1700522764
82
+ {
83
+ name: 'AxiosError',
84
+ message: 'something went wrong',
85
+ response: { status: 500 }
86
+ }
87
+ 1700529489
88
+ 1700529490
89
+ 1700529491
82
90
  Promise timed out after 1000ms
83
91
  { x: 1, y: 2, c: { d: true } }
92
+ str empty true
84
93
  1 empty false
85
94
  [] empty true
95
+ First letter upper
96
+ first Letter Lower
97
+ This Must Be Title
86
98
  LONG...
87
99
  SAFE TEXT
88
- i9ULmdbboTDL7NPgJRiY1i6O1x0D71wG
89
- 91d59653
90
- 50fe22be-a4e9-46cd-b73b-da5669ca43b4
100
+ 15WY89Q4yAMCzPmNsU0ANGX2eiOz7Gfy
101
+ 9eb93429
102
+ 7e1fb299-251c-4a75-bb37-f7cc3a730121
91
103
  strongProbability
92
- kpG7GBnGf8kK2JGwSNe8EaIdkrKl5OEr
93
- 4f592b6e
94
- e7947cc3-d975-446c-82ec-fc77d84a67bb
104
+ STIhrofUYVAQ4anplyJW2T7GEwSJkuk7
105
+ 6db791a1
106
+ 0cbef42d-a277-4f66-8bcc-e4de337c2b56
95
107
  strongProbability
96
108
  8d777f385d3dfec8815d20f7496026dc
97
- $2b$10$m3gbDZMz6P/NKtOBtcJPTe5Dt9TtGaFVE5M.F07QR4bLHoKuezfpm
109
+ $2b$10$IsuTscKKHbcf6sBp7BrCOOcg6A8v32G9UxzdYN3Y6xyMaUynweYX2
98
110
  passwordHash true
99
111
  {
100
- '1P_JAR': '2023-11-20-23',
101
- AEC: 'Ackid1QUUwFH8ZlfrHR1RFoG3nbxsOvmYckU_mnIw4Z6cE4ue9_mbng2mmU',
102
- NID: '511=m55MFOJ7XlxlkanJtm0q7eK5PkaePFQiaxEeMcAR_ojuPBWZ0bqw6tbDq4VGuT2CrTNgGWw_lLECx100Qlm1bRBNYEx_0wWtVNCh582q9-zhvQFSDbAI3vDtl-vMlMbpv_6JYJ7YBhGf1S6zbqv6Q84hlbLBOIg8Dt633-b5b94'
112
+ '1P_JAR': '2023-11-21-01',
113
+ AEC: 'Ackid1TlDwA2YJw3rzP5t3x5vBdxZt-4AzkhdwLahUVpj3vhdVHvPlw0VWM',
114
+ NID: '511=tD21gyuziCvCgZSQZd5h_xDFOF6df8AhkFy0iXq9MwHG9K8J3FEkT7L0CACgjJhGDVQFoZG_Pwi2Wo8Kf7NnmvcNGVmk-lDhY768PI9sVSUmSHIYwpfsuVvG4NwNwk3iPNKmbqaC_H-YVGZhEJVn2c6YYUVxE0oEDtfuyPhGOXw'
103
115
  }
104
- 1P_JAR=2023-11-20-23;AEC=Ackid1QUUwFH8ZlfrHR1RFoG3nbxsOvmYckU_mnIw4Z6cE4ue9_mbng2mmU;NID=511=m55MFOJ7XlxlkanJtm0q7eK5PkaePFQiaxEeMcAR_ojuPBWZ0bqw6tbDq4VGuT2CrTNgGWw_lLECx100Qlm1bRBNYEx_0wWtVNCh582q9-zhvQFSDbAI3vDtl-vMlMbpv_6JYJ7YBhGf1S6zbqv6Q84hlbLBOIg8Dt633-b5b94
116
+ 1P_JAR=2023-11-21-01;AEC=Ackid1TlDwA2YJw3rzP5t3x5vBdxZt-4AzkhdwLahUVpj3vhdVHvPlw0VWM;NID=511=tD21gyuziCvCgZSQZd5h_xDFOF6df8AhkFy0iXq9MwHG9K8J3FEkT7L0CACgjJhGDVQFoZG_Pwi2Wo8Kf7NnmvcNGVmk-lDhY768PI9sVSUmSHIYwpfsuVvG4NwNwk3iPNKmbqaC_H-YVGZhEJVn2c6YYUVxE0oEDtfuyPhGOXw
105
117
  http://id:pw-{SESSION}@127.0.0.1:8080
106
118
  {
107
119
  protocol: 'http',
@@ -109,7 +121,7 @@ http://id:pw-{SESSION}@127.0.0.1:8080
109
121
  port: 8080,
110
122
  auth: { username: 'id', password: 'pw-{SESSION}' }
111
123
  }
112
- http://id:pw-06cbcd75@127.0.0.1:8080
124
+ http://id:pw-527ef984@127.0.0.1:8080
113
125
  127.0.0.1
114
126
  HTTP CODE: 401 FOREIGN false
115
127
  HTTP CODE: 407 FOREIGN (Failed Proxy Auth) true
@@ -3,36 +3,52 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.CONSTANTS = undefined;
6
7
  exports.Exception = Exception;
7
- exports.cookieDict = cookieDict;
8
- exports.cookieHeader = cookieHeader;
8
+ exports.time = time;
9
+ exports.sleepMs = sleepMs;
10
+ exports.sleep = sleep;
11
+ exports.promiseTimeout = promiseTimeout;
12
+ exports.splitLines = splitLines;
9
13
  exports.findKeyNode = findKeyNode;
10
- exports.foreignHttpError = foreignHttpError;
11
- exports.hashBcrypt = hashBcrypt;
12
- exports.isEmpty = isEmpty;
14
+ exports.checkEmpty = checkEmpty;
15
+ exports.pascalCase = pascalCase;
16
+ exports.upperCaseFirst = upperCaseFirst;
17
+ exports.lowerCaseFirst = lowerCaseFirst;
18
+ exports.titleString = titleString;
13
19
  exports.limitString = limitString;
14
- exports.promiseTimeout = promiseTimeout;
15
- exports.randomHex = randomHex;
20
+ exports.safeString = safeString;
16
21
  exports.randomString = randomString;
22
+ exports.randomHex = randomHex;
17
23
  exports.randomUuid = randomUuid;
18
24
  exports.randomWeighted = randomWeighted;
19
- exports.safeString = safeString;
20
- exports.sleep = sleep;
21
- exports.sleepMs = sleepMs;
22
- exports.time = time;
23
- exports.verifyBcrypt = verifyBcrypt;
24
- var _ = _interopRequireWildcard(require("lodash"));
25
- var _xss = _interopRequireDefault(require("xss"));
26
- var _bcrypt = _interopRequireDefault(require("bcrypt"));
27
- var _setCookieParser = _interopRequireDefault(require("set-cookie-parser"));
25
+ exports.cookieDict = cookieDict;
26
+ exports.cookieHeader = cookieHeader;
27
+ exports.isIntlHttpCode = isIntlHttpCode;
28
+ exports.isIntlError = isIntlError;
29
+ var _xss = require("xss");
30
+ var _xss2 = _interopRequireDefault(_xss);
31
+ var _camelCase = require("lodash/camelCase.js");
32
+ var _camelCase2 = _interopRequireDefault(_camelCase);
33
+ var _capitalize = require("lodash/capitalize.js");
34
+ var _capitalize2 = _interopRequireDefault(_capitalize);
35
+ var _isEmpty = require("lodash/isEmpty.js");
36
+ var _isEmpty2 = _interopRequireDefault(_isEmpty);
37
+ var _setCookieParser = require("set-cookie-parser");
38
+ var _setCookieParser2 = _interopRequireDefault(_setCookieParser);
28
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
- 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); }
30
- 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 && Object.prototype.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; }
31
- function Exception(message, response = {}) {
40
+ const CONSTANTS = exports.CONSTANTS = {
41
+ LOWER_CASE: "abcdefghijklmnopqrstuvwxyz",
42
+ UPPER_CASE: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
43
+ HEXADECIMAL: "0123456789abcdef",
44
+ NUMBERS: "0123456789"
45
+ };
46
+ function Exception(message, response = {}, name = null) {
32
47
  response.status = response.status || 400;
33
48
  return {
34
- message: message,
35
- response: response
49
+ name: pascalCase(name),
50
+ message,
51
+ response
36
52
  };
37
53
  }
38
54
  function time() {
@@ -58,6 +74,9 @@ function promiseTimeout(milliseconds, promise) {
58
74
  });
59
75
  });
60
76
  }
77
+ function splitLines(text) {
78
+ return text.split(/\r?\n/).filter(item => !checkEmpty(item)).map(item => item.trim());
79
+ }
61
80
  function findKeyNode(key, node, pair = null) {
62
81
  if (node && node.hasOwnProperty(key) && (pair ? node[key] === pair : true)) {
63
82
  return node;
@@ -71,13 +90,28 @@ function findKeyNode(key, node, pair = null) {
71
90
  }
72
91
  return null;
73
92
  }
74
- function isEmpty(value) {
93
+ function checkEmpty(value) {
75
94
  if (typeof value === "number") {
76
95
  return value === 0;
77
96
  } else {
78
- return _.isEmpty(value);
97
+ return (0, _isEmpty2.default)(value);
79
98
  }
80
99
  }
100
+ function pascalCase(str) {
101
+ return upperCaseFirst((0, _camelCase2.default)(str));
102
+ }
103
+ function upperCaseFirst(str) {
104
+ str = str || "";
105
+ return str[0].toUpperCase() + str.slice(1);
106
+ }
107
+ function lowerCaseFirst(str) {
108
+ str = str || "";
109
+ return str[0].toLowerCase() + str.slice(1);
110
+ }
111
+ function titleString(str) {
112
+ str = str || "";
113
+ return str.split(' ').map(word => (0, _capitalize2.default)(word)).join(' ');
114
+ }
81
115
  function limitString(str, limit = 35) {
82
116
  str = str || "";
83
117
  if (str.length <= limit) {
@@ -86,20 +120,18 @@ function limitString(str, limit = 35) {
86
120
  return str.substring(0, limit - 3) + "...";
87
121
  }
88
122
  }
89
- function safeString(source) {
90
- return (0, _xss.default)(source, {
123
+ function safeString(str) {
124
+ str = str || "";
125
+ return (0, _xss2.default)(str, {
91
126
  whiteList: {},
92
127
  stripIgnoreTag: true,
93
128
  stripIgnoreTagBody: ["script"]
94
129
  });
95
130
  }
96
131
  function randomString(length, useNumbers = true, useUppercase = false) {
97
- const lowercaseChars = 'abcdefghijklmnopqrstuvwxyz';
98
- const uppercaseChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
99
- const numbers = '0123456789';
100
- let characters = lowercaseChars;
101
- if (useUppercase) characters += uppercaseChars;
102
- if (useNumbers) characters += numbers;
132
+ let characters = CONSTANTS.LOWER_CASE;
133
+ if (useUppercase) characters += CONSTANTS.UPPER_CASE;
134
+ if (useNumbers) characters += CONSTANTS.NUMBERS;
103
135
  let randomString = '';
104
136
  for (let i = 0; i < length; i++) {
105
137
  const randomIndex = Math.floor(Math.random() * characters.length);
@@ -109,10 +141,9 @@ function randomString(length, useNumbers = true, useUppercase = false) {
109
141
  }
110
142
  function randomHex(length) {
111
143
  let result = '';
112
- const characters = '0123456789abcdef';
113
144
  for (let i = 0; i < length; i++) {
114
- const randomIndex = Math.floor(Math.random() * characters.length);
115
- result += characters[randomIndex];
145
+ const randomIndex = Math.floor(Math.random() * CONSTANTS.HEXADECIMAL.length);
146
+ result += CONSTANTS.HEXADECIMAL[randomIndex];
116
147
  }
117
148
  return result;
118
149
  }
@@ -138,15 +169,9 @@ function randomWeighted(dict, randomFunc = totalWeight => Math.random() * totalW
138
169
  }
139
170
  }
140
171
  }
141
- function hashBcrypt(plainText) {
142
- return _bcrypt.default.hashSync(plainText, _bcrypt.default.genSaltSync(10));
143
- }
144
- function verifyBcrypt(plainText, hash) {
145
- return _bcrypt.default.compareSync(plainText, hash);
146
- }
147
172
  function cookieDict(res, decodeValues = false) {
148
173
  let dict = {};
149
- const cookies = _setCookieParser.default.parse(res, {
174
+ const cookies = _setCookieParser2.default.parse(res, {
150
175
  decodeValues: decodeValues
151
176
  });
152
177
  for (let cookie of cookies) {
@@ -157,6 +182,10 @@ function cookieDict(res, decodeValues = false) {
157
182
  function cookieHeader(cookieDict) {
158
183
  return Object.entries(cookieDict).map(([key, value]) => `${key}=${value}`).join(';');
159
184
  }
160
- function foreignHttpError(httpCode) {
185
+ function isIntlHttpCode(httpCode) {
161
186
  return httpCode === undefined || httpCode === null || httpCode === 0 || httpCode === 402 || httpCode === 407 || httpCode === 466 || 500 <= httpCode;
162
- }
187
+ }
188
+ function isIntlError(e) {
189
+ 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);
190
+ }
191
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["Exception","exports","time","sleepMs","sleep","promiseTimeout","splitLines","findKeyNode","checkEmpty","pascalCase","upperCaseFirst","lowerCaseFirst","titleString","limitString","safeString","randomString","randomHex","randomUuid","randomWeighted","cookieDict","cookieHeader","isIntlHttpCode","isIntlError","_xss","require","_xss2","_interopRequireDefault","_camelCase","_camelCase2","_capitalize","_capitalize2","_isEmpty","_isEmpty2","_setCookieParser","_setCookieParser2","obj","__esModule","default","CONSTANTS","LOWER_CASE","UPPER_CASE","HEXADECIMAL","NUMBERS","message","response","name","status","Math","floor","Date","now","milliseconds","Promise","resolve","setTimeout","seconds","promise","reject","timer","Error","then","value","clearTimeout","catch","reason","text","split","filter","item","map","trim","key","node","pair","hasOwnProperty","index","result","isEmpty","str","camelCase","toUpperCase","slice","toLowerCase","word","capitalize","join","limit","length","substring","xss","whiteList","stripIgnoreTag","stripIgnoreTagBody","useNumbers","useUppercase","characters","i","randomIndex","random","useDashes","d","uuid","replace","c","r","toString","replaceAll","dict","randomFunc","totalWeight","elements","Object","keys","weights","values","reduce","sum","weight","randomNum","weightSum","res","decodeValues","cookies","setCookieParser","parse","cookie","entries","httpCode","undefined","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":";;;;;;QAcgBA,SAAS,GAATA,SAAS;AAAAC,OAAA,CASTC,IAAI,GAAJA,IAAI;AAAAD,OAAA,CAIEE,OAAO,GAAPA,OAAO;AAAAF,OAAA,CAIPG,KAAK,GAALA,KAAK;AAAAH,OAAA,CAIXI,cAAc,GAAdA,cAAc;AAAAJ,OAAA,CAkBdK,UAAU,GAAVA,UAAU;AAAAL,OAAA,CAIVM,WAAW,GAAXA,WAAW;AAAAN,OAAA,CAcXO,UAAU,GAAVA,UAAU;AAAAP,OAAA,CAQVQ,UAAU,GAAVA,UAAU;AAAAR,OAAA,CAIVS,cAAc,GAAdA,cAAc;AAAAT,OAAA,CAKdU,cAAc,GAAdA,cAAc;AAAAV,OAAA,CAKdW,WAAW,GAAXA,WAAW;AAAAX,OAAA,CAQXY,WAAW,GAAXA,WAAW;AAAAZ,OAAA,CASXa,UAAU,GAAVA,UAAU;AAAAb,OAAA,CASVc,YAAY,GAAZA,YAAY;AAAAd,OAAA,CAeZe,SAAS,GAATA,SAAS;AAAAf,OA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G,WAAWA,CAAC2G,CAAC,EAAE;EAC3B,OACIA,CAAC,EAAEtF,OAAO,EAAEuC,WAAW,GAAG,CAAC,EAAEgD,QAAQ,GAAG,SAAS,CAAC,IAClDD,CAAC,EAAEtF,OAAO,EAAEuC,WAAW,GAAG,CAAC,EAAEgD,QAAQ,GAAG,SAAS,CAAC,IAClDD,CAAC,EAAEtF,OAAO,EAAEuC,WAAW,GAAG,CAAC,EAAEgD,QAAQ,GAAG,gBAAgB,CAAC,IACzDD,CAAC,EAAEtF,OAAO,EAAEuC,WAAW,GAAG,CAAC,EAAEgD,QAAQ,GAAG,aAAa,CAAC,IACtD7G,cAAc,CAAC4G,CAAC,EAAErF,QAAQ,EAAEE,MAAM,CAAC;AAE3C"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
package/mjs/index.js ADDED
@@ -0,0 +1,235 @@
1
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
5
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
11
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
12
+ import xss from "xss";
13
+ import camelCase from "lodash/camelCase.js";
14
+ import capitalize from "lodash/capitalize.js";
15
+ import isEmpty from "lodash/isEmpty.js";
16
+ import setCookieParser from "set-cookie-parser";
17
+ export var CONSTANTS = {
18
+ LOWER_CASE: "abcdefghijklmnopqrstuvwxyz",
19
+ UPPER_CASE: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
20
+ HEXADECIMAL: "0123456789abcdef",
21
+ NUMBERS: "0123456789"
22
+ };
23
+ export function Exception(message) {
24
+ var response = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
25
+ var name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
26
+ response.status = response.status || 400;
27
+ return {
28
+ name: pascalCase(name),
29
+ message: message,
30
+ response: response
31
+ };
32
+ }
33
+ export function time() {
34
+ return Math.floor(Date.now() / 1000);
35
+ }
36
+ export function sleepMs(_x) {
37
+ return _sleepMs.apply(this, arguments);
38
+ }
39
+ function _sleepMs() {
40
+ _sleepMs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(milliseconds) {
41
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
42
+ while (1) switch (_context.prev = _context.next) {
43
+ case 0:
44
+ return _context.abrupt("return", new Promise(function (resolve) {
45
+ return setTimeout(resolve, milliseconds);
46
+ }));
47
+ case 1:
48
+ case "end":
49
+ return _context.stop();
50
+ }
51
+ }, _callee);
52
+ }));
53
+ return _sleepMs.apply(this, arguments);
54
+ }
55
+ export function sleep(_x2) {
56
+ return _sleep.apply(this, arguments);
57
+ }
58
+ function _sleep() {
59
+ _sleep = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(seconds) {
60
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
61
+ while (1) switch (_context2.prev = _context2.next) {
62
+ case 0:
63
+ _context2.next = 2;
64
+ return sleepMs(seconds * 1000);
65
+ case 2:
66
+ return _context2.abrupt("return", _context2.sent);
67
+ case 3:
68
+ case "end":
69
+ return _context2.stop();
70
+ }
71
+ }, _callee2);
72
+ }));
73
+ return _sleep.apply(this, arguments);
74
+ }
75
+ export function promiseTimeout(milliseconds, promise) {
76
+ return new Promise(function (resolve, reject) {
77
+ var timer = setTimeout(function () {
78
+ reject(new Error('Promise timed out after ' + milliseconds + 'ms'));
79
+ }, milliseconds);
80
+ promise.then(function (value) {
81
+ clearTimeout(timer);
82
+ resolve(value);
83
+ }).catch(function (reason) {
84
+ clearTimeout(timer);
85
+ reject(reason);
86
+ });
87
+ });
88
+ }
89
+ export function splitLines(text) {
90
+ return text.split(/\r?\n/).filter(function (item) {
91
+ return !checkEmpty(item);
92
+ }).map(function (item) {
93
+ return item.trim();
94
+ });
95
+ }
96
+ export function findKeyNode(key, node) {
97
+ var pair = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
98
+ if (node && node.hasOwnProperty(key) && (pair ? node[key] === pair : true)) {
99
+ return node;
100
+ } else if (_typeof(node) === 'object') {
101
+ for (var index in node) {
102
+ var result = findKeyNode(key, node[index], pair);
103
+ if (result) {
104
+ return result;
105
+ }
106
+ }
107
+ }
108
+ return null;
109
+ }
110
+ export function checkEmpty(value) {
111
+ if (typeof value === "number") {
112
+ return value === 0;
113
+ } else {
114
+ return isEmpty(value);
115
+ }
116
+ }
117
+ export function pascalCase(str) {
118
+ return upperCaseFirst(camelCase(str));
119
+ }
120
+ export function upperCaseFirst(str) {
121
+ str = str || "";
122
+ return str[0].toUpperCase() + str.slice(1);
123
+ }
124
+ export function lowerCaseFirst(str) {
125
+ str = str || "";
126
+ return str[0].toLowerCase() + str.slice(1);
127
+ }
128
+ export function titleString(str) {
129
+ str = str || "";
130
+ return str.split(' ').map(function (word) {
131
+ return capitalize(word);
132
+ }).join(' ');
133
+ }
134
+ export function limitString(str) {
135
+ var limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 35;
136
+ str = str || "";
137
+ if (str.length <= limit) {
138
+ return str;
139
+ } else {
140
+ return str.substring(0, limit - 3) + "...";
141
+ }
142
+ }
143
+ export function safeString(str) {
144
+ str = str || "";
145
+ return xss(str, {
146
+ whiteList: {},
147
+ stripIgnoreTag: true,
148
+ stripIgnoreTagBody: ["script"]
149
+ });
150
+ }
151
+ export function randomString(length) {
152
+ var useNumbers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
153
+ var useUppercase = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
154
+ var characters = CONSTANTS.LOWER_CASE;
155
+ if (useUppercase) characters += CONSTANTS.UPPER_CASE;
156
+ if (useNumbers) characters += CONSTANTS.NUMBERS;
157
+ var randomString = '';
158
+ for (var i = 0; i < length; i++) {
159
+ var randomIndex = Math.floor(Math.random() * characters.length);
160
+ randomString += characters[randomIndex];
161
+ }
162
+ return randomString;
163
+ }
164
+ export function randomHex(length) {
165
+ var result = '';
166
+ for (var i = 0; i < length; i++) {
167
+ var randomIndex = Math.floor(Math.random() * CONSTANTS.HEXADECIMAL.length);
168
+ result += CONSTANTS.HEXADECIMAL[randomIndex];
169
+ }
170
+ return result;
171
+ }
172
+ export function randomUuid() {
173
+ var useDashes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
174
+ var d = Date.now();
175
+ var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
176
+ var r = (d + Math.random() * 16) % 16 | 0;
177
+ d = Math.floor(d / 16);
178
+ return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
179
+ });
180
+ return useDashes ? uuid : uuid.replaceAll("-", "");
181
+ }
182
+ export function randomWeighted(dict) {
183
+ var randomFunc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (totalWeight) {
184
+ return Math.random() * totalWeight;
185
+ };
186
+ var elements = Object.keys(dict);
187
+ var weights = Object.values(dict);
188
+ var totalWeight = weights.reduce(function (sum, weight) {
189
+ return sum + weight;
190
+ }, 0);
191
+ var randomNum = randomFunc(totalWeight);
192
+ var weightSum = 0;
193
+ for (var i = 0; i < elements.length; i++) {
194
+ weightSum += weights[i];
195
+ if (randomNum <= weightSum) {
196
+ return elements[i];
197
+ }
198
+ }
199
+ }
200
+ export function cookieDict(res) {
201
+ var decodeValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
202
+ var dict = {};
203
+ var cookies = setCookieParser.parse(res, {
204
+ decodeValues: decodeValues
205
+ });
206
+ var _iterator = _createForOfIteratorHelper(cookies),
207
+ _step;
208
+ try {
209
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
210
+ var cookie = _step.value;
211
+ dict[cookie.name] = cookie.value;
212
+ }
213
+ } catch (err) {
214
+ _iterator.e(err);
215
+ } finally {
216
+ _iterator.f();
217
+ }
218
+ return dict;
219
+ }
220
+ export function cookieHeader(cookieDict) {
221
+ return Object.entries(cookieDict).map(function (_ref) {
222
+ var _ref2 = _slicedToArray(_ref, 2),
223
+ key = _ref2[0],
224
+ value = _ref2[1];
225
+ return "".concat(key, "=").concat(value);
226
+ }).join(';');
227
+ }
228
+ export function isIntlHttpCode(httpCode) {
229
+ return httpCode === undefined || httpCode === null || httpCode === 0 || httpCode === 402 || httpCode === 407 || httpCode === 466 || 500 <= httpCode;
230
+ }
231
+ export function isIntlError(e) {
232
+ var _e$message, _e$message$toLowerCas, _e$message$toLowerCas2, _e$message2, _e$message2$toLowerCa, _e$message2$toLowerCa2, _e$message3, _e$message3$toLowerCa, _e$message3$toLowerCa2, _e$message4, _e$message4$toLowerCa, _e$message4$toLowerCa2, _e$response;
233
+ return (e === null || e === void 0 || (_e$message = e.message) === null || _e$message === void 0 || (_e$message$toLowerCas = _e$message.toLowerCase) === null || _e$message$toLowerCas === void 0 || (_e$message$toLowerCas = _e$message$toLowerCas.call(_e$message)) === null || _e$message$toLowerCas === void 0 || (_e$message$toLowerCas2 = _e$message$toLowerCas.includes) === null || _e$message$toLowerCas2 === void 0 ? void 0 : _e$message$toLowerCas2.call(_e$message$toLowerCas, "timeout")) || (e === null || e === void 0 || (_e$message2 = e.message) === null || _e$message2 === void 0 || (_e$message2$toLowerCa = _e$message2.toLowerCase) === null || _e$message2$toLowerCa === void 0 || (_e$message2$toLowerCa = _e$message2$toLowerCa.call(_e$message2)) === null || _e$message2$toLowerCa === void 0 || (_e$message2$toLowerCa2 = _e$message2$toLowerCa.includes) === null || _e$message2$toLowerCa2 === void 0 ? void 0 : _e$message2$toLowerCa2.call(_e$message2$toLowerCa, "aborted")) || (e === null || e === void 0 || (_e$message3 = e.message) === null || _e$message3 === void 0 || (_e$message3$toLowerCa = _e$message3.toLowerCase) === null || _e$message3$toLowerCa === void 0 || (_e$message3$toLowerCa = _e$message3$toLowerCa.call(_e$message3)) === null || _e$message3$toLowerCa === void 0 || (_e$message3$toLowerCa2 = _e$message3$toLowerCa.includes) === null || _e$message3$toLowerCa2 === void 0 ? void 0 : _e$message3$toLowerCa2.call(_e$message3$toLowerCa, "tls connection")) || (e === null || e === void 0 || (_e$message4 = e.message) === null || _e$message4 === void 0 || (_e$message4$toLowerCa = _e$message4.toLowerCase) === null || _e$message4$toLowerCa === void 0 || (_e$message4$toLowerCa = _e$message4$toLowerCa.call(_e$message4)) === null || _e$message4$toLowerCa === void 0 || (_e$message4$toLowerCa2 = _e$message4$toLowerCa.includes) === null || _e$message4$toLowerCa2 === void 0 ? void 0 : _e$message4$toLowerCa2.call(_e$message4$toLowerCa, "socket hang")) || isIntlHttpCode(e === null || e === void 0 || (_e$response = e.response) === null || _e$response === void 0 ? void 0 : _e$response.status);
234
+ }
235
+ //# sourceMappingURL=index.js.map