nodejs-nomer 1.0.3 → 1.0.4

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
@@ -2,18 +2,30 @@
2
2
 
3
3
  var _utils = require("./utils");
4
4
  var _result = _interopRequireDefault(require("./result"));
5
+ var _propertiesFile = require("properties-file");
5
6
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
6
7
  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); }
8
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
+ 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."); }
10
+ 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); }
11
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
+ 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; }
7
14
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
15
  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); } }
9
16
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
+ 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; }
10
18
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
11
19
  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); }
12
20
  var Nomer = /*#__PURE__*/function () {
13
21
  function Nomer() {
14
- var properties = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
22
+ var propertiesPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
15
23
  var echoOpt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
16
24
  _classCallCheck(this, Nomer);
25
+ _defineProperty(this, "propertiesPath", null);
26
+ _defineProperty(this, "echoOpt", "");
27
+ this.propertiesPath = propertiesPath;
28
+ this.echoOpt = echoOpt;
17
29
  }
18
30
 
19
31
  /**
@@ -29,29 +41,25 @@ var Nomer = /*#__PURE__*/function () {
29
41
  }, {
30
42
  key: "clean",
31
43
  value: function clean() {
32
- var properties = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
33
- var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("clean", this.getProperties(properties)));
44
+ var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("clean", this.getPropertiesPath()));
34
45
  return res;
35
46
  }
36
47
  }, {
37
48
  key: "inputSchema",
38
49
  value: function inputSchema() {
39
- var properties = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
40
- var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("input-schema", this.getProperties(properties)));
50
+ var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("input-schema", this.getPropertiesPath()));
41
51
  return res;
42
52
  }
43
53
  }, {
44
54
  key: "outputSchema",
45
55
  value: function outputSchema() {
46
- var properties = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
47
- var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("output-schema", this.getProperties(properties)));
56
+ var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("output-schema", this.getPropertiesPath()));
48
57
  return res;
49
58
  }
50
59
  }, {
51
60
  key: "properties",
52
61
  value: function properties() {
53
- var _properties = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
54
- var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("properties", this.getProperties(_properties)));
62
+ var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("properties", this.getPropertiesPath()));
55
63
  return res;
56
64
  }
57
65
  }, {
@@ -66,8 +74,7 @@ var Nomer = /*#__PURE__*/function () {
66
74
  key: "validateTerm",
67
75
  value: function validateTerm() {
68
76
  var filepath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
69
- var properties = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
70
- var res = (0, _utils.runNomer)((0, _utils.getNomerValidateCmd)(filepath, "validate-term-link", this.getProperties(properties)));
77
+ var res = (0, _utils.runNomer)((0, _utils.getNomerValidateCmd)(filepath, "validate-term-link", this.getPropertiesPath()));
71
78
  return res;
72
79
  }
73
80
  }, {
@@ -75,9 +82,7 @@ var Nomer = /*#__PURE__*/function () {
75
82
  value: function replace() {
76
83
  var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
77
84
  var matcher = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "globi-taxon-cache";
78
- var properties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
79
- var echoOpt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
80
- var res = (0, _utils.runNomer)((0, _utils.getNomerMatchCmd)(query, "replace", matcher, this.getProperties(properties), null, echoOpt));
85
+ var res = (0, _utils.runNomer)((0, _utils.getNomerMatchCmd)(query, "replace", matcher, this.getPropertiesPath(), null, this.echoOpt));
81
86
  return res;
82
87
  }
83
88
  }, {
@@ -85,16 +90,14 @@ var Nomer = /*#__PURE__*/function () {
85
90
  value: function append() {
86
91
  var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
87
92
  var matcher = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "globi-taxon-cache";
88
- var properties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
89
- var outputFormat = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "tsv";
90
- var echoOpt = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
91
- var res = (0, _utils.runNomer)((0, _utils.getNomerMatchCmd)(query, "append", matcher, this.getProperties(properties), outputFormat, echoOpt));
93
+ var outputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "tsv";
94
+ var res = (0, _utils.runNomer)((0, _utils.getNomerMatchCmd)(query, "append", matcher, this.getPropertiesPath(), outputFormat, this.echoOpt));
92
95
  return res;
93
96
  }
94
97
  }, {
95
- key: "getProperties",
96
- value: function getProperties(p) {
97
- return p;
98
+ key: "getPropertiesPath",
99
+ value: function getPropertiesPath() {
100
+ return this.propertiesPath;
98
101
  }
99
102
  }, {
100
103
  key: "toJson",
@@ -109,7 +112,15 @@ var Nomer = /*#__PURE__*/function () {
109
112
  }, {
110
113
  key: "toObject",
111
114
  value: function toObject(result) {
112
- return _result["default"].tsv(result, true);
115
+ var content = this.properties(this.getPropertiesPath());
116
+ var properties = (0, _propertiesFile.getProperties)(content);
117
+ var schemaInput = JSON.parse(properties["nomer.schema.input"]).map(function (i) {
118
+ return i.type + 'Input';
119
+ });
120
+ var schemaAppend = JSON.parse(properties["nomer.append.schema.output"]).map(function (i) {
121
+ return i.type;
122
+ });
123
+ return _result["default"].tsv(result, [].concat(_toConsumableArray(schemaInput), _toConsumableArray(schemaAppend)));
113
124
  }
114
125
  }]);
115
126
  return Nomer;
package/dist/result.js CHANGED
@@ -13,7 +13,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
13
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; }
14
14
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
15
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'];
16
+ var TSV_COLUMNS = ['inputId', 'inputName', 'match', 'externalId', 'name', 'authorship', 'rank', 'commonNames', 'path', 'pathIds', 'pathNames', 'pathAuthorship', 'externalUrl'];
17
17
  var Result = /*#__PURE__*/function () {
18
18
  function Result() {
19
19
  _classCallCheck(this, Result);
@@ -21,16 +21,25 @@ var Result = /*#__PURE__*/function () {
21
21
  _createClass(Result, null, [{
22
22
  key: "json",
23
23
  value: function json(result) {
24
- return JSON.parse(result);
24
+ var arr = [];
25
+ result.split("\n").forEach(function (e) {
26
+ return arr.push(JSON.parse(e));
27
+ });
28
+ return arr;
25
29
  }
26
30
  }, {
27
31
  key: "tsv",
28
32
  value: function tsv(result) {
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;
33
+ var columns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
34
+ var arr = [];
35
+ result.split('\n').forEach(function (line) {
36
+ arr.push(line.split('\t'));
37
+ });
38
+ return columns ? arr.map(function (v) {
39
+ return Object.assign.apply(Object, _toConsumableArray(columns.map(function (k, i) {
40
+ return _defineProperty({}, k, v[i]);
41
+ })));
42
+ }) : arr;
34
43
  }
35
44
  }]);
36
45
  return Result;
package/dist/utils.js CHANGED
@@ -52,7 +52,7 @@ var runNomer = function runNomer(nomerCmd) {
52
52
  try {
53
53
  var result = execSync(nomerCmd).toString();
54
54
  if (result) {
55
- return result.trim();
55
+ return result.trimEnd();
56
56
  }
57
57
  } catch (error) {
58
58
  console.log("Error running nomer cmd: " + error.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs-nomer",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "NodeJS wrapper for nomer",
5
5
  "config": {
6
6
  "nomerVersion": "0.5.6"
@@ -29,5 +29,8 @@
29
29
  "@babel/cli": "^7.23.9",
30
30
  "@babel/core": "^7.24.0",
31
31
  "@babel/preset-env": "^7.24.0"
32
+ },
33
+ "dependencies": {
34
+ "properties-file": "^3.5.1"
32
35
  }
33
36
  }
package/src/index.js CHANGED
@@ -1,10 +1,16 @@
1
1
  import { runNomer, getNomerSimpleCmd, getNomerValidateCmd, getNomerMatchCmd } from "./utils";
2
2
  import Result from './result'
3
+ import { getProperties } from "properties-file";
4
+
3
5
 
4
6
  class Nomer {
5
7
 
6
- constructor(properties = null, echoOpt = "") {
8
+ propertiesPath = null;
9
+ echoOpt = "";
7
10
 
11
+ constructor(propertiesPath = null, echoOpt = "") {
12
+ this.propertiesPath = propertiesPath;
13
+ this.echoOpt = echoOpt;
8
14
  }
9
15
 
10
16
  /**
@@ -16,23 +22,23 @@ class Nomer {
16
22
  return res;
17
23
  }
18
24
 
19
- clean(properties = null) {
20
- const res = runNomer(getNomerSimpleCmd("clean", this.getProperties(properties)))
25
+ clean() {
26
+ const res = runNomer(getNomerSimpleCmd("clean", this.getPropertiesPath()))
21
27
  return res;
22
28
  }
23
29
 
24
- inputSchema(properties = null) {
25
- const res = runNomer(getNomerSimpleCmd("input-schema", this.getProperties(properties)))
30
+ inputSchema() {
31
+ const res = runNomer(getNomerSimpleCmd("input-schema", this.getPropertiesPath()))
26
32
  return res;
27
33
  }
28
34
 
29
- outputSchema(properties = null) {
30
- const res = runNomer(getNomerSimpleCmd("output-schema", this.getProperties(properties)))
35
+ outputSchema() {
36
+ const res = runNomer(getNomerSimpleCmd("output-schema", this.getPropertiesPath()))
31
37
  return res;
32
38
  }
33
39
 
34
- properties(properties = null) {
35
- const res = runNomer(getNomerSimpleCmd("properties", this.getProperties(properties)))
40
+ properties() {
41
+ const res = runNomer(getNomerSimpleCmd("properties", this.getPropertiesPath()))
36
42
  return res;
37
43
  }
38
44
 
@@ -41,41 +47,41 @@ class Nomer {
41
47
  return res;
42
48
  }
43
49
 
44
- validateTerm(filepath = "", properties = null) {
45
- const res = runNomer(getNomerValidateCmd(filepath, "validate-term-link", this.getProperties(properties)))
50
+ validateTerm(filepath = "") {
51
+ const res = runNomer(getNomerValidateCmd(filepath, "validate-term-link", this.getPropertiesPath()))
46
52
  return res;
47
53
  }
48
54
 
49
- replace(query = "", matcher = "globi-taxon-cache", properties = null, echoOpt = "") {
55
+ replace(query = "", matcher = "globi-taxon-cache") {
50
56
  const res = runNomer(
51
57
  getNomerMatchCmd(
52
58
  query,
53
59
  "replace",
54
60
  matcher,
55
- this.getProperties(properties),
61
+ this.getPropertiesPath(),
56
62
  null,
57
- echoOpt
63
+ this.echoOpt
58
64
  )
59
65
  );
60
66
  return res;
61
67
  }
62
68
 
63
- append(query = "", matcher = "globi-taxon-cache", properties = null, outputFormat = "tsv", echoOpt = "") {
69
+ append(query = "", matcher = "globi-taxon-cache", outputFormat = "tsv") {
64
70
  const res = runNomer(
65
71
  getNomerMatchCmd(
66
72
  query,
67
73
  "append",
68
74
  matcher,
69
- this.getProperties(properties),
75
+ this.getPropertiesPath(),
70
76
  outputFormat,
71
- echoOpt
77
+ this.echoOpt
72
78
  )
73
79
  );
74
80
  return res;
75
81
  }
76
82
 
77
- getProperties(p) {
78
- return p;
83
+ getPropertiesPath() {
84
+ return this.propertiesPath;
79
85
  }
80
86
 
81
87
  toJson(result) {
@@ -87,7 +93,11 @@ class Nomer {
87
93
  }
88
94
 
89
95
  toObject(result) {
90
- return Result.tsv(result, true)
96
+ const content = this.properties(this.getPropertiesPath())
97
+ const properties = getProperties(content)
98
+ const schemaInput = JSON.parse(properties["nomer.schema.input"]).map((i) => i.type + 'Input')
99
+ const schemaAppend = JSON.parse(properties["nomer.append.schema.output"]).map((i) => i.type)
100
+ return Result.tsv(result, [...schemaInput, ...schemaAppend])
91
101
  }
92
102
 
93
103
 
package/src/result.js CHANGED
@@ -1,4 +1,6 @@
1
1
  const TSV_COLUMNS = [
2
+ 'inputId',
3
+ 'inputName',
2
4
  'match',
3
5
  'externalId',
4
6
  'name',
@@ -15,12 +17,18 @@ const TSV_COLUMNS = [
15
17
  class Result {
16
18
 
17
19
  static json(result) {
18
- return JSON.parse(result)
20
+ const arr = [];
21
+ result.split("\n").forEach((e) => arr.push(JSON.parse(e)))
22
+ return arr;
19
23
  }
20
24
 
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
25
+ static tsv(result, columns = null) {
26
+ const arr = [];
27
+ result.split('\n').forEach((line) => {
28
+ arr.push(line.split('\t'));
29
+ });
30
+
31
+ return columns ? arr.map((v) => Object.assign(...columns.map((k, i) => ({ [k]: v[i] })))) : arr
24
32
  }
25
33
  }
26
34
 
package/src/utils.js CHANGED
@@ -43,7 +43,7 @@ const runNomer = (nomerCmd) => {
43
43
  try {
44
44
  const result = execSync(nomerCmd).toString();
45
45
  if (result) {
46
- return result.trim();
46
+ return result.trimEnd();
47
47
  }
48
48
  } catch (error) {
49
49
  console.log("Error running nomer cmd: " + error.message);