Namespace: Strings:truncate

Strings:truncate

Source:

Methods

truncate(subject, maxLengthopt, nullable, suffixopt, nullable) → {String}

Truncates a given string after a certain number of characters to enforce length restrictions.

Parameters:
Name Type Attributes Default Description
subject String

the string to check and truncate

maxLength Number <optional>
<nullable>
30

the maximum allowed character length for the string

suffix String <optional>
<nullable>
'...'

the trailing string to end a truncated string with

Source:
Throws:

error if suffix length is bigger than defined maxLength

Returns:
the (truncated) subject
Type
String
Example
const truncatedString = truncate(string, 10, '...');