@types/haversine
TypeScript icon, indicating that this package has built-in type declarations

1.1.8 • Public • Published

Installation

npm install --save @types/haversine

Summary

This package contains type definitions for haversine (https://github.com/njj/haversine).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/haversine.

index.d.ts

declare namespace haversine {
    interface CoordinateLongitudeLatitude {
        longitude: number;
        latitude: number;
    }

    interface CoordinateLonLat {
        lon: number;
        lat: number;
    }

    interface CoordinateLatLng {
        lat: number;
        lng: number;
    }

    type LatLonTuple = [number, number];

    interface GeoJSON {
        geometry: {
            coordinates: number[]; // matches Point type in types/geojson.
        };
    }

    type Coordinate = CoordinateLongitudeLatitude | CoordinateLonLat | CoordinateLatLng | LatLonTuple | GeoJSON;

    interface Options {
        /** Unit of measurement applied to result. Default: "km". */
        unit?: "km" | "mile" | "meter" | "nmi" | undefined;
        /**
         * If passed, will result in library returning boolean value of whether or not the start and end points are within that supplied threshold.
         */
        threshold?: number | null | undefined;
        /** Format of coordinate arguments. */
        format?: "[lat,lon]" | "[lon,lat]" | "{lon,lat}" | "{lat,lng}" | "geojson" | undefined;
    }

    // The input & output types of haversine() both depend on the Options object.
    type ParamType<T extends Options | undefined> = T extends undefined ? CoordinateLongitudeLatitude
        : T extends { format: "[lat,lon]" | "[lon,lat]" } ? [number, number]
        : T extends { format: "{lat,lon}" } ? CoordinateLonLat
        : T extends { format: "{lat,lng}" } ? CoordinateLatLng
        : T extends { format: "geojson" } ? GeoJSON
        : Coordinate;

    type Return<T extends Options | undefined> = T extends { threshold: number } ? boolean : number;
}

/**
 * Determines the great-circle distance between two points on a sphere given their longitudes and latitudes
 */
declare function haversine<OptionsT extends haversine.Options | undefined = undefined>(
    start: haversine.ParamType<OptionsT>,
    end: haversine.ParamType<OptionsT>,
    options?: OptionsT,
): haversine.Return<OptionsT>;

export = haversine;

Additional Details

  • Last updated: Tue, 07 Nov 2023 03:09:37 GMT
  • Dependencies: none

Credits

These definitions were written by Christian Rackerseder, and Dan Vanderkam.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.824,752ts5.8
1.1.824,752ts5.7
1.1.824,752latest
1.1.824,752ts4.5
1.1.824,752ts4.6
1.1.824,752ts4.7
1.1.824,752ts4.8
1.1.824,752ts4.9
1.1.824,752ts5.0
1.1.824,752ts5.1
1.1.824,752ts5.2
1.1.824,752ts5.3
1.1.824,752ts5.4
1.1.824,752ts5.5
1.1.824,752ts5.6
1.1.824,752ts5.9
1.1.57,817ts3.6
1.1.57,817ts3.7
1.1.57,817ts3.8
1.1.57,817ts3.9
1.1.57,817ts4.0
1.1.57,817ts4.1
1.1.57,817ts4.2
1.1.57,817ts4.3
1.1.57,817ts4.4
1.1.41,913ts2.8
1.1.41,913ts2.9
1.1.41,913ts3.0
1.1.41,913ts3.1
1.1.41,913ts3.2
1.1.41,913ts3.3
1.1.41,913ts3.4
1.1.41,913ts3.5
1.1.222ts2.0
1.1.222ts2.1
1.1.222ts2.2
1.1.222ts2.3
1.1.222ts2.4
1.1.222ts2.5
1.1.222ts2.6
1.1.222ts2.7

Version History

VersionDownloads (Last 7 Days)Published
1.1.824,752
1.1.7243
1.1.67
1.1.57,817
1.1.41,913
1.1.30
1.1.222
1.1.10
1.1.0486
1.0.10
1.0.00

Package Sidebar

Install

npm i @types/haversine

Weekly Downloads

35,240

Version

1.1.8

License

MIT

Unpacked Size

6.83 kB

Total Files

5

Last publish

Collaborators

  • types