lastNWords
Import from @varavel/vdl-plugin-sdk/utils/strings.
Returns the last n normalized words from a string.
Word boundaries are determined by the shared words tokenizer, which makes
this helper suitable for preview text, normalized identifiers, and compact
labels derived from mixed-case or separator-heavy inputs.
When truncation happens, an ellipsis is appended by default. Non-positive and non-finite lengths return an empty string.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
str |
string |
undefined |
Source string to tokenize and shorten. |
n |
number |
undefined |
Maximum number of trailing words to keep. |
ellipsis |
boolean |
true |
When true, appends ... if truncation occurs. |
Returns
string
The trailing normalized words, optionally suffixed with an ellipsis.