limit
Limits a string to a maximum number of original characters. When the string is longer than the provided length, the method returns substring(0, length) plus the appending value. Pass an empty string or null when no suffix should be shown.
Usage
ts
const label = 'Dashboard overview'.limit(9, '...');
// 'Dashboard...'Parameters
| Name | Type | Description |
|---|---|---|
length | number | Maximum number of original characters to keep. |
appending | string | null | Suffix used when the string is truncated. |
Returns
The original string when it fits, otherwise the truncated string plus appending.
Type signature
ts
interface String {
limit(length: number, appending: string | null): string;
}