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
| Name | Type | Description |
|---|---|---|
address1 | ParsedAddress | The first address, as |
address2 | ParsedAddress | The second address. |
options (optional) | AddressComparisonOptions | How to compare: which parts to ignore and how close a fuzzy match must be (see
|
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"exactWhat it prints (run when this page was built)