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

@Pipe({
  name: 'truncateText',
})
export class TruncateTextPipe implements PipeTransform {
  transform(value: string, wordCount: number = 30): string {
    const actualWordCount = value.split(' ').length;
    if (actualWordCount <= wordCount) {
      return value;
    } else {
      const newText = value.split(' ').slice(0, wordCount).join(' ');
      return newText + ' ...';
    }
  }
}
