mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 16:26:16 -04:00
Tidied up Geohash operations
This commit is contained in:
parent
e9fe227ed7
commit
415beaa0b0
6 changed files with 29 additions and 33 deletions
|
@ -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"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue