projects/maplander/components/src/lib/pipes/address/address-format.pipe.ts
Name | addressFormat |
transform |
transform(value: Address, long?: boolean, country?: string)
|
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;
}
}