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 · 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

NameTypeDescription
postcodestring

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)

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