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

parsePostalCodefunction

Takes a ZIP code, ZIP+4 or Canadian postal code off the end of a text.

Import it

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

Definition

function parsePostalCode(text: string): { zip: string | undefined; plus4: string | undefined; remaining: string; detectedCountry?: "US" | "CA"; detectedProvince?: string; }

Parameters

NameTypeDescription
textstring

The text, such as Toronto ON M5H 2N2.

Returns

{ zip: string | undefined; plus4: string | undefined; remaining: string; detectedCountry?: "US" | "CA"; detectedProvince?: string; }

The code and its ZIP+4 (undefined when there is none), the text that remains, and the country and province the code points to.

Examples

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

console.log(parsePostalCode("Toronto ON M5H 2N2"));
// → {"zip":"M5H 2N2","remaining":"Toronto ON","detectedCountry":"CA","detectedProvince":"ON"}
{
  zip: 'M5H 2N2',
  plus4: undefined,
  remaining: 'Toronto ON',
  detectedCountry: 'CA',
  detectedProvince: 'ON'
}

What it prints (run when this page was built)

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