From 1d5a32186357b684c0490338f7c6a684f5f24154 Mon Sep 17 00:00:00 2001 From: Miao Cai Date: Fri, 8 Jan 2021 11:46:04 +0800 Subject: [PATCH] fix: fix language name layout (#81) --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 913eda055..656240d98 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,11 @@ async function main() { await updateGist(stats); } +function trimRightStr(str, len) { + // Ellipsis takes 3 positions, so the index of substring is 0 to total length - 3. + return str.length > len ? str.substring(0, len - 3) + "..." : str; +} + async function updateGist(stats) { let gist; try { @@ -31,7 +36,7 @@ async function updateGist(stats) { const { name, percent, text: time } = data; const line = [ - name.padEnd(11), + trimRightStr(name, 11).padEnd(11), time.padEnd(14), generateBarChart(percent, 21), String(percent.toFixed(1)).padStart(5) + "%"