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

getAddressSimilarityfunction

The similarity of two parsed addresses, part by part, without a verdict: the score and each part's score, and the differences.

Import it

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

Definition

function getAddressSimilarity(address1: ParsedAddress, address2: ParsedAddress, options?: AddressComparisonOptions): AddressSimilarityResult

Parameters

NameTypeDescription
address1ParsedAddress

The first address, as parseLocation returns it.

address2ParsedAddress

The second address.

options (optional)AddressComparisonOptions

How to compare (see AddressComparisonOptions).

Returns

AddressSimilarityResult

The overall score from 0 to 1, the street, city, state and postal scores, and each difference with its kind.

Examples

import { getAddressSimilarity, 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("125 Main Street, Anytown, NY 12345");
if (!parsedAddress2) throw new Error("The example address did not parse.");
console.log(getAddressSimilarity(parsedAddress1, parsedAddress2).differences);
// → [{"field":"number","value1":"123","value2":"125","type":"typo","confidence":0.6}]
[
  {
    field: 'number',
    value1: '123',
    value2: '125',
    type: 'typo',
    confidence: 0.6
  }
]

What it prints (run when this page was built)

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