truncateBytes() function
Home > @cbnsndwch/zero-contracts > truncateBytes
truncateBytes() function
Truncates a UTF-8 encoded string to a specified maximum number of bytes. Ensures that the truncation does not cut off a multibyte character.
Signature:
declare function truncateBytes(msg: string, maxBytes?: number): string;Parameters
Parameter
Type
Description
msg
string
The string to be truncated.
maxBytes
number
(Optional) The maximum number of bytes the truncated string should have. Defaults to 123.
Returns:
string
The truncated string if its byte length exceeds the specified limit, otherwise the original string.
Exceptions
Will throw an error if msg is not a string or maxBytes is not a number or is less than 1.
How was this page?