/kbn

Library to scale and format numbers with common units.

Primary LanguageJavaScriptApache License 2.0Apache-2.0

kbn

Library to scale and format numbers with common units. In very early stages of development, probably not generally useful yet.

install

bower install https://github.com/Netuitive/kbn#master

testing

gulp

production build

gulp production

api

kbn.findUnitFormat(unit)

Given a string will attempt to find a unit.

kbn.formatValue(value, unit)

Given a value and unit will scale the value by the unit, round to 4 significant digits, and return a string representation of the value with the scaled units.

Supported Units

Supported unit codes recognized by the formatValue api call.

code unit
general
shortshort
percentpercent (0-100)
percentunitpercent (0.0-1.0)
humidityHumidity (%H)
ppmppm
dBdecibel
data
bitsbits
bytesbytes
kbyteskilobytes
mbytesmegabytes
gbytesgigabytes
ppspackets/sec
bpsbits/sec
Bpsbytes/sec
time
hertzHertz (1/s)
nsnanoseconds (ns)
µsmicroseconds (µs)
msmilliseconds (ms)
sseconds (s)
mminutes (m)
hhours (h)
ddays (d)
throughput
opsops/sec (ops)
rpsreads/sec (rps)
wpswrites/sec (wps)
iopsI/O ops/sec (iops)
memory
fpsfaults/sec (fps)
Ppspages/sec (Pps)
currency
currencyUSDDollars ($)
currencyGBPPounds (£)
currencyEUREuro (€)
currencyJPYYen (¥)
length
lengthmmmillimetre (mm)
lengthmmeter (m)
lengthkmkilometer (km)
lengthmimile (mi)
velocity
velocitymsm/s
velocitykmhkm/h
velocitymphmph
velocityknotknot (kn)
volume
mlitremillilitre
litrelitre
m3cubic metre
energy
wattwatt (W)
kwattkilowatt (kW)
watthwatt-hour (Wh)
kwatthkilowatt-hour (kWh)
joulejoule (J)
evelectron volt (eV)
ampAmpere (A)
voltVolt (V)
temperature
celsiusCelcius (°C)
farenheitFarenheit (°F)
kelvinKelvin (K)
pressure
pressurembarMillibars
pressurehpaHectopascals
pressurehgInches of mercury
pressurepsiPSI

originally imported from Graphana: https://github.com/grafana/grafana/blob/8ee0e5d11f8427b5a68aab69c73c6d4809bdf5bb/public/app/core/utils/kbn.js