Adds typings for latlon-geohash

This commit is contained in:
Robert Imig
2017-11-09 15:36:38 -06:00
parent c7a83919d6
commit efdcafd759
4 changed files with 93 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
// Type definitions for latlon-geohash 1.1
// Project: https://github.com/chrisveness/latlon-geohash
// Definitions by: Robert Imig <https://github.com/rimig>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module "latlon-geohash" {
enum Direction {
North = "N",
South = "S",
East = "E",
West = "W",
}
interface Neighbours {
n: string;
ne: string;
e: string;
se: string;
s: string;
sw: string;
w: string;
nw: string;
}
/*
* Encode latitude/longitude point to geohash of given precision (number of characters in resulting geohash).
* If precision is not specified, it is inferred from precision of latitude/longitude values.
*/
function encode(latitude: number, longitude: number, precision?: number): string;
/*
* return { lat, lon } of centre of given geohash, to appropriate precision.
*/
function decode(geohash: string): number[];
/*
* return { sw, ne } bounds of given geohash.
*/
function bounds(geohash: string): number[];
/*
* return adjacent cell to given geohash in specified direction (N/S/E/W).
*/
function adjacent(geohash: string, direction: (Direction | string)): string;
/*
* return all 8 adjacent cells (n/ne/e/se/s/sw/w/nw) to given geohash.
*/
function neighbours(geohash: string): Neighbours;
}
@@ -0,0 +1,19 @@
import * as Geohash from "latlon-geohash";
// Encoding
const atx_geohash: string = Geohash.encode(30.2672, -97.7431);
const atx_geohash_p3: string = Geohash.encode(30.2672, -97.7431, 3);
// Decoding
const atx_latlong: number[] = Geohash.decode(atx_geohash);
// Bounds
const atx_bounds: number[] = Geohash.bounds(atx_geohash);
// Adjacent
const atx_adj_cell1: string = Geohash.adjacent(atx_geohash, Geohash.Direction.North);
const atx_adj_cell2: string = Geohash.adjacent(atx_geohash, "N");
// Neighbors
const atx_neighbors: Geohash.Neighbours = Geohash.neighbours(atx_geohash);
const atx_adj_cell3: string = atx_neighbors.n;
+22
View File
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"latlon-geohash-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }