blob: e660871e3b315a60e645d2f292afd6ecf9261c31 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
export class TruncateFilter {
constructor() {
let filter = <TruncateFilter>(str:string, length:number) => {
if (str.length <= length) {
return str;
}
//if(str[length - 1] === ' '){
// return str.substring(0, length - 1) + '...';
//}
let char;
let index = length;
while (char !== ' ' && index !== 0) {
index--;
char = str[index];
}
if (index === 0) {
return (index === 0) ? str : str.substring(0, length - 3) + '...';
}
return (index === 0) ? str : str.substring(0, index) + '...';
};
return filter;
}
}
|