unicode-slice
v1.0.1
Published
Slice a unicode string by it's visual width
Downloads
13,495
Readme
unicode-slice
Slice a unicode string by it's visual width
Install
npm i unicode-slice --save
Typescript definition file is already included.
EXAMPLES
const slice = require('unicode-slice').default;
// String.prototype.slice
"👶🏽".slice(0, 1);
//=>'�'
// Deal with emoji skin-tone modifer as one character
slice("👶" + "🏽", 0, 1);
//=> 👶🏽
// Won't separate emoji family :)
slice("👩👩👦👦", 0, 1);
//=> 👩👩👦👦
// Ansi color is preserved
slice("12" + chalk.red("34") + "56", 1, 5);
//=> 2\u001b[31m34\u001b[39m5
Using ES2015w Modules:
import slice from 'unicode-slice';
slice('👶🏽', 0, 1);