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
| Name | Type | Description |
|---|---|---|
zip | string | 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"WAWhat it prints (run when this page was built)