1.0.1 β€’ Published 5 years ago

unicode-slice v1.0.1

Weekly downloads
29
License
MIT
Repository
github
Last release
5 years ago

unicode-slice

Build Status Coverage Status npm

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);

Author

Rong Shen

1.0.1

5 years ago

1.0.0

6 years ago

0.1.0

6 years ago