removeLastGraphemeCluster

Remove the last n grapheme clusters (i.e., user-perceived characters) of a string.

Usage

var removeLastGraphemeCluster = require( '@stdlib/string/base/remove-last-grapheme-cluster' );

removeLastGraphemeCluster( str, n )

Removes the last n grapheme clusters (i.e., user-perceived characters) of a string.

var out = removeLastGraphemeCluster( 'last man standing', 1 );
// returns 'last man standin'

out = removeLastGraphemeCluster( 'Hidden Treasures', 1 );
// returns 'Hidden Treasure'

out = removeLastGraphemeCluster( 'foo bar', 5 );
// returns 'fo'

out = removeLastGraphemeCluster( 'foo bar', 10 );
// returns ''

Examples

var removeLastGraphemeCluster = require( '@stdlib/string/base/remove-last-grapheme-cluster' );

var str = removeLastGraphemeCluster( 'presidential election', 1 );
// returns 'presidential electio'

str = removeLastGraphemeCluster( 'JavaScript', 1 );
// returns 'JavaScrip'

str = removeLastGraphemeCluster( 'The Last of the Mohicans', 5 );
// returns 'The Last of the Moh'

str = removeLastGraphemeCluster( '๐Ÿถ๐Ÿฎ๐Ÿท๐Ÿฐ๐Ÿธ', 2 );
// returns '๐Ÿถ๐Ÿฎ๐Ÿท'

str = removeLastGraphemeCluster( '๐Ÿถ๐Ÿฎ๐Ÿท๐Ÿฐ๐Ÿธ', 10 );
// returns ''
Did you find this page helpful?