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

@Pipe({
  name: 'linefeedtohtml'
})
export class LinefeedToHtmlPipe implements PipeTransform {
  public transform(str: string): string {
    return str
      .replace(/\r\n/g, '<br />')
      .replace(/\r/g, '<br />')
      .replace(/\n/g, '<br />');
  }
}

@Pipe({
  name: 'htmltolinefeed'
})
export class HtmlToLinefeedPipe implements PipeTransform {
  public transform(str: string): string {
    return str.replace(/(<|<\/)br([\s.'"=a-zA-Z/]*)>/gi, '\n');
  }
}
