Truncates a string to a specified length.
This function takes a string and a maximum length as input and returns a truncated string. If the string is shorter than the specified length, it returns the original string.
The string to truncate.
The maximum length of the truncated string.
The truncated string.
truncate("Hello, world!", 5); // "Hello..."truncate("Hello, world!", 13); // "Hello, world!"truncate("Hello, world!", 20); // "Hello, world!" Copy
truncate("Hello, world!", 5); // "Hello..."truncate("Hello, world!", 13); // "Hello, world!"truncate("Hello, world!", 20); // "Hello, world!"
Truncates a string to a specified length.
This function takes a string and a maximum length as input and returns a truncated string. If the string is shorter than the specified length, it returns the original string.