Giter Club home page Giter Club logo

zip2state's Introduction

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

Script Description
dev Starts up local development process
build Builds component
parse Parses 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

zip2state's People

Contributors

meandmybadself avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.