Skip to content
Snippets Groups Projects
Commit 3ba8ee00 authored by Kawtar Laariche's avatar Kawtar Laariche
Browse files

#19: add truncate pipe

parent 9c93750a
No related branches found
No related tags found
No related merge requests found
import { TruncatePipe } from './truncate.pipe';
describe('TruncatePipe', () => {
it('create an instance', () => {
const pipe = new TruncatePipe();
expect(pipe).toBeTruthy();
});
});
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'truncate',
standalone: true,
})
export class TruncatePipe implements PipeTransform {
transform(
value: string,
limit = 25,
completeWords = false,
ellipsis = '...',
) {
if (completeWords) {
limit = value.slice(0, limit).lastIndexOf(' ');
}
return value.length > limit ? value.slice(0, limit) + ellipsis : value;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment