nodejs-nomer 1.0.2 → 1.0.3

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/dist/index.js CHANGED
@@ -106,6 +106,11 @@ var Nomer = /*#__PURE__*/function () {
106
106
  value: function toArray(result) {
107
107
  return _result["default"].tsv(result);
108
108
  }
109
+ }, {
110
+ key: "toObject",
111
+ value: function toObject(result) {
112
+ return _result["default"].tsv(result, true);
113
+ }
109
114
  }]);
110
115
  return Nomer;
111
116
  }();
package/dist/result.js CHANGED
@@ -1,11 +1,19 @@
1
1
  "use strict";
2
2
 
3
3
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
11
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
12
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
13
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
14
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
15
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
+ var TSV_COLUMNS = ['match', 'externalId', 'name', 'authorship', 'rank', 'commonNames', 'path', 'pathIds', 'pathNames', 'pathAuthorship', 'externalUrl'];
9
17
  var Result = /*#__PURE__*/function () {
10
18
  function Result() {
11
19
  _classCallCheck(this, Result);
@@ -18,7 +26,11 @@ var Result = /*#__PURE__*/function () {
18
26
  }, {
19
27
  key: "tsv",
20
28
  value: function tsv(result) {
21
- return result.split('\t');
29
+ var toObject = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
30
+ var values = result.split('\t').slice(1);
31
+ return toObject ? Object.assign.apply(Object, _toConsumableArray(TSV_COLUMNS.map(function (k, i) {
32
+ return _defineProperty({}, k, values[i]);
33
+ }))) : values;
22
34
  }
23
35
  }]);
24
36
  return Result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs-nomer",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "NodeJS wrapper for nomer",
5
5
  "config": {
6
6
  "nomerVersion": "0.5.6"
package/src/index.js CHANGED
@@ -86,6 +86,10 @@ class Nomer {
86
86
  return Result.tsv(result);
87
87
  }
88
88
 
89
+ toObject(result) {
90
+ return Result.tsv(result, true)
91
+ }
92
+
89
93
 
90
94
  }
91
95
 
package/src/result.js CHANGED
@@ -1,11 +1,26 @@
1
+ const TSV_COLUMNS = [
2
+ 'match',
3
+ 'externalId',
4
+ 'name',
5
+ 'authorship',
6
+ 'rank',
7
+ 'commonNames',
8
+ 'path',
9
+ 'pathIds',
10
+ 'pathNames',
11
+ 'pathAuthorship',
12
+ 'externalUrl'
13
+ ];
14
+
1
15
  class Result {
2
16
 
3
17
  static json(result) {
4
18
  return JSON.parse(result)
5
19
  }
6
20
 
7
- static tsv(result) {
8
- return result.split('\t')
21
+ static tsv(result, toObject = false) {
22
+ const values = result.split('\t').slice(1);
23
+ return toObject ? Object.assign(...TSV_COLUMNS.map((k, i) => ({ [k]: values[i] }))) : values
9
24
  }
10
25
  }
11
26