Truncate the string securely, not cutting a word in half. It always returns the last full word.
Install
Install all functions of strman
yarn add strman
or just the safeTruncate function
yarn add strman.safetruncate
Usage
import { safeTruncate } from 'strman'
// OR
import safeTruncate from 'strman.safetruncate'
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
String | Value will be truncated securely. |
||
length |
Number | Max size of the returned string. |
||
append |
String |
<optional> |
'' | Value that will be added to the end of the return string. |
- Source:
Returns:
String truncated safely.
- Type
- String
Example
const title = 'A Javascript string manipulation library.'
safeTruncate(title, 15, '...');
// => 'A Javascript...'