@ezs/basics 1.22.7 → 1.23.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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
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
+ # [1.23.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.7...@ezs/basics@1.23.0) (2023-01-20)
7
+
8
+
9
+ ### Features
10
+
11
+ * 🎸 add new parameter to FILESave ([8fae7b8](https://github.com/Inist-CNRS/ezs/commit/8fae7b8009824d8e73c98e8277e15ffacd87d572))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [1.22.7](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.6...@ezs/basics@1.22.7) (2023-01-13)
7
18
 
8
19
 
package/README.md CHANGED
@@ -262,6 +262,8 @@ Output:
262
262
 
263
263
  - `location` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Directory location (optional, default `TMPDIR`)
264
264
  - `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** File name
265
+ - `content` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Content to save instead of using input object
266
+ - `jsonl` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Save as json line (optional, default `false`)
265
267
  - `compress` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable gzip compression (optional, default `false`)
266
268
 
267
269
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
package/lib/file-save.js CHANGED
@@ -23,6 +23,9 @@ var _debug = _interopRequireDefault(require("debug"));
23
23
 
24
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
25
 
26
+ const eol = '\n';
27
+
28
+ const toJSONL = line => JSON.stringify(line).concat(eol);
26
29
  /**
27
30
  * Take data, convert it to buffer and append it to file
28
31
  *
@@ -55,12 +58,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
55
58
  * @name FILESave
56
59
  * @param {String} [location=TMPDIR] Directory location
57
60
  * @param {String} [identifier] File name
61
+ * @param {String} [content] Content to save instead of using input object
62
+ * @param {Boolean} [jsonl=false] Save as json line
58
63
  * @param {Boolean} [compress=false] Enable gzip compression
59
64
  * @returns {Object}
60
65
  */
61
- function FILESave(data, feed) {
62
- const buf = Buffer.from(String(data));
63
66
 
67
+
68
+ function FILESave(data, feed) {
64
69
  if (this.isFirst()) {
65
70
  const identifier = String(this.getParam('identifier'));
66
71
  const location = this.getParam('location', (0, _os.tmpdir)());
@@ -102,5 +107,9 @@ function FILESave(data, feed) {
102
107
  return this.whenFinish.then(stats => feed.write(stats)).catch(err => feed.stop(err)).finally(() => feed.close());
103
108
  }
104
109
 
110
+ const jsonl = Boolean(this.getParam('jsonl', false));
111
+ const bufContent = this.getParam('content', data);
112
+ const bufFunc = jsonl ? toJSONL : String;
113
+ const buf = Buffer.from(bufFunc(bufContent));
105
114
  (0, _streamWrite.default)(this.input, buf, () => feed.end());
106
115
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ezs/basics",
3
3
  "description": "Basics statements for EZS",
4
- "version": "1.22.7",
4
+ "version": "1.23.0",
5
5
  "author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
6
6
  "bugs": "https://github.com/Inist-CNRS/ezs/issues",
7
7
  "dependencies": {
@@ -37,7 +37,7 @@
37
37
  "directories": {
38
38
  "test": "test"
39
39
  },
40
- "gitHead": "73aeeddfdd1152f879116a7c064ab3028419021c",
40
+ "gitHead": "20ec5a02e63dfff4859d64e96cd5e2bb05e48504",
41
41
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
42
42
  "keywords": [
43
43
  "ezs"