VDL Plugin SDK

lastNChars

Import from @varavel/vdl-plugin-sdk/utils/strings.

function lastNChars(
   str, 
   n, 
   ellipsis?
): string;

Returns the last n characters from a string.

When truncation happens, an ellipsis is appended by default so generated labels and previews can communicate that the returned segment is partial.

Non-positive and non-finite lengths return an empty string.

Parameters

ParameterTypeDefault valueDescription
strstringundefinedSource string to shorten.
nnumberundefinedMaximum number of trailing characters to keep.
ellipsis?booleantrueWhen true, appends ... if truncation occurs.

Returns

string

The trailing character slice, optionally suffixed with an ellipsis.

Example

lastNChars("Hello world", 5);
// "world..."