diff options
author | tv <tv@nomic.retiolum> | 2013-11-07 13:35:32 +0100 |
---|---|---|
committer | tv <tv@nomic.retiolum> | 2013-11-07 13:35:32 +0100 |
commit | 712612634f53cc96be760a547bb13743f9ee77d0 (patch) | |
tree | 3f59402932866af24219f364f0cb840229a01e05 /gold/bitcoinwisdom/ticker.js | |
parent | 03d7962c7346cb5aa09466c763a2010d89eb7d45 (diff) |
bitcoinwisdom ticker: generalize pad_left to pad
Diffstat (limited to 'gold/bitcoinwisdom/ticker.js')
-rw-r--r-- | gold/bitcoinwisdom/ticker.js | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/gold/bitcoinwisdom/ticker.js b/gold/bitcoinwisdom/ticker.js index 95861229..be60ddb8 100644 --- a/gold/bitcoinwisdom/ticker.js +++ b/gold/bitcoinwisdom/ticker.js @@ -45,9 +45,9 @@ function ticker_data_handler (data) { freq = (2000 + 1000000 * diff) | 0; var out = [ - format_date(data.now) + '+' + pad_left(lag, 2, '0'), + format_date(data.now) + '+' + pad(lag, -2, '0'), 'btceltcbtc', - '[' + diff_color(diff) + 'm' + ticker.last + '[m', + '\e[' + diff_color(diff) + 'm' + pad(ticker.last, 2 + 8, '0') + '\e[m', lag, freq, ]; @@ -75,10 +75,18 @@ function format_date (unix) { .replace(/\.000Z$/, 'Z') } -function pad_left (obj, num, char) { +// num < 0: pad left +// num > 0: pad right +function pad (obj, num, char) { var str = obj.toString(); - while (str.length < num) { - str += char; + if (num < 0) { + while (str.length < -num) { + str = char + str; + } + } if (num > 0) { + while (str.length < num) { + str = str + char; + } } return str; } |