File

projects/maplander/components/src/lib/pipes/address/address-format.pipe.ts

Metadata

Name addressFormat

Methods

transform
transform(value: Address, long?: boolean, country?: string)
Parameters :
Name Type Optional
value Address No
long boolean Yes
country string Yes
Returns : string
import {Pipe, PipeTransform} from '@angular/core';
import {Address} from '@maplander/types';

@Pipe({
  name: 'addressFormat'
})
export class AddressFormatPipe implements PipeTransform {

  transform(value: Address, long?: boolean, country?: string): string {
    let result = '';
    const language = country || 'mx';
    result += value.street;
    switch (language) {
      case 'mx':
        if (long) {
          result += `, ${value.colony || ''}`;
          result += `, ${value.postalCode || ''}`;
          result += `, ${value.city || ''}`;
          result += `, ${value.state || ''}`;
          result += `, ${value.country || ''}`;
        } else {
          result += value.street;
          result += `, ${value.colony || ''}`;
        }
        break;
      case 'usa':
        if (long) {
          result += `, ${value.city || ''}`;
          result += `, ${value.state || ''}`;
          result += `, ${value.postalCode || ''}`;
          result += `, ${value.country || ''}`;
        } else {
          result += value.street;
          result += `, ${value.city || ''}`;
          result += `, ${value.state || ''}`;
        }
        break;
    }
    return result;
  }

}

result-matching ""

    No results matching ""