jadpo

packages / @jadpo

@jadpo/uk-address-format

UK addresses from Royal Mail's Postcode Address File: a record's fragments laid out as Royal Mail's Clear Addressing guidelines say, as address lines, a post town and a postcode, with the premise, number and unit, and sorted as a street's addresses are.

Install
jadpo package add @jadpo/uk-address-format

Adds the newest version, skipping any that were withdrawn (yanked) and pre-releases such as 2.0.0-beta.1. --to 1.0.0 picks a version. Your app then calls it as UkAddressFormat.v1.

Use it in your app

@jadpo hasn't added a recipe to this package yet. A recipe is a working example of using the package in an app. After installing it, jadpo package show @jadpo/uk-address-format lists its operations (the calls it makes to an outside API), functions and types, and the guide on installing and using a package shows how to add one to your app.

What this package can do

  • Works only on the values your app gives itIt doesn't call any other service or store anything, so it can't change your database or send data anywhere.
  • Can fail in ways your app must handleOne function can fail: paf.format can fail with PostTownUnreadable and PostcodeOutsideGb. Your app must say what happens when it does, and it won't compile until it does.
  • Doesn't work with Jadpo 0.6.0, Jadpo's newest releaseIt works with 0.4.0 and 0.4.1. With 0.6.0 it fails the checks jadpo.dev runs on every version before it's published, such as compiling and passing its tests. jadpo.dev has emailed the errors to its publisher.0.4.0 · 0.4.1

jadpo.dev works out what this package can do from its code each time it checks a version, such as which services it calls and what personal data it sends, so the list doesn't depend on what its author says.

Guidewritten by @jadpo

Give paf.format a record as Royal Mail's Postcode Address File holds it, each field as the file writes it: an empty or blank field counts as left out, and a building number of 0 means none. Store the record's fields as they came, and the UkAddress it gives where you show or post the address: postal_address for a label or an envelope (text.format writes it in Great Britain's order), line_1 to line_3 for a form with three address lines, and premise, number and unit for search or display.

paf.format fails PostcodeOutsideGb when the postcode isn't in Great Britain's form, which a PAF record's never is; treat it as a record that didn't come from PAF. It fails PostTownUnreadable only for a post town with a line break or another control character in it.

Sort the addresses of one postcode or street with paf.sorted before offering them in a picker, so 2 comes before 10 and 10 before 10A.

What it offersgenerated from the package's code

Functions

Functions your app can call.

paf.format

A record laid out as an address: its lines, its post town in capitals and its postcode, as a `PostalAddress` in Great Britain, with the premise, number and unit on their own. A building name such as `12A` or `1-2` goes before the street, as Royal Mail's Exception Rule says, and a name ending in a range is split.

signature (record: PafAddress) -> UkAddress
fails PostTownUnreadable
fails PostcodeOutsideGb
paf.sorted

The addresses in the order their street numbers them: by building number (or a building or sub-building name the Exception Rule applies to), then building name, sub-building name, organisation, department and PO Box, each compared in its lower case with its runs of digits as numbers, so `2` comes before `10` and `10` before `10A`. Addresses that compare as equal keep their order.

signature (addresses: List<PafAddress>) -> List<PafAddress>

Types

The shapes of the values it takes and gives back.

AddressText= Text

Text laid out from a Postcode Address File record: an address line, a premise, a building number or a unit.

PafAddress= Input

A Postcode Address File record's fragments, as Royal Mail's PAF names them (with PAF's own spelling, `dependant`). Every field may be left out.

building_name: PafText? default none
building_number: PafText? default none
department_name: PafText? default none
dependant_locality: PafText? default none
dependant_thoroughfare: PafText? default none
double_dependant_locality: PafText? default none
organisation_name: PafText? default none
po_box: PafText? default none
post_town: PafText? default none
postcode: PostalCode? default none
sub_building_name: PafText? default none
thoroughfare: PafText? default none
PafText= Text

One field of a Postcode Address File record, as the file holds it. A field that is empty or only white space counts as left out.

UkAddress= Object

A Postcode Address File record laid out by Royal Mail's Clear Addressing rules. `line_1` to `line_3` are the premise and street lines, the third holding every line after the second, joined by `, `; the postal address holds those lines, the post town in capitals and the postcode.

line_1: AddressText?
line_2: AddressText?
line_3: AddressText?
number: AddressText?
postal_address: PostalAddress
premise: AddressText?
unit: AddressText?

Failures

The errors its calls can end with, which your app must handle.

PostTownUnreadable

The record's post town can't be one line of an address: it holds a line break or another control character, or is over 200 characters.

kind invalid_value
PostcodeOutsideGb

The record's postcode isn't in the form of a postcode in Great Britain.

kind invalid_value