From 693f4f0a6b042937afa2868b17f8276eea941036 Mon Sep 17 00:00:00 2001 From: ItsHarper Date: Wed, 22 Oct 2025 16:05:34 -0500 Subject: [PATCH 1/2] Add failing test that truncates a single-char string --- test.js | 1 + 1 file changed, 1 insertion(+) 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 => { From 7ac307d4ed095cbe7b685c3520e1be438c055b45 Mon Sep 17 00:00:00 2001 From: ItsHarper Date: Wed, 22 Oct 2025 16:09:19 -0500 Subject: [PATCH 2/2] Don't "truncate" a single-character string --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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,