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

zipcode-detail-lookup

v1.1.5

Published

Given a US Zip Code, this program returns the associated State, County, City, and other useful information. It also supports querying and returning broader location demographic information using fields like city, state, county, population size, and milita

Downloads

2,036

Readme

zipcode-detail-lookup

Build Status

Line Coverage Statement Coverage Function Coverage Branch Coverage

Given a US zip code, provided or random, this program returns the associated State, County, City, and other useful information; latitude, longitude, density, population, military designation, timezone. Also, provides ability to search for zip codes using population size, state, county, city, latitude, and longitude. Last, the ability is provided to calculate the miles or kilometers between two zip codes.

The data source contains US states and territories.

The database is originally derived from the 2024 free-tier list provided by SimpleMaps https://simplemaps.com/data/us-zips.

Installation

Install zipcode-detail-lookup as a dependency in your project.

npm install zipcode-detail-lookup --save

After, import it into your code at the top of your project

import {
  lookupZip,
  lookupZipsWith,
  randomZip,
  distanceBetweenZips,
} from 'zipcode-detail-lookup';

Usage

Zip Code Lookup provides 3 functions; lookupZip, randomZip, searchBy, and distanceBetweenZips. zip and random return a single zip code object result whereas searchBy will return an array of matches. distanceBetweenZips returns the distance between two zipes codes in miles or kilometers using their associated latitude and longitude.

lookupZip(zipCode: string)

const fll = lookupZip(33316); // For returning an object for the 33316 Ft. Lauderdale zip code.
console.log(fll.state); // Florida
console.log(fll.stateAbbreviation); // FL
console.log(fll.county); // Broward
console.log(fll.city); // Fort Lauderdale

randomZip()

This will return a random zip code from the data set and will include all the properties as mentioned in the previous example (state, city, county, demographics, location, etc.)

const rZip = randomZip();

console.log(rZip.zip); // Random zip code e.g. 11122

lookupZipsWith({...searchParams: ISearchParams})

This method will let you search for any optional combination of criteria involving city, county, stateName, stateAbbreviation, military classification, and population count.

// To return an array of results matching the state abbreviation FL with population greather than 27000.
const searchResults = lookupZipsWith({
  stateAbbreviation: 'FL',
  population: 27000,
  populationOperator: '>',
});

You can optionally use any combination of these settings exposed on the interface.

interface ISearchParams {
  city?: string;
  county?: string;
  stateName?: string;
  stateAbbreviation?: string;
  militaryZip?: boolean;
  population?: number;
  populationOperator?: '<' | '>' | '=';
}

distanceBetweenZips(firstZipCode: string, secondZipCode: string, distanceInMiles = true)

Provided two zip codes, distanceBetweenZips will return the direct distance between their associated latitude and longitude taking into account the approximate curvature of the Earth.

const newYork = '10001';
const losAngeles = '90001';

const distanceInMiles = distanceBetweenZips(newYork, losAngeles, true); // --> 2448.350696991183
const distanceInKilometers = distanceBetweenZips(newYork, losAngeles, false); // --> 3940.239723114183

Available Properties

The following demographic information is exposed in the ZipCode result objects returned singly or in array form from the searchBy method.

{
  'zip': string;
  'latitude': number;
  'longitude': number;
  'city': string;
  'stateName': string;
  'stateAbbreviation': string;
  'zcta': boolean;
  'parent_zcta': string;
  'population': number | null;
  'density': number | null;
  'county_fips': number;
  'county': string;
  'county_weights': any;
  'county_names_all': string;
  'county_fips_all': string;
  'imprecise': boolean;
  'militaryZip': boolean;
  'timezone': string;
}