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

@mardillu/us-cities-utils

v1.2.7

Published

A lightweight TypeScript utility library to work with US cities and ZIP codes — perfect for filters, maps, address lookups, and geolocation logic.

Readme

Publish Package to NPM Publish Package to Github Run Unit Tests

US Cities & Zipcode Utilities

A lightweight TypeScript utility library to work with US cities and ZIP codes — perfect for filters, maps, address lookups, and geolocation logic.


Features

  • 🔍 Get states and cities from a normalized dataset
  • 📬 Lookup city data by ZIP code
  • 🗺️ Find the nearest city by coordinates (lat/lon)
  • 🏙️ Search cities by name (fuzzy search)
  • 📌 Filter cities by state, county, or ZIP
  • 📦 Pure, fast, and dependency-free

Installation

npm install @mardillu/us-cities-utils
# or
yarn add @mardillu/us-cities-utils

Usage

import {
  getStates,
  getCities,
  getCity,
  getAllZips,
  searchCities,
  groupCitiesByState,
  getCitiesByCounty,
  getNearestCity
} from '@mardillu/us-cities-utils';

API Reference

getStates(): UsState[]

Returns a list of all US states in { nameAbbr: string, name: string } format.


getCities(stateAbbr: string): UsCity[]

Returns all cities in a given state abbreviation (e.g. 'NY', 'CA').


getCitiesBySateName(state): UsCity[]

Returns all cities in a given state name (e.g. 'New York', 'California').


getZipcodes(stateAbbr): UsCity[]

Returns all cities and zipcodes in a given state abbreviation (e.g. 'NY', 'CA').


getZipcodesBySateName(state): UsCity[]

Returns all cities and zipcodes in a given state name (e.g. 'New York', 'California').


getCity(zip: string): UsCity | undefined

Returns city information for a given ZIP code.


searchCities(query: string): UsCity[]

Returns cities whose names match (or partially match) the search string.


searchCitiesInSate(stateAbbr: string, query: string): UsCity[]

Returns cities whose names match (or partially match) the search string withing the provided state abbreviation.


searchCitiesInSateByStateName(state: string, query: string): UsCity[]

Returns cities whose names match (or partially match) the search string withing the provided state name.


groupCitiesByState(): Record<string, UsCity[]>

Groups all cities in the dataset by their state abbreviation.


getAllZips(): string[]

Returns a list of all ZIP codes in the dataset.


getCitiesByCounty(county: string): UsCity[]

Returns a list of cities belonging to a given county name.


getNearestCity(lat: number, lon: number): UsCity | undefined

Finds and returns the city nearest to the given latitude and longitude using the Haversine formula.


Testing

npm test

Includes robust unit tests for all exported functions and geolocation logic.


Data Format

Each city is in the format:

interface UsCity {
  zip: string;
  name: string;
  state: string;
  stateAbbr: string;
  county: string;
  countCode: string;
  latitude: number;
  longitude: number;
}

Roadmap

  • [ ] Add support for Canadian provinces
  • [ ] Add caching for nearest city lookup
  • [ ] Add fuzzy scoring to searchCities()

Contribution

PRs are welcome! If you'd like to contribute, open an issue or submit a PR.


License

MIT © \Mardillu