nodejs-nomer 1.1.0 → 1.2.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.
@@ -0,0 +1,25 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
+
4
+ name: Node.js Package
5
+
6
+ on:
7
+ release:
8
+ types: [published]
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+ id-token: write
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: actions/setup-node@v3
19
+ with:
20
+ node-version: '21.x'
21
+ registry-url: 'https://registry.npmjs.org'
22
+ - run: npm ci
23
+ - run: npm publish
24
+ env:
25
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/bin/nomer ADDED
Binary file
package/install_nomer.sh CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/bin/sh
2
2
 
3
- NOMER_VERSION=$1
3
+ NOMER_VERSION="0.5.13"
4
4
 
5
5
  mkdir -p ./bin
6
6
  echo "https://github.com/globalbioticinteractions/nomer/releases/download/${NOMER_VERSION}/nomer.jar)"
package/package.json CHANGED
@@ -1,18 +1,15 @@
1
1
  {
2
2
  "name": "nodejs-nomer",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "NodeJS wrapper for nomer",
5
5
  "bin": {
6
6
  "nomer": "./bin/nomer"
7
7
  },
8
- "config": {
9
- "nomerVersion": "0.5.7"
10
- },
11
8
  "main": "index.js",
12
9
  "scripts": {
13
10
  "test": "npm run test",
14
11
  "build": "babel src -d dist",
15
- "preinstall": "./install_nomer.sh ${npm_package_config_nomerVersion}"
12
+ "preinstall": "./install_nomer.sh"
16
13
  },
17
14
  "repository": {
18
15
  "type": "git",
package/DEVELOPMENT.md DELETED
@@ -1,17 +0,0 @@
1
- # DEVELOPMENT
2
-
3
- Build:
4
- `npm run build`
5
-
6
- Link:
7
-
8
- `npm link`
9
-
10
- Use package for testing:
11
- `npm link nodejs-nomer`
12
-
13
- Run `script.js`
14
- `node script.js`
15
-
16
- # PUBLISH
17
-
package/dist/index.js DELETED
@@ -1,135 +0,0 @@
1
- "use strict";
2
-
3
- var _utils = require("./utils");
4
- var _result = _interopRequireDefault(require("./result"));
5
- var _propertiesFile = require("properties-file");
6
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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; }
14
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
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; }
18
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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); }
20
- var Nomer = /*#__PURE__*/function () {
21
- function Nomer() {
22
- var propertiesPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
23
- var echoOpt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
24
- _classCallCheck(this, Nomer);
25
- _defineProperty(this, "propertiesPath", null);
26
- _defineProperty(this, "echoOpt", "");
27
- this.propertiesPath = propertiesPath;
28
- this.echoOpt = echoOpt;
29
- }
30
-
31
- /**
32
- * Show version
33
- * @returns string
34
- */
35
- _createClass(Nomer, [{
36
- key: "version",
37
- value: function version() {
38
- var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)());
39
- return res;
40
- }
41
- }, {
42
- key: "clean",
43
- value: function clean() {
44
- var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("clean", false, this.getPropertiesPath()));
45
- return res;
46
- }
47
- }, {
48
- key: "inputSchema",
49
- value: function inputSchema() {
50
- var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("input-schema", false, this.getPropertiesPath()));
51
- return res;
52
- }
53
- }, {
54
- key: "outputSchema",
55
- value: function outputSchema() {
56
- var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("output-schema", false, this.getPropertiesPath()));
57
- return res;
58
- }
59
- }, {
60
- key: "properties",
61
- value: function properties() {
62
- var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("properties", false, this.getPropertiesPath()));
63
- return res;
64
- }
65
- }, {
66
- key: "matcher",
67
- value: function matcher() {
68
- var outputFormat = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "tsv";
69
- var verbose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
70
- var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("matchers", verbose, null, outputFormat));
71
- return res;
72
- }
73
- }, {
74
- key: "validateTerm",
75
- value: function validateTerm() {
76
- var filepath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
77
- var res = (0, _utils.runNomer)((0, _utils.getNomerValidateCmd)(filepath, "validate-term-link", this.getPropertiesPath()));
78
- return res;
79
- }
80
- }, {
81
- key: "replace",
82
- value: function replace() {
83
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
84
- var matcher = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "globi-taxon-cache";
85
- var res = (0, _utils.runNomer)((0, _utils.getNomerMatchCmd)(query, "replace", matcher, this.getPropertiesPath(), null, this.echoOpt));
86
- return res;
87
- }
88
- }, {
89
- key: "append",
90
- value: function append() {
91
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
92
- var matcher = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "globi-taxon-cache";
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), query);
95
- return res;
96
- }
97
- }, {
98
- key: "appendAsync",
99
- value: function appendAsync() {
100
- var matcher = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "globi-taxon-cache";
101
- var outputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "tsv";
102
- return (0, _utils.runNomerAsync)("nomer append ".concat(matcher, " -o ").concat(outputFormat));
103
- }
104
- }, {
105
- key: "getPropertiesPath",
106
- value: function getPropertiesPath() {
107
- return this.propertiesPath;
108
- }
109
- }, {
110
- key: "toJson",
111
- value: function toJson(result) {
112
- return _result["default"].json(result);
113
- }
114
- }, {
115
- key: "toArray",
116
- value: function toArray(result) {
117
- return _result["default"].tsv(result);
118
- }
119
- }, {
120
- key: "toObject",
121
- value: function toObject(result) {
122
- var content = this.properties(this.getPropertiesPath());
123
- var properties = (0, _propertiesFile.getProperties)(content);
124
- var schemaInput = JSON.parse(properties["nomer.schema.input"]).map(function (i) {
125
- return i.type + 'Input';
126
- });
127
- var schemaAppend = JSON.parse(properties["nomer.append.schema.output"]).map(function (i) {
128
- return i.type;
129
- });
130
- return _result["default"].tsv(result, [].concat(_toConsumableArray(schemaInput), ["matchType"], _toConsumableArray(schemaAppend)));
131
- }
132
- }]);
133
- return Nomer;
134
- }();
135
- module.exports = Nomer;
package/dist/result.js DELETED
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
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; }
11
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
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
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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 Result = /*#__PURE__*/function () {
17
- function Result() {
18
- _classCallCheck(this, Result);
19
- }
20
- _createClass(Result, null, [{
21
- key: "json",
22
- value: function json(result) {
23
- var arr = [];
24
- result.split("\n").forEach(function (e) {
25
- return arr.push(JSON.parse(e));
26
- });
27
- return arr;
28
- }
29
- }, {
30
- key: "tsv",
31
- value: function tsv(result) {
32
- var columns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
33
- var arr = [];
34
- result.split('\n').forEach(function (line) {
35
- arr.push(line.split('\t'));
36
- });
37
- return columns ? arr.map(function (v) {
38
- return Object.assign.apply(Object, _toConsumableArray(columns.map(function (k, i) {
39
- return _defineProperty({}, k, v[i]);
40
- })));
41
- }) : arr;
42
- }
43
- }]);
44
- return Result;
45
- }();
46
- module.exports = Result;
package/dist/utils.js DELETED
@@ -1,80 +0,0 @@
1
- "use strict";
2
-
3
- var _require = require('child_process'),
4
- execSync = _require.execSync,
5
- exec = _require.exec,
6
- spawn = _require.spawn;
7
- var getNomerValidateCmd = function getNomerValidateCmd() {
8
- var filepath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
9
- var cmd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "validate-term";
10
- var properties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
11
- if (filepath === "") {
12
- throw new Exception("Filepath cannot be empty string");
13
- }
14
- var nomerCmd = "curl -L ".concat(filepath, " | nomer ").concat(cmd);
15
- if (properties) {
16
- nomerCmd = "".concat(nomerCmd, " -p ").concat(properties);
17
- }
18
- return nomerCmd;
19
- };
20
- var getNomerMatchCmd = function getNomerMatchCmd() {
21
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
22
- var cmd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "append";
23
- var matcher = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "globi-taxon-cache";
24
- var properties = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
25
- var outputFormat = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
26
- var echoOpt = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "-e";
27
- var nomerCmd = "echo ".concat(echoOpt, " '").concat(query, "' | nomer ").concat(cmd, " ").concat(matcher);
28
- if (properties) {
29
- nomerCmd = "".concat(nomerCmd, " -p ").concat(properties);
30
- }
31
- if (outputFormat) {
32
- nomerCmd = "".concat(nomerCmd, " -o ").concat(outputFormat);
33
- }
34
- return nomerCmd;
35
- };
36
- var getNomerSimpleCmd = function getNomerSimpleCmd() {
37
- var cmd = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "version";
38
- var verbose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
39
- var properties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
40
- var outputFormat = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
41
- var nomerCmd = "nomer ".concat(cmd);
42
- if (properties) {
43
- nomerCmd = "".concat(nomerCmd, " -p ").concat(properties);
44
- }
45
- if (outputFormat) {
46
- nomerCmd = "".concat(nomerCmd, " -o ").concat(outputFormat);
47
- }
48
- if (verbose) {
49
- nomerCmd = "".concat(nomerCmd, " -v");
50
- }
51
- return nomerCmd;
52
- };
53
- var runNomer = function runNomer(nomerCmd) {
54
- try {
55
- var result = execSync(nomerCmd, {
56
- maxBuffer: 4096 * 4096
57
- }).toString();
58
- if (result) {
59
- return result.trimEnd();
60
- }
61
- } catch (error) {
62
- console.log("Error running nomer cmd: " + error.message);
63
- return null;
64
- }
65
- };
66
- var runNomerAsync = function runNomerAsync(nomerCmd) {
67
- var nomerCmdArr = nomerCmd.split(/\s+/);
68
- var p = spawn(nomerCmdArr[0], nomerCmdArr.slice(1), {
69
- // maxBuffer: 4096 * 4096
70
- shell: true
71
- });
72
- return p;
73
- };
74
- module.exports = {
75
- getNomerValidateCmd: getNomerValidateCmd,
76
- getNomerMatchCmd: getNomerMatchCmd,
77
- getNomerSimpleCmd: getNomerSimpleCmd,
78
- runNomer: runNomer,
79
- runNomerAsync: runNomerAsync
80
- };
package/test/script.js DELETED
@@ -1,23 +0,0 @@
1
- const Nomer = require("nodejs-nomer")
2
-
3
- const nomer = new Nomer();
4
-
5
- console.time("version")
6
- console.log(nomer.version());
7
- console.timeEnd("version")
8
-
9
-
10
-
11
- // console.time("append")
12
- // const results = []
13
- // for (let index = 0; index < 100; index++) {
14
- // results.push(nomer.append("\tBauhinia rufa\t", "gbif"))
15
- // }
16
- // console.timeEnd("append")
17
-
18
- // console.time("toObject")
19
- // for (let index = 0; index < results.length; index++) {
20
- // const element = results[index];
21
- // nomer.toObject(element)
22
- // }
23
- // console.timeEnd("toObject")