Skip to the content

address-plusアドレスプラス

Parse, validate, format and compare addresses locally, add country modules and mount an optional native form field.

address-plus extends the parse-address style with typed results, validation, formatting and country modules. About the name

Contents

Reference · Parsing, formatting and shared types

getStateFromZipfunction

The state or territory a US ZIP code is in.

Import it

import { getStateFromZip } from "@johnmorrisdotca/address-plus";

Definition

function getStateFromZip(zip: string | number): StateCode | undefined

Parameters

NameTypeDescription
zipstring | number

A five-digit ZIP or a ZIP+4, as a string or a number (a number loses its leading zeros, which are put back).

Returns

StateCode | undefined

The two-letter code, or undefined for a ZIP no state uses or a malformed one.

Examples

import { getStateFromZip } from "@johnmorrisdotca/address-plus";

console.log(getStateFromZip("98101"));
// → "WA"
WA

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/address-plus 1.7.0.