0.0.3 • Published 3 years ago

@hotoo/unistring v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

UniString

Fast Unicode String.

benchmark image

USAGE

import unistring from '@hotoo/unistring';

// length:   1  2  2  4  8  11
// unilength:1  1  1  1  1  1
const str = '张 𤰉 😀 👦🏿 👨‍👩‍👧 👨‍👩‍👧‍👦';
const unistr = unistring(str);

str.length; // 33
unistr.length; // 9

str.substr(2, 1); // '�'
unistr.substr(2, 1); // '𤰉'

str.substr(5, 1); // '�'
str.substr(5, 2); // '😀'
unistr.substr(5, 1); // ' '
unistr.substr(5, 2); // ' 👦🏿'

str.split('');
// [ '张', ' ',
//   '�', '�', ' ',
//   '�', '�', ' ',
//   '�', '�', '�', '�', ' ',
//   '�', '�',  '‍',  '�', '�', '‍',  '�', '�', ' ',
//   '�', '�', '‍',  '�', '�', '‍', '�',  '�', '‍',  '�', '�'
// ]

unistr.split('');
// [ '张', ' ',
//   '𤰉', ' ',
//   '😀', ' ',
//   '👦🏿', ' ',
//   '👨‍👩‍👧', ' ',
//   '👨‍👩‍👧‍👦'
// ]

References

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago