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

AddressFormattingOptionstype

Options for formatAddress and cleanAddress: what to abbreviate, capitals, the unit, the country and the line separator.

Import it

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

Definition

interface AddressFormattingOptions {
    includeCountry?: boolean;
    includeSecondaryUnit?: boolean;
    upperCase?: boolean;
    separator?: string;
    abbreviateStreetTypes?: boolean;
    abbreviateDirections?: boolean;
    abbreviateStates?: boolean;
    usePlusCode?: boolean;
}

Members

NameTypeDescription
includeCountry (optional)boolean | undefined
includeSecondaryUnit (optional)boolean | undefined
upperCase (optional)boolean | undefined
separator (optional)string | undefined
abbreviateStreetTypes (optional)boolean | undefined
abbreviateDirections (optional)boolean | undefined
abbreviateStates (optional)boolean | undefined
usePlusCode (optional)boolean | undefined

Examples

import { formatAddress, parseLocation } from "@johnmorrisdotca/address-plus";
import type { AddressFormattingOptions } 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, { upperCase: true }).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.