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 · Australian country module

australiaconstant

Australia's module, for parseLocation and validateAddress: pass it in countries, and an address that ends with a state and its postcode (or Australia) is read as Australian; country: "AU" reads any address as one.

Import it

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

Definition

const australia: CountryModule = {
    code: "AU",
    codes: ["AU"],
    name: "Australia",
    detect: looksAustralian,
    parse: parseAustralianAddress,
    validate: validateAustralianAddress,
    format: (address) => formatAustraliaPost(address),
    compare: compareAustralianAddresses,
}

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 { australia } from "@johnmorrisdotca/address-plus/au";

console.log(parseLocation("3/12 Smith St, Parramatta NSW 2150", { countries: [australia] })?.secUnitNum);
// → "3"
3

What it prints (run when this page was built)

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