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

compareAddressesfunction

Compares two parsed addresses field by field, allowing for abbreviations (Street and St), state names and codes, letter case and small typos.

Import it

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

Definition

function compareAddresses(address1: ParsedAddress, address2: ParsedAddress, options?: AddressComparisonOptions): AddressComparisonResult

Parameters

NameTypeDescription
address1ParsedAddress

The first address, as parseLocation returns it.

address2ParsedAddress

The second address.

options (optional)AddressComparisonOptions

How to compare: which parts to ignore and how close a fuzzy match must be (see AddressComparisonOptions).

Returns

AddressComparisonResult

Whether they are the same place, how strong the match is (exact to none), the similarity score from 0 to 1 and every difference found.

Examples

import { compareAddresses, 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.");
const parsedAddress2=parseLocation("123 Main St, Anytown, New York 12345");
if (!parsedAddress2) throw new Error("The example address did not parse.");
console.log(compareAddresses(parsedAddress1, parsedAddress2).matchType);
// → "exact"
exact

What it prints (run when this page was built)

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