1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00
Files
browser/libs/angular/src/pipes/ellipsis.pipe.ts
2022-06-03 16:24:40 +02:00

18 lines
503 B
TypeScript

import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "ellipsis",
})
export class EllipsisPipe implements PipeTransform {
transform(value: string, limit = 25, completeWords = false, ellipsis = "...") {
if (value.length <= limit) {
return value;
}
limit -= ellipsis.length;
if (completeWords && value.length > limit && value.indexOf(" ") > 0) {
limit = value.substring(0, limit).lastIndexOf(" ");
}
return value.substring(0, limit) + ellipsis;
}
}