Skip to content

Bars Specification 0.1.0 — Transform: truncate

Category: string · Since: 0.1.0

Shortens a string to a maximum length, appending an ellipsis.

If length is at least the input length, the input is returned unchanged. Otherwise the result is the first length - ellipsis.length characters followed by ellipsis (default "..."); when length is shorter than the ellipsis, the first length characters of the ellipsis are returned. A negative length is a degenerate-value soft failure.

Input coercion: string

Arguments

Name Type Optional Default
length integer no
ellipsis string yes "..."

Arity: 1–2

Worked examples

{{ phrase | truncate: 11 }}

Ground c...
{{ phrase | truncate: 11 ", and so on" }}

, and so on

Full fixture: transforms/transform-truncate.json