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
| Name | Type | Description |
|---|---|---|
result | ParsedAddress | ParsedIntersection | The parsed address or intersection to set the code on. |
zipCode | string | The code as written. |
options | 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)