@stdlib/string-base-last-grapheme-cluster
v0.1.0
Published
Return the last grapheme cluster (i.e., user-perceived character) of a string.
Downloads
8
Readme
lastGraphemeCluster
Return the last
n
grapheme clusters (i.e., user-perceived characters) of a string.
Installation
npm install @stdlib/string-base-last-grapheme-cluster
Usage
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 '六書'
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.