andrew4582

String Number.implement

Jun 6th, 2011
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String.implement({
  2.     pad: function (a, d, b) {
  3.         var c = this;
  4.         d = d || " ";
  5.         b = b || "right";
  6.         a -= c.length;
  7.         if (a < 0) {
  8.             return c
  9.         }
  10.         d = (new Array(Math.ceil(a / d.length) + 1)).join(d).substr(0, a);
  11.         return ((b == "left") ? (d + c) : (c + d))
  12.     }
  13. });
  14. Number.implement({
  15.     toFileSize: function (a) {
  16.         a = a || 1;
  17.         var c = [lang[CONST.SIZE_KB], lang[CONST.SIZE_MB], lang[CONST.SIZE_GB]];
  18.         var b = this;
  19.         var d = 0;
  20.         b /= 1024;
  21.         while ((b >= 1024) && (d < 2)) {
  22.             b /= 1024;
  23.             d++
  24.         }
  25.         return (b.toFixed(a) + " " + c[d])
  26.     },
  27.     toTimeString: function () {
  28.         var f = Number(this);
  29.         if (f > 63072000) {
  30.             return "\u221E"
  31.         }
  32.         var a, i, j, g, e, c, k, b = "";
  33.         i = Math.floor(f / 31536000);
  34.         a = f % 31536000;
  35.         j = Math.floor(a / 604800);
  36.         a = a % 604800;
  37.         g = Math.floor(a / 86400);
  38.         a = a % 86400;
  39.         e = Math.floor(a / 3600);
  40.         a = a % 3600;
  41.         c = Math.floor(a / 60);
  42.         k = a % 60;
  43.         if (i > 0) {
  44.             b = lang[CONST.TIME_YEARS_WEEKS].replace(/%d/, i).replace(/%d/, j)
  45.         } else {
  46.             if (j > 0) {
  47.                 b = lang[CONST.TIME_WEEKS_DAYS].replace(/%d/, j).replace(/%d/, g)
  48.             } else {
  49.                 if (g > 0) {
  50.                     b = lang[CONST.TIME_DAYS_HOURS].replace(/%d/, g).replace(/%d/, e)
  51.                 } else {
  52.                     if (e > 0) {
  53.                         b = lang[CONST.TIME_HOURS_MINS].replace(/%d/, e).replace(/%d/, c)
  54.                     } else {
  55.                         if (c > 0) {
  56.                             b = lang[CONST.TIME_MINS_SECS].replace(/%d/, c).replace(/%d/, k)
  57.                         } else {
  58.                             b = lang[CONST.TIME_SECS].replace(/%d/, k)
  59.                         }
  60.                     }
  61.                 }
  62.             }
  63.         }
  64.         return b
  65.     }
  66. });
Advertisement
Add Comment
Please, Sign In to add comment