@vbarbarosh/node-helpers 3.56.0 → 3.57.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "3.56.0",
5
+ "version": "3.57.0",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -23,18 +23,19 @@
23
23
  "url": "https://github.com/vbarbarosh/node-helpers/issues"
24
24
  },
25
25
  "peerDependencies": {
26
- "axios": "^1.3.2",
26
+ "axios": "^1.7.9",
27
27
  "bluebird": "^3.7.2",
28
- "form-data": "^4.0.0",
29
- "htmlparser2": "^9.1.0",
30
- "json-stable-stringify": "^1.0.2",
28
+ "csv-parse": "^5.6.0",
29
+ "form-data": "^4.0.1",
30
+ "htmlparser2": "^10.0.0",
31
+ "json-stable-stringify": "^1.2.1",
31
32
  "mime-types": "^2.1.35",
32
33
  "sanitize-filename": "^1.6.3",
33
34
  "split": "^1.0.1",
34
- "ssh2": "^1.15.0"
35
+ "ssh2": "^1.16.0"
35
36
  },
36
37
  "devDependencies": {
37
- "mocha": "^10.2.0",
38
+ "mocha": "^11.0.1",
38
39
  "redis-v1": "npm:redis@1",
39
40
  "redis-v2": "npm:redis@2",
40
41
  "redis-v3": "npm:redis@3",
@@ -0,0 +1,12 @@
1
+ const os = require('os');
2
+ const homedir = os.homedir();
3
+
4
+ /**
5
+ * @link https://github.com/sindresorhus/untildify/blob/a901e25ef782d93df1eba04ed48f56c79d157c74/index.js
6
+ */
7
+ function fs_path_untildify(path)
8
+ {
9
+ return homedir ? path.replace(/^~(?=$|\/|\\)/, homedir) : path;
10
+ }
11
+
12
+ module.exports = fs_path_untildify;
@@ -0,0 +1,13 @@
1
+ const csv_parse = require('csv-parse');
2
+
3
+ /**
4
+ * Parse input stream as CSV data.
5
+ *
6
+ * @link https://csv.js.org/parse/options/
7
+ */
8
+ function stream_parse_csv({delimiter = ',', relax_column_count = false} = {})
9
+ {
10
+ return csv_parse.parse({delimiter, relax_column_count, });
11
+ }
12
+
13
+ module.exports = stream_parse_csv;
@@ -0,0 +1,8 @@
1
+ const zlib = require('zlib');
2
+
3
+ function stream_gunzip(options)
4
+ {
5
+ return zlib.createGunzip(options);
6
+ }
7
+
8
+ module.exports = stream_gunzip;
@@ -0,0 +1,46 @@
1
+ const htmlparser2 = require('htmlparser2');
2
+ const stream = require('stream');
3
+
4
+ /**
5
+ * Consume XML, produce an object with analytics about provided xml stream.
6
+ */
7
+ function stream_xml_analyze()
8
+ {
9
+ let out;
10
+ const path = [];
11
+ let path_str = '';
12
+ let analytics = {};
13
+
14
+ const options = {xmlMode: true};
15
+ const events = {
16
+ onopentag: function (name, attrs) {
17
+ path.push(name);
18
+ path_str = path.join(' > ');
19
+ analytics[path_str] ??= 0;
20
+ analytics[path_str]++;
21
+ },
22
+ onclosetag: function (name) {
23
+ path.pop();
24
+ },
25
+ ontext: function (text) {
26
+ },
27
+ onend: function () {
28
+ out.push(analytics);
29
+ },
30
+ };
31
+
32
+ const parser = new htmlparser2.Parser(events, options);
33
+ return out = new stream.Transform({
34
+ objectMode: true,
35
+ transform: function (buf, encoding, callback) {
36
+ parser.write(buf.toString());
37
+ callback();
38
+ },
39
+ flush: function (callback) {
40
+ parser.end();
41
+ callback();
42
+ },
43
+ });
44
+ }
45
+
46
+ module.exports = stream_xml_analyze;
@@ -1,3 +1,4 @@
1
+ const assert = require('assert');
1
2
  const const_stream = require('./const_stream');
2
3
  const htmlparser2 = require('htmlparser2');
3
4
  const stream = require('stream');
@@ -5,7 +6,7 @@ const stream = require('stream');
5
6
  /**
6
7
  * Consume XML, produce objects.
7
8
  */
8
- function stream_parse_xml(selector, mapper = stream_parse_xml.guess)
9
+ function stream_xml_parse(selector, mapper = stream_xml_parse.guess)
9
10
  {
10
11
  let out;
11
12
  let elem = {name: '#doc', parent: null, attrs: {}, text: [], children: [], raw: []};
@@ -27,6 +28,8 @@ function stream_parse_xml(selector, mapper = stream_parse_xml.guess)
27
28
  if (path_str === selector_str) {
28
29
  const tmp = mapper(elem);
29
30
  out.push((tmp === null ? const_stream.null : tmp));
31
+ elem.parent.raw.pop();
32
+ assert.strictEqual(elem.parent.children.pop(), elem);
30
33
  }
31
34
  elem = elem.parent;
32
35
  path.pop();
@@ -72,7 +75,7 @@ function guess(node)
72
75
  if (node.children.length > 1) {
73
76
  const tmp = node.children[0].name;
74
77
  if (node.children.every(v => v.name === tmp)) {
75
- return node.children.map(v => stream_parse_xml.guess);
78
+ return node.children.map(v => stream_xml_parse.guess(v));
76
79
  }
77
80
  }
78
81
  }
@@ -87,7 +90,7 @@ function guess(node)
87
90
  }
88
91
 
89
92
  node.children.forEach(function (child) {
90
- const tmp = stream_parse_xml.guess(child);
93
+ const tmp = stream_xml_parse.guess(child);
91
94
  if (child.name in out) {
92
95
  if (Array.isArray(out[child.name])) {
93
96
  out[child.name].push(tmp);
@@ -115,7 +118,7 @@ function ashtml(node)
115
118
  }
116
119
  }
117
120
 
118
- stream_parse_xml.guess = guess;
119
- stream_parse_xml.ashtml = ashtml;
121
+ stream_xml_parse.guess = guess;
122
+ stream_xml_parse.ashtml = ashtml;
120
123
 
121
- module.exports = stream_parse_xml;
124
+ module.exports = stream_xml_parse;