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 🙏

© 2024 – Pkg Stats / Ryan Hefner

geo2zip

v4.0.2

Published

Translates latitude / longitude geolocations to the nearest corresponding U.S. zip code

Downloads

2,623

Readme

geo2zip

🌎🔍 Quickly find the the nearest U.S. ZIP codes to a latitude/longitude geolocation using k-nearest neighbors

Travis

Takes a geolocation and returns the nearest US ZIP codes.

⚠️ NOTE: The top result may not return the actual ZIP code containing the location. This library returns the ZIP code where the approximate center of the ZIP is nearest the given location. Larger ZIP code areas may show lower in the results when searching nearby points because the center can be so far away. If you're relying on something as inaccurate as ZIP codes, the top result is likely close enough.

Also, ZIP codes change. They change in shape and location. New ones are created and old ones are removed. They're even recycled. If you know of a reliable, more up-to-date list of ZIP codes, please let us know by opening an issue.

Can I use this in the browser? Yes but please don't. This is made to run on a Node.js server. This depends on a roughly 2 MB list of US ZIP codes and sorts those in-memory. Please don't do that to my phone. If you're experimenting or know what you're doing, use this wherever and however it works for you.

Isn't sorting and filtering on a 2MB file slow in JavaScript? No. A lookup is created when the main file is imported/required. After the lookup is created, you should be able to run the examples in this README millions of times per second; showing output would be the limit. The tradeoff is your server may take a 1-2 seconds longer to start up initially (e.g. from npm run start).

Install

With Yarn or npm installed, run:

yarn add geo2zip

# ...or, if using `npm`
npm install geo2zip

Usage

Get the nearest ZIP to a location:

import geo2zip from "geo2zip";

const location = {
  latitude: 34.659698,
  longitude: -88.242903,
};

const closestZip = await geo2zip(location);

console.log(closestZip); // ['38873']

Get the closest 5 ZIPs to a location:

import geo2zip from "geo2zip";

const location = {
  latitude: 34.659698,
  longitude: -88.242903,
};

await geo2zip(location, { limit: 5 });
// [ '38873', '38838', '38827', '38859', '38852' ]

API

geo2zip(location, options)

location

Type: Object

A geolocation with valid latitude and longitude properties.

options

Type: Object

Properties:

  • limit - the number of results to return
    • Type: Number
    • Default: 1

See Also

  • standardize-geolocation - takes geolocations of different formats and outputs a standardized version
  • sphere-knn - find the k nearest neighbors for points on a sphere
  • us-zips - a list of US ZIP codes and their geolocations

License

MIT