@stdlib/string-base-last-grapheme-cluster
v0.1.1
Published
Return the last grapheme cluster (i.e., user-perceived character) of a string.
Readme
lastGraphemeCluster
Return the last
ngrapheme clusters (i.e., user-perceived characters) of a string.
Installation
npm install @stdlib/string-base-last-grapheme-clusterUsage
var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );lastGraphemeCluster( str, n )
Returns the last n grapheme clusters (i.e., user-perceived characters) of a string.
var out = lastGraphemeCluster( 'Hello World', 1 );
// returns 'd'
out = lastGraphemeCluster( 'Evening', 3 );
// returns 'ing'
out = lastGraphemeCluster( 'foo bar', 10 );
// returns 'foo bar'Examples
var lastGraphemeCluster = require( '@stdlib/string-base-last-grapheme-cluster' );
var str = lastGraphemeCluster( 'Hello World!', 1 );
// returns '!'
str = lastGraphemeCluster( 'JavaScript', 6 );
// returns 'Script'
str = lastGraphemeCluster( 'stdlib', 10 );
// returns 'stdlib'
str = lastGraphemeCluster( '🐶🐮🐷🐰🐸', 2 );
// returns '🐰🐸'
str = lastGraphemeCluster( '六书/六書', 2 );
// returns '六書'See Also
@stdlib/string-base/first-grapheme-cluster: return the first grapheme cluster (i.e., user-perceived character) of a string.@stdlib/string-base/last-code-point: return the last Unicode code point of a string.@stdlib/string-base/last: return the last UTF-16 code unit of a string.
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-2026. The Stdlib Authors.
