@stdlib/string-base-slice-grapheme-clusters
v0.1.1
Published
Slice a string based on grapheme cluster (i.e., user-perceived character) indices.
Readme
sliceGraphemeClusters
Slice a string based on grapheme cluster (i.e., user-perceived character) indices.
Installation
npm install @stdlib/string-base-slice-grapheme-clustersUsage
var sliceGraphemeClusters = require( '@stdlib/string-base-slice-grapheme-clusters' );sliceGraphemeClusters( str, start, end )
Slices a string based on grapheme cluster (i.e., user-perceived character) indices.
var out = sliceGraphemeClusters( 'Hello World', 0, 5 );
// returns 'Hello'
out = sliceGraphemeClusters( '👋👋👋', 0, 2 );
// returns '👋👋'
out = sliceGraphemeClusters( '六书/六書', 1, 5 );
// returns '书/六書'
out = sliceGraphemeClusters( '🌷🍕👉🏿', 1, 2 );
// returns '🍕'The function accepts the following arguments:
- str: input string.
- start: the
ithgrapheme cluster to start a slice (inclusive). - end: the
jthgrapheme cluster to end a slice (exclusive).
Examples
var sliceGraphemeClusters = require( '@stdlib/string-base-slice-grapheme-clusters' );
console.log( sliceGraphemeClusters( 'Hello World', 0, 5 ) );
// => 'Hello'
console.log( sliceGraphemeClusters( 'Hello World', -5, -1 ) );
// => 'Worl'
console.log( sliceGraphemeClusters( '👋👋👋', 0, 2 ) );
// => '👋👋'
console.log( sliceGraphemeClusters( '六书/六書', 1, 5 ) );
// => '书/六書'
console.log( sliceGraphemeClusters( '👨👩👧👦👨👩👧👦👨👩👧👦', 0, 2 ) );
// => '👨👩👧👦👨👩👧👦'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.
