Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 903 Bytes

truncate.md

File metadata and controls

38 lines (26 loc) · 903 Bytes

strings.truncate

truncate([string], [options={}])

Truncates string if it's longer than the given maximum string length. The last characters of the truncated string are replaced with the omission string which defaults to "...".

Arguments

  1. [string] (string): string to truncate
  2. [options={}] (Object): object containing options
  3. [options.length=30] (number): Max length of truncated string
  4. [options.omission='...'] (string): string to indicate omitted text
  5. [options.separator] (RegExp|string): the pattern to end truncation

Returns

(string): returns truncated string

Example

const result = strings.truncate('This sentence starts with', 'This');
console.log(result);
> true
*