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

setValidatedPostalCodefunction

Sets a ZIP or postal code on a result, the way the parsers do: split into ZIP and ZIP+4, a Canadian code in capitals with one space, with zipValid set, and in strict mode only when the code is well formed. It changes the object it is given.

Import it

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

Definition

function setValidatedPostalCode(result: ParsedAddress | ParsedIntersection, zipCode: string, options: ParseOptions): void

Parameters

NameTypeDescription
resultParsedAddress | ParsedIntersection

The parsed address or intersection to set the code on.

zipCodestring

The code as written.

optionsParseOptions

strict keeps a malformed code out (see ParseOptions).

Examples

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

const parsed = { city: "Toronto", state: "ON" };
setValidatedPostalCode(parsed, "m5h2n2", {});
console.log(parsed);
// → {"city":"Toronto","state":"ON","zip":"M5H 2N2"}
{ city: 'Toronto', state: 'ON', zip: 'M5H 2N2' }

What it prints (run when this page was built)

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