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

formatAddressfunction

Writes a parsed address back out as lines and as one line, with abbreviations or in full.

Import it

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

Definition

function formatAddress(address: ParsedAddress, options?: AddressFormattingOptions): FormattedAddress

Parameters

NameTypeDescription
addressParsedAddress

The address, as parseLocation returns it.

options (optional)AddressFormattingOptions

How to write it: abbreviated or in full, the letter case, the country (see AddressFormattingOptions).

Returns

FormattedAddress

The address as an array of lines and as one line.

Examples

import { formatAddress, parseLocation } from "@johnmorrisdotca/address-plus";

const parsedAddress1=parseLocation("123 Main Street, Anytown, NY 12345");
if (!parsedAddress1) throw new Error("The example address did not parse.");
console.log(formatAddress(parsedAddress1).singleLine);
// → "123 Main St, Anytown NY 12345"
123 Main St, Anytown NY 12345

What it prints (run when this page was built)

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