Skip to content

Instantly share code, notes, and snippets.

@davidpett
Created October 31, 2013 22:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davidpett/7258142 to your computer and use it in GitHub Desktop.
Save davidpett/7258142 to your computer and use it in GitHub Desktop.
filesize handlebars helper
Ember.Handlebars.helper('filesize', function(value) {
if (typeof value === 'undefined') {
return null;
}
var i,
filesize,
units = ['B', 'KB', 'MB', 'GB', 'TB'];
for (i = 0; i < units.length; i++) {
if (value < 1024) {
filesize = Math.floor(value) + units[i];
break;
}
value = value / 1024;
}
return filesize;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment