Nodejs String Fill fill(o)

Here you can find the source of fill(o)

Method Source Code

// Ignore how this function works but know how to use it
String.prototype.fill = function (o) {
    return this.replace(/{([^{}]*)}/g,
        function (a, b) {
            var r = o[b];
            return typeof r === 'string' || typeof r === 'number' ? r : a;
        }/*from w  w w .  j  av a  2s  . com*/
    );
};

Related

  1. fill(c, n)
    String.prototype.fill = function(c, n) {
        var l = n - this.length;
        if (l <= 0) l = 1;
        return c.repeat(l).concat(this);
    
  2. fill(char, count)
    String.prototype.fill = function(char, count) {
      var charToPad = "";
      for(var index = 0; index < count; index++ ) {
        charToPad +=  char;
      return this + charToPad;
    };