1.2.5 • Published 3 years ago

zip2state v1.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago