Skip to main content

Function: truncateWords()

truncateWords(this, left, wordCount, end): string

Return the input string truncated to the specified number of words, with the second argument appended. The number of words (first argument) defaults to 15. The second argument defaults to an ellipsis (...).

If the input string already has fewer than the given number of words, it is returned unchanged.

Parameters

this: FilterContext

An object containing a reference to the active render context and any keyword/named arguments.

left: unknown

Any value. Will be coerced to a string if it's not one already.

wordCount: unknown = 15

Any value. If it can't be converted to a number, zero will be used instead. Defaults to 15.

end: unknown = "..."

Any value. Will be coerced to a string if it's not one already. Defaults to ....

Returns

string

The input string truncated to the specified number of words.

Defined in

src/builtin/filters/string.ts:574