Skip to content

Commit

Permalink
add documentation for truncate function
Browse files Browse the repository at this point in the history
  • Loading branch information
pratyush1712 committed Oct 29, 2023
1 parent 133c8a5 commit 568a2e3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions frontend/src/components/Notification/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ type Message = {
markAsRead: (key: number) => void;
};

const truncate = (str: string) => {
/**
* Truncates a string to a maximum length of 30 characters.
* If the string is longer than 30 characters, it appends '...' to the end.
*
* @param {string} str - The string to be truncated.
* @returns {string} - The truncated string. If the original string is 30 characters or fewer, it returns the original string.
*/
function truncate(str: string) {
if (str.length <= 30) {
return str;
}
return `${str.slice(0, 30)}...`;
};
}

const DisplayMessage = ({
key,
Expand Down

0 comments on commit 568a2e3

Please sign in to comment.