Represents a physical address.

Address is immutable and validates required fields. Provides formatting and comparison capabilities.

const result = Address.create({
street: '123 Main St',
city: 'San Francisco',
state: 'CA',
postalCode: '94102',
country: 'USA'
});
if (result.isSuccess) {
const address = result.value;
console.log(address.format());
}

Hierarchy (View Summary)

Methods

  • Compares this Value Object with another for equality. Value Objects are equal if they are of the same type and all equality components match.

    Parameters

    • other: ValueObject

      The other Value Object to compare with

    Returns boolean

    true if the Value Objects are equal, false otherwise

  • Formats the address as a single line string.

    Returns string

    A formatted address string

    const address = Address.create({
    street: '123 Main St',
    city: 'San Francisco',
    state: 'CA',
    postalCode: '94102',
    country: 'USA'
    }).unwrap();
    console.log(address.format());
    // "123 Main St, San Francisco, CA 94102, USA"
  • Formats the address as a multi-line string.

    Returns string

    A multi-line formatted address string

    const address = Address.create({
    street: '123 Main St',
    city: 'San Francisco',
    state: 'CA',
    postalCode: '94102',
    country: 'USA',
    additionalInfo: 'Apt 4B'
    }).unwrap();
    console.log(address.formatMultiline());
    // 123 Main St
    // Apt 4B
    // San Francisco, CA 94102
    // USA
  • Checks if this address is in the same city as another address.

    Parameters

    • other: Address

      The other address to compare

    Returns boolean

    true if both addresses are in the same city

    const addr1 = Address.create({...}).unwrap();
    const addr2 = Address.create({...}).unwrap();
    console.log(addr1.isSameCity(addr2));
  • Checks if this address is in the same country as another address.

    Parameters

    • other: Address

      The other address to compare

    Returns boolean

    true if both addresses are in the same country

    const addr1 = Address.create({...}).unwrap();
    const addr2 = Address.create({...}).unwrap();
    console.log(addr1.isSameCountry(addr2));

Properties

street: string
city: string
state: string
postalCode: string
country: string
additionalInfo?: string