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

/**
 * Convert string tu phone format
 *
 * Usage:
 *   value | phone
 * Example:
 *   {{ '777777777' | phone }}
 *   return +420 777 777 777
 */
@Pipe({ name: 'phone' })
export class PhonePipe implements PipeTransform {
    transform(value: string): string {
        if (value && value.length === 9) {
            return value.replace(/(\d{3})(\d{3})(\d{3})/, '+420 $1 $2 $3');
        }

        return value;
    }
}
