Skip to content

Instantly share code, notes, and snippets.

@hatemhosny
Created September 25, 2017 16:29
Show Gist options
  • Save hatemhosny/931f0525ee823ad033280379b4468be5 to your computer and use it in GitHub Desktop.
Save hatemhosny/931f0525ee823ad033280379b4468be5 to your computer and use it in GitHub Desktop.
TruncatePipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'truncate'
})
export class TruncatePipe implements PipeTransform {
transform(value: string, limit = 250, trail = '...'): string {
if (value.length > limit) {
return value.substring(0, limit) + trail;
} else {
return value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment