From 796c4eca0bacf67c186768de66fcfee21867045f Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 12 Jun 2022 14:08:23 +0200 Subject: Prettify number of issues (#17760) * Prettify number of issues - Use the PrettyNumber function to add commas in large amount of issues. * Use client-side formatting * prettify on both server and client * remove unused i18n entries * handle more cases, support other int types in PrettyNumber * specify locale to avoid issues with node default locale * remove superfluos argument * introduce template helper, octicon tweaks, js refactor * Update modules/templates/helper.go * Apply some suggestions. * Add comment * Update templates/user/dashboard/issues.tmpl Co-authored-by: silverwind Co-authored-by: silverwind Co-authored-by: Lunny Xiao --- web_src/js/utils.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'web_src/js/utils.js') diff --git a/web_src/js/utils.js b/web_src/js/utils.js index 67f8f1cc98..f01f2d3b22 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -90,3 +90,10 @@ export function strSubMatch(full, sub) { } return res; } + +// pretty-print a number using locale-specific separators, e.g. 1200 -> 1,200 +export function prettyNumber(num, locale = 'en-US') { + if (typeof num !== 'number') return ''; + const {format} = new Intl.NumberFormat(locale); + return format(num); +} -- cgit v1.2.3