npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zero-deps-toolkit/geo

v0.0.3

Published

A zero-dependency TypeScript library for geographical calculations and operations.

Readme

@zero-deps-toolkit/geo

A zero-dependency TypeScript library for geographical calculations and operations. Built with performance and simplicity in mind.

npm version License: MIT

Features

  • Zero Dependencies: No external dependencies, minimal bundle size
  • TypeScript First: Full TypeScript support with complete type definitions
  • Tree-Shakeable: Import only what you need
  • Well-Tested: Comprehensive test coverage
  • ESM Support: Modern ES Module format

Installation

npm install @zero-deps-toolkit/geo
yarn add @zero-deps-toolkit/geo
pnpm add @zero-deps-toolkit/geo

Usage

Calculate Distance Between Coordinates

import { distanceInKm, distanceInMeters, haversineDistance } from '@zero-deps-toolkit/geo';

const pointA = { lat: 40.7128, lng: -74.0060 }; // New York
const pointB = { lat: 51.5074, lng: -0.1278 };  // London

// Distance in kilometers
const km = distanceInKm(pointA, pointB);
console.log(`Distance: ${km.toFixed(2)} km`); // Distance: 5570.27 km

// Distance in meters
const meters = distanceInMeters(pointA, pointB);
console.log(`Distance: ${meters.toFixed(2)} m`); // Distance: 5570274.48 m

// Using haversineDistance with explicit unit
const distance = haversineDistance(pointA, pointB, 'km');

API Reference

Types

LatLng

Represents a geographic coordinate with latitude and longitude.

interface LatLng {
  lat: number;  // Latitude in degrees (-90 to 90)
  lng: number;  // Longitude in degrees (-180 to 180)
}

Functions

haversineDistance(point1, point2, unit?)

Calculates the great circle distance between two points on Earth using the Haversine formula. This formula accounts for the spherical shape of the Earth and provides accurate distance calculations.

Parameters:

  • point1: LatLng - First coordinate point
  • point2: LatLng - Second coordinate point
  • unit?: 'km' | 'm' - Unit of measurement (default: 'km')

Returns: number - Distance in the specified unit

Example:

const distance = haversineDistance(
  { lat: 48.8566, lng: 2.3522 },  // Paris
  { lat: 52.5200, lng: 13.4050 }, // Berlin
  'km'
);

distanceInKm(point1, point2)

Convenience function to calculate distance in kilometers.

Parameters:

  • point1: LatLng - First coordinate point
  • point2: LatLng - Second coordinate point

Returns: number - Distance in kilometers

Example:

const km = distanceInKm(
  { lat: 48.8566, lng: 2.3522 },
  { lat: 52.5200, lng: 13.4050 }
);

distanceInMeters(point1, point2)

Convenience function to calculate distance in meters.

Parameters:

  • point1: LatLng - First coordinate point
  • point2: LatLng - Second coordinate point

Returns: number - Distance in meters

Example:

const meters = distanceInMeters(
  { lat: 48.8566, lng: 2.3522 },
  { lat: 52.5200, lng: 13.4050 }
);

How It Works

The library uses the Haversine formula to calculate distances between coordinates. This formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes.

The Haversine formula is:

a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)
c = 2 ⋅ atan2(√a, √(1−a))
d = R ⋅ c

Where:

  • φ is latitude
  • λ is longitude
  • R is Earth's radius (6371 km or 6371000 m)
  • Δ represents the difference between coordinates

This approach provides accurate results for most practical purposes, with typical accuracy within 0.5% for distances up to a few hundred kilometers.

Performance

The library is optimized for performance:

  • Zero external dependencies
  • Minimal computational overhead
  • Small bundle size (~1KB minified)
  • Tree-shakeable - only import what you need

Browser and Node.js Support

  • Node.js: 14.x and above
  • Browsers: All modern browsers (ES2015+)
  • TypeScript: 4.0 and above

Contributing

Contributions are welcome! This package is part of the zero-deps-toolkit monorepo.

License

MIT

Links