mod-bot/src/utils/customSubstring.ts
2024-05-12 01:52:39 -07:00

12 lines
432 B
TypeScript

/**
* Determines if a string is longer than the given length, and if so
* substrings it and appends an ellipsis.
*
* @param {string} str The string to shorten.
* @param {number} len The maximum allowed length for the string.
* @returns {string} The potentially shortened string.
*/
export const customSubstring = (str: string, len: number): string => {
return str.length > len ? str.substring(0, len - 3) + "..." : str;
};