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

FormattedAddresstype

A formatted address: its lines, and the same on one line.

Import it

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

Also exported from: @johnmorrisdotca/address-plus/gb, @johnmorrisdotca/address-plus/de, @johnmorrisdotca/address-plus/fr, @johnmorrisdotca/address-plus

Definition

interface FormattedAddress {
    lines: string[];
    singleLine: string;
    deliveryLine?: string;
    lastLine?: string;
    country?: string;
    format: "standard" | "usps" | "canada-post" | "international" | "australia-post" | "royal-mail" | "la-poste" | "deutsche-post";
}

Members

NameTypeDescription
linesstring[]
singleLinestring
deliveryLine (optional)string | undefined
lastLine (optional)string | undefined
country (optional)string | undefined
format"standard" | "usps" | "canada-post" | "international" | "australia-post" | "royal-mail" | "la-poste" | "deutsche-post"

Examples

import { formatUSPS, parseLocation } from "@johnmorrisdotca/address-plus";
import type { FormattedAddress } from "@johnmorrisdotca/address-plus/au";

const parsedAddress1=parseLocation("123 Main St, Anytown, NY 12345");
if (!parsedAddress1) throw new Error("The example address did not parse.");
console.log(formatUSPS(parsedAddress1));
// → {"lines":["123 MAIN ST","ANYTOWN NY 12345"],"singleLine":"123 Main St, Anytown NY 12345","deliveryLine":"123 Main St","lastLine":"Anytown NY 12345","country":"US","format":"usps"}
{
  lines: [ '123 MAIN ST', 'ANYTOWN NY 12345' ],
  singleLine: '123 Main St, Anytown NY 12345',
  deliveryLine: '123 Main St',
  lastLine: 'Anytown NY 12345',
  country: 'US',
  format: 'usps'
}

What it prints (run when this page was built)

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