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-codes-api

v0.1.0

Published

TypeScript/JavaScript client for the ZIP Codes API — US & Canadian postal data: address validation + ZIP+4, ZIP/postal & place autocomplete, radius search, distance, and 14 years of Census ACS demographics. Isomorphic, zero dependencies.

Readme

zip-codes-api

TypeScript/JavaScript client for the ZIP Codes API — US & Canadian postal data: address validation + ZIP+4, ZIP/postal lookups, ZIP/postal & place autocomplete, radius search, distance, and 14 years of US Census ACS demographics.

Isomorphic (browser + Node 18+), zero runtime dependencies (uses native fetch), fully typed.

npm install zip-codes-api
import { ZipCodesClient } from "zip-codes-api";

// Public demo key works for demo codes (90210, 10001, M5V, ...). For everything else,
// get a free key at https://www.zip-codes.com/api/signup (2,500 credits/day, no card).
const client = new ZipCodesClient({ apiKey: "zc_test_DEMOAPIKEY000000000000" });

Single-target methods return the first result object; batch methods return the array of results. Pass { raw: true } for the full envelope. client.lastMeta holds the most recent response's meta (including credits).

Address validation + ZIP+4

address() validates and standardizes a US street address and appends ZIP+4. result.matches holds the candidate standardizations (more than one if the input is ambiguous) — for checkout, CRM intake, and mailing-list cleanup:

const res = await client.address("200 N Spring St, Los Angeles CA 90012");
const best = res.matches[0];
console.log(best.zip, best.zip4, best.delivery_point);

ZIP / postal code & place autocomplete

suggest() is a typo-tolerant typeahead for ZIP/postal codes and place names (not street addresses) — good for a code or city picker. Suggestions are in result.matches:

const res = await client.suggest("9021", { limit: 8, country: "US" });
for (const m of res.matches) console.log(m.name, m.state);
// Debounced ZIP / place picker (React/Vue/vanilla)
let t: ReturnType<typeof setTimeout>;
input.addEventListener("input", () => {
  clearTimeout(t);
  t = setTimeout(async () => {
    const { matches } = await client.suggest(input.value, { limit: 8 });
    render(matches); // ZIP codes / cities matching what the user typed
  }, 150);
});

ZIP / postal lookups

await client.quickZip("M5V");                 // Canadian FSA → city/province/coords
const z = await client.zip("90210", { include: ["timezone", "acs_demographic"] });
console.log(z.city, z.acs.current.demographic.sex_and_age.median_age.est);

Distance & radius

const d = await client.distance("90210", "10001");
console.log(d.distance.miles, d.bearing);

// Spatial mode: ACS aggregate in result.stats is coverage-weighted by each ZIP's pct_inside.
const r = await client.radius("90210", { max: 10, mode: "spatial", include: "acs_demographic" });
console.log(r.stats.acs.current.demographic.sex_and_age.total_population.est, "people within 10 mi");

Batch (up to 100; paid subscription key)

const rows = await client.zipBatch(["90210", "10001", "M5V"], { include: "timezone" });

Errors

Failures throw typed errors carrying the API's code, status, and requestId:

import { RateLimitError, InsufficientCreditsError, ValidationError } from "zip-codes-api";

try {
  await client.suggest("9021");
} catch (e) {
  if (e instanceof RateLimitError) console.log("retry after", e.retryAfter, "s");
  else if (e instanceof InsufficientCreditsError) { /* top up */ }
  else if (e instanceof ValidationError) console.log(e.code, e.message);
  else throw e;
}

The client retries 429 / 5xx automatically (honoring Retry-After), up to maxRetries (default 2).

Options

new ZipCodesClient({
  apiKey: "zc_live_...",
  baseUrl: "https://api.zip-codes.com", // default
  timeoutMs: 30000,                      // default
  maxRetries: 2,                         // default
  fetch: customFetch,                    // optional (Node < 18 polyfill)
});

Browser note

The API allows cross-origin requests. Don't ship a zc_live_ key in client-side code — front-end usage should call through your own backend, or use a key with per-key origin/IP restrictions configured in the API portal.

Links

License

MIT.