diff --git a/web/src/common/utils.ts b/web/src/common/utils.ts index 1d26396b1..c016e7fd6 100644 --- a/web/src/common/utils.ts +++ b/web/src/common/utils.ts @@ -29,6 +29,20 @@ export function convertToTitle(text: string): string { }); } +/** + * Truncate a string based on maximum word count + */ +export function truncateWords(string: string, length = 10): string { + string = string || ""; + const array = string.trim().split(" "); + const ellipsis = array.length > length ? "..." : ""; + + return array.slice(0, length).join(" ") + ellipsis; +} + +/** + * Truncate a string based on character count + */ export function truncate(string: string, length = 10): string { return string.length > length ? `${string.substring(0, length)}...` : string; } diff --git a/web/src/user/LibraryApplication.ts b/web/src/user/LibraryApplication.ts index 6d374dbff..6ad3e75ae 100644 --- a/web/src/user/LibraryApplication.ts +++ b/web/src/user/LibraryApplication.ts @@ -1,6 +1,6 @@ import { uiConfig } from "@goauthentik/common/ui/config"; import { me } from "@goauthentik/common/users"; -import { truncate } from "@goauthentik/common/utils"; +import { truncateWords } from "@goauthentik/common/utils"; import { AKElement } from "@goauthentik/elements/Base"; import { t } from "@lingui/macro"; @@ -127,7 +127,7 @@ export class LibraryApplication extends AKElement {