@ezs/basics 2.8.1 → 2.9.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/README.md CHANGED
@@ -320,6 +320,7 @@ Output:
320
320
  * `content` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Content to save instead of using input object
321
321
  * `jsonl` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Save as json line (optional, default `false`)
322
322
  * `compress` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable gzip compression (optional, default `false`)
323
+ * `append` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable append mode (add content to an existing file) (optional, default `false`)
323
324
 
324
325
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
325
326
 
package/lib/csv-object.js CHANGED
@@ -9,7 +9,7 @@ function CSVObject(data, feed) {
9
9
  return feed.close();
10
10
  }
11
11
  if (!this.columns) {
12
- this.columns = data.map(name => name.replace(/\./g, ''));
12
+ this.columns = Array().concat(data).map(name => String(name).replace(/\./g, ''));
13
13
  const countCols = {};
14
14
  const renamedCols = {};
15
15
  this.columns.forEach(colname => {
package/lib/file-save.js CHANGED
@@ -50,6 +50,7 @@ const toJSONL = line => JSON.stringify(line).concat(eol);
50
50
  * @param {String} [content] Content to save instead of using input object
51
51
  * @param {Boolean} [jsonl=false] Save as json line
52
52
  * @param {Boolean} [compress=false] Enable gzip compression
53
+ * @param {Boolean} [append=false] Enable append mode (add content to an existing file)
53
54
  * @returns {Object}
54
55
  */
55
56
  function FILESave(data, feed) {
@@ -57,6 +58,7 @@ function FILESave(data, feed) {
57
58
  const identifier = String(this.getParam('identifier'));
58
59
  const location = _path.default.normalize(this.getParam('location', (0, _os.tmpdir)()));
59
60
  const compress = this.getParam('compress', false);
61
+ const flags = Boolean(this.getParam('append', false)) ? 'a' : 'w';
60
62
  if (location.indexOf((0, _os.tmpdir)()) !== 0 && location.indexOf(process.cwd()) !== 0) {
61
63
  feed.stop(new Error('File location check failed.'));
62
64
  return;
@@ -67,7 +69,9 @@ function FILESave(data, feed) {
67
69
  (0, _fs.accessSync)(location, _fs.constants.R_OK | _fs.constants.W_OK);
68
70
  const name = compress ? `${identifier}.gz` : identifier;
69
71
  const filename = _path.default.resolve(location, name);
70
- this.input = compress ? (0, _zlib.createGzip)() : (0, _fs.createWriteStream)(filename);
72
+ this.input = compress ? (0, _zlib.createGzip)() : (0, _fs.createWriteStream)(filename, {
73
+ flags
74
+ });
71
75
  this.whenFinish = new Promise((resolve, reject) => {
72
76
  const output = compress ? this.input.pipe((0, _fs.createWriteStream)(filename)) : this.input;
73
77
  output.once('error', err => {
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.8.1",
4
+ "version": "2.9.0",
5
5
  "author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
6
6
  "bugs": "https://github.com/Inist-CNRS/ezs/issues",
7
7
  "dependencies": {
@@ -35,7 +35,7 @@
35
35
  "directories": {
36
36
  "test": "test"
37
37
  },
38
- "gitHead": "70981fd51496c085059265ed683ba5fcfb0f8b9f",
38
+ "gitHead": "cb751815b6c62b99231ce1e034854f4301df65f3",
39
39
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
40
40
  "keywords": [
41
41
  "ezs"