diff --git a/types/haversine/haversine-tests.ts b/types/haversine/haversine-tests.ts index 043d7d5898..5c068ea4b3 100644 --- a/types/haversine/haversine-tests.ts +++ b/types/haversine/haversine-tests.ts @@ -1,11 +1,11 @@ import haversine = require('haversine'); -const start: haversine.Coordinate = { +const start: haversine.CoordinateLongitudeLatitude = { longitude: 48.1548256, latitude: 11.4017529 }; -const end: haversine.Coordinate = { +const end: haversine.CoordinateLongitudeLatitude = { longitude: 52.5065133, latitude: 13.1445551 }; @@ -16,3 +16,51 @@ const options: haversine.Options = { }; haversine(start, end, options); + +const startShort: haversine.CoordinateLonLat = { + lon: 48.1548256, + lat: 11.4017529 +}; + +const endShort: haversine.CoordinateLonLat = { + lon: 52.5065133, + lat: 13.1445551 +}; + +const optionsShort: haversine.Options = { + format: '{lon,lat}' +}; + +haversine(startShort, endShort, optionsShort); + +const startLatLon: haversine.LatLonTuple = [11.4017529, 48.1548256]; + +const endLatLon: haversine.LatLonTuple = [13.1445551, 52.5065133]; + +const optionsLatLon: haversine.Options = { + format: '[lat,lon]' +}; + +haversine(startLatLon, endLatLon, optionsLatLon); + +const startGeoJSON = { + type: "Feature", + geometry: { + type: "LineString", + coordinates: startLatLon + } +}; + +const endGeoJSON = { + type: "Feature", + geometry: { + type: "LineString", + coordinates: endLatLon + } +}; + +const optionsGeoJSON: haversine.Options = { + format: 'geojson' +}; + +haversine(startGeoJSON, endGeoJSON, optionsGeoJSON); diff --git a/types/haversine/index.d.ts b/types/haversine/index.d.ts index 6fed860d8b..5f6d1e9173 100644 --- a/types/haversine/index.d.ts +++ b/types/haversine/index.d.ts @@ -1,14 +1,29 @@ -// Type definitions for haversine 1.0 +// Type definitions for haversine 1.1 // Project: https://github.com/njj/haversine // Definitions by: Christian Rackerseder // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace haversine { - interface Coordinate { + interface CoordinateLongitudeLatitude { longitude: number; latitude: number; } + interface CoordinateLonLat { + lon: number; + lat: number; + } + + type LatLonTuple = [number, number]; + + interface GeoJSON { + geometry: { + coordinates: LatLonTuple + }; + } + + type Coordinate = (CoordinateLongitudeLatitude | CoordinateLonLat | LatLonTuple | GeoJSON); + interface Options { /** * Unit of measurement applied to result. Default: "km". @@ -18,6 +33,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'; } }