Truncates a string to a specified maximum length and appends a suffix if truncated.
The string to truncate.
Maximum length of the truncated string including suffix.
String to append after truncation (default: '...').
The truncated string with suffix if truncated, otherwise the original string.
// ES Moduleimport { truncate } from '@bnidev/js-utils'// CommonJSconst { truncate } = require('@bnidev/js-utils') Copy
// ES Moduleimport { truncate } from '@bnidev/js-utils'// CommonJSconst { truncate } = require('@bnidev/js-utils')
truncate('Hello World', 8) // → 'Hello...'truncate('Hello', 10) // → 'Hello'truncate('Hello World', 5, '~~') // → 'Hel~~' Copy
truncate('Hello World', 8) // → 'Hello...'truncate('Hello', 10) // → 'Hello'truncate('Hello World', 5, '~~') // → 'Hel~~'
Truncates a string to a specified maximum length and appends a suffix if truncated.