@ezs/basics 1.17.1 → 1.18.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.18.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.17.1...@ezs/basics@1.18.0) (2022-06-21)
7
+
8
+
9
+ ### Features
10
+
11
+ * 🎸 add [FILESave] ([2e7dfd7](https://github.com/Inist-CNRS/ezs/commit/2e7dfd76f769418a56f7b9b6cb23d156f37b6789))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [1.17.1](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.17.0...@ezs/basics@1.17.1) (2022-04-01)
7
18
 
8
19
 
package/README.md CHANGED
@@ -18,6 +18,7 @@ npm install @ezs/basics
18
18
  - [CSVObject](#csvobject)
19
19
  - [CSVParse](#csvparse)
20
20
  - [CSVString](#csvstring)
21
+ - [FILESave](#filesave)
21
22
  - [INIString](#inistring)
22
23
  - [JSONParse](#jsonparse)
23
24
  - [JSONString](#jsonstring)
@@ -189,6 +190,43 @@ a;b;c
189
190
 
190
191
  Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
191
192
 
193
+ ### FILESave
194
+
195
+ Take data, convert it to buffer and append it to file
196
+
197
+ ##### Example
198
+
199
+ Input:
200
+
201
+ ```json
202
+ [
203
+ {"a": "a"},
204
+ {"a": "b"},
205
+ {"a": "c" }
206
+ ]
207
+ ```
208
+
209
+ Script:
210
+
211
+ ```ini
212
+ [FILESave]
213
+ location = /tmp
214
+ identifier = toto
215
+ ```
216
+
217
+ Output:
218
+
219
+ ```json
220
+ ["/tmp/truc.json"]
221
+ ```
222
+
223
+ #### Parameters
224
+
225
+ - `location` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Directory location (optional, default `TMPDIR`)
226
+ - `identifier` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** File name
227
+
228
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
229
+
192
230
  ### INIString
193
231
 
194
232
  Take `Object` and generate INI
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = FILESave;
7
+
8
+ var _fs = require("fs");
9
+
10
+ var _path = _interopRequireDefault(require("path"));
11
+
12
+ var _os = require("os");
13
+
14
+ var _pathExists = _interopRequireDefault(require("path-exists"));
15
+
16
+ var _makeDir = _interopRequireDefault(require("make-dir"));
17
+
18
+ var _streamWrite = _interopRequireDefault(require("stream-write"));
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ /**
23
+ * Take data, convert it to buffer and append it to file
24
+ *
25
+ * #### Example
26
+ *
27
+ * Input:
28
+ *
29
+ * ```json
30
+ * [
31
+ * {"a": "a"},
32
+ * {"a": "b"},
33
+ * {"a": "c" }
34
+ * ]
35
+ * ```
36
+ *
37
+ * Script:
38
+ *
39
+ * ```ini
40
+ * [FILESave]
41
+ * location = /tmp
42
+ * identifier = toto
43
+ * ```
44
+ *
45
+ * Output:
46
+ *
47
+ * ```json
48
+ * ["/tmp/truc.json"]
49
+ * ```
50
+ *
51
+ * @name FILESave
52
+ * @param {String} [location=TMPDIR] Directory location
53
+ * @param {Number} [identifier] File name
54
+ * @returns {Object}
55
+ */
56
+ async function FILESave(data, feed) {
57
+ if (!this.handle) {
58
+ const identifier = String(this.getParam('identifier'));
59
+ const location = this.getParam('location', (0, _os.tmpdir)());
60
+
61
+ if (!_pathExists.default.sync(location)) {
62
+ _makeDir.default.sync(location);
63
+ }
64
+
65
+ this.filename = _path.default.resolve(location, identifier);
66
+ this.handle = (0, _fs.createWriteStream)(this.filename);
67
+ }
68
+
69
+ if (this.isLast()) {
70
+ this.handle.close();
71
+ return (0, _fs.lstat)(this.filename, (err, stat) => {
72
+ feed.write({
73
+ filename: this.filename,
74
+ ...stat
75
+ });
76
+ return feed.close();
77
+ });
78
+ }
79
+
80
+ (0, _streamWrite.default)(this.handle, Buffer.from(String(data)), () => feed.end());
81
+ }
package/lib/index.js CHANGED
@@ -53,6 +53,8 @@ var _zipExtract = _interopRequireDefault(require("./zip-extract"));
53
53
 
54
54
  var _iniString = _interopRequireDefault(require("./ini-string"));
55
55
 
56
+ var _fileSave = _interopRequireDefault(require("./file-save"));
57
+
56
58
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
57
59
 
58
60
  const funcs = {
@@ -80,6 +82,7 @@ const funcs = {
80
82
  TXTZip: _txtZip.default,
81
83
  ZIPExtract: _zipExtract.default,
82
84
  INIString: _iniString.default,
85
+ FILESave: _fileSave.default,
83
86
  // aliases
84
87
  bufferify: _bufObject.default.BUFObject,
85
88
  concat: _txtConcat.default.TXTConcat,
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.17.1",
4
+ "version": "1.18.0",
5
5
  "author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
6
6
  "bugs": "https://github.com/Inist-CNRS/ezs/issues",
7
7
  "dependencies": {
@@ -18,9 +18,11 @@
18
18
  "lodash.mapvalues": "4.6.0",
19
19
  "lodash.set": "4.3.2",
20
20
  "lodash.zipobject": "4.1.3",
21
+ "make-dir": "3.1.0",
21
22
  "micromatch": "4.0.4",
22
23
  "node-abort-controller": "1.1.0",
23
24
  "parse-headers": "2.0.4",
25
+ "path-exists": "4.0.0",
24
26
  "stream-write": "1.0.1",
25
27
  "tmp-filepath": "2.0.0",
26
28
  "unzipper": "0.10.11",
@@ -34,7 +36,7 @@
34
36
  "directories": {
35
37
  "test": "test"
36
38
  },
37
- "gitHead": "0ccde3c9e03a451c95a20372ff41437c9ec214e7",
39
+ "gitHead": "346fbfb891990dda7dd2d445e1f32ab2276c7020",
38
40
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
39
41
  "keywords": [
40
42
  "ezs"