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

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

NameTypeDescription
postalCodestring

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"
QC

What it prints (run when this page was built)

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