Преглед на файлове

Tidied up Geohash operations

n1474335 преди 6 години
родител
ревизия
415beaa0b0

+ 11 - 16
package-lock.json

@@ -4197,14 +4197,12 @@
         "balanced-match": {
           "version": "1.0.0",
           "bundled": true,
-          "dev": true,
-          "optional": true
+          "dev": true
         },
         "brace-expansion": {
           "version": "1.1.11",
           "bundled": true,
           "dev": true,
-          "optional": true,
           "requires": {
             "balanced-match": "^1.0.0",
             "concat-map": "0.0.1"
@@ -4219,20 +4217,17 @@
         "code-point-at": {
           "version": "1.1.0",
           "bundled": true,
-          "dev": true,
-          "optional": true
+          "dev": true
         },
         "concat-map": {
           "version": "0.0.1",
           "bundled": true,
-          "dev": true,
-          "optional": true
+          "dev": true
         },
         "console-control-strings": {
           "version": "1.1.0",
           "bundled": true,
-          "dev": true,
-          "optional": true
+          "dev": true
         },
         "core-util-is": {
           "version": "1.0.2",
@@ -4349,8 +4344,7 @@
         "inherits": {
           "version": "2.0.3",
           "bundled": true,
-          "dev": true,
-          "optional": true
+          "dev": true
         },
         "ini": {
           "version": "1.3.5",
@@ -4362,7 +4356,6 @@
           "version": "1.0.0",
           "bundled": true,
           "dev": true,
-          "optional": true,
           "requires": {
             "number-is-nan": "^1.0.0"
           }
@@ -4377,7 +4370,6 @@
           "version": "3.0.4",
           "bundled": true,
           "dev": true,
-          "optional": true,
           "requires": {
             "brace-expansion": "^1.1.7"
           }
@@ -4489,8 +4481,7 @@
         "number-is-nan": {
           "version": "1.0.1",
           "bundled": true,
-          "dev": true,
-          "optional": true
+          "dev": true
         },
         "object-assign": {
           "version": "4.1.1",
@@ -4623,7 +4614,6 @@
           "version": "1.0.2",
           "bundled": true,
           "dev": true,
-          "optional": true,
           "requires": {
             "code-point-at": "^1.0.0",
             "is-fullwidth-code-point": "^1.0.0",
@@ -7275,6 +7265,11 @@
       "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=",
       "dev": true
     },
+    "ngeohash": {
+      "version": "0.6.0",
+      "resolved": "https://registry.npmjs.org/ngeohash/-/ngeohash-0.6.0.tgz",
+      "integrity": "sha1-MpcT6ec9HxpG2SqrC5StuUUz9oc="
+    },
     "nice-try": {
       "version": "1.0.4",
       "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.4.tgz",

+ 4 - 4
src/core/config/Categories.json

@@ -53,9 +53,7 @@
             "To MessagePack",
             "From MessagePack",
             "To Braille",
-            "From Braille",
-            "To Geohash",
-            "From Geohash"
+            "From Braille"
         ]
     },
     {
@@ -291,7 +289,9 @@
             "Adler-32 Checksum",
             "CRC-16 Checksum",
             "CRC-32 Checksum",
-            "TCP/IP Checksum"
+            "TCP/IP Checksum",
+            "To Geohash",
+            "From Geohash"
         ]
     },
     {

+ 7 - 6
src/core/operations/FromGeohash.mjs

@@ -19,13 +19,12 @@ class FromGeohash extends Operation {
         super();
 
         this.name = "From Geohash";
-        this.module = "Default";
-        this.description = "Converts Geohash strings into Lat / Long coordinates.  For example, <code>ww8p1r4t8</code> becomes <code>37.8324,112.5584</code>.";
+        this.module = "Hashing";
+        this.description = "Converts Geohash strings into Lat/Long coordinates. For example, <code>ww8p1r4t8</code> becomes <code>37.8324,112.5584</code>.";
         this.infoURL = "https://wikipedia.org/wiki/Geohash";
         this.inputType = "string";
         this.outputType = "string";
-        this.args = [
-        ];
+        this.args = [];
     }
 
     /**
@@ -34,8 +33,10 @@ class FromGeohash extends Operation {
      * @returns {string}
      */
     run(input, args) {
-        const coords = geohash.decode(input);
-        return [coords.latitude, coords.longitude].join(",");
+        return input.split("\n").map(line => {
+            const coords = geohash.decode(line);
+            return [coords.latitude, coords.longitude].join(",");
+        }).join("\n");
     }
 
 }

+ 7 - 5
src/core/operations/ToGeohash.mjs

@@ -19,8 +19,8 @@ class ToGeohash extends Operation {
         super();
 
         this.name = "To Geohash";
-        this.module = "Default";
-        this.description = "Converts Lat / Long coordinates into a Geohash string.  For example, <code>37.8324,112.5584</code> becomes <code>ww8p1r4t8</code>.";
+        this.module = "Hashing";
+        this.description = "Converts Lat/Long coordinates into a Geohash string.  For example, <code>37.8324,112.5584</code> becomes <code>ww8p1r4t8</code>.";
         this.infoURL = "https://wikipedia.org/wiki/Geohash";
         this.inputType = "string";
         this.outputType = "string";
@@ -41,9 +41,11 @@ class ToGeohash extends Operation {
     run(input, args) {
         const [precision] = args;
 
-        input = input.replace(/ /g, "");
-        if (input === "") return "";
-        return geohash.encode(...input.split(",").map(num => parseFloat(num)), precision);
+        return input.split("\n").map(line => {
+            line = line.replace(/ /g, "");
+            if (line === "") return "";
+            return geohash.encode(...line.split(",").map(num => parseFloat(num)), precision);
+        }).join("\n");
     }
 
 }

+ 0 - 1
test/tests/operations/FromGeohash.mjs

@@ -2,7 +2,6 @@
  * To Geohash tests
  *
  * @author gchq77703
- *
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */

+ 0 - 1
test/tests/operations/ToGeohash.mjs

@@ -2,7 +2,6 @@
  * To Geohash tests
  *
  * @author gchq77703
- *
  * @copyright Crown Copyright 2018
  * @license Apache-2.0
  */