You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
498 B
21 lines
498 B
import { Pipe, PipeTransform } from '@angular/core';
|
|
|
|
@Pipe({
|
|
name: 'truncate',
|
|
standalone: true,
|
|
})
|
|
export class TruncatePipe implements PipeTransform {
|
|
|
|
transform(value: string, limit: number = 50, completeWords: boolean = false, ellipsis: string = '...'): string {
|
|
if (!value) return '';
|
|
if (value.length <= limit) return value;
|
|
|
|
if (completeWords) {
|
|
limit = value.substring(0, limit).lastIndexOf(' ');
|
|
}
|
|
return `${value.substring(0, limit)}${ellipsis}`;
|
|
}
|
|
|
|
}
|
|
|