OSDN Git Service

Add the QrCode component.
[bytom/bytom-electron.git] / src / utility / math.js
1 import _ from 'lodash'
2
3 export const sum = function(items, prop){
4   return items.reduce( function(a, b){
5     return a + Number(_.get(b,prop))
6   }, 0)
7 }
8
9 export const formatBytes = function(bytes,decimals) {
10   if (bytes == 0) return '0 Bytes'
11   let k = 1024,
12     dm = decimals <= 0 ? 0 : decimals || 2,
13     sizes = ['B', 'KB', 'MB', 'GB', 'TB'],
14     i = Math.floor(Math.log(bytes) / Math.log(k))
15   return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
16 }
17
18 export  const splitSlice = function (str, len) {
19   let ret = [ ]
20   for (let offset = 0, strLen = str.length; offset < strLen; offset += len) {
21     ret.push(str.slice(offset, len + offset))
22   }
23   return ret
24 }