-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add approximate size to titlebar of responses and redirects
- Loading branch information
1 parent
6f1ce10
commit a21c6d2
Showing
4 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { PropTypes } from 'react'; | ||
|
||
import byteFormatter from 'utils/byteFormatter'; | ||
|
||
function SizeBytes({ size }) { | ||
return ( | ||
<span title={`${size} bytes`}> | ||
{byteFormatter(size)} | ||
</span> | ||
); | ||
} | ||
|
||
SizeBytes.propTypes = { | ||
size: PropTypes.number.isRequired | ||
}; | ||
|
||
export default SizeBytes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const KB = 1024 | ||
const MB = 1024 * KB | ||
const GB = 1024 * MB | ||
|
||
/* | ||
* Formats the provided number in bytes as a string of bytes, | ||
* KB, MB, or GB, with one decimal point and the unit suffix. | ||
*/ | ||
export default function byteFormatter(bytes) { | ||
if (bytes < 100) return `${bytes} bytes` | ||
if (bytes > GB) return (bytes / GB).toFixed(1) + ' GB' | ||
if (bytes > MB) return (bytes / MB).toFixed(1) + ' MB' | ||
return (bytes / KB).toFixed(1) + ' KB' | ||
} |