chalk / slice-ansi

Slice a string with ANSI escape codes
MIT License
47 stars 21 forks source link

Support for unicode surrogate pairs #5

Closed sindresorhus closed 7 years ago

sindresorhus commented 8 years ago

https://mathiasbynens.be/notes/javascript-unicode

I've added a failing skipped test: https://github.com/chalk/slice-ansi/commit/fab456095107f514031f7ae73ced26249d6c9691

Same as https://github.com/chalk/wrap-ansi/issues/11.

sindresorhus commented 7 years ago

Fixed by https://github.com/chalk/slice-ansi/commit/cfec68f1f294eae2238b8985c7c81abd5041e919

slammayjammay commented 4 years ago

It seems to think surrogate pair character width is 1. For example this string 🎂🎂🎂🎂 has a width of 8, but slicing from 0 to 4 returns the entire string.

const string = '🎂🎂🎂🎂';
sliceAnsi(string, 0, 4); // => '🎂🎂🎂🎂'
sliceAnsi(string, 0, 2); // => '🎂🎂'

I would have expected this:

const string = '🎂🎂🎂🎂';
sliceAnsi(string, 0, 4); // => '🎂🎂'
sliceAnsi(string, 0, 2); // => '🎂'
sliceAnsi(string, 0, 8); // => '🎂🎂🎂🎂'
slammayjammay commented 4 years ago

Can this be re-opened?