8 lines
210 B
TypeScript
8 lines
210 B
TypeScript
export default function trimText<T extends string | undefined>(text: T, length?: number) {
|
|
if (!text || !length || text.length <= length) {
|
|
return text;
|
|
}
|
|
|
|
return `${text.substring(0, length)}...`;
|
|
}
|