/* Copyright CloudLinux Zug GmbH 2010-2017 All Rights Reserved
 *
 * Licensed under CLOUD LINUX LICENSE AGREEMENT
 * http://cloudlinux.com/docs/LICENSE.TXT
 */

import { Pipe, PipeTransform } from '@angular/core';
import * as linkifyStr from 'linkifyjs/string';

const linkifyOptions = {
  validate: {
    url: function (value) {
      return /^(http|ftp)s?:\/\//.test(value);
    }
  }
};

@Pipe({name: 'linkify'})
export class LinkifyPipe implements PipeTransform {
    transform(str: string): string {
        return typeof str === 'string' ? linkifyStr(str, linkifyOptions) : str;
    }
}
