diff --git a/server.js b/server.js index be03ced..e427f0c 100644 --- a/server.js +++ b/server.js @@ -67,7 +67,7 @@ function(data, match, end, ask) { badge(badgeData, makeSend(format, ask.res, end)); return; } - badgeData.text[1] = '$' + money + ' /week'; + badgeData.text[1] = '$' + metric(money) + ' /week'; if (money === 0) { badgeData.colorscheme = 'red'; } else if (money < 10) { @@ -105,7 +105,7 @@ function(data, match, end, ask) { badge(badgeData, makeSend(format, ask.res, end)); return; } - badgeData.text[1] = monthly + ' /month'; + badgeData.text[1] = metric(monthly) + ' /month'; if (monthly === 0) { badgeData.colorscheme = 'red'; } else if (monthly < 10) { @@ -155,7 +155,7 @@ function(data, match, end, ask) { badge(badgeData, makeSend(format, ask.res, end)); return; } - badgeData.text[1] = monthly + ' /month'; + badgeData.text[1] = metric(monthly) + ' /month'; if (monthly === 0) { badgeData.colorscheme = 'red'; } else if (monthly < 10) { @@ -356,3 +356,14 @@ function streamFromString(str) { newStream._read = function() { newStream.push(str); newStream.push(null); }; return newStream; } + +// Given a number, string with appropriate unit in the metric system, SI. +function metric(n) { + var limit = 1000; + if (n > limit) { + n = Math.round(n / 1000); + return ''+n + 'k'; + } else { + return ''+n; + } +} diff --git a/web/index.html b/web/index.html index 89d456f..286b7a7 100644 --- a/web/index.html +++ b/web/index.html @@ -62,7 +62,7 @@ I wanted a service for everyone.
I made the GitHub Badge Service.

-Download: .5K +Download: .5kB

Here's how it works.