@stdlib/string-base-truncate-middle
v0.2.2
Published
Truncate the middle UTF-16 code units of a string to return a string having a specified length.
Downloads
11
Readme
truncateMiddle
Truncate the middle UTF-16 code units of a string to return a string having a specified length.
Installation
npm install @stdlib/string-base-truncate-middle
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.'
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.