Reference · Parsing, formatting and shared types
getProvinceFromPostalCodefunction
The province or territory a Canadian postal code is in, from its first letter, and for the X codes of the north, its first three characters.
Import it
import { getProvinceFromPostalCode } from "@johnmorrisdotca/address-plus";
Definition
function getProvinceFromPostalCode(postalCode: string): string | null
Parameters
| Name | Type | Description |
|---|---|---|
postalCode | string | The postal code, with or without its space. |
Returns
string | null
The two-letter code, or null for a code that is not Canadian.
Examples
import { getProvinceFromPostalCode } from "@johnmorrisdotca/address-plus";
console.log(getProvinceFromPostalCode("H3G 1P1"));
// → "QC"QCWhat it prints (run when this page was built)