14 lines
388 B
TypeScript
Raw Normal View History

2019-11-12 16:39:59 +08:00
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'shortenString' })
export class ShortenStringPipe implements PipeTransform {
transform(str: string, length: number = 12) {
if (!str) { return; }
if (str.length <= length) {
return str;
}
2019-11-12 16:39:59 +08:00
const half = length / 2;
return str.substring(0, half) + '...' + str.substring(str.length - half);
}
}