haversine: add format support

haversine now supports supplying coordinates in a variety of formats
This commit is contained in:
Daniel Hritzkiv
2017-11-14 22:48:57 -05:00
parent a9d7f1bf8b
commit 7627c93a25
+25 -3
View File
@@ -4,10 +4,28 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace haversine {
interface Coordinate {
interface CoordinateLongNames {
longitude: number;
latitude: number;
}
interface CoordinateShortNames {
lat: number;
lon: number;
}
interface LatLonTuple extends Array<number> {
0: number;
1: number;
}
interface GeoJSON {
geometry: {
coordinates: LatLonTuple
}
}
type coordinate = (CoordinateLongNames | CoordinateShortNames | LatLonTuple | GeoJSON);
interface Options {
/**
@@ -18,6 +36,10 @@ declare namespace haversine {
* If passed, will result in library returning boolean value of whether or not the start and end points are within that supplied threshold. Default: null.
*/
threshold?: number;
/**
* Format of coordinate arguments.
*/
format?: '[lat,lon]' | '[lon,lat]' | '{lon,lat}' | 'geojson'
}
}
@@ -25,8 +47,8 @@ declare namespace haversine {
* Determines the great-circle distance between two points on a sphere given their longitudes and latitudes
*/
declare function haversine(
start: haversine.Coordinate,
end: haversine.Coordinate,
start: coordinate,
end: coordinate,
options?: haversine.Options
): number;