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

@simoko/geo-distance

v0.1.0

Published

geo distance calculation

Readme

@simoko/geo-distance

Lightweight, zero-dependency geographic distance and coordinate utilities for JavaScript and TypeScript.

Documentation & Playground

Features

  • Zero dependencies — pure math, nothing to install beyond this package
  • Tree-shakable — import only what you need
  • ESM + CJS — works everywhere
  • Full TypeScript support — types included, not bolted on
  • Haversine formula — accurate distance calculation for real-world coordinates

Install

npm install @simoko/geo-distance

Quick Start

import { between, nearest, filterWithin } from '@simoko/geo-distance'

const taipei = { lat: 25.0853, lng: 121.3967 }
const taichung = { lat: 24.1850, lng: 120.5523 }
const tainan = { lat: 23.1505, lng: 120.1772 }
const kenting = { lat: 21.9579, lng: 120.7791 }

// Distance between two points (km by default)
between(taipei, kenting) // 353.8059

// Find the nearest point
nearest(tainan, [taipei, taichung, kenting]) // taichung

// Filter points within 150 km
filterWithin(tainan, [taipei, taichung, kenting], 150) // [taichung, kenting]

Try it live in the playground

API

Distance

between(a, b, unit?, digits?)

Calculate distance between two coordinates using the Haversine formula.

between({ lat: 25.0853, lng: 121.3967 }, { lat: 21.9579, lng: 120.7791 })
// 353.8059 (km)

between({ lat: 25.0853, lng: 121.3967 }, { lat: 21.9579, lng: 120.7791 }, 'ft', 2)
// 1160585.03 (ft)

Navigation

bearing(a, b, digits?)

Calculate the initial bearing (forward azimuth) from point A to point B. Returns degrees (0–360).

bearing({ lat: 25.0853, lng: 121.3967 }, { lat: 21.9579, lng: 120.7791 })
// 190.597 (roughly south)

midpoint(a, b, digits?)

Calculate the geographic midpoint between two coordinates.

midpoint({ lat: 25.0853, lng: 121.3967 }, { lat: 21.9579, lng: 120.7791 })
// { lat: 23.5231, lng: 121.0845 }

destination(origin, distance, bearing, unit?, digits?)

Calculate the destination coordinate given a start point, distance, and bearing.

destination({ lat: 25.0853, lng: 121.3967 }, 100, 180)
// { lat: 24.1866, lng: 121.3967 } (100 km due south)

Query

isWithin(a, b, radius, unit?)

Check if two coordinates are within a given distance.

isWithin(taipei, taichung, 200) // true
isWithin(taipei, kenting, 100)  // false

nearest(target, coords, unit?)

Find the nearest coordinate to the target. O(n), no sorting overhead.

nearest(tainan, [taipei, taichung, kenting])
// taichung

filterWithin(target, coords, radius, unit?)

Filter coordinates within a given radius from the target.

filterWithin(tainan, [taipei, taichung, kenting], 150)
// [taichung, kenting]

nearSort(target, coords, unit?)

Sort coordinates by distance from the target, nearest first. Returns a new array.

nearSort(tainan, [taipei, taichung, kenting])
// [taichung, kenting, taipei]

Spatial

boundingBox(center, radius, unit?, digits?)

Calculate a bounding box around a center point. Useful for fast pre-filtering in database queries before applying precise distance calculations.

boundingBox({ lat: 25.0853, lng: 121.3967 }, 10)
// { minLat: 24.995413, maxLat: 25.175187, minLng: 121.296788, maxLng: 121.496589 }

Database pre-filtering example:

SELECT * FROM locations
WHERE lat BETWEEN :minLat AND :maxLat
  AND lng BETWEEN :minLng AND :maxLng

Types

interface Coord {
  name?: string
  lat: number
  lng: number
}

interface BoundingBox {
  minLat: number
  maxLat: number
  minLng: number
  maxLng: number
}

type Unit = 'km' | 'm' | 'ft'

Supported Units

| Unit | Description | Earth's Radius | |------|-------------|----------------| | km | Kilometers (default) | 6,378.137 | | m | Meters | 6,378,137 | | ft | Feet | 20,902,231.52 |

License

MIT