@ezs/basics 2.1.0 → 2.1.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.1.1](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@2.1.0...@ezs/basics@2.1.1) (2023-05-12)
7
+
8
+ **Note:** Version bump only for package @ezs/basics
9
+
10
+
11
+
12
+
13
+
6
14
  # [2.1.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@2.0.0...@ezs/basics@2.1.0) (2023-04-12)
7
15
 
8
16
 
package/README.md CHANGED
@@ -23,6 +23,7 @@ npm install @ezs/basics
23
23
  - [INIString](#inistring)
24
24
  - [JSONParse](#jsonparse)
25
25
  - [JSONString](#jsonstring)
26
+ - [OBJColumns](#objcolumns)
26
27
  - [OBJCount](#objcount)
27
28
  - [OBJFlatten](#objflatten)
28
29
  - [OBJNamespaces](#objnamespaces)
@@ -392,6 +393,38 @@ Output:
392
393
 
393
394
  Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
394
395
 
396
+ ### OBJColumns
397
+
398
+ Take an `Object` and flatten it to get only one level of keys.
399
+
400
+ <caption>Input:</caption>
401
+
402
+ ```json
403
+ [{
404
+ "foo": {
405
+ "hello": "world"
406
+ },
407
+ "bar": "anything else",
408
+ "baz": 1
409
+ }]
410
+ ```
411
+
412
+ <caption>Output:</caption>
413
+
414
+ ```json
415
+ [{
416
+ "foo": "{\"hello\":\"world\"}",
417
+ "bar": "anything else",
418
+ "baz": 1
419
+ }]
420
+ ```
421
+
422
+ #### Parameters
423
+
424
+ - `none` **[undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
425
+
426
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
427
+
395
428
  ### OBJCount
396
429
 
397
430
  Count how many objects are received, and yield the total.
@@ -695,6 +728,7 @@ read to be buffered and sent to the server (n times)
695
728
  - `timeout` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Timeout in milliseconds (optional, default `1000`)
696
729
  - `noerror` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Ignore all errors (optional, default `false`)
697
730
  - `retries` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The maximum amount of times to retry the connection (optional, default `5`)
731
+ - `encoder` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The statement to encode each chunk to a string (optional, default `dump`)
698
732
 
699
733
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
700
734
 
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = OBJColumns;
7
+
8
+ /**
9
+ * Take an `Object` and flatten it to get only one level of keys.
10
+ *
11
+ * <caption>Input:</caption>
12
+ *
13
+ * ```json
14
+ * [{
15
+ * "foo": {
16
+ * "hello": "world"
17
+ * },
18
+ * "bar": "anything else",
19
+ * "baz": 1
20
+ * }]
21
+ * ```
22
+ *
23
+ * <caption>Output:</caption>
24
+ *
25
+ * ```json
26
+ * [{
27
+ * "foo": "{\"hello\":\"world\"}",
28
+ * "bar": "anything else",
29
+ * "baz": 1
30
+ * }]
31
+ * ```
32
+ *
33
+ * @name OBJColumns
34
+ * @alias flatten
35
+ * @param {undefined} none
36
+ * @returns {Object}
37
+ */
38
+ function OBJColumns(data, feed) {
39
+ if (this.isLast()) {
40
+ feed.close();
41
+ return;
42
+ }
43
+
44
+ const obj = {};
45
+ Object.keys(data).sort((x, y) => x.localeCompare(y)).forEach(key => {
46
+ if (typeof data[key] === 'object') {
47
+ obj[key] = JSON.stringify(data[key]);
48
+ } else {
49
+ obj[key] = data[key];
50
+ }
51
+ });
52
+ feed.send(obj);
53
+ }
@@ -43,6 +43,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
43
43
  * @param {Number} [timeout=1000] Timeout in milliseconds
44
44
  * @param {Boolean} [noerror=false] Ignore all errors
45
45
  * @param {Number} [retries=5] The maximum amount of times to retry the connection
46
+ * @param {String} [encoder=dump] The statement to encode each chunk to a string
46
47
  * @returns {Object}
47
48
  */
48
49
  async function URLConnect(data, feed) {
@@ -50,6 +51,7 @@ async function URLConnect(data, feed) {
50
51
  const retries = Number(this.getParam('retries', 5));
51
52
  const noerror = Boolean(this.getParam('noerror', false));
52
53
  const json = this.getParam('json', true);
54
+ const encoder = this.getParam('encoder', 'dump');
53
55
  const {
54
56
  ezs
55
57
  } = this;
@@ -61,7 +63,7 @@ async function URLConnect(data, feed) {
61
63
  const output = ezs.createStream(ezs.objectMode());
62
64
  this.whenFinish = feed.flow(output);
63
65
  (0, _streamWrite.default)(this.input, data, () => feed.end());
64
- const streamIn = this.input.pipe(ezs('dump'));
66
+ const streamIn = this.input.pipe(ezs(encoder));
65
67
  let bodyIn;
66
68
 
67
69
  if (retries === 1) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ezs/basics",
3
3
  "description": "Basics statements for EZS",
4
- "version": "2.1.0",
4
+ "version": "2.1.1",
5
5
  "author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
6
6
  "bugs": "https://github.com/Inist-CNRS/ezs/issues",
7
7
  "dependencies": {
@@ -40,7 +40,7 @@
40
40
  "directories": {
41
41
  "test": "test"
42
42
  },
43
- "gitHead": "433621fe2399446ce458088063b2412e40975767",
43
+ "gitHead": "54e12b40d2cd6ccb6754f06ab5cae566c60bb3a9",
44
44
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
45
45
  "keywords": [
46
46
  "ezs"