import { Pipe, PipeTransform } from '@angular/core';

/**
 * Convert string tu postcode format
 *
 * Usage:
 *   value | postcode
 * Example:
 *   {{ '55555' | postcode }}
 *   return 555 55
 */
@Pipe({name: 'postcode'})
export class PostCodePipe implements PipeTransform {
    transform(value: string): string {
        if (value && value.length === 5) {
            return value.replace(/^(\d{3})(\d{2})/, '$1 $2');
        }

        return value;
    }
}
