Reference · British country module
parseUKPostcodefunction
Takes a postcode apart: outward code, inward code, area, district and sector, and says where it delivers: the
country (GB, or JE, GY or IM for the Crown Dependencies) and, in the United Kingdom, the nation. A district
that crosses a border gives the nation most of its postcodes are in; getNationsForUKPostcode gives them all.
Import it
import { parseUKPostcode } from "@johnmorrisdotca/address-plus/gb";
Definition
function parseUKPostcode(postcode: string): UKPostcode | null
Parameters
| Name | Type | Description |
|---|---|---|
postcode | string | The postcode, in any letter case, with or without its space. |
Returns
UKPostcode | null
The parts, or null when it does not follow the grammar or its area is not one Royal Mail uses.
Examples
import { parseUKPostcode } from "@johnmorrisdotca/address-plus/gb";
console.log(parseUKPostcode("JE2 3AB"));
// → {"postcode":"JE2 3AB","outward":"JE2","inward":"3AB","area":"JE","district":"JE2","sector":"JE2 3","country":"JE"}{
postcode: 'JE2 3AB',
outward: 'JE2',
inward: '3AB',
area: 'JE',
district: 'JE2',
sector: 'JE2 3',
country: 'JE'
}What it prints (run when this page was built)