all files / app/utils/pipes/ linkify.ts

100% Statements 10/10
50% Branches 1/2
100% Functions 4/4
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24            1× 1×   1×     6×           1× 1× 9×   1×  
/* 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;
    }
}