diff --git a/index.js b/index.js index 073a92d..5a1fe86 100644 --- a/index.js +++ b/index.js @@ -39,16 +39,16 @@ export default function cliTruncate(text, columns, options = {}) { return ''; } - if (columns === 1) { - return truncationCharacter; - } - const length = stringWidth(text); if (length <= columns) { return text; } + if (columns === 1) { + return truncationCharacter; + } + // ANSI escape sequence constants const ANSI = { ESC: 27, diff --git a/test.js b/test.js index 8725aec..38352f2 100644 --- a/test.js +++ b/test.js @@ -19,6 +19,7 @@ test('main', t => { t.is(cliTruncate('unicorn', 6, {position: 'start'}), '…icorn'); t.is(cliTruncate('unicorn', 5, {position: 'middle'}), 'un…rn'); t.is(cliTruncate('unicorns', 6, {position: 'middle'}), 'uni…ns'); + t.is(cliTruncate('u', 1), 'u'); }); test('space option', t => {