Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (22 sloc) 813 Bytes
import { Pipe, PipeTransform } from '@angular/core';
import { isString } from '../helpers/helpers';
@Pipe({ name: 'shorten' })
export class ShortenPipe implements PipeTransform {
transform(input: string, length?: number, suffix?: string, wordBreak?: boolean): string;
transform(input: any, length?: number, suffix?: string, wordBreak?: boolean): any;
transform(text: any, length: number = 0, suffix: string = '', wordBreak: boolean = true): string {
if (!isString(text)) {
return text;
}
if (text.length > length) {
if (wordBreak) {
return text.slice(0, length) + suffix;
}
// tslint:disable-next-line:no-bitwise
if (!!~text.indexOf(' ', length)) {
return text.slice(0, text.indexOf(' ', length)) + suffix;
}
}
return text;
}
}
You can’t perform that action at this time.