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

detectCountryfunction

Which country a parsed address is in, from its postal code, then its state or province.

Import it

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

Definition

function detectCountry(address: ParsedAddress): "US" | "CA" | undefined

Parameters

NameTypeDescription
addressParsedAddress

The parsed address, or any object with its zip and state.

Returns

"CA" | "US" | undefined

US or CA, or undefined when nothing says.

Examples

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

console.log(detectCountry({ zip: "M5H 2N2" }));
// → "CA"
CA

What it prints (run when this page was built)

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