Reference · British country module
unitedKingdomconstant
The United Kingdom's module, for parseLocation and validateAddress: pass it in countries, and an address with a
British postcode (or ending with the United Kingdom or a nation) is read as British; country: "GB" reads any
address as one. It reads Jersey (JE), Guernsey (GY) and the Isle of Man (IM) too.
Import it
import { unitedKingdom } from "@johnmorrisdotca/address-plus/gb";
Definition
const unitedKingdom: CountryModule = {
code: "GB",
codes: ["GB", "JE", "GY", "IM"],
name: "United Kingdom",
detect: looksBritish,
parse: parseUKAddress,
validate: validateUKAddress,
format: (address) => formatRoyalMail(address),
compare: compareUKAddresses,
}
Members
| Name | Type | Description |
|---|---|---|
code | string | |
codes | readonly string[] | |
name | string | |
detect | (address: string): boolean | |
parse | (address: string, options?: ParseOptions): ParsedAddress | null | |
validate | (address: ParsedAddress, options?: ValidationOptions): CountryValidation | |
format | (address: ParsedAddress): FormattedAddress | |
compare | (first: ParsedAddress, second: ParsedAddress): CountryComparison |
Examples
import { parseLocation } from "@johnmorrisdotca/address-plus";
import { unitedKingdom } from "@johnmorrisdotca/address-plus/gb";
console.log(parseLocation("221B Baker Street, London NW1 6XE", { countries: [unitedKingdom] })?.number);
// → "221B"221BWhat it prints (run when this page was built)