@ezs/basics 2.5.8 → 2.6.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/README.md CHANGED
@@ -14,6 +14,7 @@ npm install @ezs/basics
14
14
 
15
15
  #### Table of Contents
16
16
 
17
+ - [BIBParse](#bibparse)
17
18
  - [BUFObject](#bufobject)
18
19
  - [CSVObject](#csvobject)
19
20
  - [CSVParse](#csvparse)
@@ -47,6 +48,24 @@ npm install @ezs/basics
47
48
  - [XMLString](#xmlstring)
48
49
  - [ZIPExtract](#zipextract)
49
50
 
51
+ ### BIBParse
52
+
53
+ Take a `String` and split it at bibtext entry.
54
+
55
+ Input:
56
+
57
+ ```json
58
+ ["@article{my_article,\ntitle = {Hello world},\n", "journal = \"Some Journal\"\n"]
59
+ ```
60
+
61
+ Output:
62
+
63
+ ```json
64
+ ["a", "b", "c", "d"]
65
+ ```
66
+
67
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
68
+
50
69
  ### BUFObject
51
70
 
52
71
  Take `Mixed` and produce Buffer.
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _string_decoder = require("string_decoder");
8
+ var _bib2json = _interopRequireDefault(require("bib2json"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function BIBParse(data, feed) {
11
+ if (!this.decoder) {
12
+ this.decoder = new _string_decoder.StringDecoder('utf8');
13
+ this.remainder = '';
14
+ this.counter = 0;
15
+ this.parser = new _bib2json.default(entry => {
16
+ feed.write(entry);
17
+ });
18
+ }
19
+ if (this.isLast()) {
20
+ this.remainder += this.decoder.end();
21
+ if (this.remainder && this.counter > 1) {
22
+ this.parser.parse(this.remainder);
23
+ }
24
+ return feed.close();
25
+ }
26
+ let chunk;
27
+ if (Buffer.isBuffer(data)) {
28
+ chunk = this.decoder.write(data);
29
+ } else if (typeof data === 'string') {
30
+ chunk = data;
31
+ } else {
32
+ chunk = '';
33
+ }
34
+ this.parser.parse(chunk);
35
+ this.counter += 1;
36
+ feed.end();
37
+ }
38
+
39
+ /**
40
+ * Take a `String` and split it at bibtext entry.
41
+ *
42
+ * Input:
43
+ *
44
+ * ```json
45
+ * ["@article{my_article,\ntitle = {Hello world},\n", "journal = \"Some Journal\"\n"]
46
+ * ```
47
+ *
48
+ * Output:
49
+ *
50
+ * ```json
51
+ * ["a", "b", "c", "d"]
52
+ * ```
53
+ *
54
+ * @name BIBParse
55
+ * @returns {Object}
56
+ */
57
+ var _default = {
58
+ BIBParse
59
+ };
60
+ exports.default = _default;
package/lib/index.js CHANGED
@@ -9,6 +9,7 @@ var _objCount = _interopRequireDefault(require("./obj-count"));
9
9
  var _objNamespaces = _interopRequireDefault(require("./obj-namespaces"));
10
10
  var _objStandardize = _interopRequireDefault(require("./obj-standardize"));
11
11
  var _objFlatten = _interopRequireDefault(require("./obj-flatten"));
12
+ var _bibParse = _interopRequireDefault(require("./bib-parse"));
12
13
  var _txtConcat = _interopRequireDefault(require("./txt-concat"));
13
14
  var _txtObject = _interopRequireDefault(require("./txt-object"));
14
15
  var _txtParse = _interopRequireDefault(require("./txt-parse"));
@@ -43,6 +44,7 @@ const funcs = {
43
44
  OBJNamespaces: _objNamespaces.default,
44
45
  OBJStandardize: _objStandardize.default,
45
46
  OBJFlatten: _objFlatten.default,
47
+ BIBParse: _bibParse.default,
46
48
  TXTParse: _txtParse.default,
47
49
  TXTObject: _txtObject.default,
48
50
  TXTConcat: _txtConcat.default,
@@ -4,11 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = OBJNamespaces;
7
- var _lodash = _interopRequireDefault(require("lodash.zipobject"));
8
- var _lodash2 = _interopRequireDefault(require("lodash.escaperegexp"));
9
- var _lodash3 = _interopRequireDefault(require("lodash.mapkeys"));
10
- var _lodash4 = _interopRequireDefault(require("lodash.mapvalues"));
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ var _lodash = require("lodash");
12
8
  /**
13
9
  * Take `Object` and throw the same object, all keys parsed to replace namespaces with their prefixes
14
10
  *
@@ -78,13 +74,13 @@ function OBJNamespaces(data, feed) {
78
74
  if (this.isFirst()) {
79
75
  const prefixes = [].concat(this.getParam('prefix')).map(x => String(x).trim()).filter(Boolean);
80
76
  const namespaces = [].concat(this.getParam('namespace')).filter(Boolean).slice(0, prefixes.length).map(x => String(x).trim());
81
- this.mapping = (0, _lodash.default)(namespaces, prefixes);
82
- this.expression = RegExp(Object.keys(this.mapping).map(_lodash2.default).join('|'), 'g');
77
+ this.mapping = (0, _lodash.zipObject)(namespaces, prefixes);
78
+ this.expression = RegExp(Object.keys(this.mapping).map(_lodash.escapeRegExp).join('|'), 'g');
83
79
  this.references = [].concat(this.getParam('reference')).filter(Boolean).map(x => RegExp(String(x).trim(), 'g'));
84
80
  }
85
- const result = (0, _lodash3.default)(data, (val, key) => String(key).replace(this.expression, matched => this.mapping[matched]));
81
+ const result = (0, _lodash.mapKeys)(data, (val, key) => String(key).replace(this.expression, matched => this.mapping[matched]));
86
82
  if (this.references.length > 0) {
87
- const result1 = (0, _lodash4.default)(result, (value, key) => {
83
+ const result1 = (0, _lodash.mapValues)(result, (value, key) => {
88
84
  if (this.references.some(x => key.search(x) !== -1)) {
89
85
  return String(value).replace(this.expression, matched => this.mapping[matched]);
90
86
  }
package/lib/tar-dump.js CHANGED
@@ -9,7 +9,7 @@ var _util = require("util");
9
9
  var _fs = require("fs");
10
10
  var _tarStream = _interopRequireDefault(require("tar-stream"));
11
11
  var _zlib = require("zlib");
12
- var _lodash = _interopRequireDefault(require("lodash.merge"));
12
+ var _lodash = require("lodash");
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
14
  // Avoid importing from fs/promise to be compatible with node 12
15
15
  const readFilePromise = (0, _util.promisify)(_fs.readFile);
@@ -48,7 +48,7 @@ function TARDump(data, feed) {
48
48
  'processingMSTime': this.getCumulativeTimeMS()
49
49
  };
50
50
  const manifestArray = [metadata].concat(this.getParam('manifest', [])).filter(Boolean);
51
- const manifest = (0, _lodash.default)(...manifestArray);
51
+ const manifest = (0, _lodash.merge)(...manifestArray);
52
52
  this.pack.entry({
53
53
  name: 'manifest.json'
54
54
  }, JSON.stringify(manifest, null, ' '));
@@ -4,9 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _lodash = _interopRequireDefault(require("lodash.get"));
7
+ var _lodash = require("lodash");
8
8
  var _inflection = require("inflection");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
9
  const transformer = transformations => str => str && typeof str === 'string' ? (0, _inflection.transform)(str, transformations) : str;
11
10
  const TXTInflection = (data, feed, ctx) => {
12
11
  if (ctx.isLast()) {
@@ -14,7 +13,7 @@ const TXTInflection = (data, feed, ctx) => {
14
13
  }
15
14
  const transformations = [].concat(ctx.getParam('transform', [])).filter(Boolean);
16
15
  const path = ctx.getParam('path', 'value');
17
- const value = (0, _lodash.default)(data, path, '');
16
+ const value = (0, _lodash.get)(data, path, '');
18
17
  const process = transformer(transformations);
19
18
  const result = Array.isArray(value) ? value.map(item => process(item)) : process(value);
20
19
  feed.write({
@@ -4,8 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _lodash = _interopRequireDefault(require("lodash.get"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ var _lodash = require("lodash");
9
8
  const UPPER_LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
10
9
  const SENTENCE_INIT = ' ';
11
10
  const SENTENCE_ENDING = '.?!';
@@ -46,7 +45,7 @@ const TXTSentences = (data, feed, ctx) => {
46
45
  return feed.close();
47
46
  }
48
47
  const path = ctx.getParam('path', 'value');
49
- const value = (0, _lodash.default)(data, path);
48
+ const value = (0, _lodash.get)(data, path);
50
49
  const str = Array.isArray(value) ? value.map(item => typeof item === 'string' ? item : '').join(' ') : value;
51
50
  const sentences = str ? segmentSentences(str) : [];
52
51
  feed.write({
package/lib/url-fetch.js CHANGED
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = URLFetch;
7
7
  var _debug = _interopRequireDefault(require("debug"));
8
- var _lodash = _interopRequireDefault(require("lodash.get"));
9
- var _lodash2 = _interopRequireDefault(require("lodash.set"));
8
+ var _lodash = require("lodash");
10
9
  var _nodeAbortController = _interopRequireDefault(require("node-abort-controller"));
11
10
  var _parseHeaders = _interopRequireDefault(require("parse-headers"));
12
11
  var _asyncRetry = _interopRequireDefault(require("async-retry"));
@@ -43,7 +42,7 @@ async function URLFetch(data, feed) {
43
42
  const mimetype = String(this.getParam('mimetype', 'application/json'));
44
43
  const controller = new _nodeAbortController.default();
45
44
  const key = Array.isArray(path) ? path.shift() : path;
46
- const body = (0, _lodash.default)(data, key);
45
+ const body = (0, _lodash.get)(data, key);
47
46
  const parameters = {
48
47
  timeout,
49
48
  headers,
@@ -53,9 +52,9 @@ async function URLFetch(data, feed) {
53
52
  retries
54
53
  };
55
54
  if (body) {
56
- (0, _lodash2.default)(parameters, 'method', 'POST');
57
- (0, _lodash2.default)(parameters, 'body', Buffer.isBuffer(body) ? body : JSON.stringify(body));
58
- (0, _lodash2.default)(parameters, 'headers.content-type', mimetype);
55
+ (0, _lodash.set)(parameters, 'method', 'POST');
56
+ (0, _lodash.set)(parameters, 'body', Buffer.isBuffer(body) ? body : JSON.stringify(body));
57
+ (0, _lodash.set)(parameters, 'headers.content-type', mimetype);
59
58
  }
60
59
  try {
61
60
  const response = await (0, _asyncRetry.default)((0, _request.default)(url, parameters), options);
@@ -67,7 +66,7 @@ async function URLFetch(data, feed) {
67
66
  } : {
68
67
  input: data
69
68
  };
70
- (0, _lodash2.default)(result, target, value);
69
+ (0, _lodash.set)(result, target, value);
71
70
  return feed.send(result);
72
71
  }
73
72
  return feed.send(value);
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = URLRequest;
7
- var _lodash = _interopRequireDefault(require("lodash.set"));
7
+ var _lodash = require("lodash");
8
8
  var _debug = _interopRequireDefault(require("debug"));
9
9
  var _url = require("url");
10
10
  var _nodeAbortController = _interopRequireDefault(require("node-abort-controller"));
@@ -93,11 +93,11 @@ async function URLRequest(data, feed) {
93
93
  } : {
94
94
  url: data
95
95
  };
96
- (0, _lodash.default)(result, target, value);
97
- inserts.forEach(i => (0, _lodash.default)(result, i, response.headers.get(i)));
96
+ (0, _lodash.set)(result, target, value);
97
+ inserts.forEach(i => (0, _lodash.set)(result, i, response.headers.get(i)));
98
98
  return feed.send(result);
99
99
  }
100
- inserts.forEach(i => (0, _lodash.default)(value, i, response.headers.get(i)));
100
+ inserts.forEach(i => (0, _lodash.set)(value, i, response.headers.get(i)));
101
101
  return feed.send(value);
102
102
  } catch (e) {
103
103
  onError(e);
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@ezs/basics",
3
3
  "description": "Basics statements for EZS",
4
- "version": "2.5.8",
4
+ "version": "2.6.1",
5
5
  "author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
6
6
  "bugs": "https://github.com/Inist-CNRS/ezs/issues",
7
7
  "dependencies": {
8
8
  "JSONStream": "1.3.5",
9
9
  "async-retry": "1.3.3",
10
10
  "better-https-proxy-agent": "1.0.9",
11
+ "bib2json": "0.0.1",
11
12
  "csv-string": "3.2.0",
12
13
  "debug": "4.3.3",
13
14
  "fetch-with-proxy": "3.0.1",
@@ -16,13 +17,7 @@
16
17
  "get-stream": "6.0.1",
17
18
  "higher-path": "1.0.0",
18
19
  "inflection": "2.0.1",
19
- "lodash.escaperegexp": "4.1.2",
20
- "lodash.get": "4.4.2",
21
- "lodash.mapkeys": "4.6.0",
22
- "lodash.mapvalues": "4.6.0",
23
- "lodash.merge": "4.6.2",
24
- "lodash.set": "4.3.2",
25
- "lodash.zipobject": "4.1.3",
20
+ "lodash": "4.17.21",
26
21
  "make-dir": "4.0.0",
27
22
  "micromatch": "4.0.4",
28
23
  "node-abort-controller": "1.1.0",
@@ -41,7 +36,7 @@
41
36
  "directories": {
42
37
  "test": "test"
43
38
  },
44
- "gitHead": "8240602a9eb82e247626908cb578087b180b6d2a",
39
+ "gitHead": "3e4f4de9ba95082d32a5f58569955a1bee908d33",
45
40
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
46
41
  "keywords": [
47
42
  "ezs"