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

zip-coords-us

v1.0.4

Published

Super efficient, lazy-loaded library for converting US ZIP Codes (ZCTAs) to latitude and longitude.

Downloads

36

Readme

zip-coords-us

npm version license

A super-efficient, lightweight, and lazy-loaded JavaScript library for converting 5-digit US ZIP Codes (ZCTAs) to their central latitude and longitude coordinates.

The library is compatible with Node.js (via NPM) and Vanilla JavaScript (via CDN). It uses a pre-indexed JSON map for O(1) lookup time, ensuring near-instantaneous retrieval after the first load.


✨ Features

  • ⚡ O(1) Lookup Speed: Uses a JSON dictionary where the ZIP code is the key, allowing for instant access once the map is loaded.
  • 😴 Lazy Loading: The data map is only loaded from the file into memory when the convert() function is called for the very first time, minimizing application startup time and memory footprint.
  • 📦 Dual Compatibility: Works as a CommonJS module in Node.js and as a global variable script via CDN.
  • 🗺️ ZCTA Based: Coordinates are derived from U.S. Census Bureau ZCTAs (ZIP Code Tabulation Areas).

⬇️ Installation

1. For Node.js / Module Bundlers

Install via npm:

npm install zip-coords-us

2. For Vanilla JavaScript / CDN

You can load the minified file directly in your HTML via a CDN (like Unpkg or jsDelivr), making the library available as the global variable ZipCoordsUS:

<script src="[https://unpkg.com/zip-coords-us/dist/zip-coords-us.min.js](https://unpkg.com/zip-coords-us/dist/zip-coords-us.min.js)"></script>

🚀 Usage

1. Node.js / NPM Module

Require the package and destructure the convert function:

// index.js (Node.js)

const { convert } = require('zip-coords-us');

// First call loads the data, subsequent calls are instant
const coords = convert('10001'); 
console.log(`ZIP 10001: Lat ${coords.latitude}, Lng ${coords.longitude}`);

2. CDN / Vanilla JavaScript

After loading the script via CDN, the function is available globally under the variable name ZipCoordsUS.

<script>
    // Access the convert method from the global variable
    const coords = ZipCoordsUS.convert(90210);

    if (coords) {
        console.log(`ZIP 90210: Lat ${coords.latitude}, Lng ${coords.longitude}`);
    } else {
        console.log("ZIP code not found.");
    }
</script>

📚 API Reference

convert(zip_code)

| Parameter | Type | Description | | :--- | :--- | :--- | | zip_code | string or number | The 5-digit US ZIP code (will be padded with zeros if necessary, e.g., 601 becomes "00601"). |

| Returns | Type | Description | | :--- | :--- | :--- | | Found | object | { latitude: number, longitude: number } | | Not Found | null | Returns null if the ZIP code is not in the map. |


🛠️ Data Source & Methodology

The underlying JSON data map (us_zip_to_coords_map.json) was generated from the U.S. Census Bureau's ZCTA Gazetteer Files.

If you wish to download the raw CSV file to update the library's data yourself, you can find the files at the official source page:

👉 Download the ZCTA Gazetteer File CSV/TXT (U.S. Census Bureau)

Note on ZCTAs: The Census Bureau uses ZIP Code Tabulation Areas (ZCTAs) for statistical mapping, which are approximations of the general boundaries of USPS ZIP Codes.


🤝 Contributing & License

Contributing

We welcome contributions! Please feel free to submit issues or pull requests to improve the library or update the data.

License

Distributed under the ISC License. Copyright (c) 2025 Shishir Raven.