Reference · Parsing, formatting and shared types
parseStateProvincefunction
Takes a US state or Canadian province off the end of a text, by code or by name.
Import it
import { parseStateProvince } from "@johnmorrisdotca/address-plus";
Definition
function parseStateProvince(text: string): { state: string | undefined; remaining: string; detectedCountry?: "US" | "CA"; }
Parameters
| Name | Type | Description |
|---|---|---|
text | string | The text, such as |
Returns
{ state: string | undefined; remaining: string; detectedCountry?: "US" | "CA"; }
The two-letter code (undefined when there is none), the text that remains, and the country it points to.
Examples
import { parseStateProvince } from "@johnmorrisdotca/address-plus";
console.log(parseStateProvince("Anytown NY"));
// → {"state":"NY","remaining":"Anytown","detectedCountry":"US"}{ state: 'NY', remaining: 'Anytown', detectedCountry: 'US' }What it prints (run when this page was built)