Skip to main content

Overview

The UBL Builder library provides two main address classes:
  • Address - A comprehensive address class with detailed location information
  • PostalAddress - A simplified postal address class focused on mailing addresses
Both classes are used throughout UBL documents to represent physical locations for parties, deliveries, and other purposes.

Address Class

Import

import { Address } from 'ubl-builder/lib/ubl21/CommonAggregateComponents';

Constructor Parameters

id
string | UdtIdentifier
An identifier for this address within an agreed scheme of address identifiers
cityName
string | UdtName
The name of a city, town, or village
countrySubentity
string | UdtText
The political or administrative division of a country in which this address is located, such as the name of its county, province, or state
countrySubentityCode
string | UdtCode
The political or administrative division of a country expressed as a code
addressLines
AddressLine[]
An array of unstructured address lines
country
Country
The country in which this address is situated

Methods

addAddressLine()

Adds an address line to the address.
addAddressLine(value: string | AddressLine): void

setCountry()

Sets the country for the address.
setCountry(value: string | Country): void

setId()

Sets an identifier for the address.
setId(value: string | UdtIdentifier, attributes: UdtIdentifierAttributes): void

Example

import { Address, Country } from 'ubl-builder/lib/ubl21/CommonAggregateComponents';

const address = new Address({
  cityName: 'San Francisco',
  countrySubentity: 'California',
  addressLines: []
});

address.addAddressLine('100 Market Street');
address.addAddressLine('Suite 300');
address.setCountry('United States');

PostalAddress Class

Import

import { PostalAddress } from 'ubl-builder/lib/ubl21/CommonAggregateComponents';

Constructor Parameters

streetName
string | UdtText
required
The main address line in an address (e.g., “Main Street 1”)
cityName
string | UdtText
required
The common name of the city, town or village where the address is located
postalZone
string | UdtText
required
The identifier for an addressable group of properties according to the relevant postal service (e.g., ZIP code, Post Code)
AdditionalStreetName
string | UdtText
An additional address line that can be used to give further details supplementing the main line (e.g., “Po Box 351”)
countrySubentity
string | UdtText
The subdivision of a country (e.g., “Region A”)
addressLine
string | UdtText
Additional unstructured address line
country
Country
The country in which this address is situated

Usage Examples

import { PostalAddress } from 'ubl-builder/lib/ubl21/CommonAggregateComponents';

const postalAddress = new PostalAddress({
  streetName: '123 Main Street',
  cityName: 'New York',
  postalZone: '10001'
});
The PostalAddress class is more commonly used in invoices and is specifically designed for standard postal addresses. The Address class provides more flexibility with additional fields for complex addressing scenarios.

Exported Aliases

Both classes are exported under multiple semantic aliases:

Address Aliases

  • RegistrationAddress
  • JurisdictionRegionAddress
  • DeliveryAddress
  • DespatchAddress
These aliases all reference the same Address class but provide semantic meaning based on their usage context.
  • Party - Uses addresses for party locations
  • Delivery - Uses addresses for delivery locations
  • Country - Represents country information
  • AddressLine - Represents individual address lines

UBL Schema Reference

Build docs developers (and LLMs) love