OSDN Git Service

merge dashboard into dev
[bytom/bytom-electron.git] / src / utility / math.js
index 56b2c12..eb323e4 100644 (file)
@@ -5,3 +5,20 @@ export const sum = function(items, prop){
     return a + Number(_.get(b,prop))
   }, 0)
 }
+
+export const formatBytes = function(bytes,decimals) {
+  if (bytes == 0) return '0 Bytes'
+  let k = 1024,
+    dm = decimals <= 0 ? 0 : decimals || 2,
+    sizes = ['B', 'KB', 'MB', 'GB', 'TB'],
+    i = Math.floor(Math.log(bytes) / Math.log(k))
+  return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
+}
+
+export  const splitSlice = function (str, len) {
+  let ret = [ ]
+  for (let offset = 0, strLen = str.length; offset < strLen; offset += len) {
+    ret.push(str.slice(offset, len + offset))
+  }
+  return ret
+}