@vbarbarosh/node-helpers 3.62.0 → 3.63.1

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.
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6
+ <link href="https://unpkg.com/@vbarbarosh/smcss@1.2.0/dist/reset.css" rel="stylesheet">
7
+ <link href="https://unpkg.com/@vbarbarosh/smcss@1.2.0/dist/sm.css" rel="stylesheet">
8
+ <title>@vbarbarsh/node-helpers</title>
9
+ </head>
10
+ <body>
11
+
12
+ <div id="app"></div>
13
+
14
+ <script src="https://unpkg.com/axios@1.7.9/dist/axios.js"></script>
15
+ <script src="https://unpkg.com/bluebird@3.7.2/js/browser/bluebird.js"></script>
16
+ <script src="browser.js"></script>
17
+
18
+ </body>
19
+ </html>
package/package.json CHANGED
@@ -2,13 +2,18 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "3.62.0",
5
+ "version": "3.63.1",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
+ "unpkg": "dist/browser.js",
8
+ "jsdelivr": "dist/browser.js",
9
+ "homepage": "https://vbarbarosh.github.io/node-helpers/",
7
10
  "files": [
11
+ "dist",
8
12
  "src"
9
13
  ],
10
14
  "scripts": {
11
- "test": "echo \"Error: no test specified\" && exit 1"
15
+ "build": "rm -rf dist; webpack",
16
+ "test": "mocha src/**/*.test.js"
12
17
  },
13
18
  "keywords": [
14
19
  "js",
@@ -29,17 +34,22 @@
29
34
  "form-data": "^4.0.1",
30
35
  "htmlparser2": "^10.0.0",
31
36
  "json-stable-stringify": "^1.2.1",
37
+ "json-stringify-safe": "^5.0.1",
32
38
  "mime-types": "^2.1.35",
33
39
  "sanitize-filename": "^1.6.3",
34
40
  "split": "^1.0.1",
35
41
  "ssh2": "^1.16.0"
36
42
  },
37
43
  "devDependencies": {
44
+ "copy-webpack-plugin": "^12.0.2",
45
+ "express": "^4.21.2",
38
46
  "mocha": "^11.0.1",
39
47
  "redis-v1": "npm:redis@1",
40
48
  "redis-v2": "npm:redis@2",
41
49
  "redis-v3": "npm:redis@3",
42
50
  "redis-v4": "npm:redis@4",
43
- "throttle": "^1.0.3"
51
+ "throttle": "^1.0.3",
52
+ "webpack": "^5.98.0",
53
+ "webpack-cli": "^6.0.1"
44
54
  }
45
55
  }
@@ -0,0 +1,13 @@
1
+ function array_unique(values)
2
+ {
3
+ const set = new Set();
4
+ return values.filter(function (item) {
5
+ if (set.has(item)) {
6
+ return false;
7
+ }
8
+ set.add(item);
9
+ return true;
10
+ });
11
+ }
12
+
13
+ module.exports = array_unique;
@@ -0,0 +1,7 @@
1
+ // https://github.com/webpack/webpack/issues/625
2
+ // https://webpack.js.org/guides/dependency-management/#require-context
3
+ const require_tmp = require.context('..', true, /\b(array|date|http_delete|http_get_blob|http_get_buffer|http_get_json|http_get_utf8|http_head|http_patch_json|http_post_json|http_post_multipart|http_put_buffer|http_put_json|http_put_utf8|identity|ignore|format|plural|random_int|urlmod|waitcb)[^/]*(?<!\.test)\.js$/);
4
+ require_tmp.keys().forEach(function (key) {
5
+ const [, basename] = key.match(/([^/]+)\.js$/);
6
+ window[basename] = require_tmp(key);
7
+ });
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+
3
+ const axios = require('axios');
4
+ const cli = require('../../cli');
5
+ const express = require('express');
6
+ const fs_path_resolve = require('../../fs_path_resolve');
7
+ const fs_write = require('../../fs_write');
8
+ const json_stringify_safe = require('../../json_stringify_safe');
9
+
10
+ cli(main);
11
+
12
+ async function main()
13
+ {
14
+ const app = express();
15
+ app.get('/', (req, res) => {});
16
+ const server = app.listen(3000);
17
+
18
+ try {
19
+ await axios('http://127.0.0.1:3000', {timeout: 1});
20
+ }
21
+ catch (error) {
22
+ await fs_write(fs_path_resolve(__dirname, '../1.json'), json_stringify_safe(error, null, 4).replaceAll(fs_path_resolve(__dirname, '../../../..'), '/app'));
23
+ }
24
+
25
+ server.close();
26
+ }
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+
3
+ const axios = require('axios');
4
+ const cli = require('../../cli');
5
+ const express = require('express');
6
+ const fs_path_resolve = require('../../fs_path_resolve');
7
+ const fs_write = require('../../fs_write');
8
+ const json_stringify_safe = require('../../json_stringify_safe');
9
+
10
+ cli(main);
11
+
12
+ async function main()
13
+ {
14
+ const app = express();
15
+ app.post('/fail', function (req, res) {
16
+ throw new Error('Some Error Here');
17
+ });
18
+ const server = app.listen(3000);
19
+
20
+ try {
21
+ await axios.post('http://127.0.0.1:3000/fail');
22
+ }
23
+ catch (error) {
24
+ console.log(error);
25
+ await fs_write(fs_path_resolve(__dirname, '../2.json'), json_stringify_safe(error, null, 4).replaceAll(fs_path_resolve(__dirname, '../../../..'), '/app'));
26
+ }
27
+
28
+ server.close();
29
+ }
@@ -0,0 +1,65 @@
1
+ const json_stringify_safe = require('./json_stringify_safe');
2
+
3
+ function format_error_report(error)
4
+ {
5
+ if (!error) {
6
+ return json_stringify_safe({error: error === undefined ? '---undefined---' : error});
7
+ }
8
+
9
+ if (error.response?.status && error.response?.statusText && error.response?.config) {
10
+ return fm_axios_response(error);
11
+ }
12
+
13
+ if (error.config) {
14
+ return fm_axios_config(error);
15
+ }
16
+
17
+ return json_stringify_safe({
18
+ code: error.code,
19
+ name: error.name,
20
+ message: error.message ?? 'n/a',
21
+ stack: error.stack && error.stack.split(/\n\s*/)
22
+ }, null, 4);
23
+ }
24
+
25
+ function fm_axios_response(error)
26
+ {
27
+ return `
28
+ ${error.message ?? 'n/a'}
29
+
30
+ --- REQUEST ---
31
+
32
+ ${(error.response.config.method||'').toUpperCase()} ${error.response.config.url}
33
+
34
+ ${JSON.stringify(error.response.config.headers||{}, null, 4).slice(1, -1).replace(/^\s+|,$/mg, '').trim()}
35
+
36
+ --- RESPONSE ---
37
+
38
+ ${error.response.status} ${error.response.statusText}
39
+
40
+ ${(error.response.data.toString()||'').slice(0, 10240) || 'n/a'}
41
+
42
+ --- STACK ---
43
+
44
+ ${error.stack ? error.stack.split(/\\n\\s*/) : 'n/a'}
45
+ `.trimStart();
46
+ }
47
+
48
+ function fm_axios_config(error)
49
+ {
50
+ return `
51
+ ${error.message ?? 'n/a'}
52
+
53
+ --- REQUEST ---
54
+
55
+ ${(error.config.method||'').toUpperCase()} ${error.config.url}
56
+
57
+ ${JSON.stringify(error.config.headers||{}, null, 4).slice(1, -1).replace(/^\s+|,$/mg, '').trim()}
58
+
59
+ --- STACK ---
60
+
61
+ ${error.stack ? error.stack.split(/\\n\\s*/) : 'n/a'}
62
+ `.trimStart();
63
+ }
64
+
65
+ module.exports = format_error_report;
@@ -0,0 +1,3 @@
1
+ const json_stringify_safe = require('json-stringify-safe');
2
+
3
+ module.exports = json_stringify_safe;
@@ -18,6 +18,13 @@ const items = [
18
18
  ['% de disponibilidad de tiendas', 'de_disponibilidad_de_tiendas'],
19
19
  ['%Tiendas con precio moda', 'tiendas_con_precio_moda'],
20
20
 
21
+ // https://stackoverflow.com/questions/30521224/javascript-convert-pascalcase-to-underscore-case-snake-case
22
+ ['TypeOfData.AlphaBeta', 'type_of_data_alpha_beta'],
23
+ ['thisISDifficult', 'this_is_difficult'],
24
+ ['thisISNT', 'this_isnt'],
25
+ ['thisISNT', 'this_isnt'],
26
+ ['somethingEasyLikeThis', 'something_easy_like_this'],
27
+
21
28
  // https://github.com/Advanon/sanitize-s3-objectkey
22
29
  // https://github.com/hamxabaig/s3-filename
23
30
  // ['some 漢字 ćööł % #fíłéñàmé.jpg', 'some_cool_filename_jpg'],