function truncate
truncate(
text: string,
length: number,
suffix?: string
): string

Truncates a string to the given length. If truncation occurs, the suffix is appended and counted toward the total length.

Examples

Example 1

truncate(null, 10); // ""
truncate("Hello World", 5); // "He..."
truncate("Hello World", 20); // "Hello World"
truncate("Hello World", 8, "…"); // "Hello W…"

Parameters

text: string
length: number
optional
suffix: string = ...

Return Type

string

Usage

import { truncate } from ".";