We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3002c4e commit 9c8c597Copy full SHA for 9c8c597
Libraries/Utilities/truncate.js
@@ -30,7 +30,11 @@ const truncate = function(
30
options = Object.assign({}, defaultOptions, options);
31
if (str && str.length &&
32
str.length - options.minDelta + options.elipsis.length >= maxChars) {
33
- 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
34
+ var extraChar = str.charCodeAt(maxChars - options.elipsis.length) > 255
35
+ ? 1
36
+ : 0;
37
+ str = str.slice(0, maxChars - options.elipsis.length + 1 + extraChar);
38
if (options.breakOnWords) {
39
var ii = Math.max(str.lastIndexOf(' '), str.lastIndexOf('\n'));
40
str = str.slice(0, ii);
0 commit comments