Truncates a string to a specified length, adding ellipsis if necessary.
@example
// Truncate a string to a maximum length of 10 characters const truncatedString =truncate("Lorem ipsum dolor sit amet",10); console.log(truncatedString);// Output: "Lorem ipsu..."
Truncates a string to a specified length, adding ellipsis if necessary.