-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b72a958
commit 6bff119
Showing
6 changed files
with
22 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Truncates a string to a specified maximum length and adds an ellipsis if truncated. | ||
* | ||
* @param str - The input string to truncate | ||
* @param maxLength - Maximum length of the output string (default: 160 characters) | ||
* @returns The truncated string with ellipsis if truncated, or the original string if shorter than maxLength | ||
* | ||
* @example | ||
* truncate("This is a long string", 10) // Returns "This is..." | ||
* truncate("Short", 10) // Returns "Short" | ||
*/ | ||
export const truncate = (str: string, maxLength: number = 160) => { | ||
if (str.length <= maxLength) return str; | ||
return str.slice(0, 157) + "..."; | ||
}; |