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 · 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

NameTypeDescription
codestring
codesreadonly string[]
namestring
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"
221B

What it prints (run when this page was built)

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