Skip to content

Instantly share code, notes, and snippets.

@louisfisch
Last active February 18, 2016 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save louisfisch/88f901d1fe995fcc8c42 to your computer and use it in GitHub Desktop.
Save louisfisch/88f901d1fe995fcc8c42 to your computer and use it in GitHub Desktop.
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