A simple useful util to convert bytes value to pretty string with proper unit.
Install with npm:
npm install readable-bytes --saveor with yarn:
yarn add readable-bytesimportreadableBytesfrom'readable-bytes'// base 10readableBytes(1000)// 1 KBreadableBytes(1000*1000)// 1 MBparseBytes(1000*1000)// { value: 1, unit: 'MB' }// base 2readableBytes(1024,2)// 1KiBreadableBytes(1024*1024,2)// 1MiBThe result will only keep two decimal places.
readableBytes(1001)// 1 KBreadableBytes(1060)// 1.06 KBreadableBytes(1069)// 1.07 KB