Picsur/frontend/src/app/pipes/truncate.pipe.ts

16 lines
364 B
TypeScript

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'truncate',
})
export class TruncatePipe implements PipeTransform {
transform(text: string, length = 32, suffix = '...'): string {
if (text.length > length) {
const truncated: string = text.substring(0, length).trim() + suffix;
return truncated;
}
return text;
}
}