truncate

truncate is a utility function that truncates a given string from the left, right or the middle. The removed characters are replaced with a customizable string.

Import

import { truncate } from '@contentful/f36-utils';

Example

Basic usage

import { truncate } from '@contentful/f36-utils';
truncate('long string', { start: 3, end: 2 });
// lon…ng
truncate('long string', { start: 3, replacement: '***' });
// lon***

Help improve this page