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

formatUSPSfunction

Writes a parsed address the way USPS Publication 28 asks: capitals, standard abbreviations, the unit on the street line, and the city, state and ZIP+4 on the last.

Import it

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

Definition

function formatUSPS(address: ParsedAddress, options?: USPSFormattingOptions): FormattedAddress

Parameters

NameTypeDescription
addressParsedAddress

The address, as parseLocation returns it.

options (optional)USPSFormattingOptions

USPS settings (see USPSFormattingOptions).

Returns

FormattedAddress

The address as lines and as one line.

Examples

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

const parsedAddress1=parseLocation("123 Main Street Apt 4, Anytown, NY 12345");
if (!parsedAddress1) throw new Error("The example address did not parse.");
console.log(formatUSPS(parsedAddress1).lines);
// → ["123 MAIN ST APT 4","ANYTOWN NY 12345"]
[ '123 MAIN ST APT 4', '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.