JSPM

zip-code-to-state

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q10401F
  • License MIT

Get US state/territory from ZIP code

Package Exports

  • zip-code-to-state
  • zip-code-to-state/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (zip-code-to-state) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

zip-code-to-state

ZIP codes are tricky. You can usually tell which state a ZIP code is in by looking at the first two digits (19 is Pennslyvania, 90 is California, etc.)

But sometimes these two-digit prefixes are split across several states. 19xxx, for instance, has ZIP codes in Pennsylvania, but also Delaware and Maryland

This uses a USPS dataset to build a small matching table of ZIP codes with shared prefixes or other oddities. This means we can tell the user exactly where each Zip code is located without querying all 40,000+.

(There are about a dozen ZIP codes that span multiple states. In these cases, the library returns an error.)

Installation

npm install zip-code-to-state

Usage

const getStateFromZip = require('get-state-from-zip');
console.log(getStateFromZip('90210')); // Returns 'CA'
console.log(getStateFromZip('19701')); // Returns 'DE'

API

getStateFromZip(zipCode)

Returns a two-letter state/territory abbreviation for a given ZIP code.

  • zipCode (string): A 5-digit US ZIP code
  • Returns: String (two-letter state/territory abbreviation) or null if invalid/not found