Last active
February 18, 2016 10:38
-
-
Save louisfisch/88f901d1fe995fcc8c42 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function isIntAnyway(x) { | |
if (Number(x) && x % 1 === 0) | |
return true; | |
return false; | |
} | |
// Checks if value is in array | |
function inArray(value, array) { | |
return array.indexOf(value) > -1; | |
} | |
function formatFileSize(size) { | |
var formatedValue, formatedUnit; | |
if (size > 999999999) { | |
formatedValue = (size/1000000000).toFixed(1); | |
formatedUnit = 'GB'; | |
} | |
else if (size > 999999) { | |
formatedValue = (size/1000000).toFixed(1); | |
formatedUnit = 'MB'; | |
} | |
else if (size > 999) { | |
formatedValue = (size/1000).toFixed(0); | |
formatedUnit = 'kB'; | |
} | |
else { | |
formatedValue = size; | |
formatedUnit = 'B'; | |
} | |
return { | |
value: formatedValue, | |
unit: formatedUnit | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment