Socket
Book a DemoInstallSign in
Socket

zip3

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zip3

A dictionary of 3-digit zip code prefixes mapped to their corresponding metro area

1.0.4
latest
Source
npmnpm
Version published
Weekly downloads
185
16.35%
Maintainers
1
Weekly downloads
 
Created
Source

zip3

Background

Using the first three digits of a US zip code, you can roughly approximate which metropolitan area that zip code is associated with.

Demo

zip3 gif

Code Sandbox: https://codesandbox.io/s/zip3-demo-rj8oc

Data

https://en.wikipedia.org/wiki/List_of_ZIP_Code_prefixes

High Level Design

This package exports a dictionary where the keys are the three-digit zip code prefixes, and the values are objects containing id (the three-digit zip), city, and state (if available).

For example:

{
  "440": { "id": "440", "city": "Cleveland", "state": "OH" }
}

Usage

import { useState } from "react"
import zips from "zip3"

function MetroParser() {
  const [zip, setZip] = useState("90210")
  const shortenedZip = zip.slice(0, 3)
  const metroObject = zips[shortenedZip] || {}
  const { city, state } = metroObject
  const metroString = city && state ? `${city}, ${state}` : ""

  return (
    <div>
      <label>
        Zip code:
        <input
          type="number"
          placeholder="44114"
          value={zip}
          onChange={(e) => {
            const { value } = e.target
            setZip(value)
          }}
        ></input>
      </label>
      <p>Metro: {metroString}</p>
    </div>
  )
}

Keywords

zip code

FAQs

Package last updated on 30 Jun 2020

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.