Use a better notation for exporting JS components and functions

This commit is contained in:
Deluan
2020-11-10 19:27:28 -05:00
parent 8a44f61189
commit 9d2426a601
37 changed files with 112 additions and 188 deletions
+1 -3
View File
@@ -1,10 +1,8 @@
import config from '../config'
const baseUrl = (path) => {
export const baseUrl = (path) => {
const base = config.baseURL || ''
const parts = [base]
parts.push(path.replace(/^\//, ''))
return parts.join('/')
}
export default baseUrl
+36
View File
@@ -0,0 +1,36 @@
export const formatBytes = (bytes, decimals = 2) => {
if (bytes === 0) return '0 Bytes'
const k = 1024
const dm = decimals < 0 ? 0 : decimals
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
}
export const formatRange = (record, source) => {
const nameCapitalized = source.charAt(0).toUpperCase() + source.slice(1)
const min = record[`min${nameCapitalized}`]
const max = record[`max${nameCapitalized}`]
let range = []
if (min) {
range.push(min)
}
if (max && max !== min) {
range.push(max)
}
return range.join('-')
}
export const formatDuration = (d) => {
const hours = Math.floor(d / 3600)
const minutes = Math.floor(d / 60) % 60
const seconds = d % 60
return [hours, minutes, seconds]
.map((v) => Math.round(v).toString())
.map((v) => (v.length !== 2 ? '0' + v : v))
.filter((v, i) => v !== '00' || i > 0)
.join(':')
}
+3
View File
@@ -0,0 +1,3 @@
export * from './baseUrl'
export * from './docsUrl'
export * from './formatters'