@ezs/basics 1.21.0 → 1.22.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,22 @@
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.22.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.21.0...@ezs/basics@1.22.0) (2022-09-05)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * use location to check filename ([cb9c6e2](https://github.com/Inist-CNRS/ezs/commit/cb9c6e2f42d12c287d806b4ccebf8a4f8607e755))
12
+
13
+
14
+ ### Features
15
+
16
+ * 🎸 add file load ([a06c221](https://github.com/Inist-CNRS/ezs/commit/a06c221c3463b4299383db5c613f5cabc687961c))
17
+
18
+
19
+
20
+
21
+
6
22
  # [1.21.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.20.0...@ezs/basics@1.21.0) (2022-07-11)
7
23
 
8
24
 
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
+ - [FILELoad](#fileload)
21
22
  - [FILESave](#filesave)
22
23
  - [INIString](#inistring)
23
24
  - [JSONParse](#jsonparse)
@@ -192,6 +193,41 @@ a;b;c
192
193
 
193
194
  Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
194
195
 
196
+ ### FILELoad
197
+
198
+ Take `Object` containing filename et throw content by chunk
199
+
200
+ ```json
201
+ [ fi1e1.csv, file2.csv ]
202
+ ```
203
+
204
+ Script:
205
+
206
+ ```ini
207
+ [use]
208
+ plugin = analytics
209
+ plugin = basics
210
+
211
+ [FILELoad]
212
+ location = /tmp
213
+ [CSVParse]
214
+ ```
215
+
216
+ Output:
217
+
218
+ ```json
219
+ [
220
+ (...)
221
+ ]
222
+ ```
223
+
224
+ #### Parameters
225
+
226
+ - `location` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Directory location (optional, default `TMPDIR`)
227
+ - `compress` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable gzip compression (optional, default `false`)
228
+
229
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
230
+
195
231
  ### FILESave
196
232
 
197
233
  Take data, convert it to buffer and append it to file
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = FILELoad;
7
+
8
+ var _zlib = require("zlib");
9
+
10
+ var _fs = require("fs");
11
+
12
+ var _path = require("path");
13
+
14
+ var _os = require("os");
15
+
16
+ /**
17
+ * Take `Object` containing filename et throw content by chunk
18
+ *
19
+ * ```json
20
+ * [ fi1e1.csv, file2.csv ]
21
+ * ```
22
+ *
23
+ * Script:
24
+ *
25
+ * ```ini
26
+ * [use]
27
+ * plugin = analytics
28
+ * plugin = basics
29
+ *
30
+ * [FILELoad]
31
+ * location = /tmp
32
+ * [CSVParse]
33
+ *
34
+ * ```
35
+ *
36
+ * Output:
37
+ *
38
+ * ```json
39
+ * [
40
+ * (...)
41
+ * ]
42
+ * ```
43
+ *
44
+ * @name FILELoad
45
+ * @param {String} [location=TMPDIR] Directory location
46
+ * @param {Boolean} [compress=false] Enable gzip compression
47
+ * @returns {Object}
48
+ */
49
+ function FILELoad(data, feed) {
50
+ if (this.isLast()) {
51
+ feed.close();
52
+ return;
53
+ }
54
+
55
+ const cwd = process.cwd();
56
+ const tpd = (0, _os.tmpdir)();
57
+ const location = this.getParam('location', tpd);
58
+ const compress = this.getParam('compress', false);
59
+ const locations = [cwd, tpd, location];
60
+ const file = locations.filter(Boolean).map(dir => (0, _path.resolve)(dir, String(data).trim())).filter(fil => (0, _fs.existsSync)(fil)).shift();
61
+
62
+ if (!file) {
63
+ feed.end();
64
+ return;
65
+ }
66
+
67
+ if (compress) {
68
+ feed.flow((0, _fs.createReadStream)(file).pipe((0, _zlib.createGunzip)()));
69
+ return;
70
+ }
71
+
72
+ feed.flow((0, _fs.createReadStream)(file));
73
+ }
package/lib/index.js CHANGED
@@ -59,6 +59,8 @@ var _iniString = _interopRequireDefault(require("./ini-string"));
59
59
 
60
60
  var _fileSave = _interopRequireDefault(require("./file-save"));
61
61
 
62
+ var _fileLoad = _interopRequireDefault(require("./file-load"));
63
+
62
64
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
63
65
 
64
66
  const funcs = {
@@ -89,6 +91,7 @@ const funcs = {
89
91
  ZIPExtract: _zipExtract.default,
90
92
  INIString: _iniString.default,
91
93
  FILESave: _fileSave.default,
94
+ FILELoad: _fileLoad.default,
92
95
  // aliases
93
96
  bufferify: _bufObject.default.BUFObject,
94
97
  concat: _txtConcat.default.TXTConcat,
package/lib/request.js CHANGED
@@ -13,7 +13,10 @@ const request = (url, parameters) => async () => {
13
13
  const response = await (0, _fetchWithProxy.default)(url, parameters);
14
14
 
15
15
  if (!response.ok) {
16
- throw new Error(response.statusText);
16
+ const err = new Error(response.statusText);
17
+ const text = await response.text();
18
+ err.responseText = text;
19
+ throw err;
17
20
  }
18
21
 
19
22
  return response;
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.21.0",
4
+ "version": "1.22.0",
5
5
  "author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
6
6
  "bugs": "https://github.com/Inist-CNRS/ezs/issues",
7
7
  "dependencies": {
@@ -36,7 +36,7 @@
36
36
  "directories": {
37
37
  "test": "test"
38
38
  },
39
- "gitHead": "b6d40a5733f24e3f138d999f5b7b53e42d3d812a",
39
+ "gitHead": "ae3bd633484915926ad8dac4040e191635939a7d",
40
40
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
41
41
  "keywords": [
42
42
  "ezs"