From efdcafd759fc01f8ee8310d627af82a2e5f468ac Mon Sep 17 00:00:00 2001 From: Robert Imig Date: Thu, 9 Nov 2017 15:36:38 -0600 Subject: [PATCH] Adds typings for latlon-geohash --- types/latlon-geohash/index.d.ts | 51 ++++++++++++++++++++ types/latlon-geohash/latlon-geohash-tests.ts | 19 ++++++++ types/latlon-geohash/tsconfig.json | 22 +++++++++ types/latlon-geohash/tslint.json | 1 + 4 files changed, 93 insertions(+) create mode 100644 types/latlon-geohash/index.d.ts create mode 100644 types/latlon-geohash/latlon-geohash-tests.ts create mode 100644 types/latlon-geohash/tsconfig.json create mode 100644 types/latlon-geohash/tslint.json diff --git a/types/latlon-geohash/index.d.ts b/types/latlon-geohash/index.d.ts new file mode 100644 index 0000000000..26a75f276e --- /dev/null +++ b/types/latlon-geohash/index.d.ts @@ -0,0 +1,51 @@ +// Type definitions for latlon-geohash 1.1 +// Project: https://github.com/chrisveness/latlon-geohash +// Definitions by: Robert Imig +// 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; +} diff --git a/types/latlon-geohash/latlon-geohash-tests.ts b/types/latlon-geohash/latlon-geohash-tests.ts new file mode 100644 index 0000000000..e73b69e187 --- /dev/null +++ b/types/latlon-geohash/latlon-geohash-tests.ts @@ -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; diff --git a/types/latlon-geohash/tsconfig.json b/types/latlon-geohash/tsconfig.json new file mode 100644 index 0000000000..4ebc241222 --- /dev/null +++ b/types/latlon-geohash/tsconfig.json @@ -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" + ] +} diff --git a/types/latlon-geohash/tslint.json b/types/latlon-geohash/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/latlon-geohash/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }