diff --git a/types/latlon-geohash/index.d.ts b/types/latlon-geohash/index.d.ts new file mode 100644 index 0000000000..a7d843c30c --- /dev/null +++ b/types/latlon-geohash/index.d.ts @@ -0,0 +1,94 @@ +// Type definitions for latlon-geohash 1.1 +// Project: https://github.com/chrisveness/latlon-geohash +// Definitions by: Robert Imig +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +export enum Direction { + North = "N", + South = "S", + East = "E", + West = "W" +} + +export interface Neighbours { + n: string; + ne: string; + e: string; + se: string; + s: string; + sw: string; + w: string; + nw: string; +} + +export interface Bounds { + sw: Point; + ne: Point; +} + +export interface Point { + lat: number; + lon: number; +} + +/** + * Encodes latitude/longitude to geohash, either to specified precision or to automatically + * evaluated precision. + * + * @param lat - Latitude in degrees. + * @param lon - Longitude in degrees. + * @param [precision] - Number of characters in resulting geohash. + * @returns Geohash of supplied latitude/longitude. + * @throws Invalid geohash. + * + * @example + * var geohash = Geohash.encode(52.205, 0.119, 7); // geohash: 'u120fxw' + */ + +export function encode( + latitude: number, + longitude: number, + precision?: number +): string; + +/** + * Decode geohash to latitude/longitude (location is approximate centre of geohash cell, + * to reasonable precision). + * + * @param geohash - Geohash string to be converted to latitude/longitude. + * @returns (Center of) geohashed location. + * @throws Invalid geohash. + * + * @example + * var latlon = Geohash.decode('u120fxw'); // latlon: { lat: 52.205, lon: 0.1188 } + */ +export function decode(geohash: string): Point; + +/** + * Returns SW/NE latitude/longitude bounds of specified geohash. + * + * @param geohash - Cell that bounds are required of. + * @returns The Bounds + * @throws Invalid geohash. + */ +export function bounds(geohash: string): Bounds; + +/** + * Determines adjacent cell in given direction. + * + * @param geohash - Cell to which adjacent cell is required. + * @param direction - Direction from geohash (N/S/E/W). + * @returns Geocode of adjacent cell. + * @throws Invalid geohash. + */ +export function adjacent(geohash: string, direction: Direction | string): string; + +/** + * Returns all 8 adjacent cells to specified geohash. + * + * @param geohash - Geohash neighbours are required of. + * @returns The neighbours + * @throws Invalid geohash. + */ +export 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..632c7e64ed --- /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: Geohash.Point = Geohash.decode(atx_geohash); + +// Bounds +const atx_bounds: Geohash.Bounds = 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..10d9c00791 --- /dev/null +++ b/types/latlon-geohash/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": 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" }