From efdcafd759fc01f8ee8310d627af82a2e5f468ac Mon Sep 17 00:00:00 2001 From: Robert Imig Date: Thu, 9 Nov 2017 15:36:38 -0600 Subject: [PATCH 1/5] 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" } From 01606acb5ee61fdcc7404130046780a18c11693d Mon Sep 17 00:00:00 2001 From: Robert Imig Date: Fri, 10 Nov 2017 18:56:20 -0600 Subject: [PATCH 2/5] add strictFunctionTypes --- types/latlon-geohash/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/latlon-geohash/tsconfig.json b/types/latlon-geohash/tsconfig.json index 4ebc241222..10d9c00791 100644 --- a/types/latlon-geohash/tsconfig.json +++ b/types/latlon-geohash/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" From 28dcaa438ed5421453461456978ab62af803f4f6 Mon Sep 17 00:00:00 2001 From: Robert Imig Date: Fri, 10 Nov 2017 18:56:41 -0600 Subject: [PATCH 3/5] update latlon-geohash types --- types/latlon-geohash/index.d.ts | 131 ++++++++++++------- types/latlon-geohash/latlon-geohash-tests.ts | 4 +- 2 files changed, 88 insertions(+), 47 deletions(-) diff --git a/types/latlon-geohash/index.d.ts b/types/latlon-geohash/index.d.ts index 26a75f276e..f37c8845cf 100644 --- a/types/latlon-geohash/index.d.ts +++ b/types/latlon-geohash/index.d.ts @@ -3,49 +3,90 @@ // 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; +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 {number} lat - Latitude in degrees. +* @param {number} lon - Longitude in degrees. +* @param {number} [precision] - Number of characters in resulting geohash. +* @returns {string} 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 {string} geohash - Geohash string to be converted to latitude/longitude. + * @returns {Point} (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 {string} geohash - Cell that bounds are required of. + * @returns {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 {string} 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 {string} geohash - Geohash neighbours are required of. + * @returns {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 index e73b69e187..632c7e64ed 100644 --- a/types/latlon-geohash/latlon-geohash-tests.ts +++ b/types/latlon-geohash/latlon-geohash-tests.ts @@ -5,10 +5,10 @@ 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); +const atx_latlong: Geohash.Point = Geohash.decode(atx_geohash); // Bounds -const atx_bounds: number[] = Geohash.bounds(atx_geohash); +const atx_bounds: Geohash.Bounds = Geohash.bounds(atx_geohash); // Adjacent const atx_adj_cell1: string = Geohash.adjacent(atx_geohash, Geohash.Direction.North); From 42edeb3326f03ad09842c5104d0c7e094c9117f9 Mon Sep 17 00:00:00 2001 From: Robert Imig Date: Sat, 11 Nov 2017 11:11:41 -0600 Subject: [PATCH 4/5] fix lint issues --- types/latlon-geohash/index.d.ts | 39 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/types/latlon-geohash/index.d.ts b/types/latlon-geohash/index.d.ts index f37c8845cf..d87ef237b3 100644 --- a/types/latlon-geohash/index.d.ts +++ b/types/latlon-geohash/index.d.ts @@ -32,18 +32,19 @@ export interface Point { } /** -* Encodes latitude/longitude to geohash, either to specified precision or to automatically -* evaluated precision. -* -* @param {number} lat - Latitude in degrees. -* @param {number} lon - Longitude in degrees. -* @param {number} [precision] - Number of characters in resulting geohash. -* @returns {string} Geohash of supplied latitude/longitude. -* @throws Invalid geohash. -* -* @example -* var geohash = Geohash.encode(52.205, 0.119, 7); // geohash: 'u120fxw' -*/ + * 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, @@ -54,8 +55,8 @@ export function encode( * Decode geohash to latitude/longitude (location is approximate centre of geohash cell, * to reasonable precision). * - * @param {string} geohash - Geohash string to be converted to latitude/longitude. - * @returns {Point} (Center of) geohashed location. + * @param geohash - Geohash string to be converted to latitude/longitude. + * @returns (Center of) geohashed location. * @throws Invalid geohash. * * @example @@ -66,8 +67,8 @@ export function decode(geohash: string): Point; /** * Returns SW/NE latitude/longitude bounds of specified geohash. * - * @param {string} geohash - Cell that bounds are required of. - * @returns {Bounds} + * @param geohash - Cell that bounds are required of. + * @returns The Bounds * @throws Invalid geohash. */ export function bounds(geohash: string): Bounds; @@ -77,7 +78,7 @@ export function bounds(geohash: string): Bounds; * * @param geohash - Cell to which adjacent cell is required. * @param direction - Direction from geohash (N/S/E/W). - * @returns {string} Geocode of adjacent cell. + * @returns Geocode of adjacent cell. * @throws Invalid geohash. */ export function adjacent(geohash: string, direction: Direction | string): string; @@ -85,8 +86,8 @@ export function adjacent(geohash: string, direction: Direction | string): string /** * Returns all 8 adjacent cells to specified geohash. * - * @param {string} geohash - Geohash neighbours are required of. - * @returns {Neighbours} + * @param geohash - Geohash neighbours are required of. + * @returns The neighbours * @throws Invalid geohash. */ export function neighbours(geohash: string): Neighbours; From 16f784425bb48f8359cba2b3334ac28701a85958 Mon Sep 17 00:00:00 2001 From: Robert Imig Date: Sat, 11 Nov 2017 11:17:13 -0600 Subject: [PATCH 5/5] add header ts ver 2.4 --- types/latlon-geohash/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/latlon-geohash/index.d.ts b/types/latlon-geohash/index.d.ts index d87ef237b3..a7d843c30c 100644 --- a/types/latlon-geohash/index.d.ts +++ b/types/latlon-geohash/index.d.ts @@ -2,6 +2,7 @@ // 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",