Skip to content
Snippets Groups Projects
Commit 9c8c5970 authored by Vince Oppedisano's avatar Vince Oppedisano Committed by Facebook Github Bot
Browse files

Don't truncate in the middle of an emoji

Reviewed By: adiphos, mantong01

Differential Revision: D7198155

fbshipit-source-id: 360955de7ed686170a23b9883058e3137e17b277
parent 3002c4eb
No related merge requests found
......@@ -30,7 +30,11 @@ const truncate = function(
options = Object.assign({}, defaultOptions, options);
if (str && str.length &&
str.length - options.minDelta + options.elipsis.length >= maxChars) {
str = str.slice(0, maxChars - options.elipsis.length + 1);
// If the slice is happening in the middle of a wide char, add one more char
var extraChar = str.charCodeAt(maxChars - options.elipsis.length) > 255
? 1
: 0;
str = str.slice(0, maxChars - options.elipsis.length + 1 + extraChar);
if (options.breakOnWords) {
var ii = Math.max(str.lastIndexOf(' '), str.lastIndexOf('\n'));
str = str.slice(0, ii);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment