From c5baa8808b79819f7ce684f5cced135982376cc5 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 7 Jan 2023 12:55:57 -0500 Subject: [PATCH] Minor code review --- src/js/utils.js | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/js/utils.js b/src/js/utils.js index 1aefa59c0..be3b1a585 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -28,28 +28,21 @@ import µb from './background.js'; /******************************************************************************/ µb.formatCount = function(count) { - if ( typeof count !== 'number' ) { - return ''; + if ( typeof count !== 'number' ) { return ''; } + const s = `${count}`; + if ( count < 1000 ) { return s; } + if ( count < 10000 ) { + return '>' + s.slice(0,1) + 'k'; } - let s = count.toFixed(0); - if ( count >= 1000 ) { - if ( count < 10000 ) { - s = '>' + s.slice(0,1) + 'k'; - } else if ( count < 100000 ) { - s = s.slice(0,2) + 'k'; - } else if ( count < 1000000 ) { - s = s.slice(0,3) + 'k'; - } else if ( count < 10000000 ) { - s = s.slice(0,1) + 'M'; - } else { - s = s.slice(0,-6) + 'M'; - } + if ( count < 100000 ) { + return s.slice(0,2) + 'k'; } - return s; + if ( count < 1000000 ) { + return s.slice(0,3) + 'k'; + } + return s.slice(0,-6) + 'M'; }; -// https://www.youtube.com/watch?v=DyvzfyqYm_s - /******************************************************************************/ µb.dateNowToSensibleString = function() {