truncateMiddle

Truncate the middle UTF-16 code units of a string to return a string having a specified length.

Usage

var truncateMiddle = require( '@stdlib/string/base/truncate-middle' );

truncateMiddle( str, len, seq )

Truncates the middle UTF-16 code units of a string to return a string having a specified length.

var out = truncateMiddle( 'beep boop', 7, '...' );
// returns 'be...op'

out = truncateMiddle( 'beep boop', 7, '!' );
// returns 'bee!oop'

out = truncateMiddle( 'beep boop', 7, '!!!' );
// returns 'be!!!op'

Examples

var truncateMiddle = require( '@stdlib/string/base/truncate-middle' );

var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
var out = truncateMiddle( str, 15, '...' );
// returns 'Lorem ... elit.'

str = 'To be or not to be, that is the question';
out = truncateMiddle( str, 19, '|' );
// returns 'To be or | question'

str = 'The quick fox jumps over the lazy dog.';
out = truncateMiddle( str, 28, '...' );
// returns 'The quick fox...he lazy dog.'
Did you find this page helpful?