Skip to content

Instantly share code, notes, and snippets.

@zorzysty
Forked from thomseddon/gist:3511330
Last active October 28, 2015 16:22
Show Gist options
  • Save zorzysty/fdf2e64d6ee7dbde8c5e to your computer and use it in GitHub Desktop.
Save zorzysty/fdf2e64d6ee7dbde8c5e to your computer and use it in GitHub Desktop.

Revisions

  1. zorzysty revised this gist Oct 28, 2015. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions bytes.filter.js
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    "use strict";
    (function () {
    angular.module("MODULENAME")
    .filter('bytes', function () {
    return function (bytes, precision) {
    if (bytes === 0 || isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
    if (typeof precision === 'undefined') precision = 1;
    angular.module("backOffice")
    .filter('bytes', function () {
    return function (bytes, precision) {
    if (bytes === 0 || isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
    if (typeof precision === 'undefined') precision = 1;

    var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
    number = Math.floor(Math.log(bytes) / Math.log(1024)),
    val = (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision);
    var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
    number = Math.floor(Math.log(bytes) / Math.log(1024)),
    val = (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision);

    return (val.match(/\.0*$/) ? val.substr(0, val.indexOf('.')) : val) + ' ' + units[number];
    }
    });
    return (val.match(/\.0*$/) ? val.substr(0, val.indexOf('.')) : val) + ' ' + units[number];
    }
    });
    })();
  2. zorzysty revised this gist Oct 28, 2015. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions bytes.filter.js
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    "use strict";
    (function(){
    (function () {
    angular.module("MODULENAME")
    .filter('bytes', function() {
    return function(bytes, precision) {
    if (bytes === 0 || isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
    if (typeof precision === 'undefined') precision = 1;
    .filter('bytes', function () {
    return function (bytes, precision) {
    if (bytes === 0 || isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
    if (typeof precision === 'undefined') precision = 1;

    var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
    number = Math.floor(Math.log(bytes) / Math.log(1024)),
    val = (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision);
    var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
    number = Math.floor(Math.log(bytes) / Math.log(1024)),
    val = (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision);

    return (val.match(/\.0*$/) ? val.substr(0, val.indexOf('.')) : val) + ' ' + units[number];
    }
    });
    return (val.match(/\.0*$/) ? val.substr(0, val.indexOf('.')) : val) + ' ' + units[number];
    }
    });
    })();
  3. zorzysty revised this gist Oct 28, 2015. 2 changed files with 16 additions and 9 deletions.
    16 changes: 16 additions & 0 deletions bytes.filter.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    "use strict";
    (function(){
    angular.module("MODULENAME")
    .filter('bytes', function() {
    return function(bytes, precision) {
    if (bytes === 0 || isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
    if (typeof precision === 'undefined') precision = 1;

    var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
    number = Math.floor(Math.log(bytes) / Math.log(1024)),
    val = (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision);

    return (val.match(/\.0*$/) ? val.substr(0, val.indexOf('.')) : val) + ' ' + units[number];
    }
    });
    })();
    9 changes: 0 additions & 9 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +0,0 @@
    app.filter('bytes', function() {
    return function(bytes, precision) {
    if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
    if (typeof precision === 'undefined') precision = 1;
    var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
    number = Math.floor(Math.log(bytes) / Math.log(1024));
    return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
    }
    });
  4. @thomseddon thomseddon revised this gist Apr 3, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,6 @@ app.filter('bytes', function() {
    if (typeof precision === 'undefined') precision = 1;
    var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
    number = Math.floor(Math.log(bytes) / Math.log(1024));
    return (bytes/Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
    return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
    }
    });
  5. @thomseddon thomseddon created this gist Aug 29, 2012.
    9 changes: 9 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    app.filter('bytes', function() {
    return function(bytes, precision) {
    if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
    if (typeof precision === 'undefined') precision = 1;
    var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
    number = Math.floor(Math.log(bytes) / Math.log(1024));
    return (bytes/Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
    }
    });