1.1.8 • Published 6 months ago

@types/haversine v1.1.8

Weekly downloads
4,807
License
MIT
Repository
github
Last release
6 months ago

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

// Type definitions for haversine 1.1
// Project: https://github.com/njj/haversine, https://github.com/niix/haversine
// Definitions by: Christian Rackerseder <https://github.com/screendriver>
//                 Dan Vanderkam <https://github.com/danvk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8

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: Thu, 08 Jul 2021 14:22:47 GMT
  • Dependencies: none
  • Global values: none

Credits

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

1.1.8

6 months ago

1.1.7

7 months ago

1.1.6

8 months ago

1.1.5

3 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago