Socket
Book a DemoInstallSign in
Socket

zip2state

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zip2state

Automatically & reliably derive US states from postal zip codes (<5k).

latest
Source
npmnpm
Version
1.2.5
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created
Source

Zip2State

Zip2State is a function that uses an optimized zip code library to automatically & reliably derive a US state from a zip code, all for under 3k.

Animation of text input

Demo: https://meandmybadself.github.io/zip2state/

Why?

If we can reliably determine a user's state from their zip code, why have them enter both?

Current client-side solutions involve:

  • Loading all zipcodes & city/states (big file size)
  • Interacting with an API (not great for client-only solutions)

How?

Reduce entire ranges of a state's zipcodes (eg 94000-94999) into their base root (94) where possible.

Assumptions

  • Zip codes don't move between states (See Update)
  • New zip codes are added using existing numeric prefixes

Update

A zip code can be shared across states. (Reference link)

Installation

npm i zip2state

NPM Scripts

ScriptDescription
devStarts up local development process
buildBuilds component
parseParses zip code CSV into zip-state.txt

Usage

Function accepts a string (could be a partial zipcode). Returns a two-letter US state code or '' if no state was found.

import zip2state from 'zip2state'

const partialZip = zip2state('94')
console.log(partialZip) // 'CA'

const fullZip = zip2state('44446')
console.log(fullZip) // 'OH'

const fakeState = zip2state('00000')
console.log(fakeState) // ''

Data Attribution

Uses Coven, D. S., (2012). Free Zipcode Database: Unique Zipcode [data file]. Retrieved from http://federalgovernmentzipcodes.us

Keywords

zipcode

FAQs

Package last updated on 13 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts