mirror of
https://github.com/coder/coder.git
synced 2026-11-16 03:30:33 +08:00
15 lines
357 B
TypeScript
15 lines
357 B
TypeScript
import type { Nullable } from "./nullable";
|
|
|
|
/** Truncates and ellipsizes text if it's longer than maxLength */
|
|
export const ellipsizeText = (
|
|
text: Nullable<string>,
|
|
maxLength = 80,
|
|
): string | undefined => {
|
|
if (typeof text !== "string") {
|
|
return;
|
|
}
|
|
return text.length <= maxLength
|
|
? text
|
|
: `${text.substr(0, maxLength - 3)}...`;
|
|
};
|