Nodejs String Padding Left padLeft(size, prefix)

Here you can find the source of padLeft(size, prefix)

Method Source Code

(function(){//from ww  w  .  j a va2 s .  c  om

String.prototype.padLeft = function(size, prefix) {
    prefix = prefix || " ";
    var s = ''+this;
    while (s.length < size) s = prefix + s;
    return s;
};


Math.randInt = function(min, max){
  return Math.floor(Math.random() * (max - min + 1)) + min;
};

Math.cuid = function(){
    var t = Math.floor((new Date()).getTime()/1000),
        r = (Math.random() * 100000000),
        lb = Math.floor(Math.random() * 15);
    
    r = (r << 4) | lb;
    return t.toString(16) + r.toString(16).padLeft(8, '0');
};

var EXPIRES = 'Sun, 24-Mar-2024 11:11:11 GMT';
window.saveCookie = saveCookie;
function saveCookie(k, v, expires){
    expires = expires || EXPIRES;
    document.cookie = (k+'='+v+'; expires='+expires+';');
    return v;
}

window.cookieKV = fromKV(document.cookie, '; ');

})();

Related

  1. padLeft(n, str)
    String.prototype.padLeft = function(n, str) {
      return Array(n - String(this).length + 1).join(str || '0') + this;
    
  2. padLeft(pad, len)
    String.prototype.padLeft = function (pad, len)
      if (typeof(len) == "undefined") { var len = 0; }
      if (typeof(pad) == "undefined") { var pad = ' '; }
      if (len + 1 >= this.length)
          str = Array(len + 1 - this.length).join(pad) + this;
        return str;
    ...
    
  3. padLeft(padString,length)
    String.prototype.padLeft = function(padString,length){
        var str = this;
        while (str.length < length)
            str = padString + str;
        return str;
    
  4. padLeft(paddingValue)
    String.prototype.padLeft = function (paddingValue) {
      return String(paddingValue + this).slice(-paddingValue.length);
    };
    
  5. padLeft(size, char)
    String.prototype.padLeft = function (size, char) {
        if (size === 0) {
            return '';
        return (Array(size + 1).join(char) + this).slice(-size);
    };
    
  6. padLeft(totalLength, value)
    String.prototype.padLeft = function (totalLength, value) {
      if (this.length >= totalLength)
        return this;
      var str = this;
      while (str.length < totalLength)
        str = value + str;
      return str;
    };
    
  7. padl(ch, len)
    'use strict';
    String.prototype.padl = function(ch, len) {
        var s = this;
        while (s.length < len) {
            s = ch + s;
        return s;
    };
    
  8. padl(ch, len)
    String.prototype.padl = function(ch, len) {
        var s = this;
        while (s.length < len) {
            s = ch + s;
        return s;
    };
    
  9. paddingLeft(paddingValue)
    String.prototype.paddingLeft = function(paddingValue)
      return String(paddingValue + this).slice(-paddingValue.length);
    };