API Reference

Returns a string limited to a max length with "..." or custom filler. You can also choose between a leading, trailing, * or middle filler. (trailing by default)

function truncate( str: string, maxLength: number, fill: string = "...", style: "leading" | "trailing" | "middle" = "trailing" ) // Example: truncate("Hello World!", 4) //=> "Hell..." truncate("Hello World!", 4, "/") //=> "Hell/" truncate("Hello World!", 4, "...", "leading") //=> "...rld!" truncate("Hello World!", 4, "...", "middle") //=> "He...d!"