meteor - easiest way to format long numbers in javascript to the right unit? -
i building web app can show system information on website. shows hardware information (temps, ram, cpu, fan speeds , on) of pc "server" running on. opens web server showing information accessible on network. using meteor, blazejs , systeminformation ( https://github.com/sebhildebrandt/systeminformation ) this. system information shows information gets server long numbers. html:
<template name="main"> {{#if subscriptionsready}} <p>cpu manufacturer: {{get (static) 'data.cpu.manufacturer'}}</p> <p>cpu brand: {{get (static) 'data.cpu.brand'}}</p> <p>cpu model: {{get (static) 'data.cpu.model'}}</p> <p>cpu speed: {{get (static) 'data.cpu.speed'}}</p> <p>cpu cores: {{get (static) 'data.cpu.cores'}}</p> <p>total memory: {{get (dynamic) 'data.mem.total'}}</p> <p>free memory: {{get (dynamic) 'data.mem.free'}}</p> <p>used memory: {{get (dynamic) 'data.mem.used'}}</p> <p>active memory: {{get (dynamic) 'data.mem.active'}}</p> {{/if}} which shows on website
i format the long numbers "total memory x.yz gb" , similar different data. there easy use library out there use this?
also here server javascript file
meteor.startup(() => { si.getstaticdata(meteor.bindenvironment(function(data){ data.update({type: 'static'}, {data: data, type: 'static'}, {upsert: true}) })) setinterval(meteor.bindenvironment(function() { si.getdynamicdata(meteor.bindenvironment(function(data){ data.update({type: 'dynamic'}, {data: data, type: 'dynamic'}, {upsert: true}) })) }), 1000) meteor.publish('data', function(){ return data.find({}) }) }); and client javascript
let subscriptions = [ meteor.subscribe('data') ] template.main.helpers({ get: function(obj, what) { console.log(obj) return _.get(obj, what) }, dynamic: function() { return data.findone({type: 'dynamic'}) }, static: function() { return data.findone({type: 'static'}) }, subscriptionsready: function() { (let sub of subscriptions){ if (!sub.ready()) return false } return true } })
there popular pretty-bytes library (mit license):
convert bytes human readable string: 1337 → 1.34 kb
useful displaying file sizes humans.
usage:
const prettybytes = require('pretty-bytes'); prettybytes(1337); //=> '1.34 kb' prettybytes(100); //=> '100 b' note converts in base 10 (i.e. 1 gb = 1,000,000,000 b storage manufacturers use in general).
as guess referring ram memory, i think reported manufacturers using base 2 conversion (i.e. 1 gib = 1,024 * 1,024 * 1,024 b), might interested instead other popular library: filesize (bsd 3-clause license)
wiki

Comments
Post a Comment