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

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

NameTypeDescription
textstring

The text, such as Anytown NY.

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)

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