Reference · Parsing, formatting and shared types
formatCanadaPostfunction
Writes a parsed address the way Canada Post asks: capitals, the unit before the civic number joined by a hyphen, and the postal code two spaces after the province.
Import it
import { formatCanadaPost } from "@johnmorrisdotca/address-plus";
Definition
function formatCanadaPost(address: ParsedAddress, options?: CanadaPostFormattingOptions): FormattedAddress
Parameters
| Name | Type | Description |
|---|---|---|
address | ParsedAddress | The address, as |
options (optional) | CanadaPostFormattingOptions | Canada Post settings (see |
Returns
FormattedAddress
The address as lines and as one line.
Examples
import { formatCanadaPost, parseLocation } from "@johnmorrisdotca/address-plus";
const parsedAddress1=parseLocation("100 Queen Street West, Toronto, Ontario M5H 2N2");
if (!parsedAddress1) throw new Error("The example address did not parse.");
console.log(formatCanadaPost(parsedAddress1).lines);
// → ["100 QUEEN ST W","TORONTO ON M5H 2N2"][ '100 QUEEN ST W', 'TORONTO ON M5H 2N2' ]What it prints (run when this page was built)