Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Address

Index

Constructors

constructor

  • The Address class is designed to wrap a Postcode Address File (PAF) record and provide utility methods to make this data more readily consumable for humans

    Address requires an object of type AddressRecord to be instantiated which is comprised of fields readily found on PAF

    Address can be used to

    • Compute address lines based on premise and locality information
    • Sensibly compute a premise label based on (sub) building name and number
    • Sensibly sort an array of addresses
    example
    // Formatting an address
    
    const address = new Address({
        postcode: "WS11 5SB",
        post_town: "CANNOCK",
        dependant_locality: "",
        double_dependant_locality: "",
        thoroughfare: "Pye Green Road",
        building_number: "",
        building_name: "Flower House 189A",
        sub_building_name: "",
        dependant_thoroughfare: "",
        organisation_name: 'S D Alcott Florists',
    });
    
    console.log(address.formattedAddress());
    
    //
    //    {
    //        postcode: 'WS11 5SB',
    //        post_town: 'CANNOCK',
    //        line_1: 'S D Alcott Florists',
    //        line_2: 'Flower House',
    //        line_3: '189a Pye Green Road',
    //        premise: "Flower House, 189a"
    //    }
    //
    example
    // Formatting an address
    
    const addresses = await query("SELECT * FROM postcode_address_file LIMIT 10");
    
    addresses
        .map(address => new Address(address)) // Instantiate an `Address` instances
        .sort(Address.sort)                                    // Now sort
    
        // Print an example to console
        .forEach(address => console.log(address.line_1));
        // "190 Elm Road"
        // "190a Elm Road"
        // "191 Elm Road"
        // "191a Elm Road"
        // "192 Elm Road"
        // "193 Elm Road"
        // "193a Elm Road"
        // "197 Elm Road"
        // "197a Elm Road"
        // "199 Elm Road"

    Parameters

    Returns Address

Properties

Readonly administrative_county

administrative_county: string

Readonly building_name

building_name: string

Readonly building_number

building_number: string

cache

cache: FormattedAddress | null

Readonly country

country: string

Readonly county

county: string

Readonly delivery_point_suffix

delivery_point_suffix: string

Readonly department_name

department_name: string

Readonly dependant_locality

dependant_locality: string

Readonly dependant_thoroughfare

dependant_thoroughfare: string

Readonly district

district: string

Readonly double_dependant_locality

double_dependant_locality: string

Readonly eastings

eastings: number | EmptyString

Readonly latitude

latitude: number | EmptyString

Readonly longitude

longitude: number | EmptyString

Readonly merge_sub_and_building

merge_sub_and_building: boolean

Readonly northings

northings: number | EmptyString

Readonly organisation_name

organisation_name: string

Readonly po_box

po_box: string

Readonly post_town

post_town: string

Readonly postal_county

postal_county: string

Readonly postcode

postcode: string

Readonly postcode_inward

postcode_inward: string

Readonly postcode_outward

postcode_outward: string

Readonly postcode_type

postcode_type: string

Readonly su_organisation_indicator

su_organisation_indicator: string

Readonly sub_building_name

sub_building_name: string

Readonly thoroughfare

thoroughfare: string

Readonly traditional_county

traditional_county: string

Readonly udprn

udprn: number | EmptyString

Readonly umprn

umprn: number | EmptyString

Readonly ward

ward: string

Accessors

line_1

  • get line_1(): string
  • Returns string

line_2

  • get line_2(): string
  • Returns string

line_3

  • get line_3(): string
  • Returns string

premise

  • get premise(): string
  • Returns string

Methods

formattedAddress

  • Returns an object representing an address with sensibly computed address line labels according to Royal Mail's formatting rules

    Returns FormattedAddress

toJSON

  • Returns a complete JSON representation of the Address instance

    Returns AddressJSON

Static formatPostcode

  • formatPostcode(postcode: string): string
  • Parameters

    • postcode: string

    Returns string

Static sort

  • A function which allow two Address objects to be compared. This function can be readily fed into Array.prototype.sort

    example
    addresses.sort(Address.sort)

    Parameters

    Returns number